From 2f6a0233b16d25df9b79a61b93fd8a72626bad3c Mon Sep 17 00:00:00 2001 From: nathansmith117 Date: Wed, 21 Feb 2024 11:17:41 -0700 Subject: Fixed mouse position with render texture --- src/ui.c | 3 ++- src/util.c | 11 +++++++++++ src/util.h | 10 ++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/util.c create mode 100644 src/util.h (limited to 'src') diff --git a/src/ui.c b/src/ui.c index f07dc96..5fab8a6 100644 --- a/src/ui.c +++ b/src/ui.c @@ -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 + +#ifndef UTIL_H +#define UTIL_H + +// Scale from the window to render texture. +Vector2 getScaledMousePosition(); + +#endif -- cgit v1.2.3