Merge branch 'master' of https://bitbucket.org/4coder/4coder
commit
ff08a6ea24
File diff suppressed because one or more lines are too long
|
@ -49,6 +49,7 @@
|
|||
#define CHANGE_THEME_SIG(n) void n(Application_Links *app, char *name, int32_t len)
|
||||
#define CHANGE_FONT_SIG(n) void n(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files)
|
||||
#define BUFFER_SET_FONT_SIG(n) void n(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len)
|
||||
#define BUFFER_GET_FONT_SIG(n) int32_t n(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max)
|
||||
#define SET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int32_t count)
|
||||
#define GET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int32_t count)
|
||||
#define DIRECTORY_GET_HOT_SIG(n) int32_t n(Application_Links *app, char *out, int32_t capacity)
|
||||
|
@ -115,6 +116,7 @@ typedef PRINT_MESSAGE_SIG(Print_Message_Function);
|
|||
typedef CHANGE_THEME_SIG(Change_Theme_Function);
|
||||
typedef CHANGE_FONT_SIG(Change_Font_Function);
|
||||
typedef BUFFER_SET_FONT_SIG(Buffer_Set_Font_Function);
|
||||
typedef BUFFER_GET_FONT_SIG(Buffer_Get_Font_Function);
|
||||
typedef SET_THEME_COLORS_SIG(Set_Theme_Colors_Function);
|
||||
typedef GET_THEME_COLORS_SIG(Get_Theme_Colors_Function);
|
||||
typedef DIRECTORY_GET_HOT_SIG(Directory_Get_Hot_Function);
|
||||
|
@ -183,6 +185,7 @@ Print_Message_Function *print_message;
|
|||
Change_Theme_Function *change_theme;
|
||||
Change_Font_Function *change_font;
|
||||
Buffer_Set_Font_Function *buffer_set_font;
|
||||
Buffer_Get_Font_Function *buffer_get_font;
|
||||
Set_Theme_Colors_Function *set_theme_colors;
|
||||
Get_Theme_Colors_Function *get_theme_colors;
|
||||
Directory_Get_Hot_Function *directory_get_hot;
|
||||
|
@ -250,6 +253,7 @@ Print_Message_Function *print_message_;
|
|||
Change_Theme_Function *change_theme_;
|
||||
Change_Font_Function *change_font_;
|
||||
Buffer_Set_Font_Function *buffer_set_font_;
|
||||
Buffer_Get_Font_Function *buffer_get_font_;
|
||||
Set_Theme_Colors_Function *set_theme_colors_;
|
||||
Get_Theme_Colors_Function *get_theme_colors_;
|
||||
Directory_Get_Hot_Function *directory_get_hot_;
|
||||
|
@ -325,6 +329,7 @@ app_links->print_message_ = Print_Message;\
|
|||
app_links->change_theme_ = Change_Theme;\
|
||||
app_links->change_font_ = Change_Font;\
|
||||
app_links->buffer_set_font_ = Buffer_Set_Font;\
|
||||
app_links->buffer_get_font_ = Buffer_Get_Font;\
|
||||
app_links->set_theme_colors_ = Set_Theme_Colors;\
|
||||
app_links->get_theme_colors_ = Get_Theme_Colors;\
|
||||
app_links->directory_get_hot_ = Directory_Get_Hot;\
|
||||
|
@ -392,6 +397,7 @@ static inline void print_message(Application_Links *app, char *str, int32_t len)
|
|||
static inline void change_theme(Application_Links *app, char *name, int32_t len){(app->change_theme(app, name, len));}
|
||||
static inline void change_font(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files){(app->change_font(app, name, len, apply_to_all_files));}
|
||||
static inline void buffer_set_font(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len){(app->buffer_set_font(app, buffer, name, len));}
|
||||
static inline int32_t buffer_get_font(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max){return(app->buffer_get_font(app, buffer, name_out, name_max));}
|
||||
static inline void set_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->set_theme_colors(app, colors, count));}
|
||||
static inline void get_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->get_theme_colors(app, colors, count));}
|
||||
static inline int32_t directory_get_hot(Application_Links *app, char *out, int32_t capacity){return(app->directory_get_hot(app, out, capacity));}
|
||||
|
@ -459,6 +465,7 @@ static inline void print_message(Application_Links *app, char *str, int32_t len)
|
|||
static inline void change_theme(Application_Links *app, char *name, int32_t len){(app->change_theme_(app, name, len));}
|
||||
static inline void change_font(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files){(app->change_font_(app, name, len, apply_to_all_files));}
|
||||
static inline void buffer_set_font(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len){(app->buffer_set_font_(app, buffer, name, len));}
|
||||
static inline int32_t buffer_get_font(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max){return(app->buffer_get_font_(app, buffer, name_out, name_max));}
|
||||
static inline void set_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->set_theme_colors_(app, colors, count));}
|
||||
static inline void get_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->get_theme_colors_(app, colors, count));}
|
||||
static inline int32_t directory_get_hot(Application_Links *app, char *out, int32_t capacity){return(app->directory_get_hot_(app, out, capacity));}
|
||||
|
|
|
@ -158,6 +158,22 @@ HOOK_SIG(my_exit){
|
|||
return(1);
|
||||
}
|
||||
|
||||
// NOTE(allen|a4.0.12): This is for testing it may be removed and replaced with a better test for the buffer_get_font when you eventally read this and wonder what it's about.
|
||||
CUSTOM_COMMAND_SIG(write_name_of_font){
|
||||
View_Summary view = get_active_view(app, AccessOpen);
|
||||
Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen);
|
||||
|
||||
char font_name[256];
|
||||
int32_t font_max = 256;
|
||||
int32_t font_len = buffer_get_font(app, &buffer, font_name, font_max);
|
||||
|
||||
if (font_len != 0){
|
||||
write_string(app, &view, &buffer, make_string(font_name, font_len));
|
||||
}
|
||||
|
||||
print_message(app, literal("TRIED WRITING FONT NAME"));
|
||||
}
|
||||
|
||||
CUSTOM_COMMAND_SIG(newline_or_goto_position){
|
||||
View_Summary view = get_active_view(app, AccessProtected);
|
||||
Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected);
|
||||
|
@ -176,7 +192,7 @@ OPEN_FILE_HOOK_SIG(my_file_settings){
|
|||
// NOTE(allen|a4.0.8): The get_parameter_buffer was eliminated
|
||||
// and instead the buffer is passed as an explicit parameter through
|
||||
// the function call. That is where buffer_id comes from here.
|
||||
uint32_t access = AccessProtected|AccessHidden;
|
||||
uint32_t access = AccessAll;
|
||||
Buffer_Summary buffer = get_buffer(app, buffer_id, access);
|
||||
assert(buffer.exists);
|
||||
|
||||
|
@ -412,6 +428,8 @@ default_keys(Bind_Helper *context){
|
|||
bind(context, '\n', MDFR_SHIFT, newline_or_goto_position);
|
||||
bind(context, ' ', MDFR_SHIFT, write_character);
|
||||
|
||||
bind(context, ';', MDFR_ALT, write_name_of_font);
|
||||
|
||||
end_map(context);
|
||||
}
|
||||
|
||||
|
|
|
@ -1965,15 +1965,18 @@ seek_command(alphanumeric_or_camel, left, BoundaryAlphanumeric | BoundaryCamelC
|
|||
// special string writing commands
|
||||
//
|
||||
|
||||
static void
|
||||
write_string(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, String string){
|
||||
buffer_replace_range(app, buffer, view->cursor.pos, view->cursor.pos, string.str, string.size);
|
||||
view_set_cursor(app, view, seek_pos(view->cursor.pos + string.size), 1);
|
||||
}
|
||||
|
||||
static void
|
||||
write_string(Application_Links *app, String string){
|
||||
uint32_t access = AccessOpen;
|
||||
View_Summary view = get_active_view(app, access);
|
||||
Buffer_Summary buffer = get_buffer(app, view.buffer_id, access);
|
||||
buffer_replace_range(app, &buffer,
|
||||
view.cursor.pos, view.cursor.pos,
|
||||
string.str, string.size);
|
||||
view_set_cursor(app, &view, seek_pos(view.cursor.pos + string.size), true);
|
||||
write_string(app, &view, &buffer, string);
|
||||
}
|
||||
|
||||
CUSTOM_COMMAND_SIG(write_increment){
|
||||
|
|
|
@ -16,9 +16,7 @@
|
|||
#define struct_internal struct
|
||||
#endif
|
||||
|
||||
/* DOC(A Cpp_Token_Type classifies a token to make parsing easier. Some types are not
|
||||
actually output by the lexer, but exist because parsers will also make use of token
|
||||
types in their own output.) */
|
||||
/* DOC(A Cpp_Token_Type classifies a token to make parsing easier. Some types are not actually output by the lexer, but exist because parsers will also make use of token types in their own output.) */
|
||||
ENUM(uint32_t, Cpp_Token_Type){
|
||||
|
||||
CPP_TOKEN_JUNK = 0,
|
||||
|
|
2
4ed.cpp
2
4ed.cpp
|
@ -12,6 +12,7 @@
|
|||
// App Structs
|
||||
|
||||
#define DEFAULT_DISPLAY_WIDTH 672
|
||||
#define DEFAULT_MINIMUM_BASE_DISPLAY_WIDTH 550
|
||||
|
||||
typedef enum App_State{
|
||||
APP_STATE_EDIT,
|
||||
|
@ -1655,6 +1656,7 @@ App_Init_Sig(app_init){
|
|||
// NOTE(allen): file setup
|
||||
working_set_init(system, &models->working_set, partition, &vars->models.mem.general);
|
||||
models->working_set.default_display_width = DEFAULT_DISPLAY_WIDTH;
|
||||
models->working_set.default_minimum_base_display_width = DEFAULT_MINIMUM_BASE_DISPLAY_WIDTH;
|
||||
|
||||
// NOTE(allen): clipboard setup
|
||||
models->working_set.clipboard_max_size = ArrayCount(models->working_set.clipboards);
|
||||
|
|
|
@ -2083,6 +2083,26 @@ DOC(This call sets the display font of a particular buffer.)
|
|||
}
|
||||
}
|
||||
|
||||
API_EXPORT int32_t
|
||||
Buffer_Get_Font(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max)
|
||||
{
|
||||
Command_Data *cmd = (Command_Data*)app->cmd_context;
|
||||
System_Functions *system = cmd->system;
|
||||
Models *models = cmd->models;
|
||||
Editing_File *file = imp_get_file(cmd, buffer);
|
||||
|
||||
int32_t result = 0;
|
||||
if (file){
|
||||
Font_Set *set = models->font_set;
|
||||
String name = make_string_cap(name_out, 0, name_max);
|
||||
if (font_set_get_name(set, file->settings.font_id, &name)){
|
||||
result = name.size;
|
||||
}
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
API_EXPORT void
|
||||
Set_Theme_Colors(Application_Links *app, Theme_Color *colors, int32_t count)
|
||||
/*
|
||||
|
|
|
@ -91,6 +91,7 @@ struct Text_Effect{
|
|||
struct Editing_File_Settings{
|
||||
i32 base_map_id;
|
||||
i32 display_width;
|
||||
i32 minimum_base_display_width;
|
||||
b32 dos_write_mode;
|
||||
b32 virtual_white;
|
||||
i16 font_id;
|
||||
|
@ -217,6 +218,7 @@ struct Working_Set{
|
|||
File_Node *sync_check_iter;
|
||||
|
||||
i32 default_display_width;
|
||||
i32 default_minimum_base_display_width;
|
||||
};
|
||||
|
||||
//
|
||||
|
@ -452,6 +454,7 @@ working_set_alloc(Working_Set *working_set){
|
|||
result->unique_buffer_id = ++working_set->unique_file_counter;
|
||||
dll_insert(&working_set->used_sentinel, node);
|
||||
result->settings.display_width = working_set->default_display_width;
|
||||
result->settings.minimum_base_display_width = working_set->default_minimum_base_display_width;
|
||||
++working_set->file_count;
|
||||
}
|
||||
|
||||
|
|
|
@ -281,6 +281,13 @@ view_file_display_width(View *view){
|
|||
return(result);
|
||||
}
|
||||
|
||||
inline f32
|
||||
view_file_minimum_base_width(View *view){
|
||||
Editing_File *file = view->file_data.file;
|
||||
f32 result = (f32)file->settings.display_width;
|
||||
return(result);
|
||||
}
|
||||
|
||||
inline f32
|
||||
view_file_height(View *view){
|
||||
i32_Rect file_rect = view->file_region;
|
||||
|
@ -389,7 +396,6 @@ view_compute_cursor(View *view, Buffer_Seek seek, b32 return_hint){
|
|||
Buffer_Cursor_Seek_Params params;
|
||||
params.buffer = &file->state.buffer;
|
||||
params.seek = seek;
|
||||
params.width = view_file_display_width(view);
|
||||
params.font_height = (f32)font->height;
|
||||
params.adv = font->advance_data;
|
||||
params.wrap_line_index = file->state.wrap_line_index;
|
||||
|
@ -969,14 +975,23 @@ file_allocate_wrap_positions_as_needed(System_Functions *system, General_Memory
|
|||
file_allocate_metadata_as_needed(system, general, &file->state.buffer, (void**)&file->state.wrap_positions, &file->state.wrap_position_max, min_amount, sizeof(f32));
|
||||
}
|
||||
|
||||
struct Code_Wrap_X{
|
||||
f32 base_x;
|
||||
f32 paren_nesting[32];
|
||||
i32 paren_safe_top;
|
||||
i32 paren_top;
|
||||
};
|
||||
globalvar Code_Wrap_X null_wrap_x = {0};
|
||||
|
||||
struct Code_Wrap_State{
|
||||
Cpp_Token_Array token_array;
|
||||
Cpp_Token *token_ptr;
|
||||
Cpp_Token *end_token;
|
||||
|
||||
f32 paren_nesting[32];
|
||||
i32 paren_safe_top;
|
||||
i32 paren_top;
|
||||
Code_Wrap_X wrap_x;
|
||||
|
||||
b32 in_pp_body;
|
||||
Code_Wrap_X plane_wrap_x;
|
||||
|
||||
i32 *line_starts;
|
||||
i32 line_index;
|
||||
|
@ -1021,8 +1036,8 @@ wrap_state_set_i(Code_Wrap_State *state, i32 i){
|
|||
|
||||
internal void
|
||||
wrap_state_set_top(Code_Wrap_State *state, f32 line_shift){
|
||||
if (state->paren_nesting[state->paren_safe_top] > line_shift){
|
||||
state->paren_nesting[state->paren_safe_top] = line_shift;
|
||||
if (state->wrap_x.paren_nesting[state->wrap_x.paren_safe_top] > line_shift){
|
||||
state->wrap_x.paren_nesting[state->wrap_x.paren_safe_top] = line_shift;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1049,9 +1064,24 @@ wrap_state_consume_token(Code_Wrap_State *state, i32 fixed_end_point){
|
|||
state->consume_newline = 0;
|
||||
}
|
||||
|
||||
if (state->in_pp_body){
|
||||
if (!(state->token_ptr->flags & CPP_TFLAG_PP_BODY)){
|
||||
state->in_pp_body = 0;
|
||||
state->wrap_x = state->plane_wrap_x;
|
||||
}
|
||||
}
|
||||
|
||||
if (!state->in_pp_body){
|
||||
if (state->token_ptr->flags & CPP_TFLAG_PP_DIRECTIVE){
|
||||
state->in_pp_body = 1;
|
||||
state->plane_wrap_x = state->wrap_x;
|
||||
state->wrap_x = null_wrap_x;
|
||||
}
|
||||
}
|
||||
|
||||
b32 skipping_whitespace = 0;
|
||||
if (i >= state->next_line_start){
|
||||
state->x = state->paren_nesting[state->paren_safe_top];
|
||||
state->x = state->wrap_x.paren_nesting[state->wrap_x.paren_safe_top];
|
||||
skipping_whitespace = 1;
|
||||
}
|
||||
|
||||
|
@ -1121,42 +1151,42 @@ wrap_state_consume_token(Code_Wrap_State *state, i32 fixed_end_point){
|
|||
switch (state->token_ptr->type){
|
||||
case CPP_TOKEN_BRACE_OPEN:
|
||||
{
|
||||
state->paren_nesting[state->paren_safe_top] += state->tab_indent_amount;
|
||||
state->wrap_x.paren_nesting[state->wrap_x.paren_safe_top] += state->tab_indent_amount;
|
||||
}break;
|
||||
|
||||
case CPP_TOKEN_BRACE_CLOSE:
|
||||
{
|
||||
state->paren_nesting[state->paren_safe_top] -= state->tab_indent_amount;
|
||||
state->wrap_x.paren_nesting[state->wrap_x.paren_safe_top] -= state->tab_indent_amount;
|
||||
}break;
|
||||
|
||||
case CPP_TOKEN_PARENTHESE_OPEN:
|
||||
case CPP_TOKEN_BRACKET_OPEN:
|
||||
{
|
||||
++state->paren_top;
|
||||
++state->wrap_x.paren_top;
|
||||
|
||||
i32 top = state->paren_top;
|
||||
if (top >= ArrayCount(state->paren_nesting)){
|
||||
top = ArrayCount(state->paren_nesting) - 1;
|
||||
i32 top = state->wrap_x.paren_top;
|
||||
if (top >= ArrayCount(state->wrap_x.paren_nesting)){
|
||||
top = ArrayCount(state->wrap_x.paren_nesting) - 1;
|
||||
}
|
||||
state->paren_safe_top = top;
|
||||
state->wrap_x.paren_safe_top = top;
|
||||
|
||||
state->paren_nesting[top] = state->x;
|
||||
state->wrap_x.paren_nesting[top] = state->x;
|
||||
}break;
|
||||
|
||||
case CPP_TOKEN_PARENTHESE_CLOSE:
|
||||
case CPP_TOKEN_BRACKET_CLOSE:
|
||||
{
|
||||
--state->paren_top;
|
||||
--state->wrap_x.paren_top;
|
||||
|
||||
if (state->paren_top < 0){
|
||||
state->paren_top = 0;
|
||||
if (state->wrap_x.paren_top < 0){
|
||||
state->wrap_x.paren_top = 0;
|
||||
}
|
||||
|
||||
i32 top = state->paren_top;
|
||||
if (top >= ArrayCount(state->paren_nesting)){
|
||||
top = ArrayCount(state->paren_nesting) - 1;
|
||||
i32 top = state->wrap_x.paren_top;
|
||||
if (top >= ArrayCount(state->wrap_x.paren_nesting)){
|
||||
top = ArrayCount(state->wrap_x.paren_nesting) - 1;
|
||||
}
|
||||
state->paren_safe_top = top;
|
||||
state->wrap_x.paren_safe_top = top;
|
||||
}break;
|
||||
}
|
||||
|
||||
|
@ -1325,20 +1355,20 @@ stickieness_guess(Cpp_Token_Type type, Cpp_Token_Type other_type, u16 flags, u16
|
|||
|
||||
internal f32
|
||||
get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start, b32 *adjust_top_to_this){
|
||||
f32 current_shift = wrap_state->paren_nesting[wrap_state->paren_safe_top];
|
||||
f32 current_shift = wrap_state->wrap_x.paren_nesting[wrap_state->wrap_x.paren_safe_top];
|
||||
|
||||
Assert(adjust_top_to_this != 0);
|
||||
if (wrap_state->token_ptr > wrap_state->token_array.tokens){
|
||||
Cpp_Token prev_token = *(wrap_state->token_ptr-1);
|
||||
|
||||
if (wrap_state->paren_safe_top != 0 && prev_token.type == CPP_TOKEN_PARENTHESE_OPEN){
|
||||
current_shift = wrap_state->paren_nesting[wrap_state->paren_safe_top-1] + wrap_state->tab_indent_amount;
|
||||
if (wrap_state->wrap_x.paren_safe_top != 0 && prev_token.type == CPP_TOKEN_PARENTHESE_OPEN){
|
||||
current_shift = wrap_state->wrap_x.paren_nesting[wrap_state->wrap_x.paren_safe_top-1] + wrap_state->tab_indent_amount;
|
||||
|
||||
*adjust_top_to_this = 1;
|
||||
}
|
||||
|
||||
f32 statement_continuation_indent = 0.f;
|
||||
if (current_shift != 0.f && wrap_state->paren_safe_top == 0){
|
||||
if (current_shift != 0.f && wrap_state->wrap_x.paren_safe_top == 0){
|
||||
if (!(prev_token.flags & CPP_TFLAG_PP_BODY) && !(prev_token.flags & CPP_TFLAG_PP_DIRECTIVE)){
|
||||
|
||||
switch (prev_token.type){
|
||||
|
@ -1368,7 +1398,7 @@ get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start, b32 *adjust_
|
|||
switch (wrap_state->token_ptr->type){
|
||||
case CPP_TOKEN_BRACE_CLOSE:
|
||||
{
|
||||
if (wrap_state->paren_safe_top == 0){
|
||||
if (wrap_state->wrap_x.paren_safe_top == 0){
|
||||
current_shift -= wrap_state->tab_indent_amount;
|
||||
}
|
||||
}break;
|
||||
|
@ -1394,17 +1424,19 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
|
|||
params.buffer = &file->state.buffer;
|
||||
params.wrap_line_index = file->state.wrap_line_index;
|
||||
params.adv = adv;
|
||||
params.width = (f32)file->settings.display_width;
|
||||
params.virtual_white = file->settings.virtual_white;
|
||||
|
||||
f32 width = (f32)file->settings.display_width;
|
||||
f32 minimum_base_width = (f32)file->settings.minimum_base_display_width;
|
||||
|
||||
i32 size = buffer_size(params.buffer);
|
||||
|
||||
Buffer_Measure_Wrap_State state = {0};
|
||||
Buffer_Layout_Stop stop = {0};
|
||||
|
||||
f32 edge_tolerance = 50.f;
|
||||
if (edge_tolerance > params.width){
|
||||
edge_tolerance = params.width;
|
||||
if (edge_tolerance > width){
|
||||
edge_tolerance = width;
|
||||
}
|
||||
|
||||
f32 line_shift = 0.f;
|
||||
|
@ -1425,7 +1457,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
|
|||
wrap_state_init(&wrap_state, file, adv);
|
||||
use_tokens = 1;
|
||||
|
||||
potential_marks = push_array(part, Potential_Wrap_Indent_Pair, FLOOR32(params.width));
|
||||
potential_marks = push_array(part, Potential_Wrap_Indent_Pair, FLOOR32(width));
|
||||
|
||||
max_wrap_indent_mark = partition_remaining(part)/sizeof(Wrap_Indent_Pair);
|
||||
wrap_indent_marks = push_array(part, Wrap_Indent_Pair, max_wrap_indent_mark);
|
||||
|
@ -1477,7 +1509,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
|
|||
f32 adv = params.adv[ch];
|
||||
x += adv;
|
||||
self_x += adv;
|
||||
if (self_x > params.width){
|
||||
if (self_x > width){
|
||||
goto doublebreak;
|
||||
}
|
||||
}
|
||||
|
@ -1497,7 +1529,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
|
|||
|
||||
doublebreak:;
|
||||
wrap_unit_end = i;
|
||||
if (x > params.width){
|
||||
if (x > width){
|
||||
do_wrap = 1;
|
||||
file_allocate_wrap_positions_as_needed(system, general, file, wrap_position_index);
|
||||
file->state.wrap_positions[wrap_position_index++] = stop.pos;
|
||||
|
@ -1511,10 +1543,18 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
|
|||
case BLStatus_NeedWrapLineShift:
|
||||
case BLStatus_NeedLineShift:
|
||||
{
|
||||
f32 current_width = width;
|
||||
|
||||
if (use_tokens){
|
||||
Code_Wrap_State original_wrap_state = wrap_state;
|
||||
i32 next_line_start = params.buffer->line_starts[stop.line_index+1];
|
||||
|
||||
f32 base_adjusted_width = wrap_state.wrap_x.base_x + minimum_base_width;
|
||||
|
||||
if (minimum_base_width != 0 && current_width < base_adjusted_width){
|
||||
current_width = base_adjusted_width;
|
||||
}
|
||||
|
||||
if (stop.status == BLStatus_NeedLineShift){
|
||||
real_count = 0;
|
||||
potential_count = 0;
|
||||
|
@ -1531,8 +1571,9 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
|
|||
wrap_indent_marks[real_count].line_shift = clamp_bottom(0.f, current_shift);
|
||||
++real_count;
|
||||
|
||||
wrap_state.wrap_x.base_x = wrap_state.wrap_x.paren_nesting[0];
|
||||
|
||||
for (; wrap_state.token_ptr < wrap_state.end_token; ){
|
||||
|
||||
Code_Wrap_Step step = {0};
|
||||
b32 emit_comment_position = 0;
|
||||
b32 first_word = 1;
|
||||
|
@ -1578,7 +1619,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
|
|||
|
||||
f32 adv = params.adv[ch];
|
||||
x += adv;
|
||||
if (!first_word && x > params.width){
|
||||
if (!first_word && x > current_width){
|
||||
emit_comment_position = 1;
|
||||
goto doublebreak_stage1;
|
||||
}
|
||||
|
@ -1626,7 +1667,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
|
|||
}
|
||||
|
||||
b32 need_to_choose_a_wrap = 0;
|
||||
if (step.final_x > params.width){
|
||||
if (step.final_x > current_width){
|
||||
need_to_choose_a_wrap = 1;
|
||||
}
|
||||
|
||||
|
@ -1678,7 +1719,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
|
|||
}
|
||||
|
||||
wrappable_score = 64*50;
|
||||
wrappable_score += 101 - general_stickieness - wrap_state.paren_safe_top*80;
|
||||
wrappable_score += 101 - general_stickieness - wrap_state.wrap_x.paren_safe_top*80;
|
||||
|
||||
potential_marks[potential_count].wrap_position = wrap_position;
|
||||
potential_marks[potential_count].line_shift = current_shift;
|
||||
|
@ -1778,14 +1819,13 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
|
|||
if (line_shift < 0){
|
||||
line_shift = 0;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
line_shift = 0.f;
|
||||
}
|
||||
|
||||
if (line_shift > params.width - edge_tolerance){
|
||||
line_shift = params.width - edge_tolerance;
|
||||
if (line_shift > current_width - edge_tolerance){
|
||||
line_shift = current_width - edge_tolerance;
|
||||
}
|
||||
|
||||
if (stop.wrap_line_index >= file->state.line_indent_max){
|
||||
|
@ -1794,8 +1834,6 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
|
|||
|
||||
file->state.line_indents[stop.wrap_line_index] = line_shift;
|
||||
file->state.wrap_line_count = stop.wrap_line_index;
|
||||
|
||||
//wrap_state_set_x(&wrap_state, line_shift);
|
||||
}break;
|
||||
}
|
||||
}while(stop.status != BLStatus_Finished);
|
||||
|
@ -4403,8 +4441,7 @@ append_label(String *string, i32 indent_level, char *message){
|
|||
}
|
||||
|
||||
internal void
|
||||
show_gui_line(GUI_Target *target, String *string,
|
||||
i32 indent_level, i32 h_align, char *message, char *follow_up){
|
||||
show_gui_line(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message, char *follow_up){
|
||||
string->size = 0;
|
||||
append_label(string, indent_level, message);
|
||||
if (follow_up){
|
||||
|
@ -4704,7 +4741,6 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
|
|||
Assert(view->file_data.file);
|
||||
|
||||
Font_Set *font_set = models->font_set;
|
||||
Font_Info *info = 0;
|
||||
|
||||
i16 i = 1, count = (i16)models->font_set->count + 1;
|
||||
|
||||
|
@ -4723,7 +4759,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
|
|||
i16 new_font_id = font_id;
|
||||
|
||||
for (i = 1; i < count; ++i){
|
||||
info = get_font_info(font_set, i);
|
||||
Font_Info *info = get_font_info(font_set, i);
|
||||
id.id[0] = (u64)i;
|
||||
if (i != font_id){
|
||||
if (gui_do_font_button(target, id, i, info->name)){
|
||||
|
|
|
@ -204,18 +204,20 @@ font_set_add(Partition *partition, Font_Set *set,
|
|||
|
||||
internal b32
|
||||
font_set_find_pos(Font_Set *set, String name, u32 *position){
|
||||
b32 result;
|
||||
u32 hash, i, j;
|
||||
hash = font_hash(name);
|
||||
i = hash % set->max;
|
||||
j = i - 1;
|
||||
if (j <= 1) j += set->max;
|
||||
u32 hash = font_hash(name);
|
||||
u32 i = hash % set->max;
|
||||
u32 j = i - 1;
|
||||
if (j <= 1){
|
||||
j += set->max;
|
||||
}
|
||||
|
||||
result = 0;
|
||||
Font_Table_Entry *entry;
|
||||
b32 result = 0;
|
||||
for (; i != j; ++i){
|
||||
if (i == set->max) i = 0;
|
||||
entry = set->entries + i;
|
||||
if (i == set->max){
|
||||
i = 0;
|
||||
}
|
||||
|
||||
Font_Table_Entry *entry = set->entries + i;
|
||||
if (entry->hash == hash){
|
||||
if (match_ss(name, entry->name)){
|
||||
result = 1;
|
||||
|
@ -228,16 +230,20 @@ font_set_find_pos(Font_Set *set, String name, u32 *position){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal b32
|
||||
font_set_get_name(Font_Set *set, i16 font_id, String *name){
|
||||
Font_Info *info = get_font_info(set, font_id);
|
||||
b32 result = copy_checked_ss(name, info->name);
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal b32
|
||||
font_set_extract(Font_Set *set, String name, i16 *font_id){
|
||||
b32 result;
|
||||
u32 position;
|
||||
|
||||
result = font_set_find_pos(set, name, &position);
|
||||
b32 result = font_set_find_pos(set, name, &position);
|
||||
if (result){
|
||||
*font_id = set->entries[position].font_id;
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
|
10
4ed_mem.h
10
4ed_mem.h
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "4coder_mem.h"
|
||||
|
||||
#define MEMORY_DEBUG
|
||||
//#define MEMORY_DEBUG
|
||||
|
||||
static void
|
||||
general_memory_open(System_Functions *system, General_Memory *general, void *memory, int32_t size){
|
||||
|
@ -57,7 +57,7 @@ general_memory_allocate(System_Functions *system, General_Memory *general, int32
|
|||
return(result);
|
||||
}
|
||||
#else
|
||||
return general_memory_allocate(general, memory, size);
|
||||
return general_memory_allocate(general, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ general_memory_free(System_Functions *system, General_Memory *general, void *mem
|
|||
system->memory_free(0, memory, 0);
|
||||
}
|
||||
#else
|
||||
return general_memory_free(general, memory, size);
|
||||
return general_memory_free(general, memory);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ general_memory_reallocate(System_Functions *system, General_Memory *general, voi
|
|||
return(result);
|
||||
}
|
||||
#else
|
||||
return general_memory_reallocate(general, memory, size);
|
||||
return general_memory_reallocate(general, old, old_size, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ general_memory_reallocate_nocopy(System_Functions *system, General_Memory *gener
|
|||
return general_memory_allocate(system, general, size);
|
||||
}
|
||||
#else
|
||||
return general_memory_reallocate_nocopy(general, memory, size);
|
||||
return general_memory_reallocate_nocopy(general, old, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -102,17 +102,9 @@ typedef Draw_Pop_Clip_Sig(Draw_Pop_Clip);
|
|||
#define Draw_Push_Piece_Sig(name) void name(Render_Target *target, Render_Piece_Combined piece)
|
||||
typedef Draw_Push_Piece_Sig(Draw_Push_Piece);
|
||||
|
||||
#define Font_Load_Sig(name) i32 name( \
|
||||
Render_Font *font_out, \
|
||||
char *filename, \
|
||||
char *fontname, \
|
||||
i32 pt_size, \
|
||||
i32 tab_width, \
|
||||
b32 store_texture)
|
||||
#define Font_Load_Sig(name) i32 name(Render_Font *font_out, char *filename, char *fontname, i32 pt_size, i32 tab_width, b32 store_texture)
|
||||
typedef Font_Load_Sig(Font_Load);
|
||||
|
||||
|
||||
|
||||
#define Release_Font_Sig(name) void name(Render_Font *font)
|
||||
typedef Release_Font_Sig(Release_Font);
|
||||
|
||||
|
@ -140,15 +132,15 @@ struct Font_Set{
|
|||
Font_Info *info;
|
||||
Font_Table_Entry *entries;
|
||||
u32 count, max;
|
||||
|
||||
|
||||
void *font_block;
|
||||
Font_Slot free_slots;
|
||||
Font_Slot used_slots;
|
||||
|
||||
|
||||
//Font_Info_Load *font_info_load;
|
||||
Font_Load *font_load;
|
||||
Release_Font *release_font;
|
||||
|
||||
|
||||
b8 *font_used_flags;
|
||||
i16 used_this_frame;
|
||||
i16 live_max;
|
||||
|
@ -159,7 +151,7 @@ struct Render_Target{
|
|||
void *context;
|
||||
i32_Rect clip_boxes[5];
|
||||
i32 clip_top;
|
||||
i32 width, height;
|
||||
i32 width, height;
|
||||
i32 bound_texture;
|
||||
u32 color;
|
||||
|
||||
|
|
7
TODO.txt
7
TODO.txt
|
@ -176,9 +176,10 @@
|
|||
; [X] smarter wrap rule
|
||||
; [X] handle unclosed statements
|
||||
; [X] wrapped line indication
|
||||
; [] special indent rules in preprocessor body
|
||||
; [] handle comments
|
||||
; [] additional width for nesting?
|
||||
; [X] additional width for nesting?
|
||||
; [X] special indent rules in preprocessor body
|
||||
; [X] handle comments
|
||||
; [] solve the comment lead whitespace problem
|
||||
; [] fix issues when relexing happens in parallel
|
||||
; [] remeasure version of measure_wraps
|
||||
|
||||
|
|
|
@ -203,7 +203,6 @@ struct Buffer_Measure_Wrap_Params{
|
|||
Buffer_Type *buffer;
|
||||
i32 *wrap_line_index;
|
||||
f32 *adv;
|
||||
f32 width;
|
||||
b32 virtual_white;
|
||||
};
|
||||
|
||||
|
@ -235,8 +234,7 @@ struct Buffer_Measure_Wrap_State{
|
|||
#define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); }
|
||||
|
||||
internal_4tech Buffer_Layout_Stop
|
||||
buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Params params,
|
||||
f32 line_shift, b32 do_wrap, i32 wrap_unit_end){
|
||||
buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Params params, f32 line_shift, b32 do_wrap, i32 wrap_unit_end){
|
||||
Buffer_Measure_Wrap_State S = *S_ptr;
|
||||
Buffer_Layout_Stop S_stop;
|
||||
|
||||
|
@ -710,7 +708,6 @@ buffer_partial_from_line_character(Buffer_Type *buffer, i32 line, i32 character)
|
|||
struct Buffer_Cursor_Seek_Params{
|
||||
Buffer_Type *buffer;
|
||||
Buffer_Seek seek;
|
||||
f32 width;
|
||||
f32 font_height;
|
||||
f32 *adv;
|
||||
i32 *wrap_line_index;
|
||||
|
@ -745,8 +742,7 @@ struct Buffer_Cursor_Seek_State{
|
|||
#define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); }
|
||||
|
||||
internal_4tech Buffer_Layout_Stop
|
||||
buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params params,
|
||||
f32 line_shift, b32 do_wrap, i32 wrap_unit_end){
|
||||
buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params params, f32 line_shift, b32 do_wrap, i32 wrap_unit_end){
|
||||
Buffer_Cursor_Seek_State S = *S_ptr;
|
||||
Buffer_Layout_Stop S_stop;
|
||||
|
||||
|
@ -761,68 +757,68 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
|
|||
S.size = buffer_size(params.buffer);
|
||||
|
||||
// Get cursor hint
|
||||
i32 line_index = 0;
|
||||
switch (params.seek.type){
|
||||
case buffer_seek_pos:
|
||||
{
|
||||
if (params.seek.pos > S.size){
|
||||
params.seek.pos = S.size;
|
||||
}
|
||||
if (params.seek.pos < 0){
|
||||
params.seek.pos = 0;
|
||||
}
|
||||
|
||||
line_index = buffer_get_line_index(params.buffer, params.seek.pos);
|
||||
}break;
|
||||
|
||||
case buffer_seek_character_pos:
|
||||
{
|
||||
i32 line_count = params.buffer->line_count;
|
||||
i32 max_character = params.character_starts[line_count] - 1;
|
||||
if (params.seek.pos > max_character){
|
||||
params.seek.pos = max_character;
|
||||
}
|
||||
if (params.seek.pos < 0){
|
||||
params.seek.pos = 0;
|
||||
}
|
||||
|
||||
line_index = buffer_get_line_index_from_character_pos(params.character_starts, params.seek.pos,
|
||||
0, params.buffer->line_count);
|
||||
}break;
|
||||
|
||||
case buffer_seek_line_char:
|
||||
{
|
||||
line_index = params.seek.line - 1;
|
||||
if (line_index >= params.buffer->line_count){
|
||||
line_index = params.buffer->line_count - 1;
|
||||
}
|
||||
if (line_index < 0){
|
||||
line_index = 0;
|
||||
}
|
||||
}break;
|
||||
|
||||
case buffer_seek_unwrapped_xy:
|
||||
{
|
||||
line_index = (i32)(params.seek.y / params.font_height);
|
||||
if (line_index >= params.buffer->line_count){
|
||||
line_index = params.buffer->line_count - 1;
|
||||
}
|
||||
if (line_index < 0){
|
||||
line_index = 0;
|
||||
}
|
||||
}break;
|
||||
|
||||
case buffer_seek_wrapped_xy:
|
||||
{
|
||||
line_index = buffer_get_line_index_from_wrapped_y(params.wrap_line_index, params.seek.y, params.font_height,
|
||||
0, params.buffer->line_count);
|
||||
}break;
|
||||
|
||||
default: InvalidCodePath;
|
||||
}
|
||||
|
||||
// Build the cursor hint
|
||||
{
|
||||
i32 line_index = 0;
|
||||
switch (params.seek.type){
|
||||
case buffer_seek_pos:
|
||||
{
|
||||
if (params.seek.pos > S.size){
|
||||
params.seek.pos = S.size;
|
||||
}
|
||||
if (params.seek.pos < 0){
|
||||
params.seek.pos = 0;
|
||||
}
|
||||
|
||||
line_index = buffer_get_line_index(params.buffer, params.seek.pos);
|
||||
}break;
|
||||
|
||||
case buffer_seek_character_pos:
|
||||
{
|
||||
i32 line_count = params.buffer->line_count;
|
||||
i32 max_character = params.character_starts[line_count] - 1;
|
||||
if (params.seek.pos > max_character){
|
||||
params.seek.pos = max_character;
|
||||
}
|
||||
if (params.seek.pos < 0){
|
||||
params.seek.pos = 0;
|
||||
}
|
||||
|
||||
line_index = buffer_get_line_index_from_character_pos(params.character_starts, params.seek.pos,
|
||||
0, params.buffer->line_count);
|
||||
}break;
|
||||
|
||||
case buffer_seek_line_char:
|
||||
{
|
||||
line_index = params.seek.line - 1;
|
||||
if (line_index >= params.buffer->line_count){
|
||||
line_index = params.buffer->line_count - 1;
|
||||
}
|
||||
if (line_index < 0){
|
||||
line_index = 0;
|
||||
}
|
||||
}break;
|
||||
|
||||
case buffer_seek_unwrapped_xy:
|
||||
{
|
||||
line_index = (i32)(params.seek.y / params.font_height);
|
||||
if (line_index >= params.buffer->line_count){
|
||||
line_index = params.buffer->line_count - 1;
|
||||
}
|
||||
if (line_index < 0){
|
||||
line_index = 0;
|
||||
}
|
||||
}break;
|
||||
|
||||
case buffer_seek_wrapped_xy:
|
||||
{
|
||||
line_index = buffer_get_line_index_from_wrapped_y(params.wrap_line_index, params.seek.y, params.font_height,
|
||||
0, params.buffer->line_count);
|
||||
}break;
|
||||
|
||||
default: InvalidCodePath;
|
||||
}
|
||||
|
||||
// Build the cursor hint
|
||||
S.next_cursor.pos = params.buffer->line_starts[line_index];
|
||||
S.next_cursor.character_pos = params.character_starts[line_index];
|
||||
S.next_cursor.line = line_index + 1;
|
||||
|
|
Loading…
Reference in New Issue