separate ui mouse press reports by button

This commit is contained in:
jacob 2025-12-28 19:46:45 -06:00
parent 7b4edbdfbb
commit 6a418b8f9c
3 changed files with 54 additions and 35 deletions

View File

@ -122,7 +122,7 @@ V_CommandsWidgetItemReport V_PushCommandsWidgetItem(V_CommandsWidget *widget, V_
V_CommandsWidgetItemReport result = Zi; V_CommandsWidgetItemReport result = Zi;
UI_Report rep = UI_ReportFromKey(key); UI_Report rep = UI_ReportFromKey(key);
result.ui_report = rep; 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))); CopyStructs(result.new_hotkeys, desc.hotkeys, MinU32(countof(result.new_hotkeys), countof(desc.hotkeys)));
return result; return result;
} }
@ -142,9 +142,9 @@ void V_EndCommandsWidget(V_CommandsWidget *widget)
Vec4 divider_color = theme.divider_color; Vec4 divider_color = theme.divider_color;
{ {
UI_Report rep = UI_ReportFromKey(titlebar_key); 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, Rgb(0.5, 0.5, 0.5), rep.hot);
window_border_color = BlendSrgb(window_border_color, Rgb32(0x0078a6), 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) if (!window->is_viewport_window)
{ {
UI_Report rep = UI_ReportFromKey(window->key); UI_Report rep = UI_ReportFromKey(window->key);
if (rep.m1_downs > 0) if (rep.m1.downs > 0)
{ {
new_active_window_idx = window_idx; new_active_window_idx = window_idx;
} }
@ -1102,18 +1102,15 @@ void V_TickForever(WaveLaneCtx *lane)
UI_PopCP(UI_TopCP()); UI_PopCP(UI_TopCP());
} }
//- Build active window //- Build active window
if (active_window) if (active_window && !active_window->is_viewport_window)
{ {
V_Window *window = active_window; V_Window *window = active_window;
UI_SetNext(BackgroundColor, VEC4(0, 0, 0, 0.5)); UI_SetNext(BackgroundColor, VEC4(0, 0, 0, 0.5));
UI_SetNext(BorderColor, VEC4(0.5, 0.5, 0.5, 1)); UI_SetNext(BorderColor, VEC4(0.5, 0.5, 0.5, 1));
UI_SetNext(Border, 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(Width, UI_GROW(1, 0));
UI_SetNext(Height, UI_GROW(1, 0)); UI_SetNext(Height, UI_GROW(1, 0));
// UI_SetNext(Width, UI_SHRINK(0, 1)); UI_SetNext(Flags, UI_BoxFlag_Interactable);
// UI_SetNext(Height, UI_SHRINK(0, 1));
UI_PushCP(UI_BuildColumn()); UI_PushCP(UI_BuildColumn());
{ {
UI_Push(Tag, window->key.hash); 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_Key key = UI_KeyF("Tile %F", FmtString(name));
UI_Report rep = UI_ReportFromKey(key); UI_Report rep = UI_ReportFromKey(key);
if (rep.m1_downs) if (rep.m1.downs)
{ {
frame->equipped_tile = tile_kind; 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_SetNext(AxisSize, UI_PIX(10, 1), .axis = !panel->axis);
UI_BuildBoxEx(divider_key); UI_BuildBoxEx(divider_key);
if (rep.is_hot || rep.is_m1_held) if (rep.is_hot || rep.m1.held)
{ {
if (panel->axis == Axis_X) 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 panel_rep = UI_ReportFromKey(panel->key);
UI_Report parent_rep = UI_ReportFromKey(panel->parent->key); UI_Report parent_rep = UI_ReportFromKey(panel->parent->key);

View File

@ -680,9 +680,15 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color)
hovered_box = box; hovered_box = box;
} }
} }
box->report.m1_ups = 0; box->report.m1.ups = 0;
box->report.m1_downs = 0; box->report.m1.downs = 0;
box->report.m1_presses = 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 // Update state from controller events
@ -699,19 +705,21 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color)
{ {
if (hovered_box) if (hovered_box)
{ {
++hovered_box->report.m1_downs; hovered_box->report.last_down_mouse_offset = SubVec2(frame->cursor_pos, hovered_box->rect.p0);
hovered_box->report.last_m1_offset = SubVec2(frame->cursor_pos, hovered_box->rect.p0);
if (cev.button == Button_M1) 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) 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) 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; 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)
{ {
if (active_box == hovered_box) ++active_box->report.m1.ups;
{
++active_box->report.m1_presses;
}
++active_box->report.m1_ups;
if (cev.button == Button_M1) 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) 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) 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; active_box = 0;
} }

View File

@ -172,11 +172,16 @@ Struct(UI_Stack)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Report types //~ 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) Struct(UI_Report)
{ {
b32 is_m1_held;
b32 is_m2_held;
b32 is_m3_held;
b32 is_hovered; b32 is_hovered;
b32 is_hot; b32 is_hot;
@ -184,10 +189,11 @@ Struct(UI_Report)
f32 hot; f32 hot;
f32 active; f32 active;
i32 m1_downs; // Mouse button info
i32 m1_ups; Vec2 last_down_mouse_offset;
i32 m1_presses; UI_MouseReport m1;
Vec2 last_m1_offset; UI_MouseReport m2;
UI_MouseReport m3;
// Where was this box last rendered in screen coordinates // Where was this box last rendered in screen coordinates
Rng2 screen_rect; Rng2 screen_rect;