From ce27493fb350dc3bec3a8a7a7e1ee59369d28bca Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Mon, 30 May 2016 10:56:54 -0400 Subject: [PATCH] set up GUI to consume keys it uses --- 4ed.cpp | 20 ++++--- 4ed_file_view.cpp | 119 +++++++++++++++++++++++------------------ TODO.txt | 22 ++++---- power/4coder_casey.cpp | 6 +-- 4 files changed, 91 insertions(+), 76 deletions(-) diff --git a/4ed.cpp b/4ed.cpp index 7b2441f5..ea10980d 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -3884,14 +3884,13 @@ App_Step_Sig(app_step){ models->command_coroutine = command_coroutine; } else{ - app_result.perform_kill = 1; + models->keep_playing = 0; } } - // NOTE(allen): process the command_coroutine if it is unfinished + // NOTE(allen): Keyboard input to command coroutine. Available_Input available_input = init_available_input(&key_summary, &input->mouse); - // NOTE(allen): Keyboard input to command coroutine. if (models->command_coroutine != 0){ Coroutine *command_coroutine = models->command_coroutine; u32 get_flags = models->command_coroutine_flags[0]; @@ -4028,7 +4027,6 @@ App_Step_Sig(app_step){ update_command_data(vars, cmd); // NOTE(allen): pass raw input to the panels - Input_Summary dead_input = {}; dead_input.mouse.x = input->mouse.x; dead_input.mouse.y = input->mouse.y; @@ -4054,9 +4052,17 @@ App_Step_Sig(app_step){ view = panel->view; active = (panel == cmd->panel); summary = (active)?(active_input):(dead_input); - if (step_file_view(system, view, active_view, summary)){ + + View_Step_Result result = step_file_view(system, view, active_view, summary); + if (result.animating){ app_result.animating = 1; } + if (result.consume_keys){ + consume_input(&available_input, Input_AnyKey); + } + if (result.consume_keys || result.consume_esc){ + consume_input(&available_input, Input_Esc); + } } for (dll_items(panel, used_panels)){ @@ -4404,12 +4410,12 @@ App_Step_Sig(app_step){ models->prev_mouse_panel = mouse_panel; app_result.lctrl_lalt_is_altgr = models->settings.lctrl_lalt_is_altgr; + app_result.perform_kill = !models->keep_playing; + *result = app_result; Assert(general_memory_check(&models->mem.general)); - app_result.perform_kill = models->keep_playing; - // end-of-app_step } diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index c0925fab..6a5e55de 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -1811,6 +1811,7 @@ file_pre_edit_maintenance(System_Functions *system, general_memory_free(general, file->state.swap_stack.tokens); file->state.swap_stack.tokens = 0; } + file->state.still_lexing = 0; } file->state.last_4ed_edit_time = system->now_time_stamp(); } @@ -3216,9 +3217,7 @@ interactive_view_complete(System_Functions *system, View *view, String dest, i32 break; case IAct_New: - // TODO(allen): The !char_is_slash part confuses me... let's investigate this soon. - if (dest.size > 0 && - !char_is_slash(models->hot_directory.string.str[dest.size-1])){ + if (dest.size > 0 && !char_is_slash(dest.str[dest.size-1])){ view_new_file(system, models, view, dest); view_show_file(view); }break; @@ -3782,8 +3781,15 @@ app_single_number_input_step(System_Functions *system, Key_Event_Data key, Strin return result; } -internal b32 +struct View_Step_Result{ + b32 animating; + b32 consume_keys; + b32 consume_esc; +}; + +internal View_Step_Result step_file_view(System_Functions *system, View *view, View *active_view, Input_Summary input){ + View_Step_Result result = {0}; GUI_Target *target = &view->gui_target; Models *models = view->persistent.models; Key_Summary keys = input.keys; @@ -3792,6 +3798,25 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su view->current_scroll = 0; + if (view->showing_ui != VUI_None){ + b32 did_esc = 0; + Key_Event_Data key; + i32 i; + + for (i = 0; i < keys.count; ++i){ + key = get_single_key(&keys, i); + if (key.keycode == key_esc){ + did_esc = 1; + break; + } + } + + if (did_esc){ + view_show_file(view); + result.consume_esc = 1; + } + } + gui_begin_top_level(target, input); { gui_do_top_bar(target); @@ -3832,22 +3857,22 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su String empty_string = {0}; GUI_id id = {0}; id.id[1] = VUI_Menu; - + gui_do_text_field(target, message, empty_string); - + id.id[0] = 0; message = make_lit_string("Theme"); if (gui_do_fixed_option(target, id, message, 0)){ view_show_theme(view, view->map); } - + id.id[0] = 1; message = make_lit_string("Config"); if (gui_do_fixed_option(target, id, message, 0)){ view_show_config(view, view->map); } }break; - + case VUI_Config: { view->current_scroll = &view->gui_scroll; @@ -3856,16 +3881,16 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su String empty_string = {0}; GUI_id id = {0}; id.id[1] = VUI_Config; - + gui_do_text_field(target, message, empty_string); - + id.id[0] = 0; 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_Theme: { view->current_scroll = &view->gui_scroll; @@ -3873,7 +3898,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su if (view != active_view){ view->hot_file_view = active_view; } - + String message = {0}; String empty_string = {0}; @@ -3995,47 +4020,50 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su next_color_editing = i; view->color_cursor = 0; } - + if (view->current_color_editing == i){ GUI_Item_Update update = {0}; char text_space[7]; String text = make_fixed_width_string(text_space); - + color_to_hexstr(*edit_color, &text); if (gui_do_text_with_cursor(target, view->color_cursor, text, &update)){ b32 r = 0; i32 j = 0; - + for (j = 0; j < keys.count; ++j){ i16 key = keys.keys[j].keycode; switch (key){ - case key_left: --view->color_cursor; r = 1; break; - case key_right: ++view->color_cursor; r = 1; break; - + case key_left: --view->color_cursor; r = 1; result.consume_keys = 1; break; + case key_right: ++view->color_cursor; r = 1; result.consume_keys = 1; break; + case key_up: if (next_color_editing > 0){ --next_color_editing; } + result.consume_keys = 1; break; - + case key_down: if (next_color_editing <= ArrayCount(colors_to_edit)-1){ ++next_color_editing; } + result.consume_keys = 1; break; - + default: if ((key >= '0' && key <= '9') || (key >= 'a' && key <= 'f') || (key >= 'A' && key <= 'F')){ text.str[view->color_cursor] = (char)key; r = 1; + result.consume_keys = 1; } break; } - + if (view->color_cursor < 0) view->color_cursor = 0; if (view->color_cursor >= 6) view->color_cursor = 5; } - + if (r){ hexstr_to_color(text, edit_color); gui_rollback(target, &update); @@ -4044,12 +4072,12 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su } } } - + if (view->current_color_editing != next_color_editing){ view->current_color_editing = next_color_editing; view->color_cursor = 0; } - + gui_end_scrollable(target); }break; } @@ -4107,9 +4135,11 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su &hdir->string, hdir, 1, 1, 0); if (step.made_a_change){ view->list_i = 0; + result.consume_keys = 1; } if (!use_item_in_list && (key.keycode == '\n' || key.keycode == '\t')){ activate_directly = 1; + result.consume_keys = 1; } } } @@ -4128,6 +4158,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su if (gui_begin_list(target, id, view->list_i, 0, snap_into_view, &update)){ + // TODO(allen): Allow me to handle key consumption correctly here! gui_standard_list(target, id, view->current_scroll, view->scroll_region, &keys, &view->list_i, &update); } @@ -4173,19 +4204,19 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su b32 snap_into_view = 0; persist String message_unsaved = make_lit_string(" *"); persist String message_unsynced = make_lit_string(" !"); - + String message = {0}; switch (view->action){ case IAct_Switch: message = make_lit_string("Switch: "); break; case IAct_Kill: message = make_lit_string("Kill: "); break; } - + Absolutes absolutes; Editing_File *file; Working_Set *working_set = &models->working_set; Editing_Layout *layout = &models->layout; GUI_Item_Update update = {0}; - + { Single_Line_Input_Step step; Key_Event_Data key; @@ -4195,14 +4226,15 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su step = app_single_line_input_step(system, key, &view->dest); if (step.made_a_change){ view->list_i = 0; + result.consume_keys = 1; } } } - + get_absolutes(view->dest, &absolutes, 1, 1); - + gui_do_text_field(target, message, view->dest); - + scroll_context.id[0] = (u64)(working_set); if (gui_get_scroll_vars(target, scroll_context, &view->gui_scroll, &view->scroll_region)){ @@ -4210,7 +4242,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su } gui_begin_scrollable(target, scroll_context, view->gui_scroll, 9.f * view->font_height, show_scrollbar); - + id.id[0] = (u64)(working_set) + 1; if (gui_begin_list(target, id, view->list_i, 0, snap_into_view, &update)){ @@ -4356,7 +4388,9 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su } } gui_end_top_level(target); - return(target->animating); + + result.animating = target->animating; + return(result); } internal f32 @@ -4651,27 +4685,6 @@ do_input_file_view(System_Functions *system, Exchange *exchange, result.vars = scroll_vars; } - - // TODO(allen): GET RID OF THIS!!! - { - Key_Summary *keys = &user_input->keys; - b32 did_esc = 0; - Key_Event_Data key; - i32 i, count; - - count = keys->count; - for (i = 0; i < count; ++i){ - key = get_single_key(keys, i); - if (key.keycode == key_esc){ - did_esc = 1; - break; - } - } - - if (did_esc && view->showing_ui != VUI_None){ - view_show_file(view); - } - } } return(result); diff --git a/TODO.txt b/TODO.txt index 8a8d85a7..1f78229b 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,7 +1,3 @@ - -; before shipping: -; [] make sure 4coder_handmade_hero.cpp works - ; Started this list on: (18.01.2016)(dd.mm.yyyy) ; This list is an informal todo list, it may very well miss items ; checked or unchecked, that I inted to do some day. It is included @@ -67,12 +63,15 @@ ; [X] chronal's map setting issue ; [X] linux save jankieness ; [X] bouncing when scrolling down +; [X] sometimes the main cursor is not the same width as the mark cursor in the same spot +; [X] tab character wrong width +; [X] miblo's off screen cursor thing +; [X] paste snaps the cursor back into view! +; [X] new file is messed up for code files, it never finishes parsing! ; [] indication on failure to save ; [] clean whitespace doesn't appear to be cleaning trailing whitespace anymore??? -; [] sometimes the main cursor is not the same width as the mark cursor in the same spot -; [] tab character wrong width -; [] miblo's off screen cursor thing ; +; [] key presses that should be consumed in the GUI are now passed to the file! ; ; TODOS @@ -117,14 +116,13 @@ ; [X] rewrite GUI ; [X] arrow navigation of GUIs ; [] GUI API -; [] text links -> arbitrary commands / callbacks? ; ; search related tech ; [X] replace word (incremental and/or in range) +; [X] caps insensitivety ; [] optimize search ; [] allow search wrap around beginning/end ; [] improved custom API for text "streams" -; [] caps insensitivety ; ; theme related business ; [] fix the versioning system for themes @@ -173,12 +171,11 @@ ; INTERNAL TODOS ; [X] switch building non-extensible version by statically linking to custom.cpp +; [X] pack fonts more squarely ; [] general parameter handling ; [] hashed string pool for clipboard/filenames/etc -; [] ask for clipboards to update by request, not on loop -; [] pack fonts more squarely -; [] setup tests through special tool ; [] new profiling/debugging system +; [] change job canceling to a polling based thing ; ; EASY TODOS @@ -199,6 +196,7 @@ ; [] fill screen right away ; [] how to get fast repaint (do I really need double buffering?) ; [] history breaks when heavily used (disk swaping?) +; [] window stops repainting bug on a handful of machines (Win 10? Driver?) ; ; PORTING TODOS diff --git a/power/4coder_casey.cpp b/power/4coder_casey.cpp index df8fbc20..bd2cb789 100644 --- a/power/4coder_casey.cpp +++ b/power/4coder_casey.cpp @@ -104,13 +104,11 @@ #include #include +#include +#include #include "../4coder_default_include.cpp" -enum maps{ - my_code_map -}; - #ifndef Assert #define internal static #define Assert assert