diff options
| author | nathan <nathansmith@disroot.org> | 2025-11-05 14:39:05 +0000 |
|---|---|---|
| committer | nathan <nathansmith@disroot.org> | 2025-11-05 14:39:05 +0000 |
| commit | 754fc059c3a6b3a1bc204f87d58152dbb65b2abe (patch) | |
| tree | f464751fe4a9c168eb3928009dd530a9b0dcfd6f /src | |
| parent | 2769ba6929b8aff2eadbb6c2e66ef4db25332e9b (diff) | |
| download | FindThings-754fc059c3a6b3a1bc204f87d58152dbb65b2abe.tar.gz FindThings-754fc059c3a6b3a1bc204f87d58152dbb65b2abe.tar.bz2 FindThings-754fc059c3a6b3a1bc204f87d58152dbb65b2abe.zip | |
UGGGG I will have to test this shit
Diffstat (limited to 'src')
| -rw-r--r-- | src/utils.c | 133 | ||||
| -rw-r--r-- | src/utils.h | 2 |
2 files changed, 134 insertions, 1 deletions
diff --git a/src/utils.c b/src/utils.c index e8e99cf..0a17a05 100644 --- a/src/utils.c +++ b/src/utils.c @@ -43,6 +43,139 @@ void updateFloatWindow(FloatingWindow* window, const char* title) #ifndef RAYGUI_WINDOW_CLOSEBUTTON_SIZE #define RAYGUI_WINDOW_CLOSEBUTTON_SIZE 18 #endif + + int closeTitleSizeDeltaHalf = (RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT - + RAYGUI_WINDOW_CLOSEBUTTON_SIZE) / 2; + + // Window movement and resize collision check. + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && !window->moving + && !window->resizing) + { + Vector2 mousePosition = GetMousePosition(); + + Rectangle titleCollisionRect = (Rectangle){ + window->rect.x, + window->rect.y, + window->rect.width - (RAYGUI_WINDOW_CLOSEBUTTON_SIZE + + closeTitleSizeDeltaHalf), + RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT + }; + + Rectangle resizeCollisionRect = (Rectangle){ + window->rect.x + window->rect.width - 20.0, + window->rect.y + window->rect.height - 20.0, + 20.0, + 20.0 + }; + + if (CheckCollisionPointRec(mousePosition, titleCollisionRect)) + { + window->moving = true; + } + else if (!window->minimized + && CheckCollisionPointRec(mousePosition, resizeCollisionRect)) + { + window->resizing = true; + } + } + + // Window movement and resize update. + if (window->moving) + { + Vector2 mouseDelta = GetMouseDelta(); + window->rect.x += mouseDelta.x; + window->rect.y += mouseDelta.y; + + if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) + { + window->moving = false; + + // Clamp window position on screen. + window->rect.x = Clamp(window->rect.x, 0.0, + GetScreenWidth() - window->rect.width); + window->rect.y = Clamp(window->rect.y, 0.0, + GetScreenHeight() - + RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT); + } + } + else if (window->resizing) + { + Vector2 mousePosition = GetMousePosition(); + + if (mousePosition.x > window->rect.x) + { + window->rect.width = mousePosition.x - window->rect.x; + } + if (mousePosition.y > window->rect.y) + { + window->rect.height = mousePosition.y - window->rect.y; + } + + // TODO: Add window size clamp. + + if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) + { + window->resizing = true; + } + } + + if (window->minimized) + { + GuiStatusBar( + (Rectangle){window->rect.x, window->rect.y, window->rect.width, + RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT}, + title); + + window->minimized = !GuiButton( + (Rectangle){window->rect.x + window->rect.width - + RAYGUI_WINDOW_CLOSEBUTTON_SIZE - + closeTitleSizeDeltaHalf, + RAYGUI_WINDOW_CLOSEBUTTON_SIZE, + RAYGUI_WINDOW_CLOSEBUTTON_SIZE}, + "#120#"); + } + else + { + window->minimized = GuiWindowBox( + (Rectangle){window->rect.x, window->rect.y, window->rect.width, + RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT}, + title); + + if (window->callback != NULL) + { + Rectangle scissor; + + GuiScrollPanel( + (Rectangle){window->rect.x, + window->rect.y + RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT, + window->rect.width, + window->rect.height - RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT}, + NULL, + (Rectangle){window->rect.x, window->rect.y, + window->contentSize.x, window->contentSize.y}, + &window->scroll, + &scissor); + + bool requireScissor = window->rect.width < window->contentSize.x + || window->rect.height < window->contentSize.y; + + if (requireScissor) + { + BeginScissorMode(scissor.x, scissor.y, scissor.width, scissor.height); + } + + window->callback((Vector2){window->rect.x, window->rect.y}, + window->scroll); + + if (requireScissor) + { + EndScissorMode(); + } + } + + GuiDrawIcon(71, window->rect.x + window->rect.width - 20, + window->rect.y + window->rect.height - 20, 1, WHITE); + } } // Why does the universe feel strange to exist in? diff --git a/src/utils.h b/src/utils.h index 8fb2282..eba0333 100644 --- a/src/utils.h +++ b/src/utils.h @@ -56,7 +56,7 @@ #define RANDOM_DIRECTION_UNITS 4096 -typedef void (*DrawWindowContentCallback)(Rectangle rect); +typedef void (*DrawWindowContentCallback)(Vector2 position, Vector2 scroll); // Typedef hackery. typedef struct Game Game; |
