From 959550151ae8fdb9e9c6b05fb66fe678861c6219 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Tue, 23 Jan 2024 20:17:50 -0800 Subject: [PATCH] preserve per-event mouse coordinates; prefer in ui signal producing codepath --- src/os/gfx/os_gfx.h | 1 + src/os/gfx/win32/os_gfx_win32.c | 2 ++ src/ui/ui_core.c | 10 ++++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/os/gfx/os_gfx.h b/src/os/gfx/os_gfx.h index eb9f0209..57830c9e 100644 --- a/src/os/gfx/os_gfx.h +++ b/src/os/gfx/os_gfx.h @@ -71,6 +71,7 @@ struct OS_Event B32 right_sided; U32 character; U32 repeat_count; + Vec2F32 pos; Vec2F32 delta; String8List strings; }; diff --git a/src/os/gfx/win32/os_gfx_win32.c b/src/os/gfx/win32/os_gfx_win32.c index 1b8fb767..f81dc89e 100644 --- a/src/os/gfx/win32/os_gfx_win32.c +++ b/src/os/gfx/win32/os_gfx_win32.c @@ -416,6 +416,8 @@ w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) event->key = OS_Key_RightMouseButton; }break; } + event->pos.x = (F32)LOWORD(lParam); + event->pos.y = (F32)HIWORD(lParam); if(release) { ReleaseCapture(); diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index 60ab7020..73abb6a4 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -2215,8 +2215,6 @@ ui_signal_from_box(UI_Box *box) UI_Signal result = {0}; result.box = box; result.event_flags = os_get_event_flags(); - Vec2F32 mouse = ui_state->mouse; - B32 mouse_is_over = contains_2f32(box->rect, mouse); B32 disabled = !!(box->flags & UI_BoxFlag_Disabled); B32 is_focused = !!(box->flags & UI_BoxFlag_FocusHot) && !(box->flags & UI_BoxFlag_FocusHotDisabled); @@ -2248,6 +2246,14 @@ ui_signal_from_box(UI_Box *box) } } + //- rjf: unpack mouse position info + Vec2F32 mouse = ui_state->mouse; + if(left_press != 0) { mouse = left_press->pos; } + if(left_release != 0) { mouse = left_release->pos; } + if(right_press != 0) { mouse = right_press->pos; } + if(right_release != 0) { mouse = right_release->pos; } + B32 mouse_is_over = contains_2f32(box->rect, mouse); + //- rjf: check for parent that is clipping if(box->flags & (UI_BoxFlag_Clickable|UI_BoxFlag_ViewScroll) && mouse_is_over) {