From 6a418b8f9cd32652dcbc82b0b9fb7d46cfbf64a0 Mon Sep 17 00:00:00 2001 From: jacob Date: Sun, 28 Dec 2025 19:46:45 -0600 Subject: [PATCH] separate ui mouse press reports by button --- src/pp/pp_vis/pp_vis_core.c | 21 +++++++--------- src/ui/ui_core.c | 48 ++++++++++++++++++++++++------------- src/ui/ui_core.h | 20 ++++++++++------ 3 files changed, 54 insertions(+), 35 deletions(-) diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index 0e7a1167..daf767e9 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -122,7 +122,7 @@ V_CommandsWidgetItemReport V_PushCommandsWidgetItem(V_CommandsWidget *widget, V_ V_CommandsWidgetItemReport result = Zi; UI_Report rep = UI_ReportFromKey(key); result.ui_report = rep; - result.pressed = rep.m1_presses > 0; + result.pressed = rep.m1.presses > 0; CopyStructs(result.new_hotkeys, desc.hotkeys, MinU32(countof(result.new_hotkeys), countof(desc.hotkeys))); return result; } @@ -142,9 +142,9 @@ void V_EndCommandsWidget(V_CommandsWidget *widget) Vec4 divider_color = theme.divider_color; { UI_Report rep = UI_ReportFromKey(titlebar_key); - if (rep.is_m1_held) + if (rep.m1.held) { - widget->pos = SubVec2(cursor_pos, rep.last_m1_offset); + widget->pos = SubVec2(cursor_pos, rep.last_down_mouse_offset); } // window_border_color = BlendSrgb(window_border_color, Rgb(0.5, 0.5, 0.5), rep.hot); window_border_color = BlendSrgb(window_border_color, Rgb32(0x0078a6), rep.hot); @@ -1045,7 +1045,7 @@ void V_TickForever(WaveLaneCtx *lane) if (!window->is_viewport_window) { UI_Report rep = UI_ReportFromKey(window->key); - if (rep.m1_downs > 0) + if (rep.m1.downs > 0) { new_active_window_idx = window_idx; } @@ -1102,18 +1102,15 @@ void V_TickForever(WaveLaneCtx *lane) UI_PopCP(UI_TopCP()); } //- Build active window - if (active_window) + if (active_window && !active_window->is_viewport_window) { V_Window *window = active_window; UI_SetNext(BackgroundColor, VEC4(0, 0, 0, 0.5)); UI_SetNext(BorderColor, VEC4(0.5, 0.5, 0.5, 1)); UI_SetNext(Border, 1); - // UI_SetNext(Width, UI_PIX(100, 1)); - // UI_SetNext(Height, UI_PIX(100, 1)); UI_SetNext(Width, UI_GROW(1, 0)); UI_SetNext(Height, UI_GROW(1, 0)); - // UI_SetNext(Width, UI_SHRINK(0, 1)); - // UI_SetNext(Height, UI_SHRINK(0, 1)); + UI_SetNext(Flags, UI_BoxFlag_Interactable); UI_PushCP(UI_BuildColumn()); { UI_Push(Tag, window->key.hash); @@ -1125,7 +1122,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_Key key = UI_KeyF("Tile %F", FmtString(name)); UI_Report rep = UI_ReportFromKey(key); - if (rep.m1_downs) + if (rep.m1.downs) { frame->equipped_tile = tile_kind; } @@ -1191,7 +1188,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(AxisSize, UI_PIX(10, 1), .axis = !panel->axis); UI_BuildBoxEx(divider_key); - if (rep.is_hot || rep.is_m1_held) + if (rep.is_hot || rep.m1.held) { if (panel->axis == Axis_X) { @@ -1203,7 +1200,7 @@ void V_TickForever(WaveLaneCtx *lane) } } - if (rep.is_m1_held) + if (rep.m1.held) { UI_Report panel_rep = UI_ReportFromKey(panel->key); UI_Report parent_rep = UI_ReportFromKey(panel->parent->key); diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index edb8b696..a0d236ae 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -680,9 +680,15 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color) hovered_box = box; } } - box->report.m1_ups = 0; - box->report.m1_downs = 0; - box->report.m1_presses = 0; + box->report.m1.ups = 0; + box->report.m1.downs = 0; + box->report.m1.presses = 0; + box->report.m2.ups = 0; + box->report.m2.downs = 0; + box->report.m2.presses = 0; + box->report.m3.ups = 0; + box->report.m3.downs = 0; + box->report.m3.presses = 0; } // Update state from controller events @@ -699,19 +705,21 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color) { if (hovered_box) { - ++hovered_box->report.m1_downs; - hovered_box->report.last_m1_offset = SubVec2(frame->cursor_pos, hovered_box->rect.p0); + hovered_box->report.last_down_mouse_offset = SubVec2(frame->cursor_pos, hovered_box->rect.p0); if (cev.button == Button_M1) { - hovered_box->report.is_m1_held = 1; + ++hovered_box->report.m1.downs; + hovered_box->report.m1.held = 1; } else if (cev.button == Button_M2) { - hovered_box->report.is_m2_held = 1; + ++hovered_box->report.m2.downs; + hovered_box->report.m2.held = 1; } else if (cev.button == Button_M3) { - hovered_box->report.is_m3_held = 1; + ++hovered_box->report.m3.downs; + hovered_box->report.m3.held = 1; } active_box = hovered_box; } @@ -724,22 +732,30 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color) { if (active_box) { - if (active_box == hovered_box) - { - ++active_box->report.m1_presses; - } - ++active_box->report.m1_ups; + ++active_box->report.m1.ups; if (cev.button == Button_M1) { - active_box->report.is_m1_held = 0; + if (active_box == hovered_box) + { + ++active_box->report.m1.presses; + } + active_box->report.m1.held = 0; } else if (cev.button == Button_M2) { - active_box->report.is_m2_held = 0; + if (active_box == hovered_box) + { + ++active_box->report.m2.presses; + } + active_box->report.m2.held = 0; } else if (cev.button == Button_M3) { - active_box->report.is_m3_held = 0; + if (active_box == hovered_box) + { + ++active_box->report.m3.presses; + } + active_box->report.m3.held = 0; } active_box = 0; } diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index 98be896e..9eca065e 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -172,11 +172,16 @@ Struct(UI_Stack) //////////////////////////////////////////////////////////// //~ Report types +Struct(UI_MouseReport) +{ + b32 held; + i32 downs; // Mouse button down events over box causing activation + i32 ups; // Mouse button up events while box is active + i32 presses; // Mouse button events while box is active and hovered +}; + Struct(UI_Report) { - b32 is_m1_held; - b32 is_m2_held; - b32 is_m3_held; b32 is_hovered; b32 is_hot; @@ -184,10 +189,11 @@ Struct(UI_Report) f32 hot; f32 active; - i32 m1_downs; - i32 m1_ups; - i32 m1_presses; - Vec2 last_m1_offset; + // Mouse button info + Vec2 last_down_mouse_offset; + UI_MouseReport m1; + UI_MouseReport m2; + UI_MouseReport m3; // Where was this box last rendered in screen coordinates Rng2 screen_rect;