1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 07:43:01 +01:00

Apply ScreenCoordsXY to some functions

This commit is contained in:
Gymnasiast
2020-03-07 22:20:16 +01:00
parent 27af60f062
commit 5f96a121ae
4 changed files with 39 additions and 39 deletions

View File

@@ -1255,7 +1255,7 @@ void input_state_widget_pressed(
if (w->classification == WC_DROPDOWN) 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) if (dropdown_index == -1)
{ {
goto dropdown_cleanup; goto dropdown_cleanup;
@@ -1371,7 +1371,7 @@ void input_state_widget_pressed(
if (w->classification == WC_DROPDOWN) 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) if (dropdown_index == -1)
{ {
return; return;

View File

@@ -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 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); int32_t itemHeight, int32_t numColumns);
void window_dropdown_close(); 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(rct_window* w, rct_widget* widget, uint8_t dropdownColour, uint8_t selectedColour);
void window_dropdown_show_colour_available( void window_dropdown_show_colour_available(
rct_window* w, rct_widget* widget, uint8_t dropdownColour, uint8_t selectedColour, uint32_t availableColours); rct_window* w, rct_widget* widget, uint8_t dropdownColour, uint8_t selectedColour, uint32_t availableColours);

View File

@@ -31,20 +31,20 @@ constexpr int32_t WINDOW_SCROLL_PIXELS = 17;
static int32_t _previousAbsoluteWheel = 0; 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) for (auto& w : g_window_list)
{ {
if (w->flags & WF_STICK_TO_BACK) if (w->flags & WF_STICK_TO_BACK)
continue; continue;
if (x + width <= w->windowPos.x) if (loc.x + width <= w->windowPos.x)
continue; continue;
if (x >= w->windowPos.x + w->width) if (loc.x >= w->windowPos.x + w->width)
continue; continue;
if (y + height <= w->windowPos.y) if (loc.y + height <= w->windowPos.y)
continue; continue;
if (y >= w->windowPos.y + w->height) if (loc.y >= w->windowPos.y + w->height)
continue; continue;
return false; return false;
} }
@@ -52,37 +52,37 @@ static bool window_fits_between_others(int32_t x, int32_t y, int32_t width, int3
return true; 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; 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; return false;
if (x + width > context_get_width()) if (loc.x + width > context_get_width())
return false; return false;
if (y + height > context_get_height()) if (loc.y + height > context_get_height())
return false; 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 screenWidth = context_get_width();
uint16_t screenHeight = context_get_height(); uint16_t screenHeight = context_get_height();
int32_t unk; int32_t unk;
unk = -(width / 4); unk = -(width / 4);
if (x < unk) if (loc.x < unk)
return false; return false;
unk = screenWidth + (unk * 2); unk = screenWidth + (unk * 2);
if (x > unk) if (loc.x > unk)
return false; 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; return false;
unk = screenHeight - (height / 4); unk = screenHeight - (height / 4);
if (y > unk) if (loc.y > unk)
return false; return false;
return window_fits_between_others(x, y, width, height); return window_fits_between_others(loc, width, height);
} }
rct_window* window_create( rct_window* window_create(
@@ -200,22 +200,22 @@ rct_window* window_create_auto_pos(
// Place window in an empty corner of the screen // Place window in an empty corner of the screen
int32_t x = 0; int32_t x = 0;
int32_t y = 30; int32_t y = 30;
if (window_fits_within_space(x, y, width, height)) if (window_fits_within_space({ x, y }, width, height))
goto foundSpace; goto foundSpace;
x = screenWidth - width; x = screenWidth - width;
y = 30; y = 30;
if (window_fits_within_space(x, y, width, height)) if (window_fits_within_space({ x, y }, width, height))
goto foundSpace; goto foundSpace;
x = 0; x = 0;
y = screenHeight - 34 - height; y = screenHeight - 34 - height;
if (window_fits_within_space(x, y, width, height)) if (window_fits_within_space({ x, y }, width, height))
goto foundSpace; goto foundSpace;
x = screenWidth - width; x = screenWidth - width;
y = screenHeight - 34 - height; y = screenHeight - 34 - height;
if (window_fits_within_space(x, y, width, height)) if (window_fits_within_space({ x, y }, width, height))
goto foundSpace; goto foundSpace;
// Place window next to another // Place window next to another
@@ -226,42 +226,42 @@ rct_window* window_create_auto_pos(
x = w->windowPos.x + w->width + 2; x = w->windowPos.x + w->width + 2;
y = w->windowPos.y; y = w->windowPos.y;
if (window_fits_within_space(x, y, width, height)) if (window_fits_within_space({ x, y }, width, height))
goto foundSpace; goto foundSpace;
x = w->windowPos.x - w->width - 2; x = w->windowPos.x - w->width - 2;
y = w->windowPos.y; y = w->windowPos.y;
if (window_fits_within_space(x, y, width, height)) if (window_fits_within_space({ x, y }, width, height))
goto foundSpace; goto foundSpace;
x = w->windowPos.x; x = w->windowPos.x;
y = w->windowPos.y + w->height + 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; goto foundSpace;
x = w->windowPos.x; x = w->windowPos.x;
y = w->windowPos.y - w->height - 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; goto foundSpace;
x = w->windowPos.x + w->width + 2; x = w->windowPos.x + w->width + 2;
y = w->windowPos.y - w->height - 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; goto foundSpace;
x = w->windowPos.x - w->width - 2; x = w->windowPos.x - w->width - 2;
y = w->windowPos.y - w->height - 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; goto foundSpace;
x = w->windowPos.x + w->width + 2; x = w->windowPos.x + w->width + 2;
y = w->windowPos.y + w->height + 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; goto foundSpace;
x = w->windowPos.x - w->width - 2; x = w->windowPos.x - w->width - 2;
y = w->windowPos.y + w->height + 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; goto foundSpace;
} }
@@ -273,22 +273,22 @@ rct_window* window_create_auto_pos(
x = w->windowPos.x + w->width + 2; x = w->windowPos.x + w->width + 2;
y = w->windowPos.y; y = w->windowPos.y;
if (window_fits_on_screen(x, y, width, height)) if (window_fits_on_screen({ x, y }, width, height))
goto foundSpace; goto foundSpace;
x = w->windowPos.x - w->width - 2; x = w->windowPos.x - w->width - 2;
y = w->windowPos.y; y = w->windowPos.y;
if (window_fits_on_screen(x, y, width, height)) if (window_fits_on_screen({ x, y }, width, height))
goto foundSpace; goto foundSpace;
x = w->windowPos.x; x = w->windowPos.x;
y = w->windowPos.y + w->height + 2; 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; goto foundSpace;
x = w->windowPos.x; x = w->windowPos.x;
y = w->windowPos.y - w->height - 2; 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; goto foundSpace;
} }

View File

@@ -405,13 +405,13 @@ static void window_dropdown_paint(rct_window* w, rct_drawpixelinfo* dpi)
* New function based on 6e914e * New function based on 6e914e
* returns -1 if index is invalid * 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) if (top < 0)
return -1; return -1;
int32_t left = x - w->windowPos.x; int32_t left = loc.x - w->windowPos.x;
if (left >= w->width) if (left >= w->width)
return -1; return -1;
left -= 2; left -= 2;