Fix cursor weirdness

This commit is contained in:
MrLetsplay 2023-09-12 16:58:35 +02:00
parent be86af632f
commit 6a5fb84553
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg

View File

@ -27,6 +27,13 @@ static void defaultInput(GLFWwindow *window, void *data) {
kekData.player->controller->update(); 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) { static void defaultKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods, void *data) {
if(key == Input::getKeyBinding(keyExit).key && action == GLFW_PRESS) { if(key == Input::getKeyBinding(keyExit).key && action == GLFW_PRESS) {
glfwSetWindowShouldClose(window, true); 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(key == Input::getKeyBinding(keyToggleCursorMode).key && action == GLFW_PRESS) {
if(Input::getCursorMode() == GLFWCursorMode::CAPTURE) { if(Input::getCursorMode() == GLFWCursorMode::CAPTURE) {
Input::setCursorMode(GLFWCursorMode::FREE); Input::setCursorMode(GLFWCursorMode::FREE);
double x, y;
glfwGetCursorPos(kekData.window, &x, &y);
doUIMouse(x, y);
}else { }else {
Input::setCursorMode(GLFWCursorMode::CAPTURE); 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::FREE:
case GLFWCursorMode::HIDDEN: case GLFWCursorMode::HIDDEN:
{ {
for(UIElement *element : kekData.ui->elements) { doUIMouse(x, y);
UIPoint childPos = element->getPosition();
if(element->hoverAll(UIPoint((int) x - childPos.x, (int) y - childPos.y), UIPoint((int) x, (int) y))) break;
}
break; break;
} }
} }
@ -96,6 +107,7 @@ static void defaultMouseButtonCallback(GLFWwindow* window, int button, int actio
case GLFWCursorMode::CAPTURE: case GLFWCursorMode::CAPTURE:
{ {
// TODO // TODO
break;
} }
case GLFWCursorMode::FREE: case GLFWCursorMode::FREE:
case GLFWCursorMode::HIDDEN: case GLFWCursorMode::HIDDEN:
@ -113,6 +125,8 @@ static void defaultMouseButtonCallback(GLFWwindow* window, int button, int actio
} }
} }
} }
break;
} }
} }
} }