diff options
Diffstat (limited to 'src/settings.c')
| -rw-r--r-- | src/settings.c | 203 |
1 files changed, 203 insertions, 0 deletions
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); +} |
