aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/game.c13
-rw-r--r--src/game.h3
-rw-r--r--src/settings.c2
-rw-r--r--src/ui.c69
-rw-r--r--src/ui.h10
5 files changed, 81 insertions, 16 deletions
diff --git a/src/game.c b/src/game.c
index 71583f9..2775900 100644
--- a/src/game.c
+++ b/src/game.c
@@ -81,6 +81,18 @@ void initGame(Game* game)
game->player.camera.fovy = game->settings.fov;
game->player.position = Vector3Scale(game->world.size, 0.5);
+ // Window manager.
+ initWindowManager(&game->wm);
+
+ FloatingWindow window = createFloatingWindow("test1",
+ (Rectangle){0.0, 0.0,
+ 100.0, 100.0});
+ addWindowToWindowManager(&game->wm, window);
+
+ window = createFloatingWindow("test2",
+ (Rectangle){200.0, 200.0, 100.0, 100.0});
+ addWindowToWindowManager(&game->wm, window);
+
disableGameCursor(game);
}
@@ -124,6 +136,7 @@ void drawGameScreen(Game* game)
void updateGameUI(Game* game)
{
+ updateWindowManager(&game->wm);
}
void updateGameScene(Game* game)
diff --git a/src/game.h b/src/game.h
index 3edb37a..0524c25 100644
--- a/src/game.h
+++ b/src/game.h
@@ -4,6 +4,7 @@
#include "player.h"
#include "world.h"
#include "entity.h"
+#include "ui.h"
#ifndef GAME_H
#define GAME_H
@@ -26,6 +27,8 @@ struct Game {
SceneId sceneId;
bool isCursorEnabled;
+ WindowManager wm;
+
struct {
RenderTexture render;
float scale;
diff --git a/src/settings.c b/src/settings.c
index 31b70c1..776647e 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -13,7 +13,7 @@ Settings defaultSettings()
.edgeDetectionFactor = 0.11,
.gamma = 0.6,
.colorCount = 11.0,
- .maxUpdateDistance = 100.0,
+ .maxUpdateDistance = 255.0,
.mouseSpeed = 0.1,
.forwardKey = KEY_W,
.backwardKey = KEY_S,
diff --git a/src/ui.c b/src/ui.c
index 296f658..9f1ce74 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -1,9 +1,9 @@
#include "ui.h"
-FloatingWindow createFloatingWindow(const char* title)
+FloatingWindow createFloatingWindow(const char* title, Rectangle rect)
{
FloatingWindow window = (FloatingWindow){
- .rect = (Rectangle){0.0, 0.0, 100.0, 100.0},
+ .rect = rect,
.minimized = false,
.moving = false,
.resizing = false,
@@ -187,15 +187,24 @@ void updateFloatingWindowNotMinimized(FloatingWindow* window)
window->rect.y + window->rect.height - 20, 1, GREEN);
}
-void updateFloatingWindow(FloatingWindow* window)
+bool updateFloatingWindow(FloatingWindow* window)
{
+ bool focusOnThisWindow = false;
+ bool isMouseLeftClick = IsMouseButtonPressed(MOUSE_LEFT_BUTTON);
+
// Window movement and resize input and collision check.
- if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && !window->moving
- && !window->resizing)
+ if (isMouseLeftClick && !window->moving && !window->resizing)
{
floatingWindowTransformCollisionCheck(window);
}
+ // Focus on window.
+ if (isMouseLeftClick && CheckCollisionPointRec(GetMousePosition(),
+ window->rect))
+ {
+ focusOnThisWindow = true;
+ }
+
// Window movement and resize update.
if (window->moving)
{
@@ -206,7 +215,7 @@ void updateFloatingWindow(FloatingWindow* window)
updateFloatingWindowResizing(window);
}
- // window and content drawing with scissor and scroll area
+ // Window and content drawing with scissor and scroll area.
if(window->minimized)
{
updateFloatingWindowMinimized(window);
@@ -215,17 +224,55 @@ void updateFloatingWindow(FloatingWindow* window)
{
updateFloatingWindowNotMinimized(window);
}
+
+ return focusOnThisWindow;
+}
+
+void initWindowManager(WindowManager* wm)
+{
+ memset(wm, 0, sizeof(WindowManager));
+}
+
+void updateWindowManager(WindowManager* wm)
+{
+ int focusOnto = -1;
+
+ for (int index = 0; index < wm->windowCount; ++index)
+ {
+ if (updateFloatingWindow(&wm->windows[index])
+ && index != wm->windowCount - 1)
+ {
+ focusOnto = index;
+ }
+ }
+
+ if (focusOnto != -1)
+ {
+ focusOnWindow(wm, focusOnto);
+ }
}
-void initWindowManager(WindowManager* windowManager)
+void addWindowToWindowManager(WindowManager* wm, FloatingWindow window)
{
- memset(windowManager, 0, sizeof(WindowManager));
+ if (wm->windowCount < UI_WINDOW_MAX)
+ {
+ wm->windows[wm->windowCount] = window;
+ ++wm->windowCount;
+ }
+ else
+ {
+ TraceLog(LOG_ERROR, "'wm->windowCount' went over the limit");
+ }
}
-void updateWindowManager(WindowManager* windowManager)
+void focusOnWindow(WindowManager* wm, int windowIndex)
{
- for (int index = 0; index < windowManager->windowCount; ++index)
+ FloatingWindow window = wm->windows[windowIndex];
+
+ for (int index = windowIndex + 1; index < wm->windowCount; ++index)
{
- updateFloatingWindow(&windowManager->windows[index]);
+ wm->windows[index - 1] = wm->windows[index];
}
+
+ wm->windows[wm->windowCount - 1] = window;
}
diff --git a/src/ui.h b/src/ui.h
index fcf17a0..e3e5918 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -32,10 +32,12 @@ typedef struct {
int windowCount;
} WindowManager;
-FloatingWindow createFloatingWindow(const char* title);
-void updateFloatingWindow(FloatingWindow* window);
+FloatingWindow createFloatingWindow(const char* title, Rectangle rect);
+bool updateFloatingWindow(FloatingWindow* window);
-void initWindowManager(WindowManager* windowManager);
-void updateWindowManager(WindowManager* windowManager);
+void initWindowManager(WindowManager* wm);
+void updateWindowManager(WindowManager* wm);
+void addWindowToWindowManager(WindowManager* wm, FloatingWindow window);
+void focusOnWindow(WindowManager* wm, int windowIndex);
#endif