From d139c2874cbc75fa0ebddeb53be1d88002f83812 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Tue, 30 Jan 2024 09:14:59 -0800 Subject: [PATCH] add optional command spec restriction to cmd param slot -> view spec table; eliminate mouse testing when windows are not focused --- src/df/gfx/df_gfx.c | 31 ++++++++++++++++++++++-------- src/df/gfx/df_gfx.h | 22 ++++++++++++++++++--- src/df/gfx/df_gfx.mdesk | 21 +++++++++++++------- src/df/gfx/generated/df_gfx.meta.h | 13 +++++++++++++ src/ui/ui_core.c | 2 +- 5 files changed, 70 insertions(+), 19 deletions(-) diff --git a/src/df/gfx/df_gfx.c b/src/df/gfx/df_gfx.c index 538a5e75..55b6923b 100644 --- a/src/df/gfx/df_gfx.c +++ b/src/df/gfx/df_gfx.c @@ -647,12 +647,21 @@ df_view_spec_from_gfx_view_kind(DF_GfxViewKind gfx_view_kind) } internal DF_ViewSpec * -df_view_spec_from_cmd_param_slot(DF_CmdParamSlot slot) +df_view_spec_from_cmd_param_slot_spec(DF_CmdParamSlot slot, DF_CmdSpec *cmd_spec) { - DF_ViewSpec *spec = df_gfx_state->cmd_param_slot_view_spec_table[slot]; - if(spec == 0) + DF_ViewSpec *spec = &df_g_nil_view_spec; + for(DF_CmdParamSlotViewSpecRuleNode *n = df_gfx_state->cmd_param_slot_view_spec_table[slot].first; + n != 0; + n = n->next) { - spec = &df_g_nil_view_spec; + if(cmd_spec == n->cmd_spec || df_cmd_spec_is_nil(n->cmd_spec)) + { + spec = n->view_spec; + if(!df_cmd_spec_is_nil(n->cmd_spec)) + { + break; + } + } } return spec; } @@ -5018,7 +5027,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D { DF_CmdSpec *cmd_spec = ws->query_cmd_spec; DF_CmdParamSlot first_missing_slot = cmd_spec->info.query.slot; - DF_ViewSpec *view_spec = df_view_spec_from_cmd_param_slot(first_missing_slot); + DF_ViewSpec *view_spec = df_view_spec_from_cmd_param_slot_spec(first_missing_slot, cmd_spec); if(ws->query_view_stack_top->spec != view_spec || df_view_is_nil(ws->query_view_stack_top)) { @@ -5766,7 +5775,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D // rjf: more precise drop-sites on tab bar { - Vec2F32 mouse = os_mouse_from_window(ws->os); + Vec2F32 mouse = ui_mouse(); DF_View *view = df_view_from_handle(df_g_drag_drop_payload.view); if(df_drag_is_active() && window_is_focused && contains_2f32(panel_rect, mouse) && !df_view_is_nil(view)) { @@ -5842,7 +5851,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D ////////////////////////// //- rjf: less granular panel for tabs & entities drop-site // - if(df_drag_is_active() && window_is_focused && contains_2f32(panel_rect, os_mouse_from_window(ws->os))) + if(df_drag_is_active() && window_is_focused && contains_2f32(panel_rect, ui_mouse())) { DF_DragDropPayload *payload = &df_g_drag_drop_payload; DF_View *dragged_view = df_view_from_handle(payload->view); @@ -10865,8 +10874,14 @@ df_gfx_init(OS_WindowRepaintFunctionType *window_repaint_entry_point, DF_StateDe { DF_CmdParamSlot slot = df_g_cmd_param_slot_2_view_spec_src_map[idx]; String8 view_spec_name = df_g_cmd_param_slot_2_view_spec_dst_map[idx]; + String8 cmd_spec_name = df_g_cmd_param_slot_2_view_spec_cmd_map[idx]; DF_ViewSpec *view_spec = df_view_spec_from_string(view_spec_name); - df_gfx_state->cmd_param_slot_view_spec_table[slot] = view_spec; + DF_CmdSpec *cmd_spec = cmd_spec_name.size != 0 ? df_cmd_spec_from_string(cmd_spec_name) : &df_g_nil_cmd_spec; + DF_CmdParamSlotViewSpecRuleNode *n = push_array(df_gfx_state->arena, DF_CmdParamSlotViewSpecRuleNode, 1); + n->view_spec = view_spec; + n->cmd_spec = cmd_spec; + SLLQueuePush(df_gfx_state->cmd_param_slot_view_spec_table[slot].first, df_gfx_state->cmd_param_slot_view_spec_table[slot].last, n); + df_gfx_state->cmd_param_slot_view_spec_table[slot].count += 1; } } diff --git a/src/df/gfx/df_gfx.h b/src/df/gfx/df_gfx.h index ea2baaa9..4086fa7f 100644 --- a/src/df/gfx/df_gfx.h +++ b/src/df/gfx/df_gfx.h @@ -197,6 +197,22 @@ struct DF_ViewSpecInfoArray U64 count; }; +typedef struct DF_CmdParamSlotViewSpecRuleNode DF_CmdParamSlotViewSpecRuleNode; +struct DF_CmdParamSlotViewSpecRuleNode +{ + DF_CmdParamSlotViewSpecRuleNode *next; + DF_ViewSpec *view_spec; + DF_CmdSpec *cmd_spec; +}; + +typedef struct DF_CmdParamSlotViewSpecRuleList DF_CmdParamSlotViewSpecRuleList; +struct DF_CmdParamSlotViewSpecRuleList +{ + DF_CmdParamSlotViewSpecRuleNode *first; + DF_CmdParamSlotViewSpecRuleNode *last; + U64 count; +}; + //////////////////////////////// //~ rjf: View Types @@ -709,8 +725,8 @@ struct DF_GfxState DF_ViewRuleBlockSlot *view_rule_block_slots; DF_ViewRuleBlockNode *free_view_rule_block_node; - // rjf: cmd param slot -> view spec table - DF_ViewSpec *cmd_param_slot_view_spec_table[DF_CmdParamSlot_COUNT]; + // rjf: cmd param slot -> view spec rule table + DF_CmdParamSlotViewSpecRuleList cmd_param_slot_view_spec_table[DF_CmdParamSlot_COUNT]; // rjf: windows OS_WindowRepaintFunctionType *repaint_hook; @@ -891,7 +907,7 @@ internal U64 df_get_hovered_line_info_voff(void); internal void df_register_view_specs(DF_ViewSpecInfoArray specs); internal DF_ViewSpec *df_view_spec_from_string(String8 string); internal DF_ViewSpec *df_view_spec_from_gfx_view_kind(DF_GfxViewKind gfx_view_kind); -internal DF_ViewSpec *df_view_spec_from_cmd_param_slot(DF_CmdParamSlot slot); +internal DF_ViewSpec *df_view_spec_from_cmd_param_slot_spec(DF_CmdParamSlot slot, DF_CmdSpec *cmd_spec); //////////////////////////////// //~ rjf: View Rule Spec State Functions diff --git a/src/df/gfx/df_gfx.mdesk b/src/df/gfx/df_gfx.mdesk index 8470c18f..c9cc8433 100644 --- a/src/df/gfx/df_gfx.mdesk +++ b/src/df/gfx/df_gfx.mdesk @@ -274,15 +274,16 @@ DF_CmdSpec2ViewSpecMap: //////////////////////////////// //~ rjf: Command Parameter Slot -> View -@table(slot view_spec) +@table(slot view_spec opt_cmd_spec) DF_CmdParamSlot2ViewSpecMap: { - {Entity "entity_lister" } - {EntityList "entity_lister" } - {FilePath "file_system" } - {CmdSpec "commands" } - {ID "system_processes" } - {String "symbol_lister" } + {Entity "entity_lister" "" } + {EntityList "entity_lister" "" } + {FilePath "file_system" "" } + {CmdSpec "commands" "" } + {ID "system_processes" "" } + {String "symbol_lister" "goto_name" } + {String "symbol_lister" "function_breakpoint" } } //////////////////////////////// @@ -585,6 +586,12 @@ df_g_cmd_param_slot_2_view_spec_dst_map: @expand(DF_CmdParamSlot2ViewSpecMap a) `str8_lit_comp("$(a.view_spec)"),` } +@table_gen_data(type: String8, fallback:`{0}`) +df_g_cmd_param_slot_2_view_spec_cmd_map: +{ + @expand(DF_CmdParamSlot2ViewSpecMap a) `str8_lit_comp("$(a.opt_cmd_spec)"),` +} + //- rjf: default bindings table @table_gen_data(type: DF_StringBindingPair, fallback: `{0}`) diff --git a/src/df/gfx/generated/df_gfx.meta.h b/src/df/gfx/generated/df_gfx.meta.h index 4323645b..9935a75a 100644 --- a/src/df/gfx/generated/df_gfx.meta.h +++ b/src/df/gfx/generated/df_gfx.meta.h @@ -905,6 +905,7 @@ DF_CmdParamSlot_FilePath, DF_CmdParamSlot_CmdSpec, DF_CmdParamSlot_ID, DF_CmdParamSlot_String, +DF_CmdParamSlot_String, }; String8 df_g_cmd_param_slot_2_view_spec_dst_map[] = @@ -915,6 +916,18 @@ str8_lit_comp("file_system"), str8_lit_comp("commands"), str8_lit_comp("system_processes"), str8_lit_comp("symbol_lister"), +str8_lit_comp("symbol_lister"), +}; + +String8 df_g_cmd_param_slot_2_view_spec_cmd_map[] = +{ +str8_lit_comp(""), +str8_lit_comp(""), +str8_lit_comp(""), +str8_lit_comp(""), +str8_lit_comp(""), +str8_lit_comp("goto_name"), +str8_lit_comp("function_breakpoint"), }; DF_StringBindingPair df_g_default_binding_table[] = diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index 7e66044f..9c93ec6d 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -651,7 +651,7 @@ ui_begin_build(OS_EventList *events, OS_Handle window, UI_NavActionList *nav_act ui_state->events = events; ui_state->window = window; ui_state->nav_actions = nav_actions; - ui_state->mouse = os_mouse_from_window(window); + ui_state->mouse = os_window_is_focused(window) ? os_mouse_from_window(window) : v2f32(-100, -100); ui_state->animation_dt = animation_dt; MemoryZeroStruct(&ui_state->icon_info); ui_state->icon_info.icon_font = icon_info->icon_font;