diff options
-rw-r--r-- | src/ui.c | 3 | ||||
-rw-r--r-- | src/util.c | 11 | ||||
-rw-r--r-- | src/util.h | 10 |
3 files changed, 23 insertions, 1 deletions
@@ -1,5 +1,6 @@ #include "ui.h" #include "game.h" +#include "util.h" TexturedButton createTexturedButton(Texture* texture, Rectangle rect, const char* message, Color backgroundColor, Color foregroundColor) @@ -46,7 +47,7 @@ bool updateTexturedButton(TexturedButton* button) button->isPressed = false; // Outline and detect click stuff. - if (CheckCollisionPointRec(GetMousePosition(), button->rect)) + if (CheckCollisionPointRec(getScaledMousePosition(), button->rect)) { // Draw outline thingy. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..308343c --- /dev/null +++ b/src/util.c @@ -0,0 +1,11 @@ +#include "util.h" +#include "game.h" + +Vector2 getScaledMousePosition() +{ + Vector2 mousePosition = GetMousePosition(); + mousePosition.x *= (float)WINDOW_WIDTH / GetScreenWidth(); + mousePosition.y *= (float)WINDOW_HEIGHT / GetScreenHeight(); + + return mousePosition; +} diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..46193de --- /dev/null +++ b/src/util.h @@ -0,0 +1,10 @@ +#include "gameCommon.h" +#include <raylib.h> + +#ifndef UTIL_H +#define UTIL_H + +// Scale from the window to render texture. +Vector2 getScaledMousePosition(); + +#endif |