diff options
author | nathansmith117 <thenathansmithsmith@gmail.com> | 2024-02-21 18:17:41 +0000 |
---|---|---|
committer | nathansmith117 <thenathansmithsmith@gmail.com> | 2024-02-21 18:17:41 +0000 |
commit | 2f6a0233b16d25df9b79a61b93fd8a72626bad3c (patch) | |
tree | fb505b87c4492494bc43c488da594ec31bf2ab35 /src | |
parent | ba522d0b6e8172d2d9f0ee107fbb2d6499380847 (diff) | |
download | PenguinYippies-2f6a0233b16d25df9b79a61b93fd8a72626bad3c.tar.gz PenguinYippies-2f6a0233b16d25df9b79a61b93fd8a72626bad3c.tar.bz2 PenguinYippies-2f6a0233b16d25df9b79a61b93fd8a72626bad3c.zip |
Fixed mouse position with render texture
Diffstat (limited to 'src')
-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 |