aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui.c')
-rw-r--r--src/ui.c78
1 files changed, 65 insertions, 13 deletions
diff --git a/src/ui.c b/src/ui.c
index 9f1ce74..9faabcd 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -9,7 +9,8 @@ FloatingWindow createFloatingWindow(const char* title, Rectangle rect)
.resizing = false,
.callback = NULL,
.contentSize = Vector2Zero(),
- .scroll = Vector2Zero()
+ .scroll = Vector2Zero(),
+ .hasFocus = false
};
memcpy(window.title, title, UI_WINDOW_TITLE_MAX * sizeof(char));
@@ -136,7 +137,8 @@ void updateFloatingWindowMinimized(FloatingWindow* window)
window->rect.y + closeTitleSizeDeltaHalf,
RAYGUI_WINDOW_CLOSEBUTTON_SIZE,
RAYGUI_WINDOW_CLOSEBUTTON_SIZE},
- "#120#"))
+ "#120#")
+ && window->hasFocus)
{
window->minimized = false;
}
@@ -146,7 +148,7 @@ void updateFloatingWindowNotMinimized(FloatingWindow* window)
{
window->minimized = GuiWindowBox(
(Rectangle){window->rect.x, window->rect.y, window->rect.width,
- window->rect.height}, window->title);
+ window->rect.height}, window->title) & window->hasFocus;
// Scissor and draw content within a scroll panel.
if (window->callback != NULL)
@@ -187,9 +189,9 @@ void updateFloatingWindowNotMinimized(FloatingWindow* window)
window->rect.y + window->rect.height - 20, 1, GREEN);
}
-bool updateFloatingWindow(FloatingWindow* window)
+FocusCommand updateFloatingWindow(FloatingWindow* window)
{
- bool focusOnThisWindow = false;
+ FocusCommand focus = NO_FOCUS_ACTION;
bool isMouseLeftClick = IsMouseButtonPressed(MOUSE_LEFT_BUTTON);
// Window movement and resize input and collision check.
@@ -199,18 +201,18 @@ bool updateFloatingWindow(FloatingWindow* window)
}
// Focus on window.
- if (isMouseLeftClick && CheckCollisionPointRec(GetMousePosition(),
- window->rect))
+ if (!window->hasFocus && isMouseLeftClick
+ && CheckCollisionPointRec(GetMousePosition(), window->rect))
{
- focusOnThisWindow = true;
+ focus = REQUEST_FOCUS;
}
// Window movement and resize update.
- if (window->moving)
+ if (window->moving && window->hasFocus)
{
updateFloatingWindowMoving(window);
}
- else if (window->resizing)
+ else if (window->resizing && window->hasFocus)
{
updateFloatingWindowResizing(window);
}
@@ -225,7 +227,7 @@ bool updateFloatingWindow(FloatingWindow* window)
updateFloatingWindowNotMinimized(window);
}
- return focusOnThisWindow;
+ return focus;
}
void initWindowManager(WindowManager* wm)
@@ -235,14 +237,51 @@ void initWindowManager(WindowManager* wm)
void updateWindowManager(WindowManager* wm)
{
+ Vector2 mousePosition = GetMousePosition();
int focusOnto = -1;
for (int index = 0; index < wm->windowCount; ++index)
{
- if (updateFloatingWindow(&wm->windows[index])
- && index != wm->windowCount - 1)
+ FocusCommand focus = updateFloatingWindow(&wm->windows[index]);
+
+ if (focusOnto != -1)
{
+ continue;
+ }
+
+ switch (focus)
+ {
+ case NO_FOCUS_ACTION:
+ break;
+ case REQUEST_FOCUS:
+ {
+ puts("hi");
+ bool canFocus = true;
+
+ // Windows ontop of it prevent focus.
+ for (int innerIndex = index + 1; innerIndex < wm->windowCount;
+ ++innerIndex)
+ {
+ if (CheckCollisionPointRec(mousePosition,
+ wm->windows[innerIndex].rect))
+ {
+ canFocus = false;
+ break;
+ }
+ }
+
+ if (canFocus)
+ {
+ focusOnto = index;
+ }
+ }
+
+ break;
+ case DEMAND_FOCUS:
focusOnto = index;
+ break;
+ default:
+ break;
}
}
@@ -256,7 +295,13 @@ void addWindowToWindowManager(WindowManager* wm, FloatingWindow window)
{
if (wm->windowCount < UI_WINDOW_MAX)
{
+ if (wm->windowCount > 0)
+ {
+ wm->windows[wm->windowCount - 1].hasFocus = false;
+ }
+
wm->windows[wm->windowCount] = window;
+ wm->windows[wm->windowCount].hasFocus = true;
++wm->windowCount;
}
else
@@ -267,6 +312,12 @@ void addWindowToWindowManager(WindowManager* wm, FloatingWindow window)
void focusOnWindow(WindowManager* wm, int windowIndex)
{
+ if (wm->windowCount <= 1)
+ {
+ return;
+ }
+
+ wm->windows[wm->windowCount - 1].hasFocus = false;
FloatingWindow window = wm->windows[windowIndex];
for (int index = windowIndex + 1; index < wm->windowCount; ++index)
@@ -274,5 +325,6 @@ void focusOnWindow(WindowManager* wm, int windowIndex)
wm->windows[index - 1] = wm->windows[index];
}
+ window.hasFocus = true;
wm->windows[wm->windowCount - 1] = window;
}