From 571ed3f152e8c7b16afc79ba01c1916f9d402c60 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Wed, 27 Apr 2016 22:35:54 -0400 Subject: [PATCH] config menu now works, all that's left is theme --- 4ed_file_view.cpp | 90 +++++++++++++++++++++++++++++++++++++++++------ 4ed_gui.cpp | 27 ++++++++++++++ 2 files changed, 106 insertions(+), 11 deletions(-) diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index d63eec81..af313243 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -88,12 +88,6 @@ struct View{ String dest; #if 0 - // interactive stuff - b32 finished; - char query_[256]; - String query; - i32 user_action; - // theme stuff View *hot_file_view; u32 *palette; @@ -2639,12 +2633,19 @@ view_show_theme(View *view, Command_Map *gui_map){ } #endif +inline void +view_show_menu(View *view, Command_Map *gui_map){ + view->map_for_file = view->map; + view->map = gui_map; + view->showing_ui = VUI_Menu; +} inline void -view_show_menu(View *view, Command_Map *gui_map){} - -inline void -view_show_config(View *view, Command_Map *gui_map){} +view_show_config(View *view, Command_Map *gui_map){ + view->map_for_file = view->map; + view->map = gui_map; + view->showing_ui = VUI_Config; +} inline void view_show_interactive(System_Functions *system, View *view, @@ -3671,6 +3672,44 @@ step_file_view(System_Functions *system, View *view, b32 is_active){ else{ do_widget(view, target); switch (view->showing_ui){ + case VUI_Menu: + { + String message = make_lit_string("Menu"); + String empty_string = {0}; + GUI_id id = {0}; + + gui_do_text_field(target, message, empty_string); + + id.id[0] = (u64)(0 + (IInt_Sure_To_Close << 8)); + message = make_lit_string("Theme"); + if (gui_do_fixed_option(target, id, message, 0)){ + view_show_theme(view, view->map); + } + + id.id[0] = (u64)(1 + (IInt_Sure_To_Close << 8)); + message = make_lit_string("Config"); + if (gui_do_fixed_option(target, id, message, 0)){ + view_show_config(view, view->map); + } + } + break; + + case VUI_Config: + { + String message = make_lit_string("Config"); + String empty_string = {0}; + GUI_id id = {0}; + + gui_do_text_field(target, message, empty_string); + + id.id[0] = (u64)(0 + (IInt_Sure_To_Close << 8)); + message = make_lit_string("Left Ctrl + Left Alt = AltGr"); + if (gui_do_fixed_option_checkbox(target, id, message, 0, (b8)models->settings.lctrl_lalt_is_altgr)){ + models->settings.lctrl_lalt_is_altgr = !models->settings.lctrl_lalt_is_altgr; + } + } + break; + case VUI_Interactive: switch (view->interaction){ case IInt_Sys_File_List: @@ -4130,6 +4169,7 @@ do_input_file_view(System_Functions *system, Exchange *exchange, }break; case guicom_fixed_option: + case guicom_fixed_option_checkbox: { Key_Event_Data key; Key_Summary *keys = &user_input->keys; @@ -4582,7 +4622,8 @@ do_render_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Re } internal void -draw_fat_option_block(GUI_Target *gui_target, Render_Target *target, View *view, i32_Rect rect, GUI_id id, String text, String pop){ +draw_fat_option_block(GUI_Target *gui_target, Render_Target *target, View *view, i32_Rect rect, GUI_id id, + String text, String pop, i8 checkbox = -1){ Models *models = view->models; Style *style = &models->style; @@ -4617,6 +4658,21 @@ draw_fat_option_block(GUI_Target *gui_target, Render_Target *target, View *view, draw_rectangle(target, inner, back); draw_margin(target, rect, inner, margin); + if (checkbox != -1){ + u32 checkbox_color = style->main.margin_active_color; + i32_Rect checkbox_rect = get_inner_rect(inner, (inner.y1 - inner.y0 - h)/2); + checkbox_rect.x1 = checkbox_rect.x0 + (checkbox_rect.y1 - checkbox_rect.y0); + + if (checkbox == 0){ + draw_rectangle_outline(target, checkbox_rect, checkbox_color); + } + else{ + draw_rectangle(target, checkbox_rect, checkbox_color); + } + + x = checkbox_rect.x1 + 3; + } + x = draw_string(target, font_id, text, x, y, text_color); draw_string(target, font_id, pop, x, y, pop_color); } @@ -4701,6 +4757,18 @@ do_render_file_view(System_Functions *system, Exchange *exchange, draw_fat_option_block(gui_target, target, view, gui_session.rect, b->id, f, m); }break; + case guicom_fixed_option_checkbox: + { + GUI_Interactive *b = (GUI_Interactive*)h; + void *ptr = (b + 1); + String f = gui_read_string(&ptr); + gui_read_byte(&ptr); + b8 status = (b8)gui_read_byte(&ptr); + String m = {0}; + + draw_fat_option_block(gui_target, target, view, gui_session.rect, b->id, f, m, status); + }break; + case guicom_scrollable: { Models *models = view->models; diff --git a/4ed_gui.cpp b/4ed_gui.cpp index 03e602f7..88a63a4a 100644 --- a/4ed_gui.cpp +++ b/4ed_gui.cpp @@ -128,6 +128,7 @@ enum GUI_Command_Type{ guicom_file_input, guicom_file_option, guicom_fixed_option, + guicom_fixed_option_checkbox, guicom_scrollable, guicom_scrollable_top, guicom_scrollable_slider, @@ -377,6 +378,23 @@ gui_do_fixed_option(GUI_Target *target, GUI_id id, String message, char key){ return(result); } +internal b32 +gui_do_fixed_option_checkbox(GUI_Target *target, GUI_id id, String message, char key, b8 state){ + b32 result = 0; + GUI_Interactive *b = gui_push_button_command(target, guicom_fixed_option_checkbox, id); + GUI_Header *h = (GUI_Header*)b; + gui_push_string(target, h, message); + gui_push_item(target, h, &key, 1); + gui_push_item(target, h, &state, 1); + gui_align(target, h); + + if (gui_id_eq(id, target->active)){ + result = 1; + } + + return(result); +} + internal GUI_id gui_id_scrollbar(){ GUI_id id; @@ -691,6 +709,7 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){ case guicom_file_option: case guicom_fixed_option: + case guicom_fixed_option_checkbox: give_to_user = 1; rect = gui_layout_fixed_h(session, y, session->line_height * 2); end_v = rect.y1; @@ -799,6 +818,14 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){ #define NextHeader(h) ((GUI_Header*)((char*)(h) + (h)->size)) +internal i8 +gui_read_byte(void **ptr){ + i8 result; + result = *(i8*)*ptr; + *ptr = ((char*)*ptr) + 1; + return(result); +} + internal i32 gui_read_integer(void **ptr){ i32 result;