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) { static void defaultMouseCallback(GLFWwindow *window, double x, double y, void *data) {
switch(Input::getCursorMode()) {
case GLFWCursorMode::CAPTURE:
{
static bool firstMouse = true; static bool firstMouse = true;
static double lastX = 0, lastY = 0; static double lastX = 0, lastY = 0;
if(firstMouse) { if(firstMouse) {
@ -78,6 +81,16 @@ static void defaultMouseCallback(GLFWwindow *window, double x, double y, void *d
kekData.activeCamera->rotateYaw(xoff); kekData.activeCamera->rotateYaw(xoff);
kekData.activeCamera->rotatePitch(yoff); 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() { void init() {

View File

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