From 0075263e2fd513f46fe5da360a78b30afc978082 Mon Sep 17 00:00:00 2001 From: jacob Date: Fri, 19 Dec 2025 20:11:32 -0600 Subject: [PATCH] working horizontal panel drag --- src/platform/platform_win32/platform_win32.h | 25 ---------- src/pp/pp_vis/pp_vis_core.c | 51 +++++++++++++------- src/pp/pp_vis/pp_vis_core.h | 2 + src/window/window.h | 20 ++++++++ src/window/window_win32/window_win32.c | 41 ++++++++++++++++ src/window/window_win32/window_win32.h | 8 +++ 6 files changed, 104 insertions(+), 43 deletions(-) diff --git a/src/platform/platform_win32/platform_win32.h b/src/platform/platform_win32/platform_win32.h index 279cf519..7a7cc86f 100644 --- a/src/platform/platform_win32/platform_win32.h +++ b/src/platform/platform_win32/platform_win32.h @@ -1,28 +1,3 @@ -//////////////////////////////////////////////////////////// -//~ Win32 libs - -#pragma warning(push, 0) - #include - #include - #include - #include - #include - #include - #include - #include - #include -#pragma warning(pop) - -#pragma comment(lib, "kernel32") -#pragma comment(lib, "user32") -#pragma comment(lib, "shell32") -#pragma comment(lib, "ole32") -#pragma comment(lib, "winmm") -#pragma comment(lib, "dwmapi") -#pragma comment(lib, "synchronization") -#pragma comment(lib, "avrt") -#pragma comment(lib, "ws2_32.lib") - //////////////////////////////////////////////////////////// //~ Watch types diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index 04c7607f..5d0fabd6 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -501,6 +501,7 @@ void V_TickForever(WaveLaneCtx *lane) ui_frame_flags |= UI_FrameFlag_Vsync * !!VSYNC; UI_Frame *ui_frame = UI_BeginFrame(ui_frame_flags, swapchain_color); WND_Frame window_frame = ui_frame->window_frame; + WND_PushCmd(window_frame, .kind = WND_CmdKind_SetCursor, .cursor = WND_CursorKind_Default); /* Restore window */ { @@ -896,23 +897,44 @@ void V_TickForever(WaveLaneCtx *lane) panel_dfs->visited = 1; /* Push children to dfs stack */ - f32 ratio_accum = 0; + V_Panel *ratio_diff_panel = 0; for (V_Panel *child = panel->last; child; child = child->prev) { PanelDfsNode *n = PushStruct(frame->arena, PanelDfsNode); - ratio_accum += child->pref_ratio; n->panel = child; SllStackPush(first_panel_dfs, n); + if (child->pref_ratio_diff != 0) + { + ratio_diff_panel = child; + } + } + + /* Apply ratio diff */ + if (ratio_diff_panel) + { + f32 min_ratio = 0.05; + f32 ratio_diff = ratio_diff_panel->pref_ratio_diff; + { + ratio_diff += MaxF32(min_ratio - (ratio_diff_panel->pref_ratio + ratio_diff), 0); + ratio_diff -= MaxF32(min_ratio - (ratio_diff_panel->next->pref_ratio - ratio_diff), 0); + } + ratio_diff_panel->next->pref_ratio -= ratio_diff; + ratio_diff_panel->pref_ratio += ratio_diff; + ratio_diff_panel->pref_ratio_diff = 0; } /* Constrain child raitos */ + f32 ratio_accum = 0; + for (V_Panel *child = panel->last; child; child = child->prev) + { + child->pref_ratio = MaxF32(child->pref_ratio, 0.01); + ratio_accum += child->pref_ratio; + } for (V_Panel *child = panel->last; child; child = child->prev) { child->pref_ratio += (1.0 - ratio_accum) / panel->count; - // child->pref_ratio = MaxF32(child->pref_ratio, 0.01); } - UI_SetNext(AxisSize, UI_GROW(panel->pref_ratio, 0), .axis = !panel->axis); UI_SetNext(AxisSize, UI_GROW(1, 0), .axis = panel->axis); if (panel->axis == Axis_X) @@ -1053,9 +1075,13 @@ void V_TickForever(WaveLaneCtx *lane) // UI_SetNext(Border, 2); UI_SetNext(AxisSize, UI_GROW(1, 1), .axis = panel->axis); UI_SetNext(AxisSize, UI_PIX(3, 1), .axis = !panel->axis); - /* FIXME: Non-transient key */ UI_BuildBoxEx(divider_key); + if (rep.is_hovered) + { + WND_PushCmd(window_frame, .kind = WND_CmdKind_SetCursor, WND_CursorKind_HorizontalResize); + } + if (rep.is_m1_held) { UI_Report panel_rep = UI_ReportFromKey(panel->key); @@ -1065,20 +1091,9 @@ void V_TickForever(WaveLaneCtx *lane) f32 parent_width = DimsFromRng2(parent_rep.screen_rect).x; f32 old_ratio = panel->pref_ratio; - // f32 new_ratio = MaxF32((frame->ui_cursor.x - panel_rep.screen_rect.p0.x) / parent_width, 0.01); - f32 new_ratio = MaxF32(frame->ui_cursor.x - panel_rep.screen_rect.p0.x, 20) / parent_width; + f32 new_ratio = (frame->ui_cursor.x - panel_rep.screen_rect.p0.x) / parent_width; f32 ratio_diff = new_ratio - old_ratio; - panel->pref_ratio = new_ratio; - - if (ratio_diff > 0.1) - { - DEBUGBREAKABLE; - } - - if (panel->next) - { - panel->next->pref_ratio -= ratio_diff; - } + panel->pref_ratio_diff = ratio_diff; } } diff --git a/src/pp/pp_vis/pp_vis_core.h b/src/pp/pp_vis/pp_vis_core.h index 3ef0227c..5ddf1037 100644 --- a/src/pp/pp_vis/pp_vis_core.h +++ b/src/pp/pp_vis/pp_vis_core.h @@ -161,6 +161,8 @@ Struct(V_Panel) UI_Key key; f32 pref_ratio; + f32 pref_ratio_diff; + Axis axis; b32 is_organizing_panel; diff --git a/src/window/window.h b/src/window/window.h index f4c45f2e..2b8fb359 100644 --- a/src/window/window.h +++ b/src/window/window.h @@ -6,6 +6,24 @@ Struct(WND_Handle) u64 v; }; +//////////////////////////////////////////////////////////// +//~ Cursor types + +Enum(WND_CursorKind) +{ + WND_CursorKind_Default, + WND_CursorKind_Text, + WND_CursorKind_No, + WND_CursorKind_Hand, + WND_CursorKind_Move, + WND_CursorKind_HorizontalResize, + WND_CursorKind_VerticalResize, + WND_CursorKind_TlBrResize, + WND_CursorKind_TrBlResize, + + WND_CursorKind_Count +}; + //////////////////////////////////////////////////////////// //~ Cmd types @@ -16,12 +34,14 @@ Enum(WND_CmdKind) WND_CmdKind_SetMaximized, WND_CmdKind_SetFullscreen, WND_CmdKind_SetForcedTop, + WND_CmdKind_SetCursor, WND_CmdKind_Restore, }; Struct(WND_Cmd) { WND_CmdKind kind; + WND_CursorKind cursor; String restore; b32 v; }; diff --git a/src/window/window_win32/window_win32.c b/src/window/window_win32/window_win32.c index d65249e5..6cf35a1c 100644 --- a/src/window/window_win32/window_win32.c +++ b/src/window/window_win32/window_win32.c @@ -52,6 +52,23 @@ void WND_Bootstrap(void) g->vk_to_button[VK_OEM_1] = Button_Semicolon; } + //- Initialize cursors + { + HCURSOR arrow = LoadCursor(0, IDC_ARROW); + for (u64 cursor_idx = 0; cursor_idx < countof(g->cursors); ++cursor_idx) + { + g->cursors[cursor_idx] = arrow; + } + g->cursors[WND_CursorKind_Text] = LoadCursor(0, IDC_IBEAM); + g->cursors[WND_CursorKind_No] = LoadCursor(0, IDC_NO); + g->cursors[WND_CursorKind_Hand] = LoadCursor(0, IDC_HAND); + g->cursors[WND_CursorKind_Move] = LoadCursor(0, IDC_SIZEALL); + g->cursors[WND_CursorKind_HorizontalResize] = LoadCursor(0, IDC_SIZEWE); + g->cursors[WND_CursorKind_VerticalResize] = LoadCursor(0, IDC_SIZENS); + g->cursors[WND_CursorKind_TlBrResize] = LoadCursor(0, IDC_SIZENWSE); + g->cursors[WND_CursorKind_TrBlResize] = LoadCursor(0, IDC_SIZENESW); + } + //- Create window class { HMODULE instance = GetModuleHandle(0); @@ -200,6 +217,20 @@ LRESULT CALLBACK WND_W32_WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM l WND_W32_PushEvent(window, (ControllerEvent) { .kind = ControllerEventKind_Quit }); } break; + //- Cursor kind + + case WM_SETCURSOR: + { + /* FIXME */ + HCURSOR new_cursor = (HCURSOR)Atomic64Fetch(&window->new_cursor); + if (new_cursor != window->active_cursor) + { + SetCursor(new_cursor); + window->active_cursor = new_cursor; + result = 1; + } + } break; + //- Keyboard button case WM_SYSKEYUP: case WM_SYSKEYDOWN: @@ -535,6 +566,7 @@ void WND_EndFrame(WND_Frame frame, i32 vsync) /* Process cmds */ b32 was_restored = 0; + WND_CursorKind new_cursor = (WND_CursorKind)Atomic64Fetch(&window->new_cursor); for (WND_W32_CmdNode *n = window->first_cmd; n; n = n->next) { WND_Cmd cmd = n->cmd; @@ -604,6 +636,12 @@ void WND_EndFrame(WND_Frame frame, i32 vsync) SetWindowPos(hwnd, window->is_forced_top ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } break; + //- Cursor + case WND_CmdKind_SetCursor: + { + new_cursor = cmd.cursor; + } break; + //- Restore case WND_CmdKind_Restore: { @@ -664,6 +702,9 @@ void WND_EndFrame(WND_Frame frame, i32 vsync) BringWindowToTop(hwnd); } + /* Set cursor */ + Atomic64Set(&window->new_cursor, (u64)g->cursors[new_cursor]); + /* Commit backbuffer */ G_CommitBackbuffer(frame.backbuffer, vsync); diff --git a/src/window/window_win32/window_win32.h b/src/window/window_win32/window_win32.h index 8e5d7f8c..cc5ae470 100644 --- a/src/window/window_win32/window_win32.h +++ b/src/window/window_win32/window_win32.h @@ -10,6 +10,7 @@ Struct(WND_W32_Window) /* Window proc state */ u16 previous_utf16_high_surrogate; + HCURSOR active_cursor; /* User state */ Arena *frame_arena; @@ -23,6 +24,9 @@ Struct(WND_W32_Window) /* Window proc -> User */ TicketMutex w2u_tm; Arena *w2u_events_arena; + + /* User -> Window proc */ + Atomic64 new_cursor; }; //////////////////////////////////////////////////////////// @@ -66,7 +70,11 @@ Struct(WND_W32_CmdNode) Struct(WND_W32_SharedState) { Button vk_to_button[256]; + + HCURSOR cursors[WND_CursorKind_Count]; + WNDCLASSEXW window_class; + WND_W32_Window window; /* Single-window for now */ } extern WND_W32_shared_state;