From d888eded896731cd850054e25ab25f69d10e22b6 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 23 Nov 2023 14:42:26 +0300 Subject: [PATCH] Locked cursor GUI interaction fix --- src/frontend/gui/GUI.cpp | 19 ++++++++++++++----- src/frontend/gui/GUI.h | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/frontend/gui/GUI.cpp b/src/frontend/gui/GUI.cpp index c1b67b77..db2b97a8 100644 --- a/src/frontend/gui/GUI.cpp +++ b/src/frontend/gui/GUI.cpp @@ -36,10 +36,7 @@ PagesControl* GUI::getMenu() { return menu; } -void GUI::act(float delta) { - container->size(vec2(Window::width, Window::height)); - container->act(delta); - +void GUI::actMouse(float delta) { int mx = Events::x; int my = Events::y; @@ -55,7 +52,6 @@ void GUI::act(float delta) { } this->hover = hover; - auto prevfocus = focus; if (Events::jclicked(0)) { if (pressed == nullptr && this->hover) { pressed = hover; @@ -76,6 +72,17 @@ void GUI::act(float delta) { pressed->mouseRelease(this, mx, my); pressed = nullptr; } +} + +void GUI::act(float delta) { + container->size(vec2(Window::width, Window::height)); + container->act(delta); + auto prevfocus = focus; + + if (!Events::_cursor_locked) { + actMouse(delta); + } + if (focus) { if (Events::jpressed(keycode::ESCAPE)) { focus->defocus(); @@ -88,6 +95,8 @@ void GUI::act(float delta) { focus->keyPressed(key); } if (Events::clicked(mousecode::BUTTON_1)) { + int mx = Events::x; + int my = Events::y; focus->mouseMove(this, mx, my); } if (prevfocus == focus){ diff --git a/src/frontend/gui/GUI.h b/src/frontend/gui/GUI.h index 3d4adc6b..6e5fc5f6 100644 --- a/src/frontend/gui/GUI.h +++ b/src/frontend/gui/GUI.h @@ -57,6 +57,7 @@ namespace gui { Camera* uicamera; PagesControl* menu; + void actMouse(float delta); public: GUI(); ~GUI();