Transfer the last of the config variables to new system; rip out Config_Data type and simplify config loading code paths

master
Allen Webster 2020-11-27 10:03:23 -08:00
parent 2151ff8b28
commit 0c046972d6
7 changed files with 15 additions and 72 deletions

View File

@ -1363,76 +1363,29 @@ change_mode(Application_Links *app, String_Const_u8 mode){
//////////////////////////////// ////////////////////////////////
function void // TODO(allen): cleanup this mess some more
config_init_default(Config_Data *config){
config->cursor_roundness = .45f;
config->mark_thickness = 2.f;
config->lister_roundness = .20f;
}
function Config* function Config*
config_parse__data(Application_Links *app, Arena *arena, String_Const_u8 file_name, config_parse__file_handle(Application_Links *app, Arena *arena, String_Const_u8 file_name, FILE *file){
String_Const_u8 data, Config_Data *config){
config_init_default(config);
b32 success = false;
Config *parsed = def_config_from_text(app, arena, file_name, data);
if (parsed != 0){
success = true;
{
i32 x = 0;
if (config_int_var(parsed, "cursor_roundness", 0, &x)){
config->cursor_roundness = ((f32)x)*0.01f;
}
if (config_int_var(parsed, "mark_thickness", 0, &x)){
config->mark_thickness = (f32)x;
}
if (config_int_var(parsed, "lister_roundness", 0, &x)){
config->lister_roundness = ((f32)x)*0.01f;
}
}
}
if (!success){
config_init_default(config);
}
return(parsed);
}
function Config*
config_parse__file_handle(Application_Links *app, Arena *arena,
String_Const_u8 file_name, FILE *file, Config_Data *config){
Config *parsed = 0; Config *parsed = 0;
Data data = dump_file_handle(arena, file); Data data = dump_file_handle(arena, file);
if (data.data != 0){ if (data.data != 0){
parsed = config_parse__data(app, arena, file_name, SCu8(data), config); parsed = def_config_from_text(app, arena, file_name, SCu8(data));
}
else{
config_init_default(config);
} }
return(parsed); return(parsed);
} }
function Config* function Config*
config_parse__file_name(Application_Links *app, Arena *arena, char *file_name, Config_Data *config){ config_parse__file_name(Application_Links *app, Arena *arena, char *file_name){
Config *parsed = 0; Config *parsed = 0;
b32 success = false;
FILE *file = open_file_try_current_path_then_binary_path(app, file_name); FILE *file = open_file_try_current_path_then_binary_path(app, file_name);
if (file != 0){ if (file != 0){
Data data = dump_file_handle(arena, file); Data data = dump_file_handle(arena, file);
fclose(file); fclose(file);
if (data.data != 0){ if (data.data != 0){
parsed = config_parse__data(app, arena, SCu8(file_name), SCu8(data), parsed = def_config_from_text(app, arena, SCu8(file_name), SCu8(data));
config);
success = true;
} }
} }
if (!success){
config_init_default(config);
}
return(parsed); return(parsed);
} }
@ -1525,12 +1478,11 @@ theme_parse__file_name(Application_Links *app, Arena *arena, char *file_name, Ar
// TODO(allen): review this function // TODO(allen): review this function
function void function void
load_config_and_apply(Application_Links *app, Arena *out_arena, Config_Data *config, load_config_and_apply(Application_Links *app, Arena *out_arena, i32 override_font_size, b32 override_hinting){
i32 override_font_size, b32 override_hinting){
Scratch_Block scratch(app, out_arena); Scratch_Block scratch(app, out_arena);
linalloc_clear(out_arena); linalloc_clear(out_arena);
Config *parsed = config_parse__file_name(app, out_arena, "config.4coder", config); Config *parsed = config_parse__file_name(app, out_arena, "config.4coder");
if (parsed != 0){ if (parsed != 0){
// Errors // Errors

View File

@ -174,15 +174,6 @@ struct Config_Get_Result_List{
i32 count; i32 count;
}; };
////////////////////////////////
// NOTE(allen): Config Data Type
struct Config_Data{
f32 cursor_roundness;
f32 mark_thickness;
f32 lister_roundness;
};
//////////////////////////////// ////////////////////////////////
// NOTE(allen): Config Parser Functions // NOTE(allen): Config Parser Functions

View File

@ -597,8 +597,7 @@ setup_essential_mapping(Mapping *mapping, i64 global_id, i64 file_id, i64 code_i
} }
function void function void
default_4coder_initialize(Application_Links *app, String_Const_u8_Array file_names, default_4coder_initialize(Application_Links *app, String_Const_u8_Array file_names, i32 override_font_size, b32 override_hinting){
i32 override_font_size, b32 override_hinting){
#define M \ #define M \
"Welcome to " VERSION "\n" \ "Welcome to " VERSION "\n" \
"If you're new to 4coder there is a built in tutorial\n" \ "If you're new to 4coder there is a built in tutorial\n" \
@ -616,7 +615,7 @@ default_4coder_initialize(Application_Links *app, String_Const_u8_Array file_nam
Scratch_Block scratch(app); Scratch_Block scratch(app);
load_config_and_apply(app, &global_config_arena, &global_config, override_font_size, override_hinting); load_config_and_apply(app, &global_config_arena, override_font_size, override_hinting);
String_Const_u8 bindings_file_name = string_u8_litexpr("bindings.4coder"); String_Const_u8 bindings_file_name = string_u8_litexpr("bindings.4coder");
String_Const_u8 mapping = def_get_config_string(scratch, vars_save_string_lit("mapping")); String_Const_u8 mapping = def_get_config_string(scratch, vars_save_string_lit("mapping"));

View File

@ -83,7 +83,6 @@ global ID_Pos_Jump_Location prev_location = {};
global Arena global_permanent_arena = {}; global Arena global_permanent_arena = {};
global Arena global_config_arena = {}; global Arena global_config_arena = {};
global Config_Data global_config = {};
global char previous_isearch_query[256] = {}; global char previous_isearch_query[256] = {};

View File

@ -287,8 +287,9 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id,
// NOTE(allen): Cursor shape // NOTE(allen): Cursor shape
Face_Metrics metrics = get_face_metrics(app, face_id); Face_Metrics metrics = get_face_metrics(app, face_id);
f32 cursor_roundness = metrics.normal_advance*global_config.cursor_roundness; u64 cursor_roundness_100 = def_get_config_u64(app, vars_save_string_lit("cursor_roundness"));
f32 mark_thickness = (f32)global_config.mark_thickness; f32 cursor_roundness = metrics.normal_advance*cursor_roundness_100*0.01f;
f32 mark_thickness = (f32)def_get_config_u64(app, vars_save_string_lit("mark_thickness"));
// NOTE(allen): Token colorizing // NOTE(allen): Token colorizing
Token_Array token_array = get_token_array_from_buffer(app, buffer); Token_Array token_array = get_token_array_from_buffer(app, buffer);

View File

@ -321,7 +321,8 @@ lister_render(Application_Links *app, Frame_Info frame_info, View_ID view){
highlight = UIHighlight_Hover; highlight = UIHighlight_Hover;
} }
f32 roundness = block_height*global_config.lister_roundness; u64 lister_roundness_100 = def_get_config_u64(app, vars_save_string_lit("lister_roundness"));
f32 roundness = block_height*lister_roundness_100*0.01f;
draw_rectangle_fcolor(app, item_rect, roundness, get_item_margin_color(highlight)); draw_rectangle_fcolor(app, item_rect, roundness, get_item_margin_color(highlight));
draw_rectangle_fcolor(app, item_inner, roundness, get_item_margin_color(highlight, 1)); draw_rectangle_fcolor(app, item_inner, roundness, get_item_margin_color(highlight, 1));

View File

@ -372,7 +372,7 @@ static Command_Metadata fcoder_metacmd_table[250] = {
{ PROC_LINKS(list_all_substring_locations, 0), false, "list_all_substring_locations", 28, "Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.", 103, "W:\\4ed\\code\\custom\\4coder_search.cpp", 36, 174 }, { PROC_LINKS(list_all_substring_locations, 0), false, "list_all_substring_locations", 28, "Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.", 103, "W:\\4ed\\code\\custom\\4coder_search.cpp", 36, 174 },
{ PROC_LINKS(list_all_substring_locations_case_insensitive, 0), false, "list_all_substring_locations_case_insensitive", 45, "Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.", 105, "W:\\4ed\\code\\custom\\4coder_search.cpp", 36, 186 }, { PROC_LINKS(list_all_substring_locations_case_insensitive, 0), false, "list_all_substring_locations_case_insensitive", 45, "Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.", 105, "W:\\4ed\\code\\custom\\4coder_search.cpp", 36, 186 },
{ PROC_LINKS(load_project, 0), false, "load_project", 12, "Looks for a project.4coder file in the current directory and tries to load it. Looks in parent directories until a project file is found or there are no more parents.", 167, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 972 }, { PROC_LINKS(load_project, 0), false, "load_project", 12, "Looks for a project.4coder file in the current directory and tries to load it. Looks in parent directories until a project file is found or there are no more parents.", 167, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 972 },
{ PROC_LINKS(load_theme_current_buffer, 0), false, "load_theme_current_buffer", 25, "Parse the current buffer as a theme file and add the theme to the theme list. If the buffer has a .4coder postfix in it's name, it is removed when the name is saved.", 165, "W:\\4ed\\code\\custom\\4coder_config.cpp", 36, 1621 }, { PROC_LINKS(load_theme_current_buffer, 0), false, "load_theme_current_buffer", 25, "Parse the current buffer as a theme file and add the theme to the theme list. If the buffer has a .4coder postfix in it's name, it is removed when the name is saved.", 165, "W:\\4ed\\code\\custom\\4coder_config.cpp", 36, 1573 },
{ PROC_LINKS(load_themes_default_folder, 0), false, "load_themes_default_folder", 26, "Loads all the theme files in the default theme folder.", 54, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 535 }, { PROC_LINKS(load_themes_default_folder, 0), false, "load_themes_default_folder", 26, "Loads all the theme files in the default theme folder.", 54, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 535 },
{ PROC_LINKS(load_themes_hot_directory, 0), false, "load_themes_hot_directory", 25, "Loads all the theme files in the current hot directory.", 55, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 547 }, { PROC_LINKS(load_themes_hot_directory, 0), false, "load_themes_hot_directory", 25, "Loads all the theme files in the current hot directory.", 55, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 547 },
{ PROC_LINKS(make_directory_query, 0), false, "make_directory_query", 20, "Queries the user for a name and creates a new directory with the given name.", 76, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1495 }, { PROC_LINKS(make_directory_query, 0), false, "make_directory_query", 20, "Queries the user for a name and creates a new directory with the given name.", 76, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1495 },