From f2c74cbcb2d1565709d9c1e84f00e9dee7847757 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Mon, 5 Feb 2024 09:29:50 -0800 Subject: [PATCH] float mousemove detection & ui mouse position rules down to ui core layer --- src/df/gfx/df_gfx.c | 10 +--------- src/df/gfx/df_gfx.h | 1 - src/raddbg/raddbg.c | 8 -------- src/ui/ui_core.c | 15 ++++++++++++--- src/ui/ui_core.h | 3 ++- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/df/gfx/df_gfx.c b/src/df/gfx/df_gfx.c index c3eee070..c6485ea2 100644 --- a/src/df/gfx/df_gfx.c +++ b/src/df/gfx/df_gfx.c @@ -2881,16 +2881,8 @@ 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, mouse_ui, ws->os, &nav_actions, &icon_info, df_dt(), df_dt()); + ui_begin_build(events, 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 f145a192..09a5abb1 100644 --- a/src/df/gfx/df_gfx.h +++ b/src/df/gfx/df_gfx.h @@ -689,7 +689,6 @@ 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/raddbg/raddbg.c b/src/raddbg/raddbg.c index 1af26d46..d8414795 100644 --- a/src/raddbg/raddbg.c +++ b/src/raddbg/raddbg.c @@ -69,14 +69,6 @@ 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 83fad38c..1dea3a7a 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, Vec2F32 mouse, OS_Handle window, UI_NavActionList *nav_actions, UI_IconInfo *icon_info, F32 real_dt, F32 animation_dt) +ui_begin_build(OS_EventList *events, OS_Handle window, UI_NavActionList *nav_actions, UI_IconInfo *icon_info, F32 real_dt, F32 animation_dt) { //- rjf: reset per-build ui state { @@ -646,12 +646,21 @@ ui_begin_build(OS_EventList *events, Vec2F32 mouse, OS_Handle window, UI_NavActi ui_state->ctx_menu_changed = 0; } + //- rjf: detect mouse-moves + for(OS_Event *e = events->first; e != 0; e = e->next) + { + if(e->kind == OS_EventKind_MouseMove && os_handle_match(e->window, window)) + { + ui_state->last_time_mousemoved_us = os_now_microseconds(); + } + } + //- rjf: fill build phase parameters { ui_state->events = events; ui_state->window = window; ui_state->nav_actions = nav_actions; - ui_state->mouse = mouse; + ui_state->mouse = (os_window_is_focused(window) || ui_state->last_time_mousemoved_us+500000 >= os_now_microseconds()) ? 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; @@ -922,7 +931,7 @@ ui_begin_build(OS_EventList *events, Vec2F32 mouse, OS_Handle window, UI_NavActi } //- rjf: setup parent box for tooltip - 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_FixedX(ui_state->mouse.x+15.f) UI_FixedY(ui_state->mouse.y) UI_PrefWidth(ui_children_sum(1.f)) UI_PrefHeight(ui_children_sum(1.f)) { ui_set_next_child_layout_axis(Axis2_Y); ui_state->tooltip_root = ui_build_box_from_stringf(0, "###tooltip_%I64x", window.u64[0]); diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index 9069d703..1eff61f2 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -426,6 +426,7 @@ struct UI_State D_FancyRunList string_hover_fancy_runs; U64 string_hover_begin_us; U64 string_hover_build_index; + U64 last_time_mousemoved_us; //- rjf: tooltip state F32 tooltip_open_t; @@ -560,7 +561,7 @@ internal UI_Box * ui_box_from_key(UI_Key key); //////////////////////////////// //~ rjf: Top-Level Building API -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_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_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);