From 0be4680ec927c264f154a3dfa75ed6ae1c241362 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Sat, 3 Feb 2024 18:04:21 -0800 Subject: [PATCH] os_gfx -> report mouse move events; still allow passive mouse interaction if window is unfocused, but have recently received mousemove events --- src/df/gfx/df_gfx.c | 10 +++++++++- src/df/gfx/df_gfx.h | 1 + src/os/gfx/os_gfx.h | 1 + src/os/gfx/win32/os_gfx_win32.c | 7 +++++++ src/raddbg/raddbg.c | 8 ++++++++ src/ui/ui_core.c | 5 ++--- src/ui/ui_core.h | 2 +- 7 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/df/gfx/df_gfx.c b/src/df/gfx/df_gfx.c index c6485ea2..c3eee070 100644 --- a/src/df/gfx/df_gfx.c +++ b/src/df/gfx/df_gfx.c @@ -2881,8 +2881,16 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D icon_info.icon_kind_text_map[UI_IconKind_CheckFilled] = df_g_icon_kind_text_table[DF_IconKind_CheckFilled]; } + // rjf: form mouse position used for passive UI mouse interaction + Vec2F32 mouse_ui = os_mouse_from_window(ws->os); + if(!os_window_is_focused(ws->os) && + df_gfx_state->last_time_mousemoved_us+500000 <= os_now_microseconds()) + { + mouse_ui = v2f32(-100, -100); + } + // rjf: begin & push initial stack values - ui_begin_build(events, ws->os, &nav_actions, &icon_info, df_dt(), df_dt()); + ui_begin_build(events, mouse_ui, ws->os, &nav_actions, &icon_info, df_dt(), df_dt()); ui_push_font(main_font); ui_push_font_size(main_font_size); ui_push_pref_width(ui_em(20.f, 1)); diff --git a/src/df/gfx/df_gfx.h b/src/df/gfx/df_gfx.h index 09a5abb1..f145a192 100644 --- a/src/df/gfx/df_gfx.h +++ b/src/df/gfx/df_gfx.h @@ -689,6 +689,7 @@ struct DF_GfxState // rjf: frame request state U64 num_frames_requested; + U64 last_time_mousemoved_us; // rjf: history cache DF_StateDeltaHistory *hist; diff --git a/src/os/gfx/os_gfx.h b/src/os/gfx/os_gfx.h index 0eacd1c2..5237ff30 100644 --- a/src/os/gfx/os_gfx.h +++ b/src/os/gfx/os_gfx.h @@ -40,6 +40,7 @@ typedef enum OS_EventKind OS_EventKind_Null, OS_EventKind_Press, OS_EventKind_Release, + OS_EventKind_MouseMove, OS_EventKind_Text, OS_EventKind_Scroll, OS_EventKind_WindowLoseFocus, diff --git a/src/os/gfx/win32/os_gfx_win32.c b/src/os/gfx/win32/os_gfx_win32.c index 0ef4f561..e3463815 100644 --- a/src/os/gfx/win32/os_gfx_win32.c +++ b/src/os/gfx/win32/os_gfx_win32.c @@ -429,6 +429,13 @@ w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) } }break; + case WM_MOUSEMOVE: + { + OS_Event *event = w32_push_event(OS_EventKind_MouseMove, window); + event->pos.x = (F32)LOWORD(lParam); + event->pos.y = (F32)HIWORD(lParam); + }break; + case WM_MOUSEWHEEL: { S16 wheel_delta = HIWORD(wParam); diff --git a/src/raddbg/raddbg.c b/src/raddbg/raddbg.c index d8414795..1af26d46 100644 --- a/src/raddbg/raddbg.c +++ b/src/raddbg/raddbg.c @@ -69,6 +69,14 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data) OS_EventList new_events = os_get_events(scratch.arena, df_gfx_state->num_frames_requested == 0); os_event_list_concat_in_place(&events, &leftover_events_copy); os_event_list_concat_in_place(&events, &new_events); + for(OS_Event *e = events.first; e != 0; e = e->next) + { + if(e->kind == OS_EventKind_MouseMove) + { + df_gfx_state->last_time_mousemoved_us = os_now_microseconds(); + break; + } + } } //- rjf: enable txti change detection diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index 5f866bdb..83fad38c 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -631,7 +631,7 @@ ui_box_from_key(UI_Key key) //~ rjf: Top-Level Building API internal void -ui_begin_build(OS_EventList *events, OS_Handle window, UI_NavActionList *nav_actions, UI_IconInfo *icon_info, F32 real_dt, F32 animation_dt) +ui_begin_build(OS_EventList *events, Vec2F32 mouse, OS_Handle window, UI_NavActionList *nav_actions, UI_IconInfo *icon_info, F32 real_dt, F32 animation_dt) { //- rjf: reset per-build ui state { @@ -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_window_is_focused(window) ? os_mouse_from_window(window) : v2f32(-100, -100); + ui_state->mouse = mouse; ui_state->animation_dt = animation_dt; MemoryZeroStruct(&ui_state->icon_info); ui_state->icon_info.icon_font = icon_info->icon_font; @@ -922,7 +922,6 @@ ui_begin_build(OS_EventList *events, OS_Handle window, UI_NavActionList *nav_act } //- rjf: setup parent box for tooltip - Vec2F32 mouse = ui_state->mouse; UI_FixedX(mouse.x+15.f) UI_FixedY(mouse.y) UI_PrefWidth(ui_children_sum(1.f)) UI_PrefHeight(ui_children_sum(1.f)) { ui_set_next_child_layout_axis(Axis2_Y); diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index ffe1c33c..9069d703 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -560,7 +560,7 @@ internal UI_Box * ui_box_from_key(UI_Key key); //////////////////////////////// //~ rjf: Top-Level Building API -internal void ui_begin_build(OS_EventList *events, OS_Handle window, UI_NavActionList *nav_actions, UI_IconInfo *icon_info, F32 real_dt, F32 animation_dt); +internal void ui_begin_build(OS_EventList *events, Vec2F32 mouse, OS_Handle window, UI_NavActionList *nav_actions, UI_IconInfo *icon_info, F32 real_dt, F32 animation_dt); internal void ui_end_build(void); internal void ui_calc_sizes_standalone__in_place_rec(UI_Box *root, Axis2 axis); internal void ui_calc_sizes_upwards_dependent__in_place_rec(UI_Box *root, Axis2 axis);