From 6a5fb845535685d8164b59edc5ef78d0b38bcee8 Mon Sep 17 00:00:00 2001 From: MrLetsplay2003 Date: Tue, 12 Sep 2023 16:58:35 +0200 Subject: [PATCH] Fix cursor weirdness --- src/kekengine/cpp/common/defaults.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/kekengine/cpp/common/defaults.cpp b/src/kekengine/cpp/common/defaults.cpp index 634d58c..37d2d63 100644 --- a/src/kekengine/cpp/common/defaults.cpp +++ b/src/kekengine/cpp/common/defaults.cpp @@ -27,6 +27,13 @@ static void defaultInput(GLFWwindow *window, void *data) { kekData.player->controller->update(); } +static void doUIMouse(double x, double y) { + for(UIElement *element : kekData.ui->elements) { + UIPoint childPos = element->getPosition(); + if(element->hoverAll(UIPoint((int) x - childPos.x, (int) y - childPos.y), UIPoint((int) x, (int) y))) break; + } +} + static void defaultKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods, void *data) { if(key == Input::getKeyBinding(keyExit).key && action == GLFW_PRESS) { glfwSetWindowShouldClose(window, true); @@ -39,8 +46,15 @@ static void defaultKeyCallback(GLFWwindow *window, int key, int scancode, int ac if(key == Input::getKeyBinding(keyToggleCursorMode).key && action == GLFW_PRESS) { if(Input::getCursorMode() == GLFWCursorMode::CAPTURE) { Input::setCursorMode(GLFWCursorMode::FREE); + double x, y; + glfwGetCursorPos(kekData.window, &x, &y); + doUIMouse(x, y); }else { Input::setCursorMode(GLFWCursorMode::CAPTURE); + + for(auto e : UI::getElements()) { + if(e->hovering) e->hoverExitAll(); + } } } @@ -82,10 +96,7 @@ static void defaultMouseCallback(GLFWwindow *window, double x, double y, void *d case GLFWCursorMode::FREE: case GLFWCursorMode::HIDDEN: { - for(UIElement *element : kekData.ui->elements) { - UIPoint childPos = element->getPosition(); - if(element->hoverAll(UIPoint((int) x - childPos.x, (int) y - childPos.y), UIPoint((int) x, (int) y))) break; - } + doUIMouse(x, y); break; } } @@ -96,6 +107,7 @@ static void defaultMouseButtonCallback(GLFWwindow* window, int button, int actio case GLFWCursorMode::CAPTURE: { // TODO + break; } case GLFWCursorMode::FREE: case GLFWCursorMode::HIDDEN: @@ -113,6 +125,8 @@ static void defaultMouseButtonCallback(GLFWwindow* window, int button, int actio } } } + + break; } } }