From 4abac7a639091b0e7fb3931f41b2a37995f3671c Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 9 Jun 2016 23:20:45 -0400 Subject: [PATCH] more view debugging --- 4coder_string.h | 57 +++++++++++++ 4ed.cpp | 12 +-- 4ed_app_models.h | 1 + 4ed_file_view.cpp | 212 ++++++++++++++++++++++++++++++++++++++++------ 4ed_gui.cpp | 12 ++- TODO.txt | 1 + 6 files changed, 263 insertions(+), 32 deletions(-) diff --git a/4coder_string.h b/4coder_string.h index a519bbd5..9ebac71a 100644 --- a/4coder_string.h +++ b/4coder_string.h @@ -142,6 +142,10 @@ FSTRING_LINK int32_t u64_to_str_size(uint64_t x); FSTRING_LINK fstr_bool u64_to_str(String *s_out, uint64_t x); FSTRING_LINK fstr_bool append_u64_to_str(String *s_out, uint64_t x); +FSTRING_LINK int32_t float_to_str_size(float x); +FSTRING_LINK fstr_bool float_to_str(String *s_out, float x); +FSTRING_LINK fstr_bool append_float_to_str(String *s_out, float x); + FSTRING_LINK int32_t str_to_int(char *s); FSTRING_LINK int32_t str_to_int(String s); FSTRING_LINK int32_t hexchar_to_int(char c); @@ -800,6 +804,59 @@ append_u64_to_str(String *dest, uint64_t x){ return(result); } +struct Float_To_Str_Variables{ + fstr_bool negative; + int32_t int_part; + int32_t dec_part; +}; + +FSTRING_INLINE Float_To_Str_Variables +get_float_vars(float x){ + Float_To_Str_Variables vars = {0}; + + if (x < 0){ + vars.negative = true; + x = -x; + } + + vars.int_part = (int32_t)(x); + vars.dec_part = (int32_t)((x - vars.int_part) * 1000); + + return(vars); +} + +FSTRING_LINK int32_t +float_to_str_size(float x){ + Float_To_Str_Variables vars = get_float_vars(x); + int32_t size = + vars.negative + int_to_str_size(vars.int_part) + 1 + int_to_str_size(vars.dec_part); + return(size); +} + +FSTRING_LINK fstr_bool +append_float_to_str(String *dest, float x){ + fstr_bool result = 1; + Float_To_Str_Variables vars = get_float_vars(x); + + if (vars.negative){ + append(dest, '-'); + } + + append_int_to_str(dest, vars.int_part); + append(dest, '.'); + append_int_to_str(dest, vars.dec_part); + + return(result); +} + +FSTRING_LINK fstr_bool +float_to_str(String *dest, float x){ + fstr_bool result = 1; + dest->size = 0; + append_float_to_str(dest, x); + return(result); +} + FSTRING_LINK int32_t str_to_int(char *str){ diff --git a/4ed.cpp b/4ed.cpp index 847d0eae..165b51fb 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -59,11 +59,13 @@ struct Command_Data{ struct App_Vars{ Models models; + // TODO(allen): This wants to live in + // models with everyone else but the order + // of declaration is a little bit off... + Live_Views live_set; CLI_List cli_processes; - Live_Views live_set; - App_State state; App_State_Resizing resizing; Complete_State complete_state; @@ -1247,10 +1249,8 @@ COMMAND_DECL(open_menu){ COMMAND_DECL(open_debug){ USE_VIEW(view); -#if FRED_INTERNAL view_show_GUI(view, VUI_Debug); - view->debug_mode = DBG_Input; -#endif + view->debug_vars = debug_vars_zero(); } COMMAND_DECL(user_callback){ @@ -2847,6 +2847,8 @@ App_Init_Sig(app_init){ i32 i = 0; i32 max = 0; + models->live_set = &vars->live_set; + vars->live_set.count = 0; vars->live_set.max = panel_max_count; diff --git a/4ed_app_models.h b/4ed_app_models.h index f6671d55..d22f554e 100644 --- a/4ed_app_models.h +++ b/4ed_app_models.h @@ -69,6 +69,7 @@ struct Models{ Editing_Layout layout; Working_Set working_set; + struct Live_Views *live_set; Editing_File *message_buffer; char hot_dir_base_[256]; diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 01fefc0c..ddd013f3 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -206,6 +206,16 @@ struct View_Persistent{ Models *models; }; +struct Debug_Vars{ + i32 mode; + i32 inspecting_view_id; +}; +inline Debug_Vars +debug_vars_zero(){ + Debug_Vars vars = {0}; + return(vars); +} + struct View{ View_Persistent persistent; @@ -266,7 +276,7 @@ struct View{ b32 reinit_scrolling; - Debug_Mode debug_mode; + Debug_Vars debug_vars; }; inline void* get_view_body(View *view){ @@ -284,6 +294,12 @@ struct View_And_ID{ i32 id; }; +struct Live_Views{ + View *views; + View free_sentinel; + i32 count, max; +}; + #define LockLevel_Open 0 #define LockLevel_NoWrite 1 #define LockLevel_NoUpdate 2 @@ -3879,6 +3895,63 @@ app_single_number_input_step(System_Functions *system, Key_Event_Data key, Strin return result; } +internal void +append_label(String *string, i32 indent_level, char *message){ + i32 r = 0; + for (r = 0; r < indent_level; ++r){ + append(string, '>'); + } + append(string, message); +} + +internal void +show_gui_line(GUI_Target *target, String *string, + i32 indent_level, i32 h_align, char *message, char *follow_up){ + string->size = 0; + append_label(string, indent_level, message); + if (follow_up){ + append_padding(string, '-', h_align); + append(string, ' '); + append(string, follow_up); + } + gui_do_text_field(target, *string, string_zero()); +} + +internal void +show_gui_int(GUI_Target *target, String *string, + i32 indent_level, i32 h_align, char *message, i32 x){ + string->size = 0; + append_label(string, indent_level, message); + append_padding(string, '-', h_align); + append(string, ' '); + append_int_to_str(string, x); + gui_do_text_field(target, *string, string_zero()); +} + +internal void +show_gui_int_int(GUI_Target *target, String *string, + i32 indent_level, i32 h_align, char *message, i32 x, i32 m){ + string->size = 0; + append_label(string, indent_level, message); + append_padding(string, '-', h_align); + append(string, ' '); + append_int_to_str(string, x); + append(string, '/'); + append_int_to_str(string, m); + gui_do_text_field(target, *string, string_zero()); +} + +internal void +show_gui_float(GUI_Target *target, String *string, + i32 indent_level, i32 h_align, char *message, float x){ + string->size = 0; + append_label(string, indent_level, message); + append_padding(string, '-', h_align); + append(string, ' '); + append_float_to_str(string, x); + gui_do_text_field(target, *string, string_zero()); +} + struct View_Step_Result{ b32 animating; b32 consume_keys; @@ -4483,11 +4556,13 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su } }break; -#if FRED_INTERNAL case VUI_Debug: { GUI_id scroll_context = {0}; - scroll_context.id[1] = VUI_Debug + ((u64)view->interaction << 32); + scroll_context.id[1] = VUI_Debug + ((u64)view->debug_vars.mode << 32); + + GUI_id id = {0}; + id.id[1] = VUI_Debug + ((u64)view->debug_vars.mode << 32); view->current_scroll = &view->gui_scroll; @@ -4517,24 +4592,24 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su } { - Debug_Mode prev_mode = view->debug_mode; + i32 prev_mode = view->debug_vars.mode; for (i32 i = 0; i < keys.count; ++i){ Key_Event_Data key = get_single_key(&keys, i); if (key.modifiers[MDFR_CONTROL_INDEX] == 0 && key.modifiers[MDFR_ALT_INDEX] == 0){ if (key.keycode == 'i'){ - view->debug_mode = DBG_Input; + view->debug_vars.mode = DBG_Input; } if (key.keycode == 'm'){ - view->debug_mode = DBG_Threads_And_Memory; + view->debug_vars.mode = DBG_Threads_And_Memory; } if (key.keycode == 'v'){ - view->debug_mode = DBG_View_Inspection; + view->debug_vars.mode = DBG_View_Inspection; } } } - if (prev_mode != view->debug_mode){ + if (prev_mode != view->debug_vars.mode){ result.consume_keys = 1; } } @@ -4542,7 +4617,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->line_height, show_scrollbar); - switch (view->debug_mode) + switch (view->debug_vars.mode) { case DBG_Input: { @@ -4688,37 +4763,132 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su case DBG_View_Inspection: { - Editing_Layout *layout = &models->layout; - Panel *panel, *sentinel; - sentinel = &layout->used_sentinel; - for (dll_items(panel, sentinel)){ - View *view = panel->view; + i32 inspecting_id = view->debug_vars.inspecting_view_id; + View *views_to_inspect[16]; + i32 view_count = 0; + b32 low_detail = true; + + if (inspecting_id == 0){ + Editing_Layout *layout = &models->layout; + + Panel *panel, *sentinel; + sentinel = &layout->used_sentinel; + for (dll_items(panel, sentinel)){ + View *view_ptr = panel->view; + views_to_inspect[view_count++] = view_ptr; + } + } + else if (inspecting_id >= 1 && inspecting_id <= 16){ + Live_Views *live_set = models->live_set; + View *view_ptr = live_set->views + inspecting_id - 1; + views_to_inspect[view_count++] = view_ptr; + low_detail = false; + } + + for (i32 i = 0; i < view_count; ++i){ + View *view_ptr = views_to_inspect[i]; + string.size = 0; append(&string, "view: "); - append_int_to_str(&string, view->persistent.id); + append_int_to_str(&string, view_ptr->persistent.id + 1); gui_do_text_field(target, string, empty_str); string.size = 0; - Editing_File *file = view->file_data.file; + Editing_File *file = view_ptr->file_data.file; append(&string, " > buffer: "); if (file){ append(&string, file->name.live_name); gui_do_text_field(target, string, empty_str); string.size = 0; - append(&string, " > buffer-slot-id: "); + append(&string, " >> buffer-slot-id: "); append_int_to_str(&string, file->id.id); } else{ append(&string, "*NULL*"); gui_do_text_field(target, string, empty_str); } + + if (low_detail){ + string.size = 0; + append(&string, "inspect this"); + + id.id[0] = (u64)(view_ptr->persistent.id); + if (gui_do_button(target, id, string)){ + view->debug_vars.inspecting_view_id = view_ptr->persistent.id + 1; + } + } + else{ + +#define SHOW_GUI_BLANK() gui_do_text_field(target, empty_str, empty_str) +#define SHOW_GUI_LINE(n, str) show_gui_line(target, &string, n, 0, " " str, 0); +#define SHOW_GUI_STRING(n, h, str, mes) show_gui_line(target, &string, n, h, " " str " ", mes); +#define SHOW_GUI_INT(n, h, str, v) show_gui_int(target, &string, n, h, " " str " ", v); +#define SHOW_GUI_INT_INT(n, h, str, v, m) show_gui_int_int(target, &string, n, h, " " str " ", v, m); +#define SHOW_GUI_FLOAT(n, h, str, v) show_gui_float(target, &string, n, h, " " str " ", v); +#define SHOW_GUI_BOOL(n, h, str, v) do { if (v) { show_gui_line(target, &string, n, h, " " str " ", "true"); }\ + else { show_gui_line(target, &string, n, h, " " str " ", "false"); } } while(false) + + i32 h_align = 31; + + SHOW_GUI_BLANK(); + { + Command_Map *map = view_ptr->map; + +#define MAP_LABEL "command map" + + if (map == &models->map_top){ + SHOW_GUI_STRING(1, h_align, MAP_LABEL, "global"); + } + else if (map == &models->map_file){ + SHOW_GUI_STRING(1, h_align, MAP_LABEL, "file"); + } + else if (map == &models->map_ui){ + SHOW_GUI_STRING(1, h_align, MAP_LABEL, "gui"); + } + else{ + i32 map_index = (i32)(view_ptr->map - models->user_maps); + i32 map_id = models->map_id_table[map_index]; + + SHOW_GUI_STRING(1, h_align, MAP_LABEL, "user"); + SHOW_GUI_INT(2, h_align, "custom map id", map_id); + } + } + + SHOW_GUI_BLANK(); + SHOW_GUI_LINE(1, "file data:"); + SHOW_GUI_BOOL(2, h_align, "has file", view_ptr->file_data.file); + SHOW_GUI_BOOL(2, h_align, "show temp highlight", view_ptr->file_data.show_temp_highlight); + SHOW_GUI_INT (2, h_align, "start temp highlight", view_ptr->file_data.temp_highlight.pos); + SHOW_GUI_INT (2, h_align, "end temp highlight", view_ptr->file_data.temp_highlight_end_pos); + SHOW_GUI_BOOL(2, h_align, "unwrapped lines", view_ptr->file_data.unwrapped_lines); + SHOW_GUI_BOOL(2, h_align, "show whitespace", view_ptr->file_data.show_whitespace); + SHOW_GUI_BOOL(2, h_align, "locked", view_ptr->file_data.file_locked); + SHOW_GUI_INT_INT(2, h_align, "line count", + view_ptr->file_data.line_count, + view_ptr->file_data.line_max); + + GUI_Scroll_Vars scroll = *view_ptr->current_scroll; + + SHOW_GUI_BLANK(); + SHOW_GUI_LINE(1, "current scroll:"); + SHOW_GUI_FLOAT(2, h_align, "scroll_y", scroll.scroll_y); + SHOW_GUI_FLOAT(2, h_align, "target_y", scroll.target_y); + SHOW_GUI_FLOAT(2, h_align, "prev_target_y", scroll.prev_target_y); + SHOW_GUI_FLOAT(2, h_align, "max_y", scroll.max_y); + + SHOW_GUI_FLOAT(2, h_align, "scroll_x", scroll.scroll_x); + SHOW_GUI_FLOAT(2, h_align, "target_x", scroll.target_x); + SHOW_GUI_FLOAT(2, h_align, "prev_target_x", scroll.prev_target_x); + + // TODO(allen): cursor + } } + }break; } gui_end_scrollable(target); }break; -#endif } } } @@ -5933,12 +6103,6 @@ view_change_size(General_Memory *general, View *view){ } } -struct Live_Views{ - View *views; - View free_sentinel; - i32 count, max; -}; - internal View_And_ID live_set_alloc_view(Live_Views *live_set, Panel *panel, Models *models){ View_And_ID result = {}; diff --git a/4ed_gui.cpp b/4ed_gui.cpp index 04fe91e2..96fbcb60 100644 --- a/4ed_gui.cpp +++ b/4ed_gui.cpp @@ -263,9 +263,15 @@ gui_update_position(GUI_Item_Update *update, i32_Rect position){ internal void* gui_push_item(GUI_Target *target, void *item, i32 size){ - void *dest = partition_allocate(&target->push, size); - if (dest && item){ - memcpy(dest, item, size); + void *dest = 0; + if (size == 0){ + dest = partition_current(&target->push); + } + else{ + dest = partition_allocate(&target->push, size); + if (dest && item){ + memcpy(dest, item, size); + } } return(dest); } diff --git a/TODO.txt b/TODO.txt index ed15ee12..956be7f9 100644 --- a/TODO.txt +++ b/TODO.txt @@ -102,6 +102,7 @@ ; [X] add high DPI support ; ; [] OS font rendering +; [] support full length unicode file names ; ; [] file status in custom API ; [] user file bar string