Fix cursor weirdness
This commit is contained in:
parent
be86af632f
commit
6a5fb84553
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user