mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-16 03:23:15 +01:00
Close #11561: Use ScreenCoordsXY in gfx_draw_string_centred_wrapped()
* Add gfx_draw_string_centred_wrapped overload using ScreenCoordsXY * Update calls to gfx_draw_string_centred_wrapped * Remove old signature of gfx_draw_string_centred_wrapped * Meaningful coordinate variable names and constructor calls
This commit is contained in:
@@ -202,55 +202,62 @@ static void window_about_openrct2_common_paint(rct_window* w, rct_drawpixelinfo*
|
||||
{
|
||||
window_draw_widgets(w, dpi);
|
||||
|
||||
int32_t x1, x2, y;
|
||||
const auto& aboutOpenRCT2 = w->widgets[WIDX_TAB_ABOUT_OPENRCT2];
|
||||
const auto& aboutRCT2 = w->widgets[WIDX_TAB_ABOUT_RCT2];
|
||||
|
||||
x1 = w->windowPos.x + (&w->widgets[WIDX_TAB_ABOUT_OPENRCT2])->left + 45;
|
||||
x2 = w->windowPos.x + (&w->widgets[WIDX_TAB_ABOUT_RCT2])->left + 45;
|
||||
y = w->windowPos.y + (((&w->widgets[WIDX_TAB_ABOUT_OPENRCT2])->top + (&w->widgets[WIDX_TAB_ABOUT_OPENRCT2])->bottom) / 2)
|
||||
- 3;
|
||||
int32_t y = w->windowPos.y + ((aboutOpenRCT2.top + aboutOpenRCT2.bottom) / 2) - 3;
|
||||
ScreenCoordsXY aboutOpenRCT2Coords(w->windowPos.x + aboutOpenRCT2.left + 45, y);
|
||||
ScreenCoordsXY aboutRCT2Coords(w->windowPos.x + aboutRCT2.left + 45, y);
|
||||
|
||||
set_format_arg(0, rct_string_id, STR_TITLE_SEQUENCE_OPENRCT2);
|
||||
gfx_draw_string_centred_wrapped(dpi, gCommonFormatArgs, x1, y, 87, STR_WINDOW_COLOUR_2_STRINGID, COLOUR_AQUAMARINE);
|
||||
gfx_draw_string_centred_wrapped(
|
||||
dpi, gCommonFormatArgs, aboutOpenRCT2Coords, 87, STR_WINDOW_COLOUR_2_STRINGID, COLOUR_AQUAMARINE);
|
||||
|
||||
set_format_arg(0, rct_string_id, STR_TITLE_SEQUENCE_RCT2);
|
||||
gfx_draw_string_centred_wrapped(dpi, gCommonFormatArgs, x2, y, 87, STR_WINDOW_COLOUR_2_STRINGID, COLOUR_AQUAMARINE);
|
||||
gfx_draw_string_centred_wrapped(
|
||||
dpi, gCommonFormatArgs, aboutRCT2Coords, 87, STR_WINDOW_COLOUR_2_STRINGID, COLOUR_AQUAMARINE);
|
||||
}
|
||||
|
||||
static void window_about_openrct2_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
||||
{
|
||||
window_about_openrct2_common_paint(w, dpi);
|
||||
|
||||
int32_t x, y, width;
|
||||
int32_t width;
|
||||
rct_size16 logoSize;
|
||||
|
||||
int32_t lineHeight = font_get_line_height(gCurrentFontSpriteBase);
|
||||
|
||||
x = w->windowPos.x + (w->width / 2);
|
||||
y = w->windowPos.y + w->widgets[WIDX_PAGE_BACKGROUND].top + lineHeight;
|
||||
ScreenCoordsXY aboutCoords(
|
||||
w->windowPos.x + (w->width / 2), w->windowPos.y + w->widgets[WIDX_PAGE_BACKGROUND].top + lineHeight);
|
||||
width = w->width - 20;
|
||||
|
||||
y += gfx_draw_string_centred_wrapped(dpi, nullptr, x, y, width, STR_ABOUT_OPENRCT2_DESCRIPTION, w->colours[2]) + lineHeight;
|
||||
aboutCoords.y += gfx_draw_string_centred_wrapped(
|
||||
dpi, nullptr, aboutCoords, width, STR_ABOUT_OPENRCT2_DESCRIPTION, w->colours[2])
|
||||
+ lineHeight;
|
||||
|
||||
logoSize = gfx_get_sprite_size(SPR_G2_LOGO);
|
||||
gfx_draw_sprite(dpi, SPR_G2_LOGO, x - (logoSize.width / 2), y, 0);
|
||||
y += logoSize.height + lineHeight * 2;
|
||||
gfx_draw_sprite(dpi, SPR_G2_LOGO, aboutCoords.x - (logoSize.width / 2), aboutCoords.y, 0);
|
||||
aboutCoords.y += logoSize.height + lineHeight * 2;
|
||||
|
||||
// About OpenRCT2 text
|
||||
y += gfx_draw_string_centred_wrapped(dpi, nullptr, x, y, width, STR_ABOUT_OPENRCT2_DESCRIPTION_2, w->colours[2])
|
||||
aboutCoords.y += gfx_draw_string_centred_wrapped(
|
||||
dpi, nullptr, aboutCoords, width, STR_ABOUT_OPENRCT2_DESCRIPTION_2, w->colours[2])
|
||||
+ lineHeight + 5;
|
||||
|
||||
// Copyright disclaimer; hidden when using truetype fonts to prevent
|
||||
// the text from overlapping the changelog button.
|
||||
if (!LocalisationService_UseTrueTypeFont())
|
||||
{
|
||||
gfx_draw_string_centred_wrapped(dpi, nullptr, x, y, width, STR_ABOUT_OPENRCT2_DESCRIPTION_3, w->colours[2]);
|
||||
gfx_draw_string_centred_wrapped(dpi, nullptr, aboutCoords, width, STR_ABOUT_OPENRCT2_DESCRIPTION_3, w->colours[2]);
|
||||
}
|
||||
|
||||
// Version info
|
||||
utf8 buffer[256];
|
||||
utf8* ch = buffer;
|
||||
openrct2_write_full_version_info(ch, sizeof(buffer) - (ch - buffer));
|
||||
gfx_draw_string_centred_wrapped(dpi, &ch, x, w->windowPos.y + WH - 25, width, STR_STRING, w->colours[2]);
|
||||
|
||||
aboutCoords.y = w->windowPos.y + WH - 25;
|
||||
gfx_draw_string_centred_wrapped(dpi, &ch, aboutCoords, width, STR_STRING, w->colours[2]);
|
||||
}
|
||||
|
||||
#pragma endregion OpenRCT2
|
||||
|
||||
@@ -223,9 +223,8 @@ static void window_ride_demolish_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
||||
auto nameArgLen = ride->FormatNameTo(gCommonFormatArgs);
|
||||
set_format_arg(nameArgLen, money32, _demolishRideCost);
|
||||
|
||||
int32_t x = w->windowPos.x + WW / 2;
|
||||
int32_t y = w->windowPos.y + (WH / 2) - 3;
|
||||
gfx_draw_string_centred_wrapped(dpi, gCommonFormatArgs, x, y, WW - 4, stringId, COLOUR_BLACK);
|
||||
ScreenCoordsXY stringCoords(w->windowPos.x + WW / 2, w->windowPos.y + (WH / 2) - 3);
|
||||
gfx_draw_string_centred_wrapped(dpi, gCommonFormatArgs, stringCoords, WW - 4, stringId, COLOUR_BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,8 +239,7 @@ static void window_ride_refurbish_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
||||
auto nameArgLen = ride->FormatNameTo(gCommonFormatArgs);
|
||||
set_format_arg(nameArgLen, money32, _demolishRideCost / 2);
|
||||
|
||||
int32_t x = w->windowPos.x + WW / 2;
|
||||
int32_t y = w->windowPos.y + (WH / 2) - 3;
|
||||
gfx_draw_string_centred_wrapped(dpi, gCommonFormatArgs, x, y, WW - 4, stringId, COLOUR_BLACK);
|
||||
ScreenCoordsXY stringCoords(w->windowPos.x + WW / 2, w->windowPos.y + (WH / 2) - 3);
|
||||
gfx_draw_string_centred_wrapped(dpi, gCommonFormatArgs, stringCoords, WW - 4, stringId, COLOUR_BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -681,8 +681,9 @@ static void window_game_bottom_toolbar_draw_middle_panel(rct_drawpixelinfo* dpi,
|
||||
// Figure out how much line height we have to work with.
|
||||
uint32_t line_height = font_get_line_height(FONT_SPRITE_BASE_MEDIUM);
|
||||
|
||||
int32_t x = w->windowPos.x + (middleOutsetWidget->left + middleOutsetWidget->right) / 2;
|
||||
int32_t y = w->windowPos.y + middleOutsetWidget->top + line_height + 1;
|
||||
ScreenCoordsXY middleWidgetCoords(
|
||||
w->windowPos.x + (middleOutsetWidget->left + middleOutsetWidget->right) / 2,
|
||||
w->windowPos.y + middleOutsetWidget->top + line_height + 1);
|
||||
int32_t width = middleOutsetWidget->right - middleOutsetWidget->left - 62;
|
||||
|
||||
// Check if there is a map tooltip to draw
|
||||
@@ -690,12 +691,13 @@ static void window_game_bottom_toolbar_draw_middle_panel(rct_drawpixelinfo* dpi,
|
||||
std::memcpy(&stringId, gMapTooltipFormatArgs, sizeof(rct_string_id));
|
||||
if (stringId == STR_NONE)
|
||||
{
|
||||
gfx_draw_string_centred_wrapped(dpi, gMapTooltipFormatArgs, x, y, width, STR_TITLE_SEQUENCE_OPENRCT2, w->colours[0]);
|
||||
gfx_draw_string_centred_wrapped(
|
||||
dpi, gMapTooltipFormatArgs, middleWidgetCoords, width, STR_TITLE_SEQUENCE_OPENRCT2, w->colours[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Show tooltip in bottom toolbar
|
||||
gfx_draw_string_centred_wrapped(dpi, gMapTooltipFormatArgs, x, y, width, STR_STRINGID, w->colours[0]);
|
||||
gfx_draw_string_centred_wrapped(dpi, gMapTooltipFormatArgs, middleWidgetCoords, width, STR_STRINGID, w->colours[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1240,9 +1240,9 @@ static void window_overwrite_prompt_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
||||
set_format_arg(0, rct_string_id, STR_STRING);
|
||||
set_format_arg(2, char*, _window_overwrite_prompt_name);
|
||||
|
||||
int32_t x = w->windowPos.x + w->width / 2;
|
||||
int32_t y = w->windowPos.y + (w->height / 2) - 3;
|
||||
gfx_draw_string_centred_wrapped(dpi, gCommonFormatArgs, x, y, w->width - 4, STR_FILEBROWSER_OVERWRITE_PROMPT, COLOUR_BLACK);
|
||||
ScreenCoordsXY stringCoords(w->windowPos.x + w->width / 2, w->windowPos.y + (w->height / 2) - 3);
|
||||
gfx_draw_string_centred_wrapped(
|
||||
dpi, gCommonFormatArgs, stringCoords, w->width - 4, STR_FILEBROWSER_OVERWRITE_PROMPT, COLOUR_BLACK);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
@@ -157,7 +157,6 @@ static void window_map_tooltip_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
||||
return;
|
||||
}
|
||||
|
||||
gfx_draw_string_centred_wrapped(
|
||||
dpi, gMapTooltipFormatArgs, w->windowPos.x + (w->width / 2), w->windowPos.y + (w->height / 2), w->width,
|
||||
STR_MAP_TOOLTIP_STRINGID, COLOUR_BLACK);
|
||||
ScreenCoordsXY stringCoords(w->windowPos.x + (w->width / 2), w->windowPos.y + (w->height / 2));
|
||||
gfx_draw_string_centred_wrapped(dpi, gMapTooltipFormatArgs, stringCoords, w->width, STR_MAP_TOOLTIP_STRINGID, COLOUR_BLACK);
|
||||
}
|
||||
|
||||
@@ -5721,13 +5721,15 @@ static void window_ride_measurements_paint(rct_window* w, rct_drawpixelinfo* dpi
|
||||
{
|
||||
rct_widget* widget = &window_ride_measurements_widgets[WIDX_PAGE_BACKGROUND];
|
||||
|
||||
int32_t x = w->windowPos.x + (widget->right - widget->left) / 2;
|
||||
int32_t y = w->windowPos.y + widget->top + 40;
|
||||
gfx_draw_string_centred_wrapped(dpi, nullptr, x, y, w->width - 8, STR_CLICK_ITEMS_OF_SCENERY_TO_SELECT, COLOUR_BLACK);
|
||||
ScreenCoordsXY widgetCoords(w->windowPos.x + (widget->right - widget->left) / 2, w->windowPos.y + widget->top + 40);
|
||||
gfx_draw_string_centred_wrapped(
|
||||
dpi, nullptr, widgetCoords, w->width - 8, STR_CLICK_ITEMS_OF_SCENERY_TO_SELECT, COLOUR_BLACK);
|
||||
|
||||
x = w->windowPos.x + 4;
|
||||
y = w->windowPos.y + window_ride_measurements_widgets[WIDX_SELECT_NEARBY_SCENERY].bottom + 17;
|
||||
gfx_fill_rect_inset(dpi, x, y, w->windowPos.x + 312, y + 1, w->colours[1], INSET_RECT_FLAG_BORDER_INSET);
|
||||
widgetCoords.x = w->windowPos.x + 4;
|
||||
widgetCoords.y = w->windowPos.y + window_ride_measurements_widgets[WIDX_SELECT_NEARBY_SCENERY].bottom + 17;
|
||||
gfx_fill_rect_inset(
|
||||
dpi, widgetCoords.x, widgetCoords.y, w->windowPos.x + 312, widgetCoords.y + 1, w->colours[1],
|
||||
INSET_RECT_FLAG_BORDER_INSET);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -6192,10 +6194,9 @@ static void window_ride_graphs_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi
|
||||
if (measurement == nullptr)
|
||||
{
|
||||
// No measurement message
|
||||
int32_t x = (widget->right - widget->left) / 2;
|
||||
int32_t y = (widget->bottom - widget->top) / 2 - 5;
|
||||
ScreenCoordsXY stringCoords((widget->right - widget->left) / 2, (widget->bottom - widget->top) / 2 - 5);
|
||||
int32_t width = widget->right - widget->left - 2;
|
||||
gfx_draw_string_centred_wrapped(dpi, gCommonFormatArgs, x, y, width, stringId, COLOUR_BLACK);
|
||||
gfx_draw_string_centred_wrapped(dpi, gCommonFormatArgs, stringCoords, width, stringId, COLOUR_BLACK);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -110,10 +110,9 @@ static void window_shortcut_change_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
||||
{
|
||||
window_draw_widgets(w, dpi);
|
||||
|
||||
int32_t x = w->windowPos.x + 125;
|
||||
int32_t y = w->windowPos.y + 30;
|
||||
ScreenCoordsXY stringCoords(w->windowPos.x + 125, w->windowPos.y + 30);
|
||||
|
||||
auto ft = Formatter::Common();
|
||||
ft.Add<rct_string_id>(CurrentShortcutKeyStringId);
|
||||
gfx_draw_string_centred_wrapped(dpi, gCommonFormatArgs, x, y, 242, STR_SHORTCUT_CHANGE_PROMPT, COLOUR_BLACK);
|
||||
gfx_draw_string_centred_wrapped(dpi, gCommonFormatArgs, stringCoords, 242, STR_SHORTCUT_CHANGE_PROMPT, COLOUR_BLACK);
|
||||
}
|
||||
|
||||
@@ -129,8 +129,6 @@ static void window_staff_fire_paint(rct_window *w, rct_drawpixelinfo *dpi)
|
||||
|
||||
peep->FormatNameTo(gCommonFormatArgs);
|
||||
|
||||
int32_t x = w->windowPos.x + WW / 2;
|
||||
int32_t y = w->windowPos.y + (WH / 2) - 3;
|
||||
|
||||
gfx_draw_string_centred_wrapped(dpi, gCommonFormatArgs, x, y, WW - 4, STR_FIRE_STAFF_ID, COLOUR_BLACK);
|
||||
ScreenCoordsXY stringCoords(w->windowPos.x + WW / 2,w->windowPos.y + (WH / 2) - 3);
|
||||
gfx_draw_string_centred_wrapped(dpi, gCommonFormatArgs, stringCoords, WW - 4, STR_FIRE_STAFF_ID, COLOUR_BLACK);
|
||||
}
|
||||
|
||||
@@ -450,9 +450,6 @@ static void window_scenarioselect_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
||||
if (widget->type == WWT_EMPTY)
|
||||
continue;
|
||||
|
||||
int32_t x = (widget->left + widget->right) / 2 + w->windowPos.x;
|
||||
int32_t y = (widget->top + widget->bottom) / 2 + w->windowPos.y - 3;
|
||||
|
||||
auto ft = Formatter::Common();
|
||||
if (gConfigGeneral.scenario_select_mode == SCENARIO_SELECT_MODE_ORIGIN || _titleEditor)
|
||||
{
|
||||
@@ -462,7 +459,10 @@ static void window_scenarioselect_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
||||
{ // old-style
|
||||
ft.Add<rct_string_id>(ScenarioCategoryStringIds[i]);
|
||||
}
|
||||
gfx_draw_string_centred_wrapped(dpi, gCommonFormatArgs, x, y, 87, format, COLOUR_AQUAMARINE);
|
||||
|
||||
ScreenCoordsXY stringCoords(
|
||||
(widget->left + widget->right) / 2 + w->windowPos.x, (widget->top + widget->bottom) / 2 + w->windowPos.y - 3);
|
||||
gfx_draw_string_centred_wrapped(dpi, gCommonFormatArgs, stringCoords, 87, format, COLOUR_AQUAMARINE);
|
||||
}
|
||||
|
||||
// Return if no scenario highlighted
|
||||
|
||||
@@ -292,7 +292,7 @@ static void window_track_delete_prompt_paint(rct_window* w, rct_drawpixelinfo* d
|
||||
window_draw_widgets(w, dpi);
|
||||
|
||||
gfx_draw_string_centred_wrapped(
|
||||
dpi, &_trackDesignFileReference->name, w->windowPos.x + 125, w->windowPos.y + 28, 246,
|
||||
dpi, &_trackDesignFileReference->name, { w->windowPos.x + 125, w->windowPos.y + 28 }, 246,
|
||||
STR_ARE_YOU_SURE_YOU_WANT_TO_PERMANENTLY_DELETE_TRACK, COLOUR_BLACK);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "../platform/platform.h"
|
||||
#include "../sprites.h"
|
||||
#include "../util/Util.h"
|
||||
#include "../world/Location.hpp"
|
||||
#include "../world/Water.h"
|
||||
|
||||
// HACK These were originally passed back through registers
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <vector>
|
||||
struct ScreenCoordsXY;
|
||||
|
||||
struct ScreenCoordsXY;
|
||||
namespace OpenRCT2
|
||||
{
|
||||
interface IPlatformEnvironment;
|
||||
@@ -555,7 +556,7 @@ void gfx_draw_string_right_clipped(
|
||||
int32_t gfx_draw_string_left_wrapped(
|
||||
rct_drawpixelinfo* dpi, void* args, int32_t x, int32_t y, int32_t width, rct_string_id format, uint8_t colour);
|
||||
int32_t gfx_draw_string_centred_wrapped(
|
||||
rct_drawpixelinfo* dpi, void* args, int32_t x, int32_t y, int32_t width, rct_string_id format, uint8_t colour);
|
||||
rct_drawpixelinfo* dpi, void* args, const ScreenCoordsXY& coords, int32_t width, rct_string_id format, uint8_t colour);
|
||||
|
||||
void gfx_draw_string_left_centred(
|
||||
rct_drawpixelinfo* dpi, rct_string_id format, void* args, int32_t colour, int32_t x, int32_t y);
|
||||
|
||||
@@ -229,7 +229,7 @@ int32_t gfx_draw_string_left_wrapped(
|
||||
}
|
||||
|
||||
int32_t gfx_draw_string_centred_wrapped(
|
||||
rct_drawpixelinfo* dpi, void* args, int32_t x, int32_t y, int32_t width, rct_string_id format, uint8_t colour)
|
||||
rct_drawpixelinfo* dpi, void* args, const ScreenCoordsXY& coords, int32_t width, rct_string_id format, uint8_t colour)
|
||||
{
|
||||
utf8 buffer[512];
|
||||
format_string(buffer, sizeof(buffer), format, args);
|
||||
@@ -248,7 +248,7 @@ int32_t gfx_draw_string_centred_wrapped(
|
||||
int32_t lineHeight = layout.GetHeight() / lineCount;
|
||||
int32_t yOffset = (lineCount - 1) * lineHeight / 2;
|
||||
|
||||
layout.Draw(dpi, x - layout.GetWidth() / 2, y - yOffset);
|
||||
layout.Draw(dpi, coords.x - layout.GetWidth() / 2, coords.y - yOffset);
|
||||
|
||||
return layout.GetHeight();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user