mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 15:52:55 +01:00
Use ScreenCoordsXY on interface/Window.cpp
This commit is contained in:
@@ -198,24 +198,20 @@ 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;
|
auto screenPos = ScreenCoordsXY{ 0, 30 };
|
||||||
int32_t y = 30;
|
if (window_fits_within_space(screenPos, width, height))
|
||||||
if (window_fits_within_space({ x, y }, width, height))
|
|
||||||
goto foundSpace;
|
goto foundSpace;
|
||||||
|
|
||||||
x = screenWidth - width;
|
screenPos = { screenWidth - width, 30 };
|
||||||
y = 30;
|
if (window_fits_within_space(screenPos, width, height))
|
||||||
if (window_fits_within_space({ x, y }, width, height))
|
|
||||||
goto foundSpace;
|
goto foundSpace;
|
||||||
|
|
||||||
x = 0;
|
screenPos = { 0, screenHeight - 34 - height };
|
||||||
y = screenHeight - 34 - height;
|
if (window_fits_within_space(screenPos, width, height))
|
||||||
if (window_fits_within_space({ x, y }, width, height))
|
|
||||||
goto foundSpace;
|
goto foundSpace;
|
||||||
|
|
||||||
x = screenWidth - width;
|
screenPos = { screenWidth - width, screenHeight - 34 - height };
|
||||||
y = screenHeight - 34 - height;
|
if (window_fits_within_space(screenPos, 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
|
||||||
@@ -224,44 +220,36 @@ rct_window* window_create_auto_pos(
|
|||||||
if (w->flags & WF_STICK_TO_BACK)
|
if (w->flags & WF_STICK_TO_BACK)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
x = w->windowPos.x + w->width + 2;
|
screenPos = { w->windowPos.x + w->width + 2, w->windowPos.y };
|
||||||
y = w->windowPos.y;
|
if (window_fits_within_space(screenPos, width, height))
|
||||||
if (window_fits_within_space({ x, y }, width, height))
|
|
||||||
goto foundSpace;
|
goto foundSpace;
|
||||||
|
|
||||||
x = w->windowPos.x - w->width - 2;
|
screenPos = { w->windowPos.x - w->width - 2, w->windowPos.y };
|
||||||
y = w->windowPos.y;
|
if (window_fits_within_space(screenPos, width, height))
|
||||||
if (window_fits_within_space({ x, y }, width, height))
|
|
||||||
goto foundSpace;
|
goto foundSpace;
|
||||||
|
|
||||||
x = w->windowPos.x;
|
screenPos = { w->windowPos.x, w->windowPos.y + w->height + 2 };
|
||||||
y = w->windowPos.y + w->height + 2;
|
if (window_fits_within_space(screenPos, width, height))
|
||||||
if (window_fits_within_space({ x, y }, width, height))
|
|
||||||
goto foundSpace;
|
goto foundSpace;
|
||||||
|
|
||||||
x = w->windowPos.x;
|
screenPos = { w->windowPos.x, w->windowPos.y - w->height - 2 };
|
||||||
y = w->windowPos.y - w->height - 2;
|
if (window_fits_within_space(screenPos, width, height))
|
||||||
if (window_fits_within_space({ x, y }, width, height))
|
|
||||||
goto foundSpace;
|
goto foundSpace;
|
||||||
|
|
||||||
x = w->windowPos.x + w->width + 2;
|
screenPos = { w->windowPos.x + w->width + 2, w->windowPos.y - w->height - 2 };
|
||||||
y = w->windowPos.y - w->height - 2;
|
if (window_fits_within_space(screenPos, width, height))
|
||||||
if (window_fits_within_space({ x, y }, width, height))
|
|
||||||
goto foundSpace;
|
goto foundSpace;
|
||||||
|
|
||||||
x = w->windowPos.x - w->width - 2;
|
screenPos = { w->windowPos.x - w->width - 2, w->windowPos.y - w->height - 2 };
|
||||||
y = w->windowPos.y - w->height - 2;
|
if (window_fits_within_space(screenPos, width, height))
|
||||||
if (window_fits_within_space({ x, y }, width, height))
|
|
||||||
goto foundSpace;
|
goto foundSpace;
|
||||||
|
|
||||||
x = w->windowPos.x + w->width + 2;
|
screenPos = { w->windowPos.x + w->width + 2, w->windowPos.y + w->height + 2 };
|
||||||
y = w->windowPos.y + w->height + 2;
|
if (window_fits_within_space(screenPos, width, height))
|
||||||
if (window_fits_within_space({ x, y }, width, height))
|
|
||||||
goto foundSpace;
|
goto foundSpace;
|
||||||
|
|
||||||
x = w->windowPos.x - w->width - 2;
|
screenPos = { w->windowPos.x - w->width - 2, w->windowPos.y + w->height + 2 };
|
||||||
y = w->windowPos.y + w->height + 2;
|
if (window_fits_within_space(screenPos, width, height))
|
||||||
if (window_fits_within_space({ x, y }, width, height))
|
|
||||||
goto foundSpace;
|
goto foundSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,47 +259,42 @@ rct_window* window_create_auto_pos(
|
|||||||
if (w->flags & WF_STICK_TO_BACK)
|
if (w->flags & WF_STICK_TO_BACK)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
x = w->windowPos.x + w->width + 2;
|
screenPos = { w->windowPos.x + w->width + 2, w->windowPos.y };
|
||||||
y = w->windowPos.y;
|
if (window_fits_on_screen(screenPos, width, height))
|
||||||
if (window_fits_on_screen({ x, y }, width, height))
|
|
||||||
goto foundSpace;
|
goto foundSpace;
|
||||||
|
|
||||||
x = w->windowPos.x - w->width - 2;
|
screenPos = { w->windowPos.x - w->width - 2, w->windowPos.y };
|
||||||
y = w->windowPos.y;
|
if (window_fits_on_screen(screenPos, width, height))
|
||||||
if (window_fits_on_screen({ x, y }, width, height))
|
|
||||||
goto foundSpace;
|
goto foundSpace;
|
||||||
|
|
||||||
x = w->windowPos.x;
|
screenPos = { w->windowPos.x, w->windowPos.y + w->height + 2 };
|
||||||
y = w->windowPos.y + w->height + 2;
|
if (window_fits_on_screen(screenPos, width, height))
|
||||||
if (window_fits_on_screen({ x, y }, width, height))
|
|
||||||
goto foundSpace;
|
goto foundSpace;
|
||||||
|
|
||||||
x = w->windowPos.x;
|
screenPos = { w->windowPos.x, w->windowPos.y - w->height - 2 };
|
||||||
y = w->windowPos.y - w->height - 2;
|
if (window_fits_on_screen(screenPos, width, height))
|
||||||
if (window_fits_on_screen({ x, y }, width, height))
|
|
||||||
goto foundSpace;
|
goto foundSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cascade
|
// Cascade
|
||||||
x = 0;
|
screenPos = { 0, 30 };
|
||||||
y = 30;
|
|
||||||
for (auto& w : g_window_list)
|
for (auto& w : g_window_list)
|
||||||
{
|
{
|
||||||
if (x == w->windowPos.x && y == w->windowPos.y)
|
if (screenPos == w->windowPos)
|
||||||
{
|
{
|
||||||
x += 5;
|
screenPos.x += 5;
|
||||||
y += 5;
|
screenPos.y += 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clamp to inside the screen
|
// Clamp to inside the screen
|
||||||
foundSpace:
|
foundSpace:
|
||||||
if (x < 0)
|
if (screenPos.x < 0)
|
||||||
x = 0;
|
screenPos.x = 0;
|
||||||
if (x + width > screenWidth)
|
if (screenPos.x + width > screenWidth)
|
||||||
x = screenWidth - width;
|
screenPos.x = screenWidth - width;
|
||||||
|
|
||||||
return window_create(ScreenCoordsXY(x, y), width, height, event_handlers, cls, flags);
|
return window_create(screenPos, width, height, event_handlers, cls, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
rct_window* window_create_centred(
|
rct_window* window_create_centred(
|
||||||
@@ -321,9 +304,8 @@ rct_window* window_create_centred(
|
|||||||
auto screenWidth = uiContext->GetWidth();
|
auto screenWidth = uiContext->GetWidth();
|
||||||
auto screenHeight = uiContext->GetHeight();
|
auto screenHeight = uiContext->GetHeight();
|
||||||
|
|
||||||
int32_t x = (screenWidth - width) / 2;
|
auto screenPos = ScreenCoordsXY{ (screenWidth - width) / 2, std::max(TOP_TOOLBAR_HEIGHT + 1, (screenHeight - height) / 2) };
|
||||||
int32_t y = std::max(TOP_TOOLBAR_HEIGHT + 1, (screenHeight - height) / 2);
|
return window_create(screenPos, width, height, event_handlers, cls, flags);
|
||||||
return window_create(ScreenCoordsXY(x, y), width, height, event_handlers, cls, flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t window_get_widget_index(rct_window* w, rct_widget* widget)
|
static int32_t window_get_widget_index(rct_window* w, rct_widget* widget)
|
||||||
|
|||||||
Reference in New Issue
Block a user