From 5f96a121aef7377fbea3d522dca741924facc48e Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 7 Mar 2020 22:20:16 +0100 Subject: [PATCH] Apply ScreenCoordsXY to some functions --- src/openrct2-ui/input/MouseInput.cpp | 4 +- src/openrct2-ui/interface/Dropdown.h | 2 +- src/openrct2-ui/interface/Window.cpp | 66 ++++++++++++++-------------- src/openrct2-ui/windows/Dropdown.cpp | 6 +-- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/openrct2-ui/input/MouseInput.cpp b/src/openrct2-ui/input/MouseInput.cpp index 067b57be58..f19031b828 100644 --- a/src/openrct2-ui/input/MouseInput.cpp +++ b/src/openrct2-ui/input/MouseInput.cpp @@ -1255,7 +1255,7 @@ void input_state_widget_pressed( if (w->classification == WC_DROPDOWN) { - dropdown_index = dropdown_index_from_point(screenCoords.x, screenCoords.y, w); + dropdown_index = dropdown_index_from_point(screenCoords, w); if (dropdown_index == -1) { goto dropdown_cleanup; @@ -1371,7 +1371,7 @@ void input_state_widget_pressed( if (w->classification == WC_DROPDOWN) { - int32_t dropdown_index = dropdown_index_from_point(screenCoords.x, screenCoords.y, w); + int32_t dropdown_index = dropdown_index_from_point(screenCoords, w); if (dropdown_index == -1) { return; diff --git a/src/openrct2-ui/interface/Dropdown.h b/src/openrct2-ui/interface/Dropdown.h index b1c7e54303..c16cb20b5c 100644 --- a/src/openrct2-ui/interface/Dropdown.h +++ b/src/openrct2-ui/interface/Dropdown.h @@ -46,7 +46,7 @@ void window_dropdown_show_image( int32_t x, int32_t y, int32_t extray, uint8_t colour, uint8_t flags, int32_t numItems, int32_t itemWidth, int32_t itemHeight, int32_t numColumns); void window_dropdown_close(); -int32_t dropdown_index_from_point(int32_t x, int32_t y, rct_window* w); +int32_t dropdown_index_from_point(const ScreenCoordsXY& loc, rct_window* w); void window_dropdown_show_colour(rct_window* w, rct_widget* widget, uint8_t dropdownColour, uint8_t selectedColour); void window_dropdown_show_colour_available( rct_window* w, rct_widget* widget, uint8_t dropdownColour, uint8_t selectedColour, uint32_t availableColours); diff --git a/src/openrct2-ui/interface/Window.cpp b/src/openrct2-ui/interface/Window.cpp index dc293707b5..6a86a49552 100644 --- a/src/openrct2-ui/interface/Window.cpp +++ b/src/openrct2-ui/interface/Window.cpp @@ -31,20 +31,20 @@ constexpr int32_t WINDOW_SCROLL_PIXELS = 17; static int32_t _previousAbsoluteWheel = 0; -static bool window_fits_between_others(int32_t x, int32_t y, int32_t width, int32_t height) +static bool window_fits_between_others(const ScreenCoordsXY& loc, int32_t width, int32_t height) { for (auto& w : g_window_list) { if (w->flags & WF_STICK_TO_BACK) continue; - if (x + width <= w->windowPos.x) + if (loc.x + width <= w->windowPos.x) continue; - if (x >= w->windowPos.x + w->width) + if (loc.x >= w->windowPos.x + w->width) continue; - if (y + height <= w->windowPos.y) + if (loc.y + height <= w->windowPos.y) continue; - if (y >= w->windowPos.y + w->height) + if (loc.y >= w->windowPos.y + w->height) continue; return false; } @@ -52,37 +52,37 @@ static bool window_fits_between_others(int32_t x, int32_t y, int32_t width, int3 return true; } -static bool window_fits_within_space(int32_t x, int32_t y, int32_t width, int32_t height) +static bool window_fits_within_space(const ScreenCoordsXY& loc, int32_t width, int32_t height) { - if (x < 0) + if (loc.x < 0) return false; - if (y <= TOP_TOOLBAR_HEIGHT && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) + if (loc.y <= TOP_TOOLBAR_HEIGHT && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) return false; - if (x + width > context_get_width()) + if (loc.x + width > context_get_width()) return false; - if (y + height > context_get_height()) + if (loc.y + height > context_get_height()) return false; - return window_fits_between_others(x, y, width, height); + return window_fits_between_others(loc, width, height); } -static bool window_fits_on_screen(int32_t x, int32_t y, int32_t width, int32_t height) +static bool window_fits_on_screen(const ScreenCoordsXY& loc, int32_t width, int32_t height) { uint16_t screenWidth = context_get_width(); uint16_t screenHeight = context_get_height(); int32_t unk; unk = -(width / 4); - if (x < unk) + if (loc.x < unk) return false; unk = screenWidth + (unk * 2); - if (x > unk) + if (loc.x > unk) return false; - if (y <= TOP_TOOLBAR_HEIGHT && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) + if (loc.y <= TOP_TOOLBAR_HEIGHT && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) return false; unk = screenHeight - (height / 4); - if (y > unk) + if (loc.y > unk) return false; - return window_fits_between_others(x, y, width, height); + return window_fits_between_others(loc, width, height); } rct_window* window_create( @@ -200,22 +200,22 @@ rct_window* window_create_auto_pos( // Place window in an empty corner of the screen int32_t x = 0; int32_t y = 30; - if (window_fits_within_space(x, y, width, height)) + if (window_fits_within_space({ x, y }, width, height)) goto foundSpace; x = screenWidth - width; y = 30; - if (window_fits_within_space(x, y, width, height)) + if (window_fits_within_space({ x, y }, width, height)) goto foundSpace; x = 0; y = screenHeight - 34 - height; - if (window_fits_within_space(x, y, width, height)) + if (window_fits_within_space({ x, y }, width, height)) goto foundSpace; x = screenWidth - width; y = screenHeight - 34 - height; - if (window_fits_within_space(x, y, width, height)) + if (window_fits_within_space({ x, y }, width, height)) goto foundSpace; // Place window next to another @@ -226,42 +226,42 @@ rct_window* window_create_auto_pos( x = w->windowPos.x + w->width + 2; y = w->windowPos.y; - if (window_fits_within_space(x, y, width, height)) + if (window_fits_within_space({ x, y }, width, height)) goto foundSpace; x = w->windowPos.x - w->width - 2; y = w->windowPos.y; - if (window_fits_within_space(x, y, width, height)) + if (window_fits_within_space({ x, y }, width, height)) goto foundSpace; x = w->windowPos.x; y = w->windowPos.y + w->height + 2; - if (window_fits_within_space(x, y, width, height)) + if (window_fits_within_space({ x, y }, width, height)) goto foundSpace; x = w->windowPos.x; y = w->windowPos.y - w->height - 2; - if (window_fits_within_space(x, y, width, height)) + if (window_fits_within_space({ x, y }, width, height)) goto foundSpace; x = w->windowPos.x + w->width + 2; y = w->windowPos.y - w->height - 2; - if (window_fits_within_space(x, y, width, height)) + if (window_fits_within_space({ x, y }, width, height)) goto foundSpace; x = w->windowPos.x - w->width - 2; y = w->windowPos.y - w->height - 2; - if (window_fits_within_space(x, y, width, height)) + if (window_fits_within_space({ x, y }, width, height)) goto foundSpace; x = w->windowPos.x + w->width + 2; y = w->windowPos.y + w->height + 2; - if (window_fits_within_space(x, y, width, height)) + if (window_fits_within_space({ x, y }, width, height)) goto foundSpace; x = w->windowPos.x - w->width - 2; y = w->windowPos.y + w->height + 2; - if (window_fits_within_space(x, y, width, height)) + if (window_fits_within_space({ x, y }, width, height)) goto foundSpace; } @@ -273,22 +273,22 @@ rct_window* window_create_auto_pos( x = w->windowPos.x + w->width + 2; y = w->windowPos.y; - if (window_fits_on_screen(x, y, width, height)) + if (window_fits_on_screen({ x, y }, width, height)) goto foundSpace; x = w->windowPos.x - w->width - 2; y = w->windowPos.y; - if (window_fits_on_screen(x, y, width, height)) + if (window_fits_on_screen({ x, y }, width, height)) goto foundSpace; x = w->windowPos.x; y = w->windowPos.y + w->height + 2; - if (window_fits_on_screen(x, y, width, height)) + if (window_fits_on_screen({ x, y }, width, height)) goto foundSpace; x = w->windowPos.x; y = w->windowPos.y - w->height - 2; - if (window_fits_on_screen(x, y, width, height)) + if (window_fits_on_screen({ x, y }, width, height)) goto foundSpace; } diff --git a/src/openrct2-ui/windows/Dropdown.cpp b/src/openrct2-ui/windows/Dropdown.cpp index 46475a9064..db4c76ac8b 100644 --- a/src/openrct2-ui/windows/Dropdown.cpp +++ b/src/openrct2-ui/windows/Dropdown.cpp @@ -405,13 +405,13 @@ static void window_dropdown_paint(rct_window* w, rct_drawpixelinfo* dpi) * New function based on 6e914e * returns -1 if index is invalid */ -int32_t dropdown_index_from_point(int32_t x, int32_t y, rct_window* w) +int32_t dropdown_index_from_point(const ScreenCoordsXY& loc, rct_window* w) { - int32_t top = y - w->windowPos.y - 2; + int32_t top = loc.y - w->windowPos.y - 2; if (top < 0) return -1; - int32_t left = x - w->windowPos.x; + int32_t left = loc.x - w->windowPos.x; if (left >= w->width) return -1; left -= 2;