Implement UI cursor (WIP)

This commit is contained in:
MrLetsplay 2022-11-02 17:11:33 +01:00
parent aba3d387e6
commit 725aebf3b1
2 changed files with 31 additions and 18 deletions

View File

@ -60,6 +60,9 @@ static void defaultKey(GLFWwindow *window, int key, int scancode, int action, in
}
static void defaultMouseCallback(GLFWwindow *window, double x, double y, void *data) {
switch(Input::getCursorMode()) {
case GLFWCursorMode::CAPTURE:
{
static bool firstMouse = true;
static double lastX = 0, lastY = 0;
if(firstMouse) {
@ -79,6 +82,16 @@ static void defaultMouseCallback(GLFWwindow *window, double x, double y, void *d
kekData.activeCamera->rotateYaw(xoff);
kekData.activeCamera->rotatePitch(yoff);
}
case GLFWCursorMode::FREE:
case GLFWCursorMode::HIDDEN:
{
for(UIElement *element : kekData.uiElements) {
UIPoint childPos = element->getPosition();
if(element->hoverAll(UIPoint((int) x - childPos.x, (int) y - childPos.y), UIPoint((int) x, (int) y))) break;
}
}
}
}
void init() {
keyForward = Input::createKeyBinding("Forward", GLFW_KEY_W);

View File

@ -223,7 +223,7 @@ void ButtonElement::setOnClickCallback(Callable onClick) {
}
void ButtonElement::hover(UIPoint pos, UIPoint screenPos) {
RectangleElement::setColor(Colors::YELLOW);
}
void ButtonElement::hoverEnter() {