From affda45ac5bebb7a36c71c8567e9a2d19bbafb27 Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Tue, 23 Jan 2018 11:12:26 +0100 Subject: [PATCH] Fixed start Menu Click event at scaled window --- startmenu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/startmenu.c b/startmenu.c index 4fdc72a..c39bb64 100644 --- a/startmenu.c +++ b/startmenu.c @@ -5,6 +5,7 @@ #include "gamestate.h" #include "main.h" +extern float XScale, YScale; SDL_Texture * TITLE_Texture; SDL_Texture * PLAYBUTTON_Texture; @@ -23,7 +24,11 @@ SDL_Rect HIGHSCORESBUTTON_Rect; SDL_Rect QUITBUTTON_Rect; int clickInRect(SDL_MouseButtonEvent b, SDL_Rect * area_rect) { - return (((b.x) >= (area_rect->x)) && ((b.x) <= ((area_rect->x) + (area_rect->w))) && ((b.y) >= (area_rect->y)) && ((b.y) <= ((area_rect->y) + (area_rect->h)))); + int clickx, clicky; + + clickx = (int)roundf((float)b.x / XScale); + clicky = (int)roundf((float)b.y / YScale); + return ((clickx >= (area_rect->x)) && (clickx <= ((area_rect->x) + (area_rect->w))) && (clicky >= (area_rect->y)) && (clicky <= ((area_rect->y) + (area_rect->h)))); } void Load_Textures(SDL_Renderer * renderer) {