diff options
| author | Aldrik Ramaekers <aldrik.ramaekers@protonmail.com> | 2020-02-11 15:03:15 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik.ramaekers@protonmail.com> | 2020-02-11 15:03:15 +0100 |
| commit | 3aae55948c7d97f54e425d43744992732823b8ff (patch) | |
| tree | fed4a34af8e4b9e1ad8df4575cdb15c831692929 /src | |
| parent | ca64112eed86aac2e7cf35b0dedfb61ea4e0240f (diff) | |
work
Diffstat (limited to 'src')
| -rw-r--r-- | src/mo_edit.c | 42 | ||||
| m--------- | src/project-base | 0 | ||||
| -rw-r--r-- | src/settings.c | 203 | ||||
| -rw-r--r-- | src/settings.h | 47 |
4 files changed, 280 insertions, 12 deletions
diff --git a/src/mo_edit.c b/src/mo_edit.c index d9505f0..b481b9f 100644 --- a/src/mo_edit.c +++ b/src/mo_edit.c @@ -43,6 +43,9 @@ array tb_translation_list; #include "save.h" #include "save.c" +#include "settings.h" +#include "settings.c" + scroll_state term_scroll; scroll_state lang_scroll; scroll_state trans_scroll; @@ -233,6 +236,22 @@ void remove_language_from_project(s32 language_id) language *l = array_at(¤t_project->languages, i); if (l->id == language_id) { + char fullpath[MAX_INPUT_LENGTH]; + fullpath[0] = 0; + string_appendn(fullpath, project_path, MAX_INPUT_LENGTH); +#ifdef OS_WIN + string_appendn(fullpath, "\\", MAX_INPUT_LENGTH); +#endif +#ifdef OS_LINUX + string_appendn(fullpath, "/", MAX_INPUT_LENGTH); +#endif + string_appendn(fullpath, l->name, MAX_INPUT_LENGTH); + string_appendn(fullpath, ".mo", MAX_INPUT_LENGTH); + if (platform_file_exists(fullpath)) + { + platform_delete_file(fullpath); + } + array_remove_at(¤t_project->languages, i); textbox_state *st = array_at(&tb_translation_list, i); mem_free(st->buffer); @@ -380,13 +399,6 @@ int main(int argc, char **argv) { platform_init(argc, argv); - bool is_command_line_run = (argc > 1); - if (is_command_line_run) - { - //handle_command_line_arguments(argc, argv); - return 0; - } - char config_path_buffer[PATH_MAX]; get_config_save_location(config_path_buffer); @@ -404,7 +416,7 @@ int main(int argc, char **argv) platform_window window = platform_open_window("mo-edit", window_w, window_h, 0, 0, 800, 600); main_window = &window; - //settings_page_create(); + settings_page_create(); load_available_localizations(); set_locale("en"); @@ -441,11 +453,11 @@ int main(int argc, char **argv) load_config(&config); while(window.is_open) { - u64 last_stamp = platform_get_time(TIME_FULL, TIME_US); + u64 last_stamp = platform_get_time(TIME_FULL, TIME_US); platform_handle_events(&window, &mouse, &keyboard); platform_set_cursor(&window, CURSOR_DEFAULT); - //settings_page_update_render(); + settings_page_update_render(); platform_window_make_current(&window); @@ -519,11 +531,17 @@ int main(int argc, char **argv) window.is_open = false; } } + if (ui_push_menu(localize("options"))) + { + if (ui_push_menu_item(localize("settings"), "")) + { + settings_page_show(); + } + } } ui_end_menu_bar(); ui_push_separator(); - global_ui_context.layout.width = 300; ui_push_vertical_dragbar(); @@ -875,7 +893,7 @@ int main(int argc, char **argv) } } - //settings_page_hide_without_save(); + settings_page_hide_without_save(); // write config file if (!string_equals(project_path, "")) diff --git a/src/project-base b/src/project-base -Subproject 807d87681c5eca52fee692321ae0279324204cc +Subproject dd286e9f696ebd631af45bca82ca458aafd2172 diff --git a/src/settings.c b/src/settings.c new file mode 100644 index 0000000..147718c --- /dev/null +++ b/src/settings.c @@ -0,0 +1,203 @@ +/* +* BSD 2-Clause “Simplified” License +* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com +* All rights reserved. +*/ + +void reset_status_text(); +void set_status_text_to_finished_search(); + +void settings_page_create() +{ + global_settings_page.active = false; + global_settings_page.font_small = assets_load_font(_binary____data_fonts_mono_ttf_start, + _binary____data_fonts_mono_ttf_end, 16); + global_settings_page.logo_img = assets_load_image(_binary____data_imgs_logo_64_png_start, + _binary____data_imgs_logo_64_png_end, true); + global_settings_page.keyboard = keyboard_input_create(); + global_settings_page.mouse = mouse_input_create(); + + camera cam; + cam.x = 0; + cam.y = 0; + cam.rotation = 0; + + global_settings_page.camera = cam; + + global_settings_page.btn_close = ui_create_button(); + global_settings_page.btn_save = ui_create_button(); + global_settings_page.dropdown_language = ui_create_dropdown(); + global_settings_page.dropdown_doubleclick = ui_create_dropdown(); + global_settings_page.textbox_max_file_size = ui_create_textbox(9); + global_settings_page.textbox_max_thread_count = ui_create_textbox(5); + global_settings_page.checkbox_parallelize_search = ui_create_checkbox(false); +} + +static void load_current_settings_into_ui() +{ + +} + +void settings_page_update_render() +{ + if (global_settings_page.active) + { + platform_window_make_current(&global_settings_page.window); + platform_handle_events(&global_settings_page.window, &global_settings_page.mouse, &global_settings_page.keyboard); + platform_set_cursor(&global_settings_page.window, CURSOR_DEFAULT); + + render_clear(); + + camera_apply_transformations(&global_settings_page.window, &global_settings_page.camera); + + global_ui_context.layout.active_window = &global_settings_page.window; + global_ui_context.keyboard = &global_settings_page.keyboard; + global_ui_context.mouse = &global_settings_page.mouse; + + ui_begin(3); + { + ui_begin_menu_bar(); + { + if (ui_push_menu(localize("interface"))) + { + global_settings_page.selected_tab_index = 1; + } + } + ui_end_menu_bar(); + + ui_push_separator(); + if (global_settings_page.selected_tab_index == 1) + { + ui_block_begin(LAYOUT_HORIZONTAL); + { + ui_push_text(localize("language")); + } + ui_block_end(); + + ui_block_begin(LAYOUT_HORIZONTAL); + { + if (ui_push_dropdown(&global_settings_page.dropdown_language, locale_get_name())) + { + for (s32 i = 0; i < global_localization.mo_files.length; i++) + { + mo_file *file = array_at(&global_localization.mo_files, i); + + if (ui_push_dropdown_item(file->icon, file->locale_full, i)) + { + set_locale(file->locale_id); + //platform_window_set_title(&global_settings_page.window, + //localize("text_search_settings")); + } + } + } + } + ui_block_end(); + +#if 0 + ui_block_begin(LAYOUT_HORIZONTAL); + { + ui_push_text("Style"); + } + ui_block_end(); + + ui_block_begin(LAYOUT_HORIZONTAL); + { + if (ui_push_color_button("Light", global_ui_context.style.id == UI_STYLE_LIGHT, rgb(250, 250, 250))) + { + ui_set_style(UI_STYLE_LIGHT); + } + if (ui_push_color_button("Dark", global_ui_context.style.id == UI_STYLE_DARK, rgb(50, 50, 50))) + { + ui_set_style(UI_STYLE_DARK); + } + } + ui_block_end(); +#endif + } + + global_ui_context.layout.offset_y = global_settings_page.window.height - 33; + + ui_block_begin(LAYOUT_HORIZONTAL); + { + if (ui_push_button(&global_settings_page.btn_close, localize("close"))) + { + global_settings_page.active = false; + set_locale(global_settings_page.current_locale_id); + settings_page_hide(); + } + if (ui_push_button(&global_settings_page.btn_close, localize("save"))) + { + global_settings_page.active = false; + settings_page_hide(); + return; + } + } + ui_block_end(); + } + ui_end(); + + if (!global_settings_page.window.is_open) + { + global_settings_page.active = false; + settings_page_hide(); + return; + } + + platform_window_swap_buffers(&global_settings_page.window); + } +} + +void settings_page_show() +{ + if (platform_window_is_valid(&global_settings_page.window)) return; + + load_current_settings_into_ui(); + + global_settings_page.window = platform_open_window(localize("mo_edit_settings"), + 350, 200, 350, 200, 350, 200); + + settings_window = &global_settings_page.window; + + global_settings_page.active = true; + global_settings_page.selected_tab_index = 1; + global_settings_page.current_locale_id = locale_get_id(); + + platform_set_icon(&global_settings_page.window, global_settings_page.logo_img); +} + +void settings_page_hide() +{ + if (platform_window_is_valid(&global_settings_page.window)) + { + settings_window = 0; + + platform_destroy_window(&global_settings_page.window); + + global_settings_page.btn_close.state = false; + global_settings_page.btn_save.state = false; + global_settings_page.active = false; + + global_settings_page.mouse.x = -1; + global_settings_page.mouse.y = -1; + } +} + +void settings_page_hide_without_save() +{ + if (platform_window_is_valid(&global_settings_page.window)) + { + global_settings_page.active = false; + set_locale(global_settings_page.current_locale_id); + settings_page_hide(); + } +} + +void settings_page_destroy() +{ + keyboard_input_destroy(&global_settings_page.keyboard); + assets_destroy_font(global_settings_page.font_small); + assets_destroy_image(global_settings_page.logo_img); + + if (platform_window_is_valid(&global_settings_page.window)) + platform_destroy_window(&global_settings_page.window); +} diff --git a/src/settings.h b/src/settings.h new file mode 100644 index 0000000..3d399cf --- /dev/null +++ b/src/settings.h @@ -0,0 +1,47 @@ +/* +* BSD 2-Clause “Simplified” License +* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com +* All rights reserved. +*/ + +#ifndef INCLUDE_SETTINGS +#define INCLUDE_SETTINGS + +typedef struct t_settings_page +{ + platform_window window; + keyboard_input keyboard; + mouse_input mouse; + camera camera; + bool active; + + font *font_small; + image *logo_img; + + button_state btn_close; + button_state btn_save; + dropdown_state dropdown_language; + dropdown_state dropdown_doubleclick; + textbox_state textbox_max_file_size; + textbox_state textbox_max_thread_count; + checkbox_state checkbox_parallelize_search; + s32 selected_tab_index; + + char *current_locale_id; +} settings_page; + +#define DEFAULT_THREAD_COUNT 10 +#define DEFAULT_MAX_FILE_SIZE 0 +#define DEFAULT_RECURSIVE_STATE 1 +#define DEFAULT_STYLE 1 + +settings_page global_settings_page; + +void settings_page_create(); +void settings_page_hide_without_save(); +void settings_page_update_render(); +void settings_page_show(); +void settings_page_hide(); +void settings_page_destroy(); + +#endif
\ No newline at end of file |
