diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index 2b78f96bd5..411b6a64b9 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -450,7 +450,7 @@ public: str = GetString(STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED); } - DrawString(r.Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect), std::move(str), TextColour::Black, SA_HOR_CENTER); + DrawString(r.Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect), std::move(str), TextColour::Black, AlignmentH::Centre); break; } diff --git a/src/bootstrap_gui.cpp b/src/bootstrap_gui.cpp index f2b7203f51..106d402249 100644 --- a/src/bootstrap_gui.cpp +++ b/src/bootstrap_gui.cpp @@ -110,7 +110,7 @@ public: void DrawWidget(const Rect &r, WidgetID widget) const override { if (widget == WID_BEM_MESSAGE) { - DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.frametext), STR_MISSING_GRAPHICS_ERROR, TextColour::FromString, SA_CENTER); + DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.frametext), STR_MISSING_GRAPHICS_ERROR, TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); } } @@ -239,7 +239,7 @@ public: { if (widget != WID_BAFD_QUESTION) return; - DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.frametext), STR_MISSING_GRAPHICS_SET_MESSAGE, TextColour::FromString, SA_CENTER); + DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.frametext), STR_MISSING_GRAPHICS_SET_MESSAGE, TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); } void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp index f461a184c6..a1786a7c93 100644 --- a/src/bridge_gui.cpp +++ b/src/bridge_gui.cpp @@ -250,7 +250,7 @@ public: auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->bridges); for (auto it = first; it != last; ++it) { const BridgeSpec *b = it->spec; - DrawSpriteIgnorePadding(b->sprite, b->pal, tr.WithWidth(this->icon_width, rtl), SA_HOR_CENTER | SA_BOTTOM); + DrawSpriteIgnorePadding(b->sprite, b->pal, tr.WithWidth(this->icon_width, rtl), {AlignmentH::Centre, AlignmentV::Bottom}); DrawStringMultiLineWithClipping(tr.Indent(this->icon_width + WidgetDimensions::scaled.hsep_normal, rtl), GetBridgeSelectString(*it)); tr = tr.Translate(0, this->resize.step_height); } diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 18b2c5441f..8a7a560947 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -989,7 +989,7 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li if (has_variants) { Rect fr = tr.WithWidth(circle_width, rtl); - DrawSpriteIgnorePadding(is_folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, fr.WithY(textr), SA_CENTER); + DrawSpriteIgnorePadding(is_folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, fr.WithY(textr), {AlignmentH::Centre, AlignmentV::Middle}); } tr = tr.Indent(circle_width + WidgetDimensions::scaled.hsep_normal, rtl); @@ -1023,10 +1023,10 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li Rect cr = tr.WithWidth(count_width, !rtl); tr = tr.Indent(count_width + WidgetDimensions::scaled.hsep_normal, !rtl); - DrawString(cr.left, cr.right, textr.top + small_text_y_offset, GetString(STR_JUST_COMMA, num_engines), TextColour::Black, SA_RIGHT | SA_FORCE, false, FontSize::Small); + DrawString(cr.left, cr.right, textr.top + small_text_y_offset, GetString(STR_JUST_COMMA, num_engines), TextColour::Black, AlignmentH::ForceRight, false, FontSize::Small); if (EngineHasReplacementForCompany(Company::Get(_local_company), item.engine_id, selected_group)) { - DrawSpriteIgnorePadding(SPR_GROUP_REPLACE_ACTIVE, num_engines == 0 ? PALETTE_CRASH : PAL_NONE, rr, SA_CENTER); + DrawSpriteIgnorePadding(SPR_GROUP_REPLACE_ACTIVE, num_engines == 0 ? PALETTE_CRASH : PAL_NONE, rr, {AlignmentH::Centre, AlignmentV::Middle}); } } @@ -1133,7 +1133,7 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li int sort_detail_width = 0; if (!sort_prop_detail.empty()) { - DrawString(tr.left, tr.right, textr.top + normal_text_y_offset, sort_prop_detail, tc, SA_RIGHT, false, FontSize::Small); + DrawString(tr.left, tr.right, textr.top + normal_text_y_offset, sort_prop_detail, tc, AlignmentH::End, false, FontSize::Small); /* If we have sort detail to show, also measure its width so that we can adjust the * main name drawing rectangle to not overlap. */ diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 28b39bdca5..3e4898725b 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -188,12 +188,12 @@ static void DrawCategories(const Rect &r) { int y = r.top; /* Draw description of 12-minute economic period. */ - DrawString(r.left, r.right, y, (TimerGameEconomy::UsingWallclockUnits() ? STR_FINANCES_PERIOD_CAPTION : STR_FINANCES_YEAR_CAPTION), TextColour::FromString, SA_LEFT, true); + DrawString(r.left, r.right, y, (TimerGameEconomy::UsingWallclockUnits() ? STR_FINANCES_PERIOD_CAPTION : STR_FINANCES_YEAR_CAPTION), TextColour::FromString, AlignmentH::Start, true); y += GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_wide; for (const ExpensesList &list : _expenses_list_types) { /* Draw category title and advance y */ - DrawString(r.left, r.right, y, list.title, TextColour::FromString, SA_LEFT); + DrawString(r.left, r.right, y, list.title, TextColour::FromString, AlignmentH::Start); y += GetCharacterHeight(FontSize::Normal); /* Draw category items and advance y */ @@ -204,7 +204,7 @@ static void DrawCategories(const Rect &r) y += WidgetDimensions::scaled.vsep_normal; /* Draw category total and advance y */ - DrawString(r.left, r.right, y, STR_FINANCES_TOTAL_CAPTION, TextColour::FromString, SA_RIGHT); + DrawString(r.left, r.right, y, STR_FINANCES_TOTAL_CAPTION, TextColour::FromString, AlignmentH::End); y += GetCharacterHeight(FontSize::Normal); /* Advance y by a blockspace after this category block */ @@ -213,7 +213,7 @@ static void DrawCategories(const Rect &r) /* Draw total profit/loss */ y += WidgetDimensions::scaled.vsep_normal; - DrawString(r.left, r.right, y, STR_FINANCES_PROFIT, TextColour::FromString, SA_LEFT); + DrawString(r.left, r.right, y, STR_FINANCES_PROFIT, TextColour::FromString, AlignmentH::Start); } /** @@ -233,7 +233,7 @@ static void DrawPrice(Money amount, int left, int right, int top, TextColour col amount = -amount; str = STR_FINANCES_POSITIVE_INCOME; } - DrawString(left, right, top, GetString(str, amount), colour, SA_RIGHT | SA_FORCE); + DrawString(left, right, top, GetString(str, amount), colour, AlignmentH::ForceRight); } /** @@ -279,7 +279,7 @@ static void DrawYearColumn(const Rect &r, TimerGameEconomy::Year year, const Exp Money sum; /* Year header */ - DrawString(r.left, r.right, y, GetString(STR_FINANCES_YEAR, year), TextColour::FromString, SA_RIGHT | SA_FORCE, true); + DrawString(r.left, r.right, y, GetString(STR_FINANCES_YEAR, year), TextColour::FromString, AlignmentH::ForceRight, true); y += GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_wide; /* Categories */ @@ -322,10 +322,10 @@ static constexpr std::initializer_list _nested_company_finances_wid NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_FINANCES_BANK_BALANCE_TITLE), SetPadding(WidgetDimensions::unscaled.vsep_normal, 0, 0, 0), EndContainer(), NWidget(NWID_VERTICAL), // Vertical column with bank balance amount, loan amount, and total. - NWidget(WWT_TEXT, Colours::Invalid, WID_CF_OWN_VALUE), SetAlignment(SA_VERT_CENTER | SA_RIGHT | SA_FORCE), - NWidget(WWT_TEXT, Colours::Invalid, WID_CF_LOAN_VALUE), SetAlignment(SA_VERT_CENTER | SA_RIGHT | SA_FORCE), + NWidget(WWT_TEXT, Colours::Invalid, WID_CF_OWN_VALUE), SetAlignment({AlignmentH::ForceRight, AlignmentV::Middle}), + NWidget(WWT_TEXT, Colours::Invalid, WID_CF_LOAN_VALUE), SetAlignment({AlignmentH::ForceRight, AlignmentV::Middle}), NWidget(WWT_EMPTY, Colours::Invalid, WID_CF_BALANCE_LINE), SetMinimalSize(0, WidgetDimensions::unscaled.vsep_normal), - NWidget(WWT_TEXT, Colours::Invalid, WID_CF_BALANCE_VALUE), SetAlignment(SA_VERT_CENTER | SA_RIGHT | SA_FORCE), + NWidget(WWT_TEXT, Colours::Invalid, WID_CF_BALANCE_VALUE), SetAlignment({AlignmentH::ForceRight, AlignmentV::Middle}), EndContainer(), NWidget(NWID_SELECTION, Colours::Invalid, WID_CF_SEL_MAXLOAN), NWidget(NWID_VERTICAL), SetPIPRatio(0, 0, 1), // Max loan information @@ -1794,14 +1794,14 @@ struct CompanyInfrastructureWindow : Window case InfrastructureItemType::Total: /* Draw line in the spacer above the total. */ GfxFillRect(costr.Translate(0, -WidgetDimensions::scaled.vsep_normal).WithHeight(WidgetDimensions::scaled.fullbevel.top), PC_WHITE); - DrawString(costr, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR, it->cost * 12), TextColour::Black, SA_RIGHT | SA_FORCE); + DrawString(costr, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR, it->cost * 12), TextColour::Black, AlignmentH::ForceRight); break; case InfrastructureItemType::Value: DrawString(labelr.Indent(WidgetDimensions::scaled.hsep_indent, rtl), GetString(it->label), TextColour::White); - DrawString(countr, GetString(STR_JUST_COMMA, it->count), TextColour::White, SA_RIGHT | SA_FORCE); + DrawString(countr, GetString(STR_JUST_COMMA, it->count), TextColour::White, AlignmentH::ForceRight); if (_settings_game.economy.infrastructure_maintenance) { - DrawString(costr, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR, it->cost * 12), TextColour::Black, SA_RIGHT | SA_FORCE); + DrawString(costr, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR, it->cost * 12), TextColour::Black, AlignmentH::ForceRight); } break; } @@ -1875,7 +1875,7 @@ static constexpr std::initializer_list _nested_company_widgets = { NWidget(WWT_EMPTY, Colours::Invalid, WID_C_DESC_COLOUR_SCHEME_EXAMPLE), SetMinimalSize(30, 0), SetFill(1, 1), EndContainer(), NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), - NWidget(WWT_TEXT, Colours::Invalid, WID_C_DESC_VEHICLE), SetStringTip(STR_COMPANY_VIEW_VEHICLES_TITLE), SetAlignment(SA_LEFT | SA_TOP), + NWidget(WWT_TEXT, Colours::Invalid, WID_C_DESC_VEHICLE), SetStringTip(STR_COMPANY_VIEW_VEHICLES_TITLE), SetAlignment({AlignmentH::Start, AlignmentV::Top}), NWidget(WWT_EMPTY, Colours::Invalid, WID_C_DESC_VEHICLE_COUNTS), SetMinimalTextLines(4, 0), SetFill(1, 1), EndContainer(), EndContainer(), @@ -1894,7 +1894,7 @@ static constexpr std::initializer_list _nested_company_widgets = { NWidget(WWT_TEXT, Colours::Invalid, WID_C_DESC_COMPANY_VALUE), SetFill(1, 0), NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), - NWidget(WWT_TEXT, Colours::Invalid, WID_C_DESC_INFRASTRUCTURE), SetStringTip(STR_COMPANY_VIEW_INFRASTRUCTURE), SetAlignment(SA_LEFT | SA_TOP), + NWidget(WWT_TEXT, Colours::Invalid, WID_C_DESC_INFRASTRUCTURE), SetStringTip(STR_COMPANY_VIEW_INFRASTRUCTURE), SetAlignment({AlignmentH::Start, AlignmentV::Top}), NWidget(WWT_EMPTY, Colours::Invalid, WID_C_DESC_INFRASTRUCTURE_COUNTS), SetMinimalTextLines(5, 0), SetFill(1, 0), NWidget(NWID_VERTICAL), SetPIPRatio(0, 0, 1), NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_C_VIEW_INFRASTRUCTURE), SetStringTip(STR_COMPANY_VIEW_INFRASTRUCTURE_BUTTON, STR_COMPANY_VIEW_INFRASTRUCTURE_TOOLTIP), @@ -2123,7 +2123,7 @@ struct CompanyWindow : Window break; case WID_C_FACE_TITLE: - DrawStringMultiLine(r, GetString(STR_COMPANY_VIEW_PRESIDENT_MANAGER_TITLE, c->index), TextColour::FromString, SA_HOR_CENTER); + DrawStringMultiLine(r, GetString(STR_COMPANY_VIEW_PRESIDENT_MANAGER_TITLE, c->index), TextColour::FromString, AlignmentH::Centre); break; case WID_C_DESC_COLOUR_SCHEME_EXAMPLE: { @@ -2389,7 +2389,7 @@ struct BuyCompanyWindow : Window { case WID_BC_QUESTION: { const Company *c = Company::Get(this->window_number); - DrawStringMultiLine(r, GetString(this->hostile_takeover ? STR_BUY_COMPANY_HOSTILE_TAKEOVER : STR_BUY_COMPANY_MESSAGE, c->index, this->company_value), TextColour::FromString, SA_CENTER); + DrawStringMultiLine(r, GetString(this->hostile_takeover ? STR_BUY_COMPANY_HOSTILE_TAKEOVER : STR_BUY_COMPANY_MESSAGE, c->index, this->company_value), TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); break; } } diff --git a/src/console_gui.cpp b/src/console_gui.cpp index 0ea9206392..d8e38294fd 100644 --- a/src/console_gui.cpp +++ b/src/console_gui.cpp @@ -200,23 +200,23 @@ struct IConsoleWindow : Window int ypos = this->height - this->line_height - WidgetDimensions::scaled.hsep_normal; for (size_t line_index = IConsoleWindow::scroll; line_index < _iconsole_buffer.size(); line_index++) { const IConsoleLine &print = _iconsole_buffer[line_index]; - ypos = DrawStringMultiLine(WidgetDimensions::scaled.frametext.left, right, -this->line_height, ypos, GetString(STR_JUST_RAW_STRING, print.buffer), print.colour, SA_LEFT | SA_BOTTOM | SA_FORCE) - WidgetDimensions::scaled.hsep_normal; + ypos = DrawStringMultiLine(WidgetDimensions::scaled.frametext.left, right, -this->line_height, ypos, GetString(STR_JUST_RAW_STRING, print.buffer), print.colour, {AlignmentH::ForceLeft, AlignmentV::Bottom}) - WidgetDimensions::scaled.hsep_normal; if (ypos < 0) break; } /* If the text is longer than the window, don't show the starting ']' */ int delta = this->width - WidgetDimensions::scaled.frametext.right - cursor_width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH; if (delta > 0) { - DrawString(WidgetDimensions::scaled.frametext.left, right, this->height - this->line_height, "]", CC_COMMAND, SA_LEFT | SA_FORCE); + DrawString(WidgetDimensions::scaled.frametext.left, right, this->height - this->line_height, "]", CC_COMMAND, AlignmentH::ForceLeft); delta = 0; } /* If we have a marked area, draw a background highlight. */ if (_iconsole_cmdline.marklength != 0) GfxFillRect(this->line_offset + delta + _iconsole_cmdline.markxoffs, this->height - this->line_height, this->line_offset + delta + _iconsole_cmdline.markxoffs + _iconsole_cmdline.marklength, this->height - 1, PC_DARK_RED); - DrawString(this->line_offset + delta, right, this->height - this->line_height, _iconsole_cmdline.GetText(), CC_COMMAND, SA_LEFT | SA_FORCE); + DrawString(this->line_offset + delta, right, this->height - this->line_height, _iconsole_cmdline.GetText(), CC_COMMAND, AlignmentH::ForceLeft); if (_focused_window == this && _iconsole_cmdline.caret) { - DrawString(this->line_offset + delta + _iconsole_cmdline.caretxoffs, right, this->height - this->line_height, "_", TextColour::White, SA_LEFT | SA_FORCE); + DrawString(this->line_offset + delta + _iconsole_cmdline.caretxoffs, right, this->height - this->line_height, "_", TextColour::White, AlignmentH::ForceLeft); } } diff --git a/src/core/geometry_func.cpp b/src/core/geometry_func.cpp index b4912e1041..0b5f757327 100644 --- a/src/core/geometry_func.cpp +++ b/src/core/geometry_func.cpp @@ -10,9 +10,24 @@ #include "../stdafx.h" #include "geometry_func.hpp" #include "math_func.hpp" +#include "../strings_func.h" +#include "../strings_type.h" #include "../safeguards.h" +/** + * Resolve horizontal alignment for the current text direction. + * @return The resolved horizontal alignment. + */ +AlignmentH Alignment::ResolveRTL() const +{ + switch (this->h) { + case AlignmentH::Start: return _current_text_dir == TD_RTL ? AlignmentH::ForceRight : AlignmentH::ForceLeft; + case AlignmentH::End: return _current_text_dir == TD_RTL ? AlignmentH::ForceLeft : AlignmentH::ForceRight; + default: return this->h; + } +} + /** * Compute bounding box of both dimensions. * @param d1 First dimension. diff --git a/src/core/geometry_type.hpp b/src/core/geometry_type.hpp index bfd13002db..c28601a100 100644 --- a/src/core/geometry_type.hpp +++ b/src/core/geometry_type.hpp @@ -16,6 +16,43 @@ # define Point OTTD_Point #endif /* __APPLE__ */ +/** Horizontal alignments. */ +enum class AlignmentH : uint8_t { + Start, ///< Align to the start, LTR/RTL aware. + Centre, ///< Align to the centre. + End, ///< Align to the end, LTR/RTL aware. + ForceLeft, ///< Force align to the left. + ForceRight, ///< Force align to the right. +}; + +/** Vertical alignments. */ +enum class AlignmentV : uint8_t { + Top, ///< Align to the top. + Middle, ///< Align to the middle. + Bottom, ///< Align to the bottom. +}; + +/** Horizontal and vertical alignment. */ +struct Alignment { + AlignmentH h; ///< Horizontal alignment. + AlignmentV v; ///< Vertical alignment. + + /** + * Construct an alignment with the specified horizontal and vertical alignment. + * @param h The horizontal alignment. + * @param v The vertical alignment. + */ + constexpr Alignment(AlignmentH h, AlignmentV v) : h(h), v(v) {} + + /** + * Construct an alignment with the specific horizontal alignment. + * @param h The horizontal alignment. + */ + constexpr Alignment(AlignmentH h) : Alignment(h, AlignmentV::Top) {} + + AlignmentH ResolveRTL() const; +}; + /** * Determine where to position a centred object. * @param min The top or left coordinate. diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 59055ec83d..025141c426 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -365,7 +365,7 @@ struct DepotWindow : Window { Rect count = text.WithWidth(this->count_width - WidgetDimensions::scaled.hsep_normal, !rtl); DrawString(count.left, count.right, count.bottom - GetCharacterHeight(FontSize::Small) + 1, GetString(STR_JUST_DECIMAL, CeilDiv(length * 10, TILE_SIZE), 1), - TextColour::Black, SA_RIGHT | SA_FORCE, false, FontSize::Small); // Draw the counter + TextColour::Black, AlignmentH::ForceRight, false, FontSize::Small); // Draw the counter break; } @@ -391,7 +391,7 @@ struct DepotWindow : Window { DrawString(text, STR_DEPOT_NO_ENGINE); } else { Rect flag = r.WithWidth(this->flag_size.width, rtl).WithHeight(this->flag_size.height).Translate(0, diff_y); - DrawSpriteIgnorePadding((v->vehstatus.Test(VehState::Stopped)) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, flag, SA_CENTER); + DrawSpriteIgnorePadding((v->vehstatus.Test(VehState::Stopped)) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, flag, {AlignmentH::Centre, AlignmentV::Middle}); DrawString(text, GetString(STR_JUST_COMMA, v->unitnumber), (v->max_age - CalendarTime::DAYS_IN_LEAP_YEAR) >= v->age ? TextColour::Black : TextColour::Red); } diff --git a/src/dropdown_common_type.h b/src/dropdown_common_type.h index bcdb62dd61..695fb6ba91 100644 --- a/src/dropdown_common_type.h +++ b/src/dropdown_common_type.h @@ -93,7 +93,7 @@ public: void Draw(const Rect &full, const Rect &r, bool sel, int click_result, Colours bg_colour) const override { bool rtl = TEnd ^ (_current_text_dir == TD_RTL); - DrawStringMultiLine(r.WithWidth(this->dim.width, rtl), this->string, this->GetColour(sel), SA_CENTER, false, TFs); + DrawStringMultiLine(r.WithWidth(this->dim.width, rtl), this->string, this->GetColour(sel), {AlignmentH::Centre, AlignmentV::Middle}, false, TFs); this->TBase::Draw(full, r.Indent(this->dim.width, rtl), sel, click_result, bg_colour); } @@ -185,7 +185,7 @@ public: { bool rtl = TEnd ^ (_current_text_dir == TD_RTL); if (this->checked) { - DrawStringMultiLine(r.WithWidth(this->dim.width, rtl), STR_JUST_CHECKMARK, this->GetColour(sel), SA_CENTER, false, TFs); + DrawStringMultiLine(r.WithWidth(this->dim.width, rtl), STR_JUST_CHECKMARK, this->GetColour(sel), {AlignmentH::Centre, AlignmentV::Middle}, false, TFs); } this->TBase::Draw(full, r.Indent(this->dim.width + WidgetDimensions::scaled.hsep_wide, rtl), sel, click_result, bg_colour); } diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp index 904bdffd89..ba5020a0f3 100644 --- a/src/engine_gui.cpp +++ b/src/engine_gui.cpp @@ -169,15 +169,15 @@ struct EnginePreviewWindow : Window { if (this->selected_index >= this->engines.size()) return; EngineID engine = this->engines[selected_index]; - int y = DrawStringMultiLine(r, GetString(STR_ENGINE_PREVIEW_MESSAGE, GetEngineCategoryName(engine)), TextColour::FromString, SA_HOR_CENTER | SA_TOP) + WidgetDimensions::scaled.vsep_wide; + int y = DrawStringMultiLine(r, GetString(STR_ENGINE_PREVIEW_MESSAGE, GetEngineCategoryName(engine)), TextColour::FromString, {AlignmentH::Centre, AlignmentV::Top}) + WidgetDimensions::scaled.vsep_wide; - DrawString(r.left, r.right, y, GetString(STR_ENGINE_NAME, PackEngineNameDParam(engine, EngineNameContext::PreviewNews)), TextColour::Black, SA_HOR_CENTER); + DrawString(r.left, r.right, y, GetString(STR_ENGINE_NAME, PackEngineNameDParam(engine, EngineNameContext::PreviewNews)), TextColour::Black, AlignmentH::Centre); y += GetCharacterHeight(FontSize::Normal); DrawVehicleEngine(r.left, r.right, this->width >> 1, y + this->vehicle_space / 2, engine, GetEnginePalette(engine, _local_company), EngineImageType::Preview); y += this->vehicle_space; - DrawStringMultiLine(r.left, r.right, y, r.bottom, GetEngineInfoString(engine), TextColour::Black, SA_CENTER); + DrawStringMultiLine(r.left, r.right, y, r.bottom, GetEngineInfoString(engine), TextColour::Black, {AlignmentH::Centre, AlignmentV::Middle}); } void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override diff --git a/src/error_gui.cpp b/src/error_gui.cpp index 62d15ad1eb..6619cee51e 100644 --- a/src/error_gui.cpp +++ b/src/error_gui.cpp @@ -192,14 +192,14 @@ public: case WID_EM_MESSAGE: if (this->detailed_msg.empty()) { - DrawStringMultiLineWithClipping(r, this->summary_msg.GetDecodedString(), TextColour::White, SA_CENTER); + DrawStringMultiLineWithClipping(r, this->summary_msg.GetDecodedString(), TextColour::White, {AlignmentH::Centre, AlignmentV::Middle}); } else if (this->extra_msg.empty()) { /* Extra space when message is shorter than company face window */ int extra = (r.Height() - this->height_summary - this->height_detailed - WidgetDimensions::scaled.vsep_wide) / 2; /* Note: NewGRF supplied error message often do not start with a colour code, so default to white. */ - DrawStringMultiLineWithClipping(r.WithHeight(this->height_summary + extra, false), this->summary_msg.GetDecodedString(), TextColour::White, SA_CENTER); - DrawStringMultiLineWithClipping(r.WithHeight(this->height_detailed + extra, true), this->detailed_msg.GetDecodedString(), TextColour::White, SA_CENTER); + DrawStringMultiLineWithClipping(r.WithHeight(this->height_summary + extra, false), this->summary_msg.GetDecodedString(), TextColour::White, {AlignmentH::Centre, AlignmentV::Middle}); + DrawStringMultiLineWithClipping(r.WithHeight(this->height_detailed + extra, true), this->detailed_msg.GetDecodedString(), TextColour::White, {AlignmentH::Centre, AlignmentV::Middle}); } else { /* Extra space when message is shorter than company face window */ int extra = (r.Height() - this->height_summary - this->height_detailed - this->height_extra - (WidgetDimensions::scaled.vsep_wide * 2)) / 3; @@ -208,9 +208,9 @@ public: Rect top_section = r.WithHeight(this->height_summary + extra, false); Rect bottom_section = r.WithHeight(this->height_extra + extra, true); Rect middle_section = top_section.WithY(top_section.bottom, bottom_section.top); - DrawStringMultiLineWithClipping(top_section, this->summary_msg.GetDecodedString(), TextColour::White, SA_CENTER); - DrawStringMultiLineWithClipping(middle_section, this->detailed_msg.GetDecodedString(), TextColour::White, SA_CENTER); - DrawStringMultiLineWithClipping(bottom_section, this->extra_msg.GetDecodedString(), TextColour::White, SA_CENTER); + DrawStringMultiLineWithClipping(top_section, this->summary_msg.GetDecodedString(), TextColour::White, {AlignmentH::Centre, AlignmentV::Middle}); + DrawStringMultiLineWithClipping(middle_section, this->detailed_msg.GetDecodedString(), TextColour::White, {AlignmentH::Centre, AlignmentV::Middle}); + DrawStringMultiLineWithClipping(bottom_section, this->extra_msg.GetDecodedString(), TextColour::White, {AlignmentH::Centre, AlignmentV::Middle}); } break; diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index 7e0fdc30df..3e3922194b 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -574,7 +574,7 @@ public: /* Create the nice lighter rectangle at the details top */ GfxFillRect(r.WithHeight(HEADER_HEIGHT).Shrink(WidgetDimensions::scaled.bevel.left, WidgetDimensions::scaled.bevel.top, WidgetDimensions::scaled.bevel.right, 0), GetColourGradient(Colours::Grey, Shade::Lightest)); - DrawString(hr.left, hr.right, hr.top, STR_SAVELOAD_DETAIL_CAPTION, TextColour::FromString, SA_HOR_CENTER); + DrawString(hr.left, hr.right, hr.top, STR_SAVELOAD_DETAIL_CAPTION, TextColour::FromString, AlignmentH::Centre); if (this->selected == nullptr) return; diff --git a/src/framerate_gui.cpp b/src/framerate_gui.cpp index 18c1cc86bc..c96391eea1 100644 --- a/src/framerate_gui.cpp +++ b/src/framerate_gui.cpp @@ -617,14 +617,14 @@ struct FramerateWindow : Window { int32_t skip = sb->GetPosition(); int drawable = this->num_displayed; int y = r.top; - DrawString(r.left, r.right, y, heading_str, TextColour::FromString, SA_CENTER, true); + DrawString(r.left, r.right, y, heading_str, TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}, true); y += GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal; for (PerformanceElement e : DISPLAY_ORDER_PFE) { if (_pf_data[e].num_valid == 0) continue; if (skip > 0) { skip--; } else { - DrawString(r.left, r.right, y, GetString(values[e].strid, values[e].GetValue(), values[e].GetDecimals()), TextColour::FromString, SA_RIGHT | SA_FORCE); + DrawString(r.left, r.right, y, GetString(values[e].strid, values[e].GetValue(), values[e].GetDecimals()), TextColour::FromString, AlignmentH::ForceRight); y += GetCharacterHeight(FontSize::Normal); drawable--; if (drawable == 0) break; @@ -638,7 +638,7 @@ struct FramerateWindow : Window { int32_t skip = sb->GetPosition(); int drawable = this->num_displayed; int y = r.top; - DrawString(r.left, r.right, y, STR_FRAMERATE_MEMORYUSE, TextColour::FromString, SA_CENTER, true); + DrawString(r.left, r.right, y, STR_FRAMERATE_MEMORYUSE, TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}, true); y += GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal; for (PerformanceElement e : DISPLAY_ORDER_PFE) { if (_pf_data[e].num_valid == 0) continue; @@ -646,12 +646,12 @@ struct FramerateWindow : Window { skip--; } else if (e == PerformanceElement::GameScript || e >= PerformanceElement::AI0) { uint64_t value = e == PerformanceElement::GameScript ? Game::GetInstance()->GetAllocatedMemory() : Company::Get(GetAIIndex(e))->ai_instance->GetAllocatedMemory(); - DrawString(r.left, r.right, y, GetString(STR_FRAMERATE_BYTES_GOOD, value), TextColour::FromString, SA_RIGHT | SA_FORCE); + DrawString(r.left, r.right, y, GetString(STR_FRAMERATE_BYTES_GOOD, value), TextColour::FromString, AlignmentH::ForceRight); y += GetCharacterHeight(FontSize::Normal); drawable--; if (drawable == 0) break; } else if (e == PerformanceElement::Sound) { - DrawString(r.left, r.right, y, GetString(STR_FRAMERATE_BYTES_GOOD, GetSoundPoolAllocatedMemory()), TextColour::FromString, SA_RIGHT | SA_FORCE); + DrawString(r.left, r.right, y, GetString(STR_FRAMERATE_BYTES_GOOD, GetSoundPoolAllocatedMemory()), TextColour::FromString, AlignmentH::ForceRight); y += GetCharacterHeight(FontSize::Normal); drawable--; if (drawable == 0) break; @@ -679,9 +679,9 @@ struct FramerateWindow : Window { skip--; } else { if (e < PerformanceElement::AI0) { - DrawString(r.left, r.right, y, STR_FRAMERATE_GAMELOOP + to_underlying(e), TextColour::FromString, SA_LEFT); + DrawString(r.left, r.right, y, STR_FRAMERATE_GAMELOOP + to_underlying(e), TextColour::FromString, AlignmentH::Start); } else { - DrawString(r.left, r.right, y, GetString(STR_FRAMERATE_AI, GetAIIndex(e) + 1, GetAIName(e)), TextColour::FromString, SA_LEFT); + DrawString(r.left, r.right, y, GetString(STR_FRAMERATE_AI, GetAIIndex(e) + 1, GetAIName(e)), TextColour::FromString, AlignmentH::Start); } y += GetCharacterHeight(FontSize::Normal); drawable--; @@ -949,11 +949,11 @@ struct FrametimeGraphWindow : Window { if ((TimingMeasurement)this->vertical_scale > TIMESTAMP_PRECISION) { DrawString(r.left, x_zero - WidgetDimensions::scaled.hsep_normal, y - GetCharacterHeight(FontSize::Small), GetString(STR_FRAMERATE_GRAPH_SECONDS, this->vertical_scale * division / 10 / TIMESTAMP_PRECISION), - TextColour::Grey, SA_RIGHT | SA_FORCE, false, FontSize::Small); + TextColour::Grey, AlignmentH::ForceRight, false, FontSize::Small); } else { DrawString(r.left, x_zero - WidgetDimensions::scaled.hsep_normal, y - GetCharacterHeight(FontSize::Small), GetString(STR_FRAMERATE_GRAPH_MILLISECONDS, this->vertical_scale * division / 10 * 1000 / TIMESTAMP_PRECISION), - TextColour::Grey, SA_RIGHT | SA_FORCE, false, FontSize::Small); + TextColour::Grey, AlignmentH::ForceRight, false, FontSize::Small); } } } @@ -964,7 +964,7 @@ struct FrametimeGraphWindow : Window { if (division % 2 == 0) { DrawString(x, x_max, y_zero + WidgetDimensions::scaled.vsep_normal, GetString(STR_FRAMERATE_GRAPH_SECONDS, division * horz_div_scl / 2), - TextColour::Grey, SA_LEFT | SA_FORCE, false, FontSize::Small); + TextColour::Grey, AlignmentH::ForceLeft, false, FontSize::Small); } } @@ -1024,9 +1024,9 @@ struct FrametimeGraphWindow : Window { uint64_t value = peak_value * 1000 / TIMESTAMP_PRECISION; int label_y = std::max(y_max, peak_point.y - GetCharacterHeight(FontSize::Small)); if (peak_point.x - x_zero > (int)this->graph_size.width / 2) { - DrawString(x_zero, peak_point.x - WidgetDimensions::scaled.hsep_normal, label_y, GetString(STR_FRAMERATE_GRAPH_MILLISECONDS, value), tc_peak, SA_RIGHT | SA_FORCE, false, FontSize::Small); + DrawString(x_zero, peak_point.x - WidgetDimensions::scaled.hsep_normal, label_y, GetString(STR_FRAMERATE_GRAPH_MILLISECONDS, value), tc_peak, AlignmentH::ForceRight, false, FontSize::Small); } else { - DrawString(peak_point.x + WidgetDimensions::scaled.hsep_normal, x_max, label_y, GetString(STR_FRAMERATE_GRAPH_MILLISECONDS, value), tc_peak, SA_LEFT | SA_FORCE, false, FontSize::Small); + DrawString(peak_point.x + WidgetDimensions::scaled.hsep_normal, x_max, label_y, GetString(STR_FRAMERATE_GRAPH_MILLISECONDS, value), tc_peak, AlignmentH::ForceLeft, false, FontSize::Small); } } } diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index 5efd33c820..bef44d9661 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -110,7 +110,7 @@ static constexpr std::initializer_list _nested_generate_landscape_w /* Mapsize X * Y. */ NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_MAPSIZE_X_PULLDOWN), SetToolTip(STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1), - NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_BY), SetFill(0, 1), SetAlignment(SA_CENTER), + NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_BY), SetFill(0, 1), SetAlignment({AlignmentH::Centre, AlignmentV::Middle}), NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_MAPSIZE_Y_PULLDOWN), SetToolTip(STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1), EndContainer(), NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_MAX_HEIGHT_PULLDOWN), SetToolTip(STR_CONFIG_SETTING_TERRAIN_TYPE_HELPTEXT), SetFill(1, 1), @@ -178,13 +178,13 @@ static constexpr std::initializer_list _nested_generate_landscape_w /* Map borders buttons for each edge. */ NWidget(NWID_VERTICAL), NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), - NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_NORTHWEST), SetPadding(0, WidgetDimensions::unscaled.hsep_normal, 0, 0), SetFill(1, 1), SetAlignment(SA_RIGHT | SA_VERT_CENTER), + NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_NORTHWEST), SetPadding(0, WidgetDimensions::unscaled.hsep_normal, 0, 0), SetFill(1, 1), SetAlignment({AlignmentH::End, AlignmentV::Middle}), NWidget(WWT_TEXTBTN, Colours::Orange, WID_GL_WATER_NW), SetToolTip(STR_MAPGEN_NORTHWEST_TOOLTIP), SetFill(1, 1), NWidget(WWT_TEXTBTN, Colours::Orange, WID_GL_WATER_NE), SetToolTip(STR_MAPGEN_NORTHEAST_TOOLTIP), SetFill(1, 1), NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_NORTHEAST), SetPadding(0, 0, 0, WidgetDimensions::unscaled.hsep_normal), SetFill(1, 1), EndContainer(), NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), - NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_SOUTHWEST), SetPadding(0, WidgetDimensions::unscaled.hsep_normal, 0, 0), SetFill(1, 1), SetAlignment(SA_RIGHT | SA_VERT_CENTER), + NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_SOUTHWEST), SetPadding(0, WidgetDimensions::unscaled.hsep_normal, 0, 0), SetFill(1, 1), SetAlignment({AlignmentH::End, AlignmentV::Middle}), NWidget(WWT_TEXTBTN, Colours::Orange, WID_GL_WATER_SW), SetToolTip(STR_MAPGEN_SOUTHWEST_TOOLTIP), SetFill(1, 1), NWidget(WWT_TEXTBTN, Colours::Orange, WID_GL_WATER_SE), SetToolTip(STR_MAPGEN_SOUTHEAST_TOOLTIP), SetFill(1, 1), NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_SOUTHEAST), SetPadding(0, 0, 0, WidgetDimensions::unscaled.hsep_normal), SetFill(1, 1), @@ -248,7 +248,7 @@ static constexpr std::initializer_list _nested_heightmap_load_widge /* Mapsize X * Y. */ NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_MAPSIZE_X_PULLDOWN), SetToolTip(STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1), - NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_BY), SetFill(0, 1), SetAlignment(SA_CENTER), + NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_BY), SetFill(0, 1), SetAlignment({AlignmentH::Centre, AlignmentV::Middle}), NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_MAPSIZE_Y_PULLDOWN), SetToolTip(STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1), EndContainer(), NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_HEIGHTMAP_ROTATION_PULLDOWN), SetToolTip(STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_TOOLTIP), SetFill(1, 1), @@ -1301,7 +1301,7 @@ static constexpr std::initializer_list _nested_create_scenario_widg /* Map size. */ NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), NWidget(WWT_DROPDOWN, Colours::Orange, WID_CS_MAPSIZE_X_PULLDOWN), SetToolTip(STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1), - NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_BY), SetFill(0, 1), SetAlignment(SA_CENTER), + NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_BY), SetFill(0, 1), SetAlignment({AlignmentH::Centre, AlignmentV::Middle}), NWidget(WWT_DROPDOWN, Colours::Orange, WID_CS_MAPSIZE_Y_PULLDOWN), SetToolTip(STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1), EndContainer(), @@ -1443,17 +1443,17 @@ struct GenerateProgressWindow : public Window { DrawFrameRect(r, Colours::Grey, {FrameFlag::BorderOnly, FrameFlag::Lowered}); Rect br = r.Shrink(WidgetDimensions::scaled.bevel); DrawFrameRect(br.WithWidth(br.Width() * GenWorldStatus::percent / 100, _current_text_dir == TD_RTL), Colours::Mauve, {}); - DrawString(br.CentreToHeight(GetCharacterHeight(FontSize::Normal)), GetString(STR_GENERATION_PROGRESS, GenWorldStatus::percent), TextColour::FromString, SA_HOR_CENTER); + DrawString(br.CentreToHeight(GetCharacterHeight(FontSize::Normal)), GetString(STR_GENERATION_PROGRESS, GenWorldStatus::percent), TextColour::FromString, AlignmentH::Centre); break; } case WID_GP_PROGRESS_TEXT: /* Tell which class we are generating */ - DrawString(r.left, r.right, r.top, GenWorldStatus::cls, TextColour::FromString, SA_HOR_CENTER); + DrawString(r.left, r.right, r.top, GenWorldStatus::cls, TextColour::FromString, AlignmentH::Centre); /* And say where we are in that class */ DrawString(r.left, r.right, r.top + GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal, - GetString(STR_GENERATION_PROGRESS_NUM, GenWorldStatus::current, GenWorldStatus::total), TextColour::FromString, SA_HOR_CENTER); + GetString(STR_GENERATION_PROGRESS_NUM, GenWorldStatus::current, GenWorldStatus::total), TextColour::FromString, AlignmentH::Centre); } } }; diff --git a/src/gfx.cpp b/src/gfx.cpp index 1dd320acd6..90d6993e57 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -556,26 +556,26 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left, } /* In case we have a RTL language we swap the alignment. */ - if (!(align & SA_FORCE) && _current_text_dir == TD_RTL && (align & SA_HOR_MASK) != SA_HOR_CENTER) align ^= SA_RIGHT; + align.h = align.ResolveRTL(); /* right is the right most position to draw on. In this case we want to do * calculations with the width of the string. In comparison right can be * seen as lastof(todraw) and width as lengthof(todraw). They differ by 1. * So most +1/-1 additions are to move from lengthof to 'indices'. */ - switch (align & SA_HOR_MASK) { - case SA_LEFT: + switch (align.h) { + case AlignmentH::ForceLeft: /* right + 1 = left + w */ right = left + w - 1; break; - case SA_HOR_CENTER: + case AlignmentH::Centre: left = RoundDivSU(right + 1 + left - w, 2); /* right + 1 = left + w */ right = left + w - 1; break; - case SA_RIGHT: + case AlignmentH::ForceRight: left = right + 1 - w; break; @@ -645,7 +645,7 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left, GfxFillRect(left, y + h, right, y + h + WidgetDimensions::scaled.bevel.top - 1, PixelColour{_string_colourremap[1]}); } - return (align & SA_HOR_MASK) == SA_RIGHT ? left : right; + return align.h == AlignmentH::ForceRight ? left : right; } /** @@ -782,7 +782,7 @@ Dimension GetStringMultiLineBoundingBox(std::string_view str, const Dimension &s * @param underline Whether to underline all strings * @param fontsize The size of the initial characters. * - * @return If \a align is #SA_BOTTOM, the top to where we have written, else the bottom to where we have written. + * @return If \a align is #AlignmentV::Bottom, the top to where we have written, else the bottom to where we have written. */ int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize) { @@ -796,16 +796,16 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_vi Layouter layout(str, maxw, fontsize); int total_height = layout.GetBounds().height; int y; - switch (align & SA_VERT_MASK) { - case SA_TOP: + switch (align.v) { + case AlignmentV::Top: y = top; break; - case SA_VERT_CENTER: + case AlignmentV::Middle: y = RoundDivSU(bottom + top - total_height, 2); break; - case SA_BOTTOM: + case AlignmentV::Bottom: y = bottom - total_height; break; @@ -827,7 +827,7 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_vi y += line_height; } - return ((align & SA_VERT_MASK) == SA_BOTTOM) ? first_line : last_line; + return align.v == AlignmentV::Bottom ? first_line : last_line; } /** @@ -844,7 +844,7 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_vi * @param underline Whether to underline all strings * @param fontsize The size of the initial characters. * - * @return If \a align is #SA_BOTTOM, the top to where we have written, else the bottom to where we have written. + * @return If \a align is #AlignmentV::Bottom, the top to where we have written, else the bottom to where we have written. */ int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize) { diff --git a/src/gfx_func.h b/src/gfx_func.h index 6d41eaf778..141770faf9 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -96,11 +96,11 @@ void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, Alignment align); /* widget.cpp */ std::unique_ptr DrawSpriteToRgbaBuffer(SpriteID spriteId, ZoomLevel zoom = _gui_zoom); -int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour = TextColour::FromString, Alignment align = SA_LEFT, bool underline = false, FontSize fontsize = FontSize::Normal); -int DrawString(int left, int right, int top, StringID str, ExtendedTextColour colour = TextColour::FromString, Alignment align = SA_LEFT, bool underline = false, FontSize fontsize = FontSize::Normal); -int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour = TextColour::FromString, Alignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal); -int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, ExtendedTextColour colour = TextColour::FromString, Alignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal); -bool DrawStringMultiLineWithClipping(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour = TextColour::FromString, Alignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal); +int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour = TextColour::FromString, Alignment align = AlignmentH::Start, bool underline = false, FontSize fontsize = FontSize::Normal); +int DrawString(int left, int right, int top, StringID str, ExtendedTextColour colour = TextColour::FromString, Alignment align = AlignmentH::Start, bool underline = false, FontSize fontsize = FontSize::Normal); +int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour = TextColour::FromString, Alignment align = {AlignmentH::Start, AlignmentV::Top}, bool underline = false, FontSize fontsize = FontSize::Normal); +int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, ExtendedTextColour colour = TextColour::FromString, Alignment align = {AlignmentH::Start, AlignmentV::Top}, bool underline = false, FontSize fontsize = FontSize::Normal); +bool DrawStringMultiLineWithClipping(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour = TextColour::FromString, Alignment align = {AlignmentH::Start, AlignmentV::Top}, bool underline = false, FontSize fontsize = FontSize::Normal); void DrawCharCentered(char32_t c, const Rect &r, TextColour colour); @@ -121,13 +121,13 @@ void DrawRectOutline(const Rect &r, PixelColour colour, int width = 1, int dash * @param fontsize The size of the initial characters. * @return In case of left or center alignment the right most pixel we have drawn to. In case of right alignment the left most pixel we have drawn to. */ -inline int DrawString(const Rect &r, std::string_view str, ExtendedTextColour colour = TextColour::FromString, Alignment align = SA_LEFT, bool underline = false, FontSize fontsize = FontSize::Normal) +inline int DrawString(const Rect &r, std::string_view str, ExtendedTextColour colour = TextColour::FromString, Alignment align = AlignmentH::Start, bool underline = false, FontSize fontsize = FontSize::Normal) { return DrawString(r.left, r.right, r.top, str, colour, align, underline, fontsize); } -/** @copydoc DrawString(const Rect &r, std::string_view str, ExtendedTextColour colour = TextColour::FromString, Alignment align = SA_LEFT, bool underline = false, FontSize fontsize = FontSize::Normal) */ -inline int DrawString(const Rect &r, StringID str, ExtendedTextColour colour = TextColour::FromString, Alignment align = SA_LEFT, bool underline = false, FontSize fontsize = FontSize::Normal) +/** @copydoc DrawString(const Rect &r, std::string_view str, ExtendedTextColour colour = TextColour::FromString, Alignment align = AlignmentH::Start, bool underline = false, FontSize fontsize = FontSize::Normal) */ +inline int DrawString(const Rect &r, StringID str, ExtendedTextColour colour = TextColour::FromString, Alignment align = AlignmentH::Start, bool underline = false, FontSize fontsize = FontSize::Normal) { return DrawString(r.left, r.right, r.top, str, colour, align, underline, fontsize); } @@ -142,15 +142,15 @@ inline int DrawString(const Rect &r, StringID str, ExtendedTextColour colour = T * @param underline Whether to underline all strings * @param fontsize The size of the initial characters. * - * @return If \a align is #SA_BOTTOM, the top to where we have written, else the bottom to where we have written. + * @return If \a align is #AlignmentV::Bottom, the top to where we have written, else the bottom to where we have written. */ -inline int DrawStringMultiLine(const Rect &r, std::string_view str, ExtendedTextColour colour = TextColour::FromString, Alignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal) +inline int DrawStringMultiLine(const Rect &r, std::string_view str, ExtendedTextColour colour = TextColour::FromString, Alignment align = {AlignmentH::Start, AlignmentV::Top}, bool underline = false, FontSize fontsize = FontSize::Normal) { return DrawStringMultiLine(r.left, r.right, r.top, r.bottom, str, colour, align, underline, fontsize); } -/** @copydoc DrawStringMultiLine(const Rect &r, std::string_view str, ExtendedTextColour colour = TextColour::FromString, Alignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal) */ -inline int DrawStringMultiLine(const Rect &r, StringID str, ExtendedTextColour colour = TextColour::FromString, Alignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal) +/** @copydoc DrawStringMultiLine(const Rect &r, std::string_view str, ExtendedTextColour colour = TextColour::FromString, Alignment align = ({AlignmentH::Start, AlignmentV::Top}), bool underline = false, FontSize fontsize = FontSize::Normal) */ +inline int DrawStringMultiLine(const Rect &r, StringID str, ExtendedTextColour colour = TextColour::FromString, Alignment align = {AlignmentH::Start, AlignmentV::Top}, bool underline = false, FontSize fontsize = FontSize::Normal) { return DrawStringMultiLine(r.left, r.right, r.top, r.bottom, str, colour, align, underline, fontsize); } @@ -169,7 +169,7 @@ inline int DrawStringMultiLine(const Rect &r, StringID str, ExtendedTextColour c * * @return \c true iff the string was drawn. */ -inline bool DrawStringMultiLineWithClipping(const Rect &r, std::string_view str, ExtendedTextColour colour = TextColour::FromString, Alignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal) +inline bool DrawStringMultiLineWithClipping(const Rect &r, std::string_view str, ExtendedTextColour colour = TextColour::FromString, Alignment align = {AlignmentH::Start, AlignmentV::Top}, bool underline = false, FontSize fontsize = FontSize::Normal) { return DrawStringMultiLineWithClipping(r.left, r.right, r.top, r.bottom, str, colour, align, underline, fontsize); } diff --git a/src/gfx_type.h b/src/gfx_type.h index 0d5c36fc58..00e277770d 100644 --- a/src/gfx_type.h +++ b/src/gfx_type.h @@ -430,24 +430,6 @@ enum class Support8bpp : uint8_t { Hardware, ///< Full 8bpp support by OS and hardware. }; - /** How to align the to-be drawn text. */ -enum Alignment : uint8_t { - SA_LEFT = 0 << 0, ///< Left align the text. - SA_HOR_CENTER = 1 << 0, ///< Horizontally center the text. - SA_RIGHT = 2 << 0, ///< Right align the text (must be a single bit). - SA_HOR_MASK = 3 << 0, ///< Mask for horizontal alignment. - - SA_TOP = 0 << 2, ///< Top align the text. - SA_VERT_CENTER = 1 << 2, ///< Vertically center the text. - SA_BOTTOM = 2 << 2, ///< Bottom align the text. - SA_VERT_MASK = 3 << 2, ///< Mask for vertical alignment. - - SA_CENTER = SA_HOR_CENTER | SA_VERT_CENTER, ///< Center both horizontally and vertically. - - SA_FORCE = 1 << 4, ///< Force the alignment, i.e. don't swap for RTL languages. -}; -DECLARE_ENUM_AS_BIT_SET(Alignment) - /** The four direction keys on a keyboard. */ enum class DirectionKey { Left, ///< Left diff --git a/src/goal_gui.cpp b/src/goal_gui.cpp index b846de92f2..bc17e9a9b8 100644 --- a/src/goal_gui.cpp +++ b/src/goal_gui.cpp @@ -211,7 +211,7 @@ struct GoalListWindow : public Window { case GC_PROGRESS: if (!s->progress.empty()) { StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS; - DrawString(r.WithWidth(progress_col_width, !rtl), GetString(str, s->progress.GetDecodedString()), TextColour::FromString, SA_RIGHT | SA_FORCE); + DrawString(r.WithWidth(progress_col_width, !rtl), GetString(str, s->progress.GetDecodedString()), TextColour::FromString, AlignmentH::ForceRight); } break; } @@ -380,7 +380,7 @@ struct GoalQuestionWindow : public Window { { if (widget != WID_GQ_QUESTION) return; - DrawStringMultiLine(r, this->question.GetDecodedString(), this->colour, SA_TOP | SA_HOR_CENTER); + DrawStringMultiLine(r, this->question.GetDecodedString(), this->colour, {AlignmentH::Centre, AlignmentV::Top}); } }; diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index fc2d1ea024..dfad22c413 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -482,11 +482,11 @@ protected: if (rtl) { DrawString(r.right + ScaleGUITrad(4), r.right + label_width + ScaleGUITrad(4), y, GetString(STR_GRAPH_Y_LABEL, this->format_str_y_axis, y_label), - GRAPH_AXIS_LABEL_COLOUR, SA_RIGHT | SA_FORCE); + GRAPH_AXIS_LABEL_COLOUR, AlignmentH::ForceRight); } else { DrawString(r.left - label_width - ScaleGUITrad(4), r.left - ScaleGUITrad(4), y, GetString(STR_GRAPH_Y_LABEL, this->format_str_y_axis, y_label), - GRAPH_AXIS_LABEL_COLOUR, SA_RIGHT | SA_FORCE); + GRAPH_AXIS_LABEL_COLOUR, AlignmentH::ForceRight); } y_label -= y_label_separation; @@ -507,11 +507,11 @@ protected: if (rtl) { DrawStringMultiLineWithClipping(x + x_sep, x, y, this->height, GetString(mo == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH, STR_MONTH_ABBREV_JAN + mo, yr), - GRAPH_AXIS_LABEL_COLOUR, SA_LEFT); + GRAPH_AXIS_LABEL_COLOUR, AlignmentH::Start); } else { DrawStringMultiLineWithClipping(x, x + x_sep, y, this->height, GetString(mo == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH, STR_MONTH_ABBREV_JAN + mo, yr), - GRAPH_AXIS_LABEL_COLOUR, SA_LEFT); + GRAPH_AXIS_LABEL_COLOUR, AlignmentH::Start); } mo += this->month_increment; @@ -538,9 +538,9 @@ protected: for (int i = 0; i < this->num_on_x_axis; i++) { if (rtl) { - DrawString(x + x_sep + 1, x - 1, y, GetString(STR_GRAPH_Y_LABEL_NUMBER, label), GRAPH_AXIS_LABEL_COLOUR, SA_HOR_CENTER); + DrawString(x + x_sep + 1, x - 1, y, GetString(STR_GRAPH_Y_LABEL_NUMBER, label), GRAPH_AXIS_LABEL_COLOUR, AlignmentH::Centre); } else { - DrawString(x + 1, x + x_sep - 1, y, GetString(STR_GRAPH_Y_LABEL_NUMBER, label), GRAPH_AXIS_LABEL_COLOUR, SA_HOR_CENTER); + DrawString(x + 1, x + x_sep - 1, y, GetString(STR_GRAPH_Y_LABEL_NUMBER, label), GRAPH_AXIS_LABEL_COLOUR, AlignmentH::Centre); } label += iterator; @@ -722,7 +722,7 @@ public: if (lowered) DrawFrameRect(line, Colours::Brown, FrameFlag::Lowered); const Rect text = line.Shrink(WidgetDimensions::scaled.framerect); - DrawString(text, str, (this->highlight_state && this->highlight_range == index) ? TextColour::White : TextColour::Black, SA_CENTER, false, FontSize::Small); + DrawString(text, str, (this->highlight_state && this->highlight_range == index) ? TextColour::White : TextColour::Black, {AlignmentH::Centre, AlignmentV::Middle}, false, FontSize::Small); if (HasBit(this->masked_range, index)) { GfxFillRect(line.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(Colours::Brown, Shade::Darker), FillRectMode::Checker); @@ -742,7 +742,7 @@ public: /* Redraw frame if selected */ if (selected_month_increment == scale.month_increment) DrawFrameRect(line, Colours::Brown, FrameFlag::Lowered); - DrawString(line.Shrink(WidgetDimensions::scaled.framerect), scale.label, TextColour::Black, SA_CENTER, false, FontSize::Small); + DrawString(line.Shrink(WidgetDimensions::scaled.framerect), scale.label, TextColour::Black, {AlignmentH::Centre, AlignmentV::Middle}, false, FontSize::Small); line = line.Translate(0, line_height); } @@ -956,7 +956,7 @@ static constexpr std::initializer_list _nested_operating_profit_wid NWidget(WWT_PANEL, Colours::Brown, WID_GRAPH_BACKGROUND), NWidget(WWT_EMPTY, Colours::Invalid, WID_GRAPH_GRAPH), SetMinimalSize(576, 160), SetFill(1, 1), SetResize(1, 1), NWidget(NWID_HORIZONTAL), - NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment(SA_CENTER), + NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment({AlignmentH::Centre, AlignmentV::Middle}), NWidget(WWT_RESIZEBOX, Colours::Brown, WID_GRAPH_RESIZE), SetResizeWidgetTypeTip(ResizeWidgetType::HideBevel, STR_TOOLTIP_RESIZE), EndContainer(), EndContainer(), @@ -1010,7 +1010,7 @@ static constexpr std::initializer_list _nested_income_graph_widgets NWidget(WWT_PANEL, Colours::Brown, WID_GRAPH_BACKGROUND), NWidget(WWT_EMPTY, Colours::Invalid, WID_GRAPH_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1), NWidget(NWID_HORIZONTAL), - NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment(SA_CENTER), + NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment({AlignmentH::Centre, AlignmentV::Middle}), NWidget(WWT_RESIZEBOX, Colours::Brown, WID_GRAPH_RESIZE), SetResizeWidgetTypeTip(ResizeWidgetType::HideBevel, STR_TOOLTIP_RESIZE), EndContainer(), EndContainer(), @@ -1062,7 +1062,7 @@ static constexpr std::initializer_list _nested_delivered_cargo_grap NWidget(WWT_PANEL, Colours::Brown, WID_GRAPH_BACKGROUND), NWidget(WWT_EMPTY, Colours::Invalid, WID_GRAPH_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1), NWidget(NWID_HORIZONTAL), - NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment(SA_CENTER), + NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment({AlignmentH::Centre, AlignmentV::Middle}), NWidget(WWT_RESIZEBOX, Colours::Brown, WID_GRAPH_RESIZE), SetResizeWidgetTypeTip(ResizeWidgetType::HideBevel, STR_TOOLTIP_RESIZE), EndContainer(), EndContainer(), @@ -1121,7 +1121,7 @@ static constexpr std::initializer_list _nested_performance_history_ NWidget(WWT_PANEL, Colours::Brown, WID_GRAPH_BACKGROUND), NWidget(WWT_EMPTY, Colours::Invalid, WID_GRAPH_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1), NWidget(NWID_HORIZONTAL), - NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment(SA_CENTER), + NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment({AlignmentH::Centre, AlignmentV::Middle}), NWidget(WWT_RESIZEBOX, Colours::Brown, WID_GRAPH_RESIZE), SetResizeWidgetTypeTip(ResizeWidgetType::HideBevel, STR_TOOLTIP_RESIZE), EndContainer(), EndContainer(), @@ -1173,7 +1173,7 @@ static constexpr std::initializer_list _nested_company_value_graph_ NWidget(WWT_PANEL, Colours::Brown, WID_GRAPH_BACKGROUND), NWidget(WWT_EMPTY, Colours::Invalid, WID_GRAPH_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1), NWidget(NWID_HORIZONTAL), - NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment(SA_CENTER), + NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment({AlignmentH::Centre, AlignmentV::Middle}), NWidget(WWT_RESIZEBOX, Colours::Brown, WID_GRAPH_RESIZE), SetResizeWidgetTypeTip(ResizeWidgetType::HideBevel, STR_TOOLTIP_RESIZE), EndContainer(), EndContainer(), @@ -1445,7 +1445,7 @@ static constexpr std::initializer_list _nested_cargo_payment_rates_ NWidget(WWT_STICKYBOX, Colours::Brown), EndContainer(), NWidget(WWT_PANEL, Colours::Brown, WID_GRAPH_BACKGROUND), SetMinimalSize(568, 128), - NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_HEADER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetStringTip(STR_GRAPH_CARGO_PAYMENT_RATES_TITLE), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment(SA_CENTER), + NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_HEADER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetStringTip(STR_GRAPH_CARGO_PAYMENT_RATES_TITLE), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment({AlignmentH::Centre, AlignmentV::Middle}), NWidget(NWID_HORIZONTAL), NWidget(WWT_EMPTY, Colours::Invalid, WID_GRAPH_GRAPH), SetMinimalSize(495, 0), SetFill(1, 1), SetResize(1, 1), NWidget(NWID_VERTICAL), @@ -1462,7 +1462,7 @@ static constexpr std::initializer_list _nested_cargo_payment_rates_ NWidget(NWID_SPACER), SetMinimalSize(5, 0), SetFill(0, 1), SetResize(0, 1), EndContainer(), NWidget(NWID_HORIZONTAL), - NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment(SA_CENTER), + NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment({AlignmentH::Centre, AlignmentV::Middle}), NWidget(WWT_RESIZEBOX, Colours::Brown, WID_GRAPH_RESIZE), SetResizeWidgetTypeTip(ResizeWidgetType::HideBevel, STR_TOOLTIP_RESIZE), EndContainer(), EndContainer(), @@ -1609,7 +1609,7 @@ struct PerformanceRatingDetailWindow : Window { DrawString(this->score_info_left, this->score_info_right, text_top, STR_PERFORMANCE_DETAIL_VEHICLES + to_underlying(score_type)); /* Draw the score */ - DrawString(this->score_info_left, this->score_info_right, text_top, GetString(STR_JUST_COMMA, score), TextColour::Black, SA_RIGHT); + DrawString(this->score_info_left, this->score_info_right, text_top, GetString(STR_JUST_COMMA, score), TextColour::Black, AlignmentH::End); /* Calculate the %-bar */ uint x = Clamp(val, 0, needed) * this->bar_width / needed; @@ -1625,7 +1625,7 @@ struct PerformanceRatingDetailWindow : Window { if (x != this->bar_right) GfxFillRect(x, bar_top, this->bar_right, bar_top + this->bar_height - 1, rtl ? colour_done : colour_notdone); /* Draw it */ - DrawString(this->bar_left, this->bar_right, text_top, GetString(STR_PERFORMANCE_DETAIL_PERCENT, Clamp(val, 0, needed) * 100 / needed), TextColour::FromString, SA_HOR_CENTER); + DrawString(this->bar_left, this->bar_right, text_top, GetString(STR_PERFORMANCE_DETAIL_PERCENT, Clamp(val, 0, needed) * 100 / needed), TextColour::FromString, AlignmentH::Centre); /* ScoreID::Loan is inverted */ if (score_type == ScoreID::Loan) val = needed - val; @@ -1867,7 +1867,7 @@ static constexpr std::initializer_list _nested_industry_production_ NWidget(NWID_SPACER), SetMinimalSize(5, 0), SetFill(0, 1), SetResize(0, 1), EndContainer(), NWidget(NWID_HORIZONTAL), - NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment(SA_CENTER), + NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment({AlignmentH::Centre, AlignmentV::Middle}), NWidget(WWT_RESIZEBOX, Colours::Brown, WID_GRAPH_RESIZE), SetResizeWidgetTypeTip(ResizeWidgetType::HideBevel, STR_TOOLTIP_RESIZE), EndContainer(), EndContainer(), @@ -2031,7 +2031,7 @@ static constexpr std::initializer_list _nested_town_cargo_graph_wid NWidget(NWID_SPACER), SetMinimalSize(5, 0), SetFill(0, 1), SetResize(0, 1), EndContainer(), NWidget(NWID_HORIZONTAL), - NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment(SA_CENTER), + NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment({AlignmentH::Centre, AlignmentV::Middle}), NWidget(WWT_RESIZEBOX, Colours::Brown, WID_GRAPH_RESIZE), SetResizeWidgetTypeTip(ResizeWidgetType::HideBevel, STR_TOOLTIP_RESIZE), EndContainer(), EndContainer(), diff --git a/src/group_gui.cpp b/src/group_gui.cpp index e9315cd2dd..0ac1727b2b 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -373,7 +373,7 @@ private: /* draw fold / unfold button */ if (has_children) { - DrawSpriteIgnorePadding(Group::Get(g_id)->folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, r.WithX(this->column_rects[VGC_FOLD]).Translate(indent * level_width, 0), SA_CENTER); + DrawSpriteIgnorePadding(Group::Get(g_id)->folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, r.WithX(this->column_rects[VGC_FOLD]).Translate(indent * level_width, 0), {AlignmentH::Centre, AlignmentV::Middle}); } /* draw group name */ @@ -381,24 +381,24 @@ private: /* draw autoreplace protection */ if (protection) { - DrawSpriteIgnorePadding(SPR_GROUP_REPLACE_PROTECT, PAL_NONE, r.WithX(this->column_rects[VGC_PROTECT]), SA_CENTER); + DrawSpriteIgnorePadding(SPR_GROUP_REPLACE_PROTECT, PAL_NONE, r.WithX(this->column_rects[VGC_PROTECT]), {AlignmentH::Centre, AlignmentV::Middle}); } /* draw autoreplace status */ if (stats.autoreplace_defined) { - DrawSpriteIgnorePadding(SPR_GROUP_REPLACE_ACTIVE, stats.autoreplace_finished ? PALETTE_CRASH : PAL_NONE, r.WithX(this->column_rects[VGC_AUTOREPLACE]), SA_CENTER); + DrawSpriteIgnorePadding(SPR_GROUP_REPLACE_ACTIVE, stats.autoreplace_finished ? PALETTE_CRASH : PAL_NONE, r.WithX(this->column_rects[VGC_AUTOREPLACE]), {AlignmentH::Centre, AlignmentV::Middle}); } /* draw the profit icon */ - DrawSpriteIgnorePadding(this->GetGroupProfitSpriteID(g_id), PAL_NONE, r.WithX(this->column_rects[VGC_PROFIT]), SA_CENTER); + DrawSpriteIgnorePadding(this->GetGroupProfitSpriteID(g_id), PAL_NONE, r.WithX(this->column_rects[VGC_PROFIT]), {AlignmentH::Centre, AlignmentV::Middle}); /* draw the number of vehicles of the group */ int num_vehicle_with_subgroups = GetGroupNumVehicle(this->vli.company, g_id, this->vli.vtype); int num_vehicle = GroupStatistics::Get(this->vli.company, g_id, this->vli.vtype).num_vehicle; if (IsAllGroupID(g_id) || IsDefaultGroupID(g_id) || num_vehicle_with_subgroups == num_vehicle) { - DrawString(r.WithX(this->column_rects[VGC_NUMBER]).CentreToHeight(this->column_size[VGC_NUMBER].height), GetString(STR_JUST_COMMA, num_vehicle), colour, SA_RIGHT | SA_FORCE, false, FontSize::Small); + DrawString(r.WithX(this->column_rects[VGC_NUMBER]).CentreToHeight(this->column_size[VGC_NUMBER].height), GetString(STR_JUST_COMMA, num_vehicle), colour, AlignmentH::ForceRight, false, FontSize::Small); } else { - DrawString(r.WithX(this->column_rects[VGC_NUMBER]).CentreToHeight(this->column_size[VGC_NUMBER].height), GetString(STR_GROUP_COUNT_WITH_SUBGROUP, num_vehicle, num_vehicle_with_subgroups - num_vehicle), colour, SA_RIGHT | SA_FORCE); + DrawString(r.WithX(this->column_rects[VGC_NUMBER]).CentreToHeight(this->column_size[VGC_NUMBER].height), GetString(STR_GROUP_COUNT_WITH_SUBGROUP, num_vehicle, num_vehicle_with_subgroups - num_vehicle), colour, AlignmentH::ForceRight); } } @@ -663,17 +663,17 @@ public: Rect tr = r.Shrink(WidgetDimensions::scaled.framerect); DrawString(tr, TimerGameEconomy::UsingWallclockUnits() ? STR_GROUP_PROFIT_THIS_PERIOD : STR_GROUP_PROFIT_THIS_YEAR, TextColour::Black); - DrawString(tr, GetString(STR_JUST_CURRENCY_LONG, this_year), TextColour::Black, SA_RIGHT); + DrawString(tr, GetString(STR_JUST_CURRENCY_LONG, this_year), TextColour::Black, AlignmentH::End); tr.top += GetCharacterHeight(FontSize::Normal); DrawString(tr, TimerGameEconomy::UsingWallclockUnits() ? STR_GROUP_PROFIT_LAST_PERIOD : STR_GROUP_PROFIT_LAST_YEAR, TextColour::Black); - DrawString(tr, GetString(STR_JUST_CURRENCY_LONG, last_year), TextColour::Black, SA_RIGHT); + DrawString(tr, GetString(STR_JUST_CURRENCY_LONG, last_year), TextColour::Black, AlignmentH::End); tr.top += GetCharacterHeight(FontSize::Normal); DrawString(tr, STR_GROUP_OCCUPANCY, TextColour::Black); const size_t vehicle_count = this->vehicles.size(); if (vehicle_count > 0) { - DrawString(tr, GetString(STR_GROUP_OCCUPANCY_VALUE, occupancy / vehicle_count), TextColour::Black, SA_RIGHT); + DrawString(tr, GetString(STR_GROUP_OCCUPANCY_VALUE, occupancy / vehicle_count), TextColour::Black, AlignmentH::End); } break; diff --git a/src/highscore_gui.cpp b/src/highscore_gui.cpp index 7af4616f78..28ac112825 100644 --- a/src/highscore_gui.cpp +++ b/src/highscore_gui.cpp @@ -158,11 +158,11 @@ struct EndGameWindow : EndGameHighScoreBaseWindow { if (this->background_img == SPR_TYCOON_IMG2_BEGIN) { // Tycoon of the century \o/ DrawStringMultiLine(pt.x + ScaleSpriteTrad(15), pt.x + ScaleSpriteTrad(640) - ScaleSpriteTrad(25), pt.y + ScaleSpriteTrad(90), pt.y + ScaleSpriteTrad(160), GetString(STR_HIGHSCORE_PRESIDENT_OF_COMPANY_ACHIEVES_STATUS, c->index, c->index, EndGameGetPerformanceTitleFromValue(c->old_economy[0].performance_history)), - TextColour::FromString, SA_CENTER); + TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); } else { DrawStringMultiLine(pt.x + ScaleSpriteTrad(36), pt.x + ScaleSpriteTrad(640), pt.y + ScaleSpriteTrad(140), pt.y + ScaleSpriteTrad(206), GetString(STR_HIGHSCORE_COMPANY_ACHIEVES_STATUS, c->index, EndGameGetPerformanceTitleFromValue(c->old_economy[0].performance_history)), - TextColour::FromString, SA_CENTER); + TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); } } }; @@ -202,7 +202,7 @@ struct HighScoreWindow : EndGameHighScoreBaseWindow { Point pt = this->GetTopLeft(ScaleSpriteTrad(640), ScaleSpriteTrad(480)); /* Draw the title. */ - DrawStringMultiLine(pt.x + ScaleSpriteTrad(70), pt.x + ScaleSpriteTrad(570), pt.y, pt.y + ScaleSpriteTrad(140), STR_HIGHSCORE_TOP_COMPANIES, TextColour::FromString, SA_CENTER); + DrawStringMultiLine(pt.x + ScaleSpriteTrad(70), pt.x + ScaleSpriteTrad(570), pt.y, pt.y + ScaleSpriteTrad(140), STR_HIGHSCORE_TOP_COMPANIES, TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); /* Draw Highscore peepz */ for (uint8_t i = 0; i < ClampTo(hs.size()); i++) { diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 4ba2033058..d09ace49a4 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -537,7 +537,7 @@ public: DrawString(tr, indsp->name, selected ? TextColour::White : TextColour::Orange); GfxFillRect(icon, selected ? PC_WHITE : PC_BLACK); GfxFillRect(icon.Shrink(WidgetDimensions::scaled.bevel), indsp->map_colour); - DrawString(tr, GetString(STR_JUST_COMMA, Industry::GetIndustryTypeCount(type)), TextColour::Black, SA_RIGHT, false, FontSize::Small); + DrawString(tr, GetString(STR_JUST_COMMA, Industry::GetIndustryTypeCount(type)), TextColour::Black, AlignmentH::End, false, FontSize::Small); text = text.Translate(0, this->resize.step_height); icon = icon.Translate(0, this->resize.step_height); @@ -2152,7 +2152,7 @@ struct CargoesField { case CargoesFieldType::Header: ypos += (small_height - GetCharacterHeight(FontSize::Normal)) / 2; - DrawString(xpos, xpos + industry_width, ypos, this->u.header, TextColour::White, SA_HOR_CENTER); + DrawString(xpos, xpos + industry_width, ypos, this->u.header, TextColour::White, AlignmentH::Centre); break; case CargoesFieldType::Industry: { @@ -2163,7 +2163,7 @@ struct CargoesField { ypos += (normal_height - GetCharacterHeight(FontSize::Normal)) / 2; if (this->u.industry.ind_type < NUM_INDUSTRYTYPES) { const IndustrySpec *indsp = GetIndustrySpec(this->u.industry.ind_type); - DrawString(xpos, xpos2, ypos, indsp->name, TextColour::White, SA_HOR_CENTER); + DrawString(xpos, xpos2, ypos, indsp->name, TextColour::White, AlignmentH::Centre); /* Draw the industry legend. */ int blob_left, blob_right; @@ -2177,7 +2177,7 @@ struct CargoesField { GfxFillRect(blob_left, ypos2 - blob_distance - CargoesField::legend.height, blob_right, ypos2 - blob_distance, PC_BLACK); // Border GfxFillRect(blob_left + 1, ypos2 - blob_distance - CargoesField::legend.height + 1, blob_right - 1, ypos2 - blob_distance - 1, indsp->map_colour); } else { - DrawString(xpos, xpos2, ypos, STR_INDUSTRY_CARGOES_HOUSES, TextColour::FromString, SA_HOR_CENTER); + DrawString(xpos, xpos2, ypos, STR_INDUSTRY_CARGOES_HOUSES, TextColour::FromString, AlignmentH::Centre); } /* Draw the other_produced/other_accepted cargoes. */ @@ -2268,7 +2268,7 @@ struct CargoesField { if (IsValidCargoType(this->u.cargo_label.cargoes[i])) { const CargoSpec *csp = CargoSpec::Get(this->u.cargo_label.cargoes[i]); DrawString(xpos + WidgetDimensions::scaled.framerect.left, xpos + industry_width - 1 - WidgetDimensions::scaled.framerect.right, ypos, csp->name, TextColour::White, - (this->u.cargo_label.left_align) ? SA_LEFT : SA_RIGHT); + (this->u.cargo_label.left_align) ? AlignmentH::Start : AlignmentH::End); } ypos += GetCharacterHeight(FontSize::Normal) + CargoesField::cargo_space.height; } diff --git a/src/intro_gui.cpp b/src/intro_gui.cpp index 9dc0894849..15b026fff5 100644 --- a/src/intro_gui.cpp +++ b/src/intro_gui.cpp @@ -267,11 +267,11 @@ struct SelectGameWindow : public Window { { switch (widget) { case WID_SGI_BASESET: - DrawStringMultiLine(r, GetString(STR_INTRO_BASESET, _missing_extra_graphics), TextColour::FromString, SA_CENTER); + DrawStringMultiLine(r, GetString(STR_INTRO_BASESET, _missing_extra_graphics), TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); break; case WID_SGI_TRANSLATION: - DrawStringMultiLine(r, GetString(STR_INTRO_TRANSLATION, _current_language->missing), TextColour::FromString, SA_CENTER); + DrawStringMultiLine(r, GetString(STR_INTRO_TRANSLATION, _current_language->missing), TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); break; } } @@ -349,16 +349,16 @@ static constexpr std::initializer_list _nested_select_game_widgets /* Single player */ NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0), - NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_GENERATE_GAME), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_LANDSCAPING, STR_INTRO_NEW_GAME, STR_INTRO_TOOLTIP_NEW_GAME), SetAlignment(SA_LEFT | SA_VERT_CENTER), SetFill(1, 0), - NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_PLAY_HEIGHTMAP), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_SHOW_COUNTOURS, STR_INTRO_PLAY_HEIGHTMAP, STR_INTRO_TOOLTIP_PLAY_HEIGHTMAP), SetAlignment(SA_LEFT | SA_VERT_CENTER), SetFill(1, 0), - NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_PLAY_SCENARIO), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_SUBSIDIES, STR_INTRO_PLAY_SCENARIO, STR_INTRO_TOOLTIP_PLAY_SCENARIO), SetAlignment(SA_LEFT | SA_VERT_CENTER), SetFill(1, 0), - NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_LOAD_GAME), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_SAVE, STR_INTRO_LOAD_GAME, STR_INTRO_TOOLTIP_LOAD_GAME), SetAlignment(SA_LEFT | SA_VERT_CENTER), SetFill(1, 0), - NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_HIGHSCORE), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_COMPANY_LEAGUE, STR_INTRO_HIGHSCORE, STR_INTRO_TOOLTIP_HIGHSCORE), SetAlignment(SA_LEFT | SA_VERT_CENTER), SetFill(1, 0), + NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_GENERATE_GAME), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_LANDSCAPING, STR_INTRO_NEW_GAME, STR_INTRO_TOOLTIP_NEW_GAME), SetAlignment({AlignmentH::Start, AlignmentV::Middle}), SetFill(1, 0), + NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_PLAY_HEIGHTMAP), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_SHOW_COUNTOURS, STR_INTRO_PLAY_HEIGHTMAP, STR_INTRO_TOOLTIP_PLAY_HEIGHTMAP), SetAlignment({AlignmentH::Start, AlignmentV::Middle}), SetFill(1, 0), + NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_PLAY_SCENARIO), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_SUBSIDIES, STR_INTRO_PLAY_SCENARIO, STR_INTRO_TOOLTIP_PLAY_SCENARIO), SetAlignment({AlignmentH::Start, AlignmentV::Middle}), SetFill(1, 0), + NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_LOAD_GAME), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_SAVE, STR_INTRO_LOAD_GAME, STR_INTRO_TOOLTIP_LOAD_GAME), SetAlignment({AlignmentH::Start, AlignmentV::Middle}), SetFill(1, 0), + NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_HIGHSCORE), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_COMPANY_LEAGUE, STR_INTRO_HIGHSCORE, STR_INTRO_TOOLTIP_HIGHSCORE), SetAlignment({AlignmentH::Start, AlignmentV::Middle}), SetFill(1, 0), EndContainer(), /* Multi player */ NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0), - NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_PLAY_NETWORK), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_COMPANY_GENERAL, STR_INTRO_MULTIPLAYER, STR_INTRO_TOOLTIP_MULTIPLAYER), SetAlignment(SA_LEFT | SA_VERT_CENTER), SetFill(1, 0), + NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_PLAY_NETWORK), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_COMPANY_GENERAL, STR_INTRO_MULTIPLAYER, STR_INTRO_TOOLTIP_MULTIPLAYER), SetAlignment({AlignmentH::Start, AlignmentV::Middle}), SetFill(1, 0), EndContainer(), NWidget(NWID_SELECTION, Colours::Invalid, WID_SGI_BASESET_SELECTION), @@ -375,10 +375,10 @@ static constexpr std::initializer_list _nested_select_game_widgets /* Other */ NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0), - NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_OPTIONS), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_SETTINGS, STR_INTRO_GAME_OPTIONS, STR_INTRO_TOOLTIP_GAME_OPTIONS), SetAlignment(SA_LEFT | SA_VERT_CENTER), SetFill(1, 0), - NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_CONTENT_DOWNLOAD), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_SHOW_VEHICLES, STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT), SetAlignment(SA_LEFT | SA_VERT_CENTER), SetFill(1, 0), - NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_EDIT_SCENARIO), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_SMALLMAP, STR_INTRO_SCENARIO_EDITOR, STR_INTRO_TOOLTIP_SCENARIO_EDITOR), SetAlignment(SA_LEFT | SA_VERT_CENTER), SetFill(1, 0), - NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_HELP), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_QUERY, STR_INTRO_HELP, STR_INTRO_TOOLTIP_HELP), SetAlignment(SA_LEFT | SA_VERT_CENTER), SetFill(1, 0), + NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_OPTIONS), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_SETTINGS, STR_INTRO_GAME_OPTIONS, STR_INTRO_TOOLTIP_GAME_OPTIONS), SetAlignment({AlignmentH::Start, AlignmentV::Middle}), SetFill(1, 0), + NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_CONTENT_DOWNLOAD), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_SHOW_VEHICLES, STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT), SetAlignment({AlignmentH::Start, AlignmentV::Middle}), SetFill(1, 0), + NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_EDIT_SCENARIO), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_SMALLMAP, STR_INTRO_SCENARIO_EDITOR, STR_INTRO_TOOLTIP_SCENARIO_EDITOR), SetAlignment({AlignmentH::Start, AlignmentV::Middle}), SetFill(1, 0), + NWidget(WWT_PUSHIMGTEXTBTN, Colours::Orange, WID_SGI_HELP), SetToolbarMinimalSize(1), SetSpriteStringTip(SPR_IMG_QUERY, STR_INTRO_HELP, STR_INTRO_TOOLTIP_HELP), SetAlignment({AlignmentH::Start, AlignmentV::Middle}), SetFill(1, 0), EndContainer(), NWidget(NWID_VERTICAL), diff --git a/src/league_gui.cpp b/src/league_gui.cpp index 0fcd3426da..26f6280e40 100644 --- a/src/league_gui.cpp +++ b/src/league_gui.cpp @@ -337,7 +337,7 @@ public: DrawString(rank_rect.left, rank_rect.right, ir.top + text_y_offset, GetString(STR_COMPANY_LEAGUE_COMPANY_RANK, rank + 1)); if (this->icon_size.width > 0 && lte->company != CompanyID::Invalid()) DrawCompanyIcon(lte->company, icon_rect.left, ir.top + icon_y_offset); DrawString(text_rect.left, text_rect.right, ir.top + text_y_offset, lte->text.GetDecodedString(), TextColour::Black); - DrawString(score_rect.left, score_rect.right, ir.top + text_y_offset, lte->score.GetDecodedString(), TextColour::Black, SA_RIGHT | SA_FORCE); + DrawString(score_rect.left, score_rect.right, ir.top + text_y_offset, lte->score.GetDecodedString(), TextColour::Black, AlignmentH::ForceRight); ir.top += this->line_height; } diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp index 509ae1e43f..e1a672a878 100644 --- a/src/linkgraph/linkgraph_gui.cpp +++ b/src/linkgraph/linkgraph_gui.cpp @@ -622,13 +622,13 @@ void LinkGraphLegendWindow::DrawWidget(const Rect &r, WidgetID widget) const str = STR_LINKGRAPH_LEGEND_SATURATED; } if (str != STR_NULL) { - DrawString(br.left, br.right, CentreBounds(br.top, br.bottom, GetCharacterHeight(FontSize::Small)), str, ExtendedTextColour{GetContrastColour(colour), ExtendedTextColourFlag::Forced}, SA_HOR_CENTER, false, FontSize::Small); + DrawString(br.left, br.right, CentreBounds(br.top, br.bottom, GetCharacterHeight(FontSize::Small)), str, ExtendedTextColour{GetContrastColour(colour), ExtendedTextColourFlag::Forced}, AlignmentH::Centre, false, FontSize::Small); } } if (IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) { const CargoSpec *cargo = _sorted_cargo_specs[widget - WID_LGL_CARGO_FIRST]; GfxFillRect(br, cargo->legend_colour); - DrawString(br.left, br.right, CentreBounds(br.top, br.bottom, GetCharacterHeight(FontSize::Small)), cargo->abbrev, GetContrastColour(cargo->legend_colour, 73), SA_HOR_CENTER, false, FontSize::Small); + DrawString(br.left, br.right, CentreBounds(br.top, br.bottom, GetCharacterHeight(FontSize::Small)), cargo->abbrev, GetContrastColour(cargo->legend_colour, 73), AlignmentH::Centre, false, FontSize::Small); } } diff --git a/src/main_gui.cpp b/src/main_gui.cpp index 39fdd4f2da..061784cf09 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -272,7 +272,7 @@ struct MainWindow : Window } int text_y = this->height - GetCharacterHeight(FontSize::Normal) * 2; - DrawString(0, this->width - 1, text_y, STR_INTRO_VERSION, TextColour::White, SA_CENTER); + DrawString(0, this->width - 1, text_y, STR_INTRO_VERSION, TextColour::White, {AlignmentH::Centre, AlignmentV::Middle}); } } diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 65cce78289..fc4fed8922 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -75,12 +75,12 @@ public: Rect ir = r.Shrink(WidgetDimensions::scaled.frametext); for (size_t i = 0; i < this->landinfo_data.size(); i++) { - DrawString(ir, this->landinfo_data[i], i == 0 ? TextColour::LightBlue : TextColour::FromString, SA_HOR_CENTER); + DrawString(ir, this->landinfo_data[i], i == 0 ? TextColour::LightBlue : TextColour::FromString, AlignmentH::Centre); ir.top += GetCharacterHeight(FontSize::Normal) + (i == 0 ? WidgetDimensions::scaled.vsep_wide : WidgetDimensions::scaled.vsep_normal); } if (!this->cargo_acceptance.empty()) { - DrawStringMultiLine(ir, GetString(STR_JUST_RAW_STRING, this->cargo_acceptance), TextColour::FromString, SA_CENTER); + DrawStringMultiLine(ir, GetString(STR_JUST_RAW_STRING, this->cargo_acceptance), TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); } } @@ -454,7 +454,7 @@ struct AboutWindow : public Window { /* Show all scrolling _credits */ for (const auto &str : _credits) { if (y >= r.top + 7 && y < r.bottom - this->line_height) { - DrawString(r.left, r.right, y, str, TextColour::Black, SA_LEFT | SA_FORCE); + DrawString(r.left, r.right, y, str, TextColour::Black, AlignmentH::ForceLeft); } y += this->line_height; } @@ -654,7 +654,7 @@ struct TooltipsWindow : public Window GfxFillRect(r, PC_BLACK); GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), PC_LIGHT_YELLOW); - DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.framerect).Shrink(WidgetDimensions::scaled.fullbevel), this->text.GetDecodedString(), TextColour::Black, SA_CENTER); + DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.framerect).Shrink(WidgetDimensions::scaled.fullbevel), this->text.GetDecodedString(), TextColour::Black, {AlignmentH::Centre, AlignmentV::Middle}); } void OnMouseLoop() override @@ -745,7 +745,7 @@ void QueryString::DrawEditBox(const Window *w, WidgetID wid) const Rect fr = r.Indent(clearbtn_width, !rtl); DrawFrameRect(cr, wi->colour, wi->IsLowered() ? FrameFlag::Lowered : FrameFlags{}); - DrawSpriteIgnorePadding(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT, PAL_NONE, cr, SA_CENTER); + DrawSpriteIgnorePadding(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT, PAL_NONE, cr, {AlignmentH::Centre, AlignmentV::Middle}); if (this->text.GetText().empty()) GfxFillRect(cr.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(wi->colour, Shade::Darker), FillRectMode::Checker); DrawFrameRect(fr, wi->colour, {FrameFlag::Lowered, FrameFlag::Darkened}); @@ -1134,7 +1134,7 @@ struct QueryWindow : public Window { { if (widget != WID_Q_TEXT) return; - DrawStringMultiLine(r, this->message.GetDecodedString(), TextColour::FromString, SA_CENTER); + DrawStringMultiLine(r, this->message.GetDecodedString(), TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); } void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override diff --git a/src/music_gui.cpp b/src/music_gui.cpp index 3be867888d..b196e821c8 100644 --- a/src/music_gui.cpp +++ b/src/music_gui.cpp @@ -757,9 +757,9 @@ struct MusicWindow : public Window { } Rect ir = r.Shrink(WidgetDimensions::scaled.framerect); if (_music.IsPlaying()) { - DrawString(ir, GetString(STR_MUSIC_TRACK_DIGIT, _music.GetCurrentSong().tracknr, 2), TextColour::FromString, SA_HOR_CENTER); + DrawString(ir, GetString(STR_MUSIC_TRACK_DIGIT, _music.GetCurrentSong().tracknr, 2), TextColour::FromString, AlignmentH::Centre); } else { - DrawString(ir, STR_MUSIC_TRACK_NONE, TextColour::FromString, SA_HOR_CENTER); + DrawString(ir, STR_MUSIC_TRACK_NONE, TextColour::FromString, AlignmentH::Centre); } break; } @@ -770,11 +770,11 @@ struct MusicWindow : public Window { MusicSystem::PlaylistEntry entry(_music.GetCurrentSong()); if (BaseMusic::GetUsedSet()->num_available == 0) { - DrawString(ir, STR_MUSIC_TITLE_NOMUSIC, TextColour::FromString, SA_HOR_CENTER); + DrawString(ir, STR_MUSIC_TITLE_NOMUSIC, TextColour::FromString, AlignmentH::Centre); } else if (_music.IsPlaying()) { - DrawString(ir, GetString(STR_MUSIC_TITLE_NAME, entry.songname), TextColour::FromString, SA_HOR_CENTER); + DrawString(ir, GetString(STR_MUSIC_TITLE_NAME, entry.songname), TextColour::FromString, AlignmentH::Centre); } else { - DrawString(ir, STR_MUSIC_TITLE_NONE, TextColour::FromString, SA_HOR_CENTER); + DrawString(ir, STR_MUSIC_TITLE_NONE, TextColour::FromString, AlignmentH::Centre); } break; diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp index f20d3521e8..40b8bee885 100644 --- a/src/network/network_chat_gui.cpp +++ b/src/network/network_chat_gui.cpp @@ -229,7 +229,7 @@ void NetworkDrawChatMessage() for (auto &cmsg : _chatmsg_list) { if (!show_all && cmsg.remove_time < now) continue; - ypos = DrawStringMultiLine(_chatmsg_box.x + ScaleGUITrad(3), _chatmsg_box.x + _chatmsg_box.width - 1, top, ypos, cmsg.message, cmsg.colour, SA_LEFT | SA_BOTTOM | SA_FORCE) - NETWORK_CHAT_LINE_SPACING; + ypos = DrawStringMultiLine(_chatmsg_box.x + ScaleGUITrad(3), _chatmsg_box.x + _chatmsg_box.width - 1, top, ypos, cmsg.message, cmsg.colour, {AlignmentH::ForceLeft, AlignmentV::Bottom}) - NETWORK_CHAT_LINE_SPACING; if (ypos < top) break; } @@ -414,7 +414,7 @@ static constexpr std::initializer_list _nested_chat_window_widgets NWidget(WWT_CLOSEBOX, Colours::Grey, WID_NC_CLOSE), NWidget(WWT_PANEL, Colours::Grey, WID_NC_BACKGROUND), NWidget(NWID_HORIZONTAL), - NWidget(WWT_TEXT, Colours::Invalid, WID_NC_DESTINATION), SetMinimalSize(62, 12), SetPadding(1, 0, 1, 0), SetAlignment(SA_VERT_CENTER | SA_RIGHT), + NWidget(WWT_TEXT, Colours::Invalid, WID_NC_DESTINATION), SetMinimalSize(62, 12), SetPadding(1, 0, 1, 0), SetAlignment({AlignmentH::End, AlignmentV::Middle}), NWidget(WWT_EDITBOX, Colours::Grey, WID_NC_TEXTBOX), SetMinimalSize(100, 0), SetPadding(1, 0, 1, 0), SetResize(1, 0), SetStringTip(STR_NETWORK_CHAT_OSKTITLE), NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_NC_SENDBUTTON), SetMinimalSize(62, 12), SetPadding(1, 0, 1, 0), SetStringTip(STR_NETWORK_CHAT_SEND), diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index 8a2e8ccbbf..8f00f9487c 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -161,19 +161,19 @@ void BaseNetworkContentDownloadStatusWindow::DrawWidget(const Rect &r, WidgetID DrawFrameRect(ir.WithWidth((uint64_t)ir.Width() * this->downloaded_bytes / this->total_bytes, _current_text_dir == TD_RTL), Colours::Mauve, {}); DrawString(ir.left, ir.right, CentreBounds(ir.top, ir.bottom, GetCharacterHeight(FontSize::Normal)), GetString(STR_CONTENT_DOWNLOAD_PROGRESS_SIZE, this->downloaded_bytes, this->total_bytes, this->downloaded_bytes * 100LL / this->total_bytes), - TextColour::FromString, SA_HOR_CENTER); + TextColour::FromString, AlignmentH::Centre); break; } case WID_NCDS_PROGRESS_TEXT: if (this->downloaded_bytes == this->total_bytes) { - DrawStringMultiLine(r, STR_CONTENT_DOWNLOAD_COMPLETE, TextColour::FromString, SA_CENTER); + DrawStringMultiLine(r, STR_CONTENT_DOWNLOAD_COMPLETE, TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); } else if (!this->name.empty()) { DrawStringMultiLine(r, GetString(STR_CONTENT_DOWNLOAD_FILE, this->name, this->downloaded_files, this->total_files), - TextColour::FromString, SA_CENTER); + TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); } else { - DrawStringMultiLine(r, STR_CONTENT_DOWNLOAD_INITIALISE, TextColour::FromString, SA_CENTER); + DrawStringMultiLine(r, STR_CONTENT_DOWNLOAD_INITIALISE, TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); } break; } @@ -684,12 +684,12 @@ public: case ContentInfo::State::DoesNotExist: sprite = SPR_BLOT; pal = PALETTE_TO_RED; break; default: NOT_REACHED(); } - DrawSpriteIgnorePadding(sprite, pal, checkbox.WithY(mr), SA_CENTER); + DrawSpriteIgnorePadding(sprite, pal, checkbox.WithY(mr), {AlignmentH::Centre, AlignmentV::Middle}); StringID str = GetContentTypeString(ci->type); - DrawString(type.left, type.right, mr.top + text_y_offset, str, TextColour::Black, SA_HOR_CENTER); + DrawString(type.left, type.right, mr.top + text_y_offset, str, TextColour::Black, AlignmentH::Centre); - int x = DrawString(name.left, name.right, mr.top + version_y_offset, ci->version, TextColour::Black, SA_RIGHT, false, FontSize::Small); + int x = DrawString(name.left, name.right, mr.top + version_y_offset, ci->version, TextColour::Black, AlignmentH::End, false, FontSize::Small); x += rtl ? WidgetDimensions::scaled.hsep_wide : -WidgetDimensions::scaled.hsep_wide; DrawString(rtl ? x : name.left, rtl ? name.right : x, mr.top + text_y_offset, ci->name, TextColour::Black); @@ -712,7 +712,7 @@ public: /* Create the nice darker rectangle at the details top */ GfxFillRect(r.WithHeight(HEADER_HEIGHT).Shrink(WidgetDimensions::scaled.bevel.left, WidgetDimensions::scaled.bevel.top, WidgetDimensions::scaled.bevel.right, 0), GetColourGradient(Colours::LightBlue, Shade::Normal)); - DrawString(hr.left, hr.right, hr.top, STR_CONTENT_DETAIL_TITLE, TextColour::FromString, SA_HOR_CENTER); + DrawString(hr.left, hr.right, hr.top, STR_CONTENT_DETAIL_TITLE, TextColour::FromString, AlignmentH::Centre); /* Draw the total download size */ DrawString(tr.left, tr.right, tr.bottom - GetCharacterHeight(FontSize::Normal) + 1, GetString(STR_CONTENT_TOTAL_DOWNLOAD_SIZE, this->filesize_sum)); @@ -720,7 +720,7 @@ public: if (this->selected == nullptr) return; /* And fill the rest of the details when there's information to place there */ - DrawStringMultiLine(hr.left, hr.right, hr.top + GetCharacterHeight(FontSize::Normal), hr.bottom, STR_CONTENT_DETAIL_SUBTITLE_UNSELECTED + to_underlying(this->selected->state), TextColour::FromString, SA_CENTER); + DrawStringMultiLine(hr.left, hr.right, hr.top + GetCharacterHeight(FontSize::Normal), hr.bottom, STR_CONTENT_DETAIL_SUBTITLE_UNSELECTED + to_underlying(this->selected->state), TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); /* Also show the total download size, so keep some space from the bottom */ tr.bottom -= GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_wide; @@ -1046,7 +1046,7 @@ static constexpr std::initializer_list _nested_network_content_list NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.sparse_resize), /* Top */ NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0), - NWidget(WWT_TEXT, Colours::Invalid, WID_NCL_FILTER_CAPT), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_CONTENT_FILTER_TITLE), SetAlignment(SA_RIGHT | SA_VERT_CENTER), + NWidget(WWT_TEXT, Colours::Invalid, WID_NCL_FILTER_CAPT), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_CONTENT_FILTER_TITLE), SetAlignment({AlignmentH::End, AlignmentV::Middle}), NWidget(WWT_EDITBOX, Colours::LightBlue, WID_NCL_FILTER), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP), EndContainer(), diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index b8e478cc1c..05eaaabb19 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -383,7 +383,7 @@ protected: Rect clients = nwid->GetCurrentRect(); DrawString(clients.left, clients.right, y + text_y_offset, GetString(STR_NETWORK_SERVER_LIST_GENERAL_ONLINE, cur_item->info.clients_on, cur_item->info.clients_max, cur_item->info.companies_on, cur_item->info.companies_max), - TextColour::FromString, SA_HOR_CENTER); + TextColour::FromString, AlignmentH::Centre); } if (const NWidgetBase *nwid = this->GetWidget(WID_NG_MAPSIZE); nwid->current_x != 0) { @@ -391,7 +391,7 @@ protected: Rect mapsize = nwid->GetCurrentRect(); DrawString(mapsize.left, mapsize.right, y + text_y_offset, GetString(STR_NETWORK_SERVER_LIST_MAP_SIZE_SHORT, cur_item->info.map_width, cur_item->info.map_height), - TextColour::FromString, SA_HOR_CENTER); + TextColour::FromString, AlignmentH::Centre); } if (const NWidgetBase *nwid = this->GetWidget(WID_NG_DATE); nwid->current_x != 0) { @@ -400,7 +400,7 @@ protected: TimerGameCalendar::YearMonthDay ymd = TimerGameCalendar::ConvertDateToYMD(cur_item->info.calendar_date); DrawString(date.left, date.right, y + text_y_offset, GetString(STR_JUST_INT, ymd.year), - TextColour::Black, SA_HOR_CENTER); + TextColour::Black, AlignmentH::Centre); } if (const NWidgetBase *nwid = this->GetWidget(WID_NG_YEARS); nwid->current_x != 0) { @@ -409,7 +409,7 @@ protected: const auto play_time = cur_item->info.ticks_playing / Ticks::TICKS_PER_SECOND; DrawString(years.left, years.right, y + text_y_offset, GetString(STR_NETWORK_SERVER_LIST_PLAY_TIME_SHORT, play_time / 60 / 60, (play_time / 60) % 60), - TextColour::Black, SA_HOR_CENTER); + TextColour::Black, AlignmentH::Centre); } /* Set top and bottom of info rect to current row. */ @@ -419,11 +419,11 @@ protected: bool rtl = _current_text_dir == TD_RTL; /* draw a lock if the server is password protected */ - if (cur_item->info.use_password) DrawSpriteIgnorePadding(SPR_LOCK, PAL_NONE, info.WithWidth(this->lock.width, rtl), SA_CENTER); + if (cur_item->info.use_password) DrawSpriteIgnorePadding(SPR_LOCK, PAL_NONE, info.WithWidth(this->lock.width, rtl), {AlignmentH::Centre, AlignmentV::Middle}); /* draw red or green icon, depending on compatibility with server */ PaletteID pal = cur_item->info.compatible ? PALETTE_TO_GREEN : (cur_item->info.version_compatible ? PALETTE_TO_YELLOW : PALETTE_TO_RED); - DrawSpriteIgnorePadding(SPR_BLOT, pal, info.WithWidth(this->blot.width, !rtl), SA_CENTER); + DrawSpriteIgnorePadding(SPR_BLOT, pal, info.WithWidth(this->blot.width, !rtl), {AlignmentH::Centre, AlignmentV::Middle}); } } @@ -648,12 +648,12 @@ public: /* Draw the right menu */ /* Create the nice darker rectangle at the details top */ GfxFillRect(r.WithHeight(header_height).Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(Colours::LightBlue, Shade::Normal)); - hr.top = DrawStringMultiLine(hr, header_msg, TextColour::FromString, SA_HOR_CENTER); + hr.top = DrawStringMultiLine(hr, header_msg, TextColour::FromString, AlignmentH::Centre); if (sel == nullptr) return; - hr.top = DrawStringMultiLine(hr, sel->info.server_name, TextColour::Orange, SA_HOR_CENTER); // game name + hr.top = DrawStringMultiLine(hr, sel->info.server_name, TextColour::Orange, AlignmentH::Centre); // game name if (sel->status != NetworkGameStatus::Online) { - tr.top = DrawStringMultiLine(tr, header_msg, TextColour::FromString, SA_HOR_CENTER); + tr.top = DrawStringMultiLine(tr, header_msg, TextColour::FromString, AlignmentH::Centre); } else { // show game info tr.top = DrawStringMultiLine(tr, GetString(STR_NETWORK_SERVER_LIST_CLIENTS, sel->info.clients_on, sel->info.clients_max, sel->info.companies_on, sel->info.companies_max)); @@ -680,12 +680,12 @@ public: tr.top += WidgetDimensions::scaled.vsep_wide; if (!sel->info.compatible) { - DrawStringMultiLine(tr, sel->info.version_compatible ? STR_NETWORK_SERVER_LIST_GRF_MISMATCH : STR_NETWORK_SERVER_LIST_VERSION_MISMATCH, TextColour::FromString, SA_HOR_CENTER); // server mismatch + DrawStringMultiLine(tr, sel->info.version_compatible ? STR_NETWORK_SERVER_LIST_GRF_MISMATCH : STR_NETWORK_SERVER_LIST_VERSION_MISMATCH, TextColour::FromString, AlignmentH::Centre); // server mismatch } else if (sel->info.clients_on == sel->info.clients_max) { /* Show: server full, when clients_on == max_clients */ - DrawStringMultiLine(tr, STR_NETWORK_SERVER_LIST_SERVER_FULL, TextColour::FromString, SA_HOR_CENTER); // server full + DrawStringMultiLine(tr, STR_NETWORK_SERVER_LIST_SERVER_FULL, TextColour::FromString, AlignmentH::Centre); // server full } else if (sel->info.use_password) { - DrawStringMultiLine(tr, STR_NETWORK_SERVER_LIST_PASSWORD, TextColour::FromString, SA_HOR_CENTER); // password warning + DrawStringMultiLine(tr, STR_NETWORK_SERVER_LIST_PASSWORD, TextColour::FromString, AlignmentH::Centre); // password warning } } } @@ -1263,7 +1263,7 @@ static constexpr std::initializer_list _nested_client_list_widgets NWidget(WWT_FRAME, Colours::Grey), SetStringTip(STR_NETWORK_CLIENT_LIST_SERVER), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0), NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_NETWORK_CLIENT_LIST_SERVER_NAME), - NWidget(WWT_TEXT, Colours::Invalid, WID_CL_SERVER_NAME), SetFill(1, 0), SetResize(1, 0), SetToolTip(STR_NETWORK_CLIENT_LIST_SERVER_NAME_TOOLTIP), SetAlignment(SA_VERT_CENTER | SA_RIGHT), + NWidget(WWT_TEXT, Colours::Invalid, WID_CL_SERVER_NAME), SetFill(1, 0), SetResize(1, 0), SetToolTip(STR_NETWORK_CLIENT_LIST_SERVER_NAME_TOOLTIP), SetAlignment({AlignmentH::End, AlignmentV::Middle}), NWidget(WWT_PUSHIMGBTN, Colours::Grey, WID_CL_SERVER_NAME_EDIT), SetAspect(WidgetDimensions::ASPECT_RENAME), SetSpriteTip(SPR_RENAME, STR_NETWORK_CLIENT_LIST_SERVER_NAME_EDIT_TOOLTIP), EndContainer(), NWidget(NWID_SELECTION, Colours::Invalid, WID_CL_SERVER_SELECTOR), @@ -1274,11 +1274,11 @@ static constexpr std::initializer_list _nested_client_list_widgets EndContainer(), NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_NETWORK_CLIENT_LIST_SERVER_INVITE_CODE), - NWidget(WWT_TEXT, Colours::Invalid, WID_CL_SERVER_INVITE_CODE), SetFill(1, 0), SetResize(1, 0), SetToolTip(STR_NETWORK_CLIENT_LIST_SERVER_INVITE_CODE_TOOLTIP), SetAlignment(SA_VERT_CENTER | SA_RIGHT), + NWidget(WWT_TEXT, Colours::Invalid, WID_CL_SERVER_INVITE_CODE), SetFill(1, 0), SetResize(1, 0), SetToolTip(STR_NETWORK_CLIENT_LIST_SERVER_INVITE_CODE_TOOLTIP), SetAlignment({AlignmentH::End, AlignmentV::Middle}), EndContainer(), NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_NETWORK_CLIENT_LIST_SERVER_CONNECTION_TYPE), - NWidget(WWT_TEXT, Colours::Invalid, WID_CL_SERVER_CONNECTION_TYPE), SetFill(1, 0), SetResize(1, 0), SetToolTip(STR_NETWORK_CLIENT_LIST_SERVER_CONNECTION_TYPE_TOOLTIP), SetAlignment(SA_VERT_CENTER | SA_RIGHT), + NWidget(WWT_TEXT, Colours::Invalid, WID_CL_SERVER_CONNECTION_TYPE), SetFill(1, 0), SetResize(1, 0), SetToolTip(STR_NETWORK_CLIENT_LIST_SERVER_CONNECTION_TYPE_TOOLTIP), SetAlignment({AlignmentH::End, AlignmentV::Middle}), EndContainer(), EndContainer(), EndContainer(), @@ -1286,7 +1286,7 @@ static constexpr std::initializer_list _nested_client_list_widgets NWidget(WWT_FRAME, Colours::Grey), SetStringTip(STR_NETWORK_CLIENT_LIST_PLAYER), NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_NETWORK_CLIENT_LIST_PLAYER_NAME), - NWidget(WWT_TEXT, Colours::Invalid, WID_CL_CLIENT_NAME), SetFill(1, 0), SetResize(1, 0), SetToolTip(STR_NETWORK_CLIENT_LIST_PLAYER_NAME_TOOLTIP), SetAlignment(SA_VERT_CENTER | SA_RIGHT), + NWidget(WWT_TEXT, Colours::Invalid, WID_CL_CLIENT_NAME), SetFill(1, 0), SetResize(1, 0), SetToolTip(STR_NETWORK_CLIENT_LIST_PLAYER_NAME_TOOLTIP), SetAlignment({AlignmentH::End, AlignmentV::Middle}), NWidget(WWT_PUSHIMGBTN, Colours::Grey, WID_CL_CLIENT_NAME_EDIT), SetAspect(WidgetDimensions::ASPECT_RENAME), SetSpriteTip(SPR_RENAME, STR_NETWORK_CLIENT_LIST_PLAYER_NAME_EDIT_TOOLTIP), EndContainer(), EndContainer(), @@ -1298,7 +1298,7 @@ static constexpr std::initializer_list _nested_client_list_widgets EndContainer(), NWidget(NWID_HORIZONTAL), NWidget(WWT_PANEL, Colours::Grey), - NWidget(WWT_TEXT, Colours::Invalid, WID_CL_CLIENT_COMPANY_COUNT), SetFill(1, 0), SetResize(1, 0), SetPadding(WidgetDimensions::unscaled.framerect), SetAlignment(SA_CENTER), SetToolTip(STR_NETWORK_CLIENT_LIST_CLIENT_COMPANY_COUNT_TOOLTIP), + NWidget(WWT_TEXT, Colours::Invalid, WID_CL_CLIENT_COMPANY_COUNT), SetFill(1, 0), SetResize(1, 0), SetPadding(WidgetDimensions::unscaled.framerect), SetAlignment({AlignmentH::Centre, AlignmentV::Middle}), SetToolTip(STR_NETWORK_CLIENT_LIST_CLIENT_COMPANY_COUNT_TOOLTIP), EndContainer(), NWidget(WWT_RESIZEBOX, Colours::Grey), EndContainer(), @@ -1494,7 +1494,7 @@ protected: for (auto &button : buttons) { Rect br = r.CentreToHeight(button->height).WithWidth(button->width, !rtl); DrawFrameRect(br, button->colour, {}); - DrawSpriteIgnorePadding(button->sprite, PAL_NONE, br, SA_CENTER); + DrawSpriteIgnorePadding(button->sprite, PAL_NONE, br, {AlignmentH::Centre, AlignmentV::Middle}); if (button->disabled) { GfxFillRect(br.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(button->colour, Shade::Darker), FillRectMode::Checker); } @@ -1520,7 +1520,7 @@ public: Dimension d = GetScaledSpriteSize(SPR_COMPANY_ICON); PaletteID pal = Company::IsValidID(this->company_id) ? GetCompanyPalette(this->company_id) : PALETTE_TO_GREY; - DrawSpriteIgnorePadding(SPR_COMPANY_ICON, pal, r.WithWidth(d.width, rtl), SA_CENTER); + DrawSpriteIgnorePadding(SPR_COMPANY_ICON, pal, r.WithWidth(d.width, rtl), {AlignmentH::Centre, AlignmentV::Middle}); Rect tr = r.CentreToHeight(GetCharacterHeight(FontSize::Normal)).Indent(d.width + WidgetDimensions::scaled.hsep_normal, rtl); if (this->company_id == COMPANY_SPECTATOR) { @@ -1564,7 +1564,7 @@ public: if (player_icon != 0) { Dimension d = GetScaledSpriteSize(player_icon); - DrawSpriteIgnorePadding(player_icon, PALETTE_TO_GREY, r.WithWidth(d.width, rtl), SA_CENTER); + DrawSpriteIgnorePadding(player_icon, PALETTE_TO_GREY, r.WithWidth(d.width, rtl), {AlignmentH::Centre, AlignmentV::Middle}); tr = tr.Indent(d.width + WidgetDimensions::scaled.hsep_normal, rtl); } @@ -2124,21 +2124,21 @@ struct NetworkJoinStatusWindow : Window { break; } DrawFrameRect(ir.WithWidth(ir.Width() * progress / 100, _current_text_dir == TD_RTL), Colours::Mauve, {}); - DrawString(ir.left, ir.right, CentreBounds(ir.top, ir.bottom, GetCharacterHeight(FontSize::Normal)), STR_NETWORK_CONNECTING_1 + to_underlying(_network_join_status), TextColour::FromString, SA_HOR_CENTER); + DrawString(ir.left, ir.right, CentreBounds(ir.top, ir.bottom, GetCharacterHeight(FontSize::Normal)), STR_NETWORK_CONNECTING_1 + to_underlying(_network_join_status), TextColour::FromString, AlignmentH::Centre); break; } case WID_NJS_PROGRESS_TEXT: switch (_network_join_status) { case NetworkJoinStatus::Waiting: - DrawStringMultiLine(r, GetString(STR_NETWORK_CONNECTING_WAITING, _network_join_waiting), TextColour::FromString, SA_CENTER); + DrawStringMultiLine(r, GetString(STR_NETWORK_CONNECTING_WAITING, _network_join_waiting), TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); break; case NetworkJoinStatus::Downloading: if (_network_join_bytes_total == 0) { - DrawStringMultiLine(r, GetString(STR_NETWORK_CONNECTING_DOWNLOADING_1, _network_join_bytes), TextColour::FromString, SA_CENTER); + DrawStringMultiLine(r, GetString(STR_NETWORK_CONNECTING_DOWNLOADING_1, _network_join_bytes), TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); } else { - DrawStringMultiLine(r, GetString(STR_NETWORK_CONNECTING_DOWNLOADING_2, _network_join_bytes, _network_join_bytes_total), TextColour::FromString, SA_CENTER); + DrawStringMultiLine(r, GetString(STR_NETWORK_CONNECTING_DOWNLOADING_2, _network_join_bytes, _network_join_bytes_total), TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); } break; @@ -2276,7 +2276,7 @@ struct NetworkAskRelayWindow : public Window { void DrawWidget(const Rect &r, WidgetID widget) const override { if (widget == WID_NAR_TEXT) { - DrawStringMultiLine(r, GetString(STR_NETWORK_ASK_RELAY_TEXT, this->server_connection_string, this->relay_connection_string), TextColour::FromString, SA_CENTER); + DrawStringMultiLine(r, GetString(STR_NETWORK_ASK_RELAY_TEXT, this->server_connection_string, this->relay_connection_string), TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); } } @@ -2318,7 +2318,7 @@ static constexpr std::initializer_list _nested_network_ask_relay_wi EndContainer(), NWidget(WWT_PANEL, Colours::Red), NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.modalpopup), - NWidget(WWT_TEXT, Colours::Invalid, WID_NAR_TEXT), SetAlignment(SA_HOR_CENTER), SetFill(1, 1), + NWidget(WWT_TEXT, Colours::Invalid, WID_NAR_TEXT), SetAlignment(AlignmentH::Centre), SetFill(1, 1), NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0), NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_NAR_NO), SetMinimalSize(71, 12), SetFill(1, 1), SetStringTip(STR_NETWORK_ASK_RELAY_NO), NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_NAR_YES_ONCE), SetMinimalSize(71, 12), SetFill(1, 1), SetStringTip(STR_NETWORK_ASK_RELAY_YES_ONCE), @@ -2376,7 +2376,7 @@ struct NetworkAskSurveyWindow : public Window { void DrawWidget(const Rect &r, WidgetID widget) const override { if (widget == WID_NAS_TEXT) { - DrawStringMultiLine(r, STR_NETWORK_ASK_SURVEY_TEXT, TextColour::Black, SA_CENTER); + DrawStringMultiLine(r, STR_NETWORK_ASK_SURVEY_TEXT, TextColour::Black, {AlignmentH::Centre, AlignmentV::Middle}); } } @@ -2420,7 +2420,7 @@ static constexpr std::initializer_list _nested_network_ask_survey_w EndContainer(), NWidget(WWT_PANEL, Colours::Grey), NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.modalpopup), - NWidget(WWT_TEXT, Colours::Invalid, WID_NAS_TEXT), SetAlignment(SA_HOR_CENTER), SetFill(1, 1), + NWidget(WWT_TEXT, Colours::Invalid, WID_NAS_TEXT), SetAlignment(AlignmentH::Centre), SetFill(1, 1), NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0), NWidget(WWT_PUSHTXTBTN, Colours::White, WID_NAS_PREVIEW), SetMinimalSize(71, 12), SetFill(1, 1), SetStringTip(STR_NETWORK_ASK_SURVEY_PREVIEW), NWidget(WWT_PUSHTXTBTN, Colours::White, WID_NAS_LINK), SetMinimalSize(71, 12), SetFill(1, 1), SetStringTip(STR_NETWORK_ASK_SURVEY_LINK), diff --git a/src/newgrf_badge_gui.cpp b/src/newgrf_badge_gui.cpp index cbb0a79d2b..91c9e0e64e 100644 --- a/src/newgrf_badge_gui.cpp +++ b/src/newgrf_badge_gui.cpp @@ -184,7 +184,7 @@ void DrawBadgeColumn(Rect r, int column_group, const GUIBadgeClasses &gui_classe PalSpriteID ps = GetBadgeSprite(badge, feature, introduction_date, remap); if (ps.sprite == 0) continue; - DrawSpriteIgnorePadding(ps.sprite, ps.pal, r.WithWidth(width, rtl), SA_CENTER); + DrawSpriteIgnorePadding(ps.sprite, ps.pal, r.WithWidth(width, rtl), {AlignmentH::Centre, AlignmentV::Middle}); break; } diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index 694bbc220e..df86926f2e 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -942,7 +942,7 @@ struct SpriteAlignerWindow : Window { for (auto it = first; it != last; ++it) { const SpriteFile *file = GetOriginFile(*it); if (file == nullptr) { - DrawString(ir, GetString(STR_JUST_COMMA, *it), *it == this->current_sprite ? TextColour::White : ExtendedTextColour{TextColour::Grey, ExtendedTextColourFlag::NoShade}, SA_RIGHT | SA_FORCE); + DrawString(ir, GetString(STR_JUST_COMMA, *it), *it == this->current_sprite ? TextColour::White : ExtendedTextColour{TextColour::Grey, ExtendedTextColourFlag::NoShade}, AlignmentH::ForceRight); } else { DrawString(ir, GetString(STR_SPRITE_ALIGNER_SPRITE, file->GetSimplifiedFilename(), GetSpriteLocalID(*it)), *it == this->current_sprite ? TextColour::White : TextColour::Black); } diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 1aff8fae3a..27635727e6 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -908,7 +908,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { case WID_NS_NEWGRF_INFO_TITLE: { /* Create the nice darker rectangle at the details top. */ GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(Colours::Mauve, Shade::Normal)); - DrawString(r.left, r.right, CentreBounds(r.top, r.bottom, GetCharacterHeight(FontSize::Normal)), STR_NEWGRF_SETTINGS_INFO_TITLE, TextColour::FromString, SA_HOR_CENTER); + DrawString(r.left, r.right, CentreBounds(r.top, r.bottom, GetCharacterHeight(FontSize::Normal)), STR_NEWGRF_SETTINGS_INFO_TITLE, TextColour::FromString, AlignmentH::Centre); break; } @@ -2185,14 +2185,14 @@ struct ScanProgressWindow : public Window { Rect ir = r.Shrink(WidgetDimensions::scaled.bevel); uint percent = scanned * 100 / std::max(1U, _settings_client.gui.last_newgrf_count); DrawFrameRect(ir.WithWidth(ir.Width() * percent / 100, _current_text_dir == TD_RTL), Colours::Mauve, {}); - DrawString(ir.left, ir.right, CentreBounds(ir.top, ir.bottom, GetCharacterHeight(FontSize::Normal)), GetString(STR_GENERATION_PROGRESS, percent), TextColour::FromString, SA_HOR_CENTER); + DrawString(ir.left, ir.right, CentreBounds(ir.top, ir.bottom, GetCharacterHeight(FontSize::Normal)), GetString(STR_GENERATION_PROGRESS, percent), TextColour::FromString, AlignmentH::Centre); break; } case WID_SP_PROGRESS_TEXT: - DrawString(r.left, r.right, r.top, GetString(STR_NEWGRF_SCAN_STATUS, this->scanned, _settings_client.gui.last_newgrf_count), TextColour::FromString, SA_HOR_CENTER); + DrawString(r.left, r.right, r.top, GetString(STR_NEWGRF_SCAN_STATUS, this->scanned, _settings_client.gui.last_newgrf_count), TextColour::FromString, AlignmentH::Centre); - DrawString(r.left, r.right, r.top + GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal, this->last_name, TextColour::Black, SA_HOR_CENTER); + DrawString(r.left, r.right, r.top + GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal, this->last_name, TextColour::Black, AlignmentH::Centre); break; } } diff --git a/src/news_gui.cpp b/src/news_gui.cpp index e515f8112b..af6c4f0127 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -112,7 +112,7 @@ static constexpr std::initializer_list _nested_normal_news_widgets NWidget(WWT_CLOSEBOX, Colours::White, WID_N_CLOSEBOX), NWidget(WWT_LABEL, Colours::Invalid, WID_N_DATE), SetTextStyle(TextColour::Black, FontSize::Small), - SetAlignment(SA_RIGHT | SA_TOP), + SetAlignment({AlignmentH::End, AlignmentV::Top}), EndContainer(), EndContainer(), /* Layer 2 */ @@ -240,7 +240,7 @@ static constexpr std::initializer_list _nested_thin_news_widgets = NWidget(WWT_CLOSEBOX, Colours::White, WID_N_CLOSEBOX), NWidget(WWT_LABEL, Colours::Invalid, WID_N_DATE), SetTextStyle(TextColour::Black, FontSize::Small), - SetAlignment(SA_RIGHT | SA_TOP), + SetAlignment({AlignmentH::End, AlignmentV::Top}), EndContainer(), EndContainer(), /* Layer 2 */ @@ -513,7 +513,7 @@ struct NewsWindow : Window { { switch (widget) { case WID_N_CAPTION: - DrawCaption(r, Colours::LightBlue, this->owner, TextColour::FromString, GetString(STR_NEWS_MESSAGE_CAPTION), SA_CENTER, FontSize::Normal); + DrawCaption(r, Colours::LightBlue, this->owner, TextColour::FromString, GetString(STR_NEWS_MESSAGE_CAPTION), {AlignmentH::Centre, AlignmentV::Middle}, FontSize::Normal); break; case WID_N_PANEL: @@ -523,7 +523,7 @@ struct NewsWindow : Window { case WID_N_MESSAGE: case WID_N_COMPANY_MSG: { const NWidgetLeaf &nwid = *this->GetWidget(widget); - DrawStringMultiLine(r, this->ni->headline.GetDecodedString(), nwid.GetTextColour(), SA_CENTER, false, nwid.GetFontSize()); + DrawStringMultiLine(r, this->ni->headline.GetDecodedString(), nwid.GetTextColour(), {AlignmentH::Centre, AlignmentV::Middle}, false, nwid.GetFontSize()); break; } @@ -535,7 +535,7 @@ struct NewsWindow : Window { } case WID_N_MGR_NAME: { const CompanyNewsInformation *cni = static_cast(this->ni->data.get()); - DrawStringMultiLine(r, GetString(STR_JUST_RAW_STRING, cni->president_name), TextColour::FromString, SA_CENTER); + DrawStringMultiLine(r, GetString(STR_JUST_RAW_STRING, cni->president_name), TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); break; } @@ -545,7 +545,7 @@ struct NewsWindow : Window { case WID_N_VEH_NAME: case WID_N_VEH_TITLE: - DrawStringMultiLine(r, this->GetNewVehicleMessageString(widget), TextColour::FromString, SA_CENTER); + DrawStringMultiLine(r, this->GetNewVehicleMessageString(widget), TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); break; case WID_N_VEH_SPR: { @@ -558,7 +558,7 @@ struct NewsWindow : Window { case WID_N_VEH_INFO: { assert(std::holds_alternative(ni->ref1)); EngineID engine = std::get(this->ni->ref1); - DrawStringMultiLine(r, GetEngineInfoString(engine), TextColour::Black, SA_CENTER); + DrawStringMultiLine(r, GetEngineInfoString(engine), TextColour::Black, {AlignmentH::Centre, AlignmentV::Middle}); break; } } diff --git a/src/object_gui.cpp b/src/object_gui.cpp index 9d2d3d1498..f4104eaa00 100644 --- a/src/object_gui.cpp +++ b/src/object_gui.cpp @@ -399,7 +399,7 @@ static constexpr std::initializer_list _nested_build_object_widgets NWidget(WWT_PANEL, Colours::Grey, WID_BO_OBJECT_SPRITE), SetToolTip(STR_OBJECT_BUILD_PREVIEW_TOOLTIP), EndContainer(), EndContainer(), EndContainer(), - NWidget(WWT_TEXT, Colours::Invalid, WID_BO_OBJECT_SIZE), SetAlignment(SA_CENTER), + NWidget(WWT_TEXT, Colours::Invalid, WID_BO_OBJECT_SIZE), SetAlignment({AlignmentH::Centre, AlignmentV::Middle}), NWidget(WWT_EMPTY, Colours::Invalid, WID_BO_INFO), SetFill(1, 0), SetResize(1, 0), EndContainer(), EndContainer(), diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 037cb320ec..bcb8b27916 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -243,7 +243,7 @@ void DrawOrderString(const Vehicle *v, const Order *order, VehicleOrderID order_ colour = TextColour::White; } - DrawString(left, rtl ? right - 2 * sprite_size.width - 3 : middle, y, GetString(STR_ORDER_INDEX, order_index + 1), colour, SA_RIGHT | SA_FORCE); + DrawString(left, rtl ? right - 2 * sprite_size.width - 3 : middle, y, GetString(STR_ORDER_INDEX, order_index + 1), colour, AlignmentH::ForceRight); std::string line; diff --git a/src/picker_gui.cpp b/src/picker_gui.cpp index bd4f91892c..bbb76e6bc8 100644 --- a/src/picker_gui.cpp +++ b/src/picker_gui.cpp @@ -421,7 +421,7 @@ void PickerWindow::DrawWidget(const Rect &r, WidgetID widget) const case WID_PW_TYPE_NAME: { StringID str = this->callbacks.GetTypeName(this->callbacks.GetSelectedClass(), this->callbacks.GetSelectedType()); - if (str != INVALID_STRING_ID) DrawString(r, str, TextColour::Gold, SA_CENTER); + if (str != INVALID_STRING_ID) DrawString(r, str, TextColour::Gold, {AlignmentH::Centre, AlignmentV::Middle}); break; } } diff --git a/src/script/script_gui.cpp b/src/script/script_gui.cpp index 850a4dfcb6..92cc427870 100644 --- a/src/script/script_gui.cpp +++ b/src/script/script_gui.cpp @@ -897,7 +897,7 @@ struct ScriptDebugWindow : public Window { if (colour == TextColour::Black) colour = TextColour::White; // Make black text readable by inverting it to white. } - DrawString(fr, line.text, colour, SA_LEFT | SA_FORCE); + DrawString(fr, line.text, colour, AlignmentH::ForceLeft); fr.top += this->resize.step_height; } } diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 794df58324..59156268d5 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -209,11 +209,11 @@ static constexpr std::initializer_list _nested_social_plugins_widge NWidget(WWT_FRAME, GAME_OPTIONS_BACKGROUND, WID_GO_SOCIAL_PLUGIN_TITLE), SetTextStyle(GAME_OPTIONS_FRAME), NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), NWidget(WWT_TEXT, Colours::Invalid), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_GAME_OPTIONS_SOCIAL_PLUGIN_PLATFORM), SetTextStyle(GAME_OPTIONS_LABEL), - NWidget(WWT_TEXT, Colours::Invalid, WID_GO_SOCIAL_PLUGIN_PLATFORM), SetAlignment(SA_RIGHT), + NWidget(WWT_TEXT, Colours::Invalid, WID_GO_SOCIAL_PLUGIN_PLATFORM), SetAlignment(AlignmentH::End), EndContainer(), NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), NWidget(WWT_TEXT, Colours::Invalid), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE), SetTextStyle(GAME_OPTIONS_LABEL), - NWidget(WWT_TEXT, Colours::Invalid, WID_GO_SOCIAL_PLUGIN_STATE), SetAlignment(SA_RIGHT), + NWidget(WWT_TEXT, Colours::Invalid, WID_GO_SOCIAL_PLUGIN_STATE), SetAlignment(AlignmentH::End), EndContainer(), EndContainer(), EndContainer(), @@ -926,7 +926,7 @@ struct GameOptionsWindow : Window { if (this->warn_missing != WHR_NONE) { DrawStringMultiLineWithClipping(panel.WithHeight(this->warn_lines * GetCharacterHeight(FontSize::Normal)), GetString(warn_str, _game_settings_restrict_dropdown[this->filter.min_cat]), - TextColour::Black, SA_CENTER); + TextColour::Black, {AlignmentH::Centre, AlignmentV::Middle}); } } @@ -1888,8 +1888,8 @@ void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool c DrawFrameRect(lr, button_colour, (state == 1) ? FrameFlag::Lowered : FrameFlags{}); DrawFrameRect(rr, button_colour, (state == 2) ? FrameFlag::Lowered : FrameFlags{}); - DrawSpriteIgnorePadding(SPR_ARROW_LEFT, PAL_NONE, lr, SA_CENTER); - DrawSpriteIgnorePadding(SPR_ARROW_RIGHT, PAL_NONE, rr, SA_CENTER); + DrawSpriteIgnorePadding(SPR_ARROW_LEFT, PAL_NONE, lr, {AlignmentH::Centre, AlignmentV::Middle}); + DrawSpriteIgnorePadding(SPR_ARROW_RIGHT, PAL_NONE, rr, {AlignmentH::Centre, AlignmentV::Middle}); /* Grey out the buttons that aren't clickable */ bool rtl = _current_text_dir == TD_RTL; @@ -1920,8 +1920,8 @@ void DrawUpDownButtons(int x, int y, Colours button_colour, uint8_t state, bool DrawFrameRect(ur, button_colour, (state == 1) ? FrameFlag::Lowered : FrameFlags{}); DrawFrameRect(dr, button_colour, (state == 2) ? FrameFlag::Lowered : FrameFlags{}); - DrawSpriteIgnorePadding(SPR_ARROW_UP, PAL_NONE, ur, SA_CENTER); - DrawSpriteIgnorePadding(SPR_ARROW_DOWN, PAL_NONE, dr, SA_CENTER); + DrawSpriteIgnorePadding(SPR_ARROW_UP, PAL_NONE, ur, {AlignmentH::Centre, AlignmentV::Middle}); + DrawSpriteIgnorePadding(SPR_ARROW_DOWN, PAL_NONE, dr, {AlignmentH::Centre, AlignmentV::Middle}); /* Grey out the buttons that aren't clickable */ if (!clickable_up) GfxFillRect(ur.Shrink(WidgetDimensions::scaled.bevel), colour, FillRectMode::Checker); @@ -1943,7 +1943,7 @@ void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool cl Rect r = {x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1}; DrawFrameRect(r, button_colour, state ? FrameFlag::Lowered : FrameFlags{}); - DrawSpriteIgnorePadding(SPR_ARROW_DOWN, PAL_NONE, r, SA_CENTER); + DrawSpriteIgnorePadding(SPR_ARROW_DOWN, PAL_NONE, r, {AlignmentH::Centre, AlignmentV::Middle}); if (!clickable) { GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), colour, FillRectMode::Checker); diff --git a/src/slider.cpp b/src/slider.cpp index 74beed0e1c..9a1dffe9d0 100644 --- a/src/slider.cpp +++ b/src/slider.cpp @@ -70,7 +70,7 @@ void DrawSliderWidget(Rect r, Colours wedge_colour, Colours handle_colour, TextC Dimension d = GetStringBoundingBox(*str, FontSize::Small); x = Clamp(x - d.width / 2, r.left, r.right - d.width); - DrawString(x, x + d.width, r.bottom + 1 + WidgetDimensions::scaled.hsep_normal, *str, text_colour, SA_CENTER, false, FontSize::Small); + DrawString(x, x + d.width, r.bottom + 1 + WidgetDimensions::scaled.hsep_normal, *str, text_colour, {AlignmentH::Centre, AlignmentV::Middle}, false, FontSize::Small); } } diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index 9de0b6faca..82815e8c28 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -1044,7 +1044,7 @@ protected: y < dpi->top + dpi->height) { /* And draw it. */ - DrawString(x, x + legend_text_width, y, tbl.legend, TextColour::White, SA_LEFT, false, FontSize::Small); + DrawString(x, x + legend_text_width, y, tbl.legend, TextColour::White, AlignmentH::Start, false, FontSize::Small); } } } diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 3b33db0857..59a842295e 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -246,7 +246,7 @@ static void StationsWndShowStationRating(int left, int right, int y, CargoType c } } - DrawString(left + padding, right, y, cs->abbrev, tc, SA_CENTER, false, FontSize::Small); + DrawString(left + padding, right, y, cs->abbrev, tc, {AlignmentH::Centre, AlignmentV::Middle}, false, FontSize::Small); /* Draw green/red ratings bar (fits under the waiting bar) */ y += height + padding + 1; diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp index b3e63aafba..da2d592ff8 100644 --- a/src/statusbar_gui.cpp +++ b/src/statusbar_gui.cpp @@ -48,7 +48,7 @@ static bool DrawScrollingStatusText(const NewsItem &ni, int scroll_pos, int left int pos = (_current_text_dir == TD_RTL) ? (scroll_pos - width) : (right - scroll_pos - left); AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); - DrawString(pos, INT16_MAX, 0, message, TextColour::LightBlue, SA_LEFT | SA_FORCE); + DrawString(pos, INT16_MAX, 0, message, TextColour::LightBlue, AlignmentH::ForceLeft); return (_current_text_dir == TD_RTL) ? (pos < right - left) : (pos + width > 0); } @@ -110,19 +110,19 @@ struct StatusBarWindow : Window { switch (widget) { case WID_S_LEFT: /* Draw the date */ - DrawString(tr, GetString(STR_JUST_DATE_LONG, TimerGameCalendar::date), TextColour::White, SA_HOR_CENTER); + DrawString(tr, GetString(STR_JUST_DATE_LONG, TimerGameCalendar::date), TextColour::White, AlignmentH::Centre); break; case WID_S_RIGHT: { if (_local_company == COMPANY_SPECTATOR) { - DrawString(tr, STR_STATUSBAR_SPECTATOR, TextColour::FromString, SA_HOR_CENTER); + DrawString(tr, STR_STATUSBAR_SPECTATOR, TextColour::FromString, AlignmentH::Centre); } else if (_settings_game.difficulty.infinite_money) { - DrawString(tr, STR_STATUSBAR_INFINITE_MONEY, TextColour::FromString, SA_HOR_CENTER); + DrawString(tr, STR_STATUSBAR_INFINITE_MONEY, TextColour::FromString, AlignmentH::Centre); } else { /* Draw company money, if any */ const Company *c = Company::GetIfValid(_local_company); if (c != nullptr) { - DrawString(tr, GetString(STR_JUST_CURRENCY_LONG, c->money), TextColour::White, SA_HOR_CENTER); + DrawString(tr, GetString(STR_JUST_CURRENCY_LONG, c->money), TextColour::White, AlignmentH::Centre); } } break; @@ -131,25 +131,25 @@ struct StatusBarWindow : Window { case WID_S_MIDDLE: /* Draw status bar */ if (this->saving) { // true when saving is active - DrawString(tr, STR_STATUSBAR_SAVING_GAME, TextColour::FromString, SA_HOR_CENTER | SA_VERT_CENTER); + DrawString(tr, STR_STATUSBAR_SAVING_GAME, TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle}); } else if (_do_autosave) { - DrawString(tr, STR_STATUSBAR_AUTOSAVE, TextColour::FromString, SA_HOR_CENTER); + DrawString(tr, STR_STATUSBAR_AUTOSAVE, TextColour::FromString, AlignmentH::Centre); } else if (_pause_mode.Any()) { StringID msg = _pause_mode.Test(PauseMode::LinkGraph) ? STR_STATUSBAR_PAUSED_LINK_GRAPH : STR_STATUSBAR_PAUSED; - DrawString(tr, msg, TextColour::FromString, SA_HOR_CENTER); + DrawString(tr, msg, TextColour::FromString, AlignmentH::Centre); } else if (this->ticker_scroll < TICKER_STOP && GetStatusbarNews() != nullptr && !GetStatusbarNews()->headline.empty()) { /* Draw the scrolling news text */ if (!DrawScrollingStatusText(*GetStatusbarNews(), ScaleGUITrad(this->ticker_scroll), tr.left, tr.right, tr.top, tr.bottom)) { InvalidateWindowData(WindowClass::Statusbar, 0, SBI_NEWS_DELETED); if (Company::IsValidID(_local_company)) { /* This is the default text */ - DrawString(tr, GetString(STR_STATUSBAR_COMPANY_NAME, _local_company), TextColour::FromString, SA_HOR_CENTER); + DrawString(tr, GetString(STR_STATUSBAR_COMPANY_NAME, _local_company), TextColour::FromString, AlignmentH::Centre); } } } else { if (Company::IsValidID(_local_company)) { /* This is the default text */ - DrawString(tr, GetString(STR_STATUSBAR_COMPANY_NAME, _local_company), TextColour::FromString, SA_HOR_CENTER); + DrawString(tr, GetString(STR_STATUSBAR_COMPANY_NAME, _local_company), TextColour::FromString, AlignmentH::Centre); } } diff --git a/src/story_gui.cpp b/src/story_gui.cpp index 2868a9b800..a91cc01cff 100644 --- a/src/story_gui.cpp +++ b/src/story_gui.cpp @@ -704,7 +704,7 @@ public: /* Title */ y_offset = DrawStringMultiLine(0, fr.right, y_offset, fr.bottom, - GetString(STR_STORY_BOOK_TITLE, !page->title.empty() ? page->title.GetDecodedString() : this->selected_generic_title), TextColour::Black, SA_TOP | SA_HOR_CENTER); + GetString(STR_STORY_BOOK_TITLE, !page->title.empty() ? page->title.GetDecodedString() : this->selected_generic_title), TextColour::Black, {AlignmentH::Centre, AlignmentV::Top}); /* Page elements */ this->EnsureStoryPageElementLayout(); @@ -717,7 +717,7 @@ public: switch (ce.pe->type) { case StoryPageElementType::Text: DrawStringMultiLineWithClipping(ce.bounds.left, ce.bounds.right, ce.bounds.top - scrollpos, ce.bounds.bottom - scrollpos, - ce.pe->text.GetDecodedString(), TextColour::Black, SA_TOP | SA_LEFT); + ce.pe->text.GetDecodedString(), TextColour::Black, {AlignmentH::Start, AlignmentV::Top}); break; case StoryPageElementType::Goal: { @@ -742,7 +742,7 @@ public: DrawFrameRect(ce.bounds.left, ce.bounds.top - scrollpos, ce.bounds.right, ce.bounds.bottom - scrollpos - 1, bgcolour, frame); DrawString(ce.bounds.left + WidgetDimensions::scaled.bevel.left, ce.bounds.right - WidgetDimensions::scaled.bevel.right, ce.bounds.top + tmargin - scrollpos, - ce.pe->text.GetDecodedString(), TextColour::White, SA_CENTER); + ce.pe->text.GetDecodedString(), TextColour::White, {AlignmentH::Centre, AlignmentV::Middle}); break; } diff --git a/src/textfile_gui.cpp b/src/textfile_gui.cpp index 0ccf3f2325..d62e5140bb 100644 --- a/src/textfile_gui.cpp +++ b/src/textfile_gui.cpp @@ -582,9 +582,9 @@ void TextfileWindow::AfterLoadMarkdown() int y_offset = (top - pos) * line_height; if (line.wrapped_width != 0) { Rect tr = fr.WithWidth(line.wrapped_width, _current_text_dir == TD_RTL); - DrawStringMultiLineWithClipping(tr.left, tr.right, y_offset, y_offset + line.num_lines * line_height, line.text, line.colour, SA_TOP | SA_LEFT, false, FontSize::Monospace); + DrawStringMultiLineWithClipping(tr.left, tr.right, y_offset, y_offset + line.num_lines * line_height, line.text, line.colour, {AlignmentH::Start, AlignmentV::Top}, false, FontSize::Monospace); } else { - DrawString(fr.left, fr.right, y_offset, line.text, line.colour, SA_TOP | SA_LEFT, false, FontSize::Monospace); + DrawString(fr.left, fr.right, y_offset, line.text, line.colour, {AlignmentH::Start, AlignmentV::Top}, false, FontSize::Monospace); } } } diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 6f97dbef4b..46b5004152 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -2401,10 +2401,10 @@ struct ScenarioEditorToolbarWindow : Window { case WID_TE_SPACER: { int height = r.Height(); if (height > 2 * GetCharacterHeight(FontSize::Normal)) { - DrawString(r.left, r.right, height / 2 - GetCharacterHeight(FontSize::Normal), STR_SCENEDIT_TOOLBAR_OPENTTD, TextColour::FromString, SA_HOR_CENTER); - DrawString(r.left, r.right, height / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TextColour::FromString, SA_HOR_CENTER); + DrawString(r.left, r.right, height / 2 - GetCharacterHeight(FontSize::Normal), STR_SCENEDIT_TOOLBAR_OPENTTD, TextColour::FromString, AlignmentH::Centre); + DrawString(r.left, r.right, height / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TextColour::FromString, AlignmentH::Centre); } else { - DrawString(r.left, r.right, (height - GetCharacterHeight(FontSize::Normal)) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TextColour::FromString, SA_HOR_CENTER); + DrawString(r.left, r.right, (height - GetCharacterHeight(FontSize::Normal)) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TextColour::FromString, AlignmentH::Centre); } break; } @@ -2574,7 +2574,7 @@ static constexpr std::initializer_list _nested_toolb_scen_inner_wid NWidget(WWT_PANEL, Colours::Grey, WID_TE_DATE_PANEL), NWidget(NWID_HORIZONTAL), SetPIP(2, 2, 2), SetPadding(1), NWidget(WWT_IMGBTN, Colours::Grey, WID_TE_DATE_BACKWARD), SetSpriteTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_BACKWARD_TOOLTIP), SetFill(0, 1), - NWidget(WWT_TEXT, Colours::Invalid, WID_TE_DATE), SetToolTip(STR_SCENEDIT_TOOLBAR_SET_DATE_TOOLTIP), SetTextStyle(TextColour::White), SetAlignment(SA_CENTER), SetFill(0, 1), + NWidget(WWT_TEXT, Colours::Invalid, WID_TE_DATE), SetToolTip(STR_SCENEDIT_TOOLBAR_SET_DATE_TOOLTIP), SetTextStyle(TextColour::White), SetAlignment({AlignmentH::Centre, AlignmentV::Middle}), SetFill(0, 1), NWidget(WWT_IMGBTN, Colours::Grey, WID_TE_DATE_FORWARD), SetSpriteTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_FORWARD_TOOLTIP), SetFill(0, 1), EndContainer(), EndContainer(), diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 110f0531c0..7d28167e3f 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1686,10 +1686,10 @@ static void DrawSmallOrderList(const Vehicle *v, int left, int right, int y, uin VehicleOrderID oid = start; do { - if (oid == v->cur_real_order_index) DrawString(left, right, y, rtl ? STR_JUST_LEFT_ARROW : STR_JUST_RIGHT_ARROW, TextColour::Black, SA_LEFT, false, FontSize::Small); + if (oid == v->cur_real_order_index) DrawString(left, right, y, rtl ? STR_JUST_LEFT_ARROW : STR_JUST_RIGHT_ARROW, TextColour::Black, AlignmentH::Start, false, FontSize::Small); if (orders[oid].IsType(OT_GOTO_STATION)) { - DrawString(left + l_offset, right - r_offset, y, GetString(STR_STATION_NAME, orders[oid].GetDestination()), TextColour::Black, SA_LEFT, false, FontSize::Small); + DrawString(left + l_offset, right - r_offset, y, GetString(STR_STATION_NAME, orders[oid].GetDestination()), TextColour::Black, AlignmentH::Start, false, FontSize::Small); y += GetCharacterHeight(FontSize::Small); if (++i == 4) break; @@ -1718,7 +1718,7 @@ static void DrawSmallOrderList(const OrderList *orderlist, int left, int right, for (const Order &order : orderlist->GetOrders()) { if (order.IsType(OT_GOTO_STATION)) { - DrawString(left + l_offset, right - r_offset, y, GetString(STR_STATION_NAME, order.GetDestination()), TextColour::Black, SA_LEFT, false, FontSize::Small); + DrawString(left + l_offset, right - r_offset, y, GetString(STR_STATION_NAME, order.GetDestination()), TextColour::Black, AlignmentH::Start, false, FontSize::Small); y += GetCharacterHeight(FontSize::Small); if (++i == 4) break; @@ -1833,22 +1833,22 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int /* The vehicle got a name so we will print it and the cargoes */ DrawString(tr.left, tr.right, ir.top, GetString(STR_VEHICLE_LIST_NAME_AND_CARGO, STR_VEHICLE_NAME, v->index, STR_VEHICLE_LIST_CARGO, vehicle_cargoes), - TextColour::Black, SA_LEFT, false, FontSize::Small); + TextColour::Black, AlignmentH::Start, false, FontSize::Small); } else if (v->group_id != DEFAULT_GROUP) { /* The vehicle has no name, but is member of a group, so print group name and the cargoes */ DrawString(tr.left, tr.right, ir.top, GetString(STR_VEHICLE_LIST_NAME_AND_CARGO, STR_GROUP_NAME, v->group_id, STR_VEHICLE_LIST_CARGO, vehicle_cargoes), - TextColour::Black, SA_LEFT, false, FontSize::Small); + TextColour::Black, AlignmentH::Start, false, FontSize::Small); } else { /* The vehicle has no name, and is not a member of a group, so just print the cargoes */ - DrawString(tr.left, tr.right, ir.top, GetString(STR_VEHICLE_LIST_CARGO, vehicle_cargoes), TextColour::Black, SA_LEFT, false, FontSize::Small); + DrawString(tr.left, tr.right, ir.top, GetString(STR_VEHICLE_LIST_CARGO, vehicle_cargoes), TextColour::Black, AlignmentH::Start, false, FontSize::Small); } } else if (!v->name.empty()) { /* The vehicle got a name so we will print it */ - DrawString(tr.left, tr.right, ir.top, GetString(STR_VEHICLE_NAME, v->index), TextColour::Black, SA_LEFT, false, FontSize::Small); + DrawString(tr.left, tr.right, ir.top, GetString(STR_VEHICLE_NAME, v->index), TextColour::Black, AlignmentH::Start, false, FontSize::Small); } else if (v->group_id != DEFAULT_GROUP) { /* The vehicle has no name, but is member of a group, so print group name */ - DrawString(tr.left, tr.right, ir.top, GetString(STR_GROUP_NAME, v->group_id), TextColour::Black, SA_LEFT, false, FontSize::Small); + DrawString(tr.left, tr.right, ir.top, GetString(STR_GROUP_NAME, v->group_id), TextColour::Black, AlignmentH::Start, false, FontSize::Small); } if (show_orderlist) DrawSmallOrderList(v, olr.left, olr.right, ir.top + GetCharacterHeight(FontSize::Small), this->order_arrow_width, v->cur_real_order_index); @@ -3276,13 +3276,13 @@ public: const Vehicle *v = Vehicle::Get(this->window_number); SpriteID image = v->vehstatus.Test(VehState::Stopped) ? SPR_FLAG_VEH_STOPPED : (v->vehicle_flags.Test(VehicleFlag::PathfinderLost)) ? SPR_WARNING_SIGN : SPR_FLAG_VEH_RUNNING; - DrawSpriteIgnorePadding(image, PAL_NONE, tr.WithWidth(icon_width, rtl), SA_CENTER); + DrawSpriteIgnorePadding(image, PAL_NONE, tr.WithWidth(icon_width, rtl), {AlignmentH::Centre, AlignmentV::Middle}); tr = tr.Indent(icon_width + WidgetDimensions::scaled.imgbtn.Horizontal(), rtl); ExtendedTextColour text_colour{TextColour::FromString}; std::string str = GetVehicleStatusString(v, text_colour); - DrawString(tr.left, tr.right, CentreBounds(tr.top, tr.bottom, GetCharacterHeight(FontSize::Normal)), str, text_colour, SA_HOR_CENTER); + DrawString(tr.left, tr.right, CentreBounds(tr.top, tr.bottom, GetCharacterHeight(FontSize::Normal)), str, text_colour, AlignmentH::Centre); } void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override diff --git a/src/viewport.cpp b/src/viewport.cpp index 24c03452b1..4c4594c9bf 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1805,10 +1805,10 @@ static void ViewportDrawStrings(ZoomLevel zoom, const StringSpriteToDrawVector * if (small && ss.flags.Test(ViewportStringFlag::Shadow)) { /* Shadow needs to be shifted 1 pixel. */ shadow_offset = WidgetDimensions::scaled.fullbevel.top; - DrawString(left + shadow_offset, right + shadow_offset, top, ss.string, TextColour::Black, SA_HOR_CENTER, false, FontSize::Small); + DrawString(left + shadow_offset, right + shadow_offset, top, ss.string, TextColour::Black, AlignmentH::Centre, false, FontSize::Small); } - DrawString(left, right, top - shadow_offset, ss.string, colour, SA_HOR_CENTER, false, small ? FontSize::Small : FontSize::Normal); + DrawString(left, right, top - shadow_offset, ss.string, colour, AlignmentH::Centre, false, small ? FontSize::Small : FontSize::Normal); } } diff --git a/src/widget.cpp b/src/widget.cpp index 2d0fab8c31..c4515ea799 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -141,17 +141,16 @@ static inline Point GetAlignedPosition(const Rect &r, const Dimension &d, Alignm { Point p; /* In case we have a RTL language we swap the alignment. */ - if (!(align & SA_FORCE) && _current_text_dir == TD_RTL && (align & SA_HOR_MASK) != SA_HOR_CENTER) align ^= SA_RIGHT; - switch (align & SA_HOR_MASK) { - case SA_LEFT: p.x = r.left; break; - case SA_HOR_CENTER: p.x = CentreBounds(r.left, r.right, d.width); break; - case SA_RIGHT: p.x = r.right + 1 - d.width; break; + switch (align.ResolveRTL()) { + case AlignmentH::ForceLeft: p.x = r.left; break; + case AlignmentH::Centre: p.x = CentreBounds(r.left, r.right, d.width); break; + case AlignmentH::ForceRight: p.x = r.right + 1 - d.width; break; default: NOT_REACHED(); } - switch (align & SA_VERT_MASK) { - case SA_TOP: p.y = r.top; break; - case SA_VERT_CENTER: p.y = CentreBounds(r.top, r.bottom, d.height); break; - case SA_BOTTOM: p.y = r.bottom + 1 - d.height; break; + switch (align.v) { + case AlignmentV::Top: p.y = r.top; break; + case AlignmentV::Middle: p.y = CentreBounds(r.top, r.bottom, d.height); break; + case AlignmentV::Bottom: p.y = r.bottom + 1 - d.height; break; default: NOT_REACHED(); } return p; @@ -398,7 +397,7 @@ static inline void DrawImageTextButtons(const Rect &r, Colours colour, bool clic Rect r_text = r.Shrink(WidgetDimensions::scaled.framerect).Indent(image_width + WidgetDimensions::scaled.hsep_wide, rtl); if (img != 0) { - DrawSpriteIgnorePadding(img, PAL_NONE, r_img, SA_HOR_CENTER | (align & SA_VERT_MASK)); + DrawSpriteIgnorePadding(img, PAL_NONE, r_img, {AlignmentH::Centre, align.v}); } if (!text.empty()) { @@ -530,8 +529,8 @@ static inline void DrawVerticalScrollbar(const Rect &r, Colours colour, bool up_ int height = NWidgetScrollbar::GetVerticalDimension().height; /* draw up/down buttons */ - DrawImageButtons(r.WithHeight(height, false), NWID_VSCROLLBAR, colour, up_clicked, SPR_ARROW_UP, SA_CENTER); - DrawImageButtons(r.WithHeight(height, true), NWID_VSCROLLBAR, colour, down_clicked, SPR_ARROW_DOWN, SA_CENTER); + DrawImageButtons(r.WithHeight(height, false), NWID_VSCROLLBAR, colour, up_clicked, SPR_ARROW_UP, {AlignmentH::Centre, AlignmentV::Middle}); + DrawImageButtons(r.WithHeight(height, true), NWID_VSCROLLBAR, colour, down_clicked, SPR_ARROW_DOWN, {AlignmentH::Centre, AlignmentV::Middle}); PixelColour c1 = GetColourGradient(colour, Shade::Dark); PixelColour c2 = GetColourGradient(colour, Shade::Lightest); @@ -570,8 +569,8 @@ static inline void DrawHorizontalScrollbar(const Rect &r, Colours colour, bool l { int width = NWidgetScrollbar::GetHorizontalDimension().width; - DrawImageButtons(r.WithWidth(width, false), NWID_HSCROLLBAR, colour, left_clicked, SPR_ARROW_LEFT, SA_CENTER); - DrawImageButtons(r.WithWidth(width, true), NWID_HSCROLLBAR, colour, right_clicked, SPR_ARROW_RIGHT, SA_CENTER); + DrawImageButtons(r.WithWidth(width, false), NWID_HSCROLLBAR, colour, left_clicked, SPR_ARROW_LEFT, {AlignmentH::Centre, AlignmentV::Middle}); + DrawImageButtons(r.WithWidth(width, true), NWID_HSCROLLBAR, colour, right_clicked, SPR_ARROW_RIGHT, {AlignmentH::Centre, AlignmentV::Middle}); PixelColour c1 = GetColourGradient(colour, Shade::Dark); PixelColour c2 = GetColourGradient(colour, Shade::Lightest); @@ -662,7 +661,7 @@ static inline void DrawFrame(const Rect &r, Colours colour, TextColour text_colo */ static inline void DrawShadeBox(const Rect &r, Colours colour, bool clicked) { - DrawImageButtons(r, WWT_SHADEBOX, colour, clicked, clicked ? SPR_WINDOW_SHADE: SPR_WINDOW_UNSHADE, SA_CENTER); + DrawImageButtons(r, WWT_SHADEBOX, colour, clicked, clicked ? SPR_WINDOW_SHADE: SPR_WINDOW_UNSHADE, {AlignmentH::Centre, AlignmentV::Middle}); } /** @@ -673,7 +672,7 @@ static inline void DrawShadeBox(const Rect &r, Colours colour, bool clicked) */ static inline void DrawStickyBox(const Rect &r, Colours colour, bool clicked) { - DrawImageButtons(r, WWT_STICKYBOX, colour, clicked, clicked ? SPR_PIN_UP : SPR_PIN_DOWN, SA_CENTER); + DrawImageButtons(r, WWT_STICKYBOX, colour, clicked, clicked ? SPR_PIN_UP : SPR_PIN_DOWN, {AlignmentH::Centre, AlignmentV::Middle}); } /** @@ -684,7 +683,7 @@ static inline void DrawStickyBox(const Rect &r, Colours colour, bool clicked) */ static inline void DrawDefSizeBox(const Rect &r, Colours colour, bool clicked) { - DrawImageButtons(r, WWT_DEFSIZEBOX, colour, clicked, SPR_WINDOW_DEFSIZE, SA_CENTER); + DrawImageButtons(r, WWT_DEFSIZEBOX, colour, clicked, SPR_WINDOW_DEFSIZE, {AlignmentH::Centre, AlignmentV::Middle}); } /** @@ -695,7 +694,7 @@ static inline void DrawDefSizeBox(const Rect &r, Colours colour, bool clicked) */ static inline void DrawDebugBox(const Rect &r, Colours colour, bool clicked) { - DrawImageButtons(r, WWT_DEBUGBOX, colour, clicked, SPR_WINDOW_DEBUG, SA_CENTER); + DrawImageButtons(r, WWT_DEBUGBOX, colour, clicked, SPR_WINDOW_DEBUG, {AlignmentH::Centre, AlignmentV::Middle}); } /** @@ -713,7 +712,7 @@ static inline void DrawResizeBox(const Rect &r, Colours colour, bool at_left, bo } else if (clicked) { GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(colour, Shade::Lighter)); } - DrawSpriteIgnorePadding(at_left ? SPR_WINDOW_RESIZE_LEFT : SPR_WINDOW_RESIZE_RIGHT, PAL_NONE, r.Shrink(ScaleGUITrad(2)), at_left ? (SA_LEFT | SA_BOTTOM | SA_FORCE) : (SA_RIGHT | SA_BOTTOM | SA_FORCE)); + DrawSpriteIgnorePadding(at_left ? SPR_WINDOW_RESIZE_LEFT : SPR_WINDOW_RESIZE_RIGHT, PAL_NONE, r.Shrink(ScaleGUITrad(2)), {at_left ? AlignmentH::ForceLeft : AlignmentH::ForceRight, AlignmentV::Bottom}); } /** @@ -784,7 +783,7 @@ static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicke } Rect button = r.WithWidth(NWidgetLeaf::dropdown_dimension.width, !rtl); - DrawImageButtons(button, WWT_DROPDOWN, colour, clicked_dropdown, SPR_ARROW_DOWN, SA_CENTER); + DrawImageButtons(button, WWT_DROPDOWN, colour, clicked_dropdown, SPR_ARROW_DOWN, {AlignmentH::Centre, AlignmentV::Middle}); } /** @@ -830,7 +829,7 @@ void Window::DrawSortButton(WidgetID widget, bool descending) const /* Sort button uses the same sprites as vertical scrollbar */ Dimension dim = NWidgetScrollbar::GetVerticalDimension(); - DrawSpriteIgnorePadding(descending ? SPR_ARROW_DOWN : SPR_ARROW_UP, PAL_NONE, r.WithWidth(dim.width, _current_text_dir == TD_LTR), SA_CENTER); + DrawSpriteIgnorePadding(descending ? SPR_ARROW_DOWN : SPR_ARROW_UP, PAL_NONE, r.WithWidth(dim.width, _current_text_dir == TD_LTR), {AlignmentH::Centre, AlignmentV::Middle}); } /** @@ -2187,7 +2186,7 @@ NWidgetBackground::NWidgetBackground(WidgetType tp, Colours colour, WidgetID ind assert(tp == WWT_PANEL || tp == WWT_INSET || tp == WWT_FRAME); this->child = std::move(child); if (this->child != nullptr) this->child->parent = this; - this->SetAlignment(SA_TOP | SA_LEFT); + this->SetAlignment({AlignmentH::Start, AlignmentV::Top}); } /** @@ -2719,7 +2718,7 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, WidgetID index, const Wi case WWT_TEXT: if (colour != Colours::Invalid) [[unlikely]] throw std::runtime_error("WWT_TEXT should not have a colour"); this->SetFill(0, 0); - this->SetAlignment(SA_LEFT | SA_VERT_CENTER); + this->SetAlignment({AlignmentH::Start, AlignmentV::Middle}); break; case WWT_LABEL: @@ -2805,7 +2804,7 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, WidgetID index, const Wi case WWT_DROPDOWN: this->SetFill(0, 0); this->SetMinimalSize(0, WidgetDimensions::WD_DROPDOWN_HEIGHT); - this->SetAlignment(SA_TOP | SA_LEFT); + this->SetAlignment({AlignmentH::Start, AlignmentV::Top}); break; default: diff --git a/src/widget_type.h b/src/widget_type.h index ef17fc7058..c95901068c 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -435,7 +435,7 @@ protected: TextColour highlight_colour{}; ///< Colour of highlight. TextColour text_colour{}; ///< Colour of text within widget. FontSize text_size = FontSize::Normal; ///< Size of text within widget. - Alignment align = SA_CENTER; ///< Alignment of text/image within widget. + Alignment align = {AlignmentH::Centre, AlignmentV::Middle}; ///< Alignment of text/image within widget. /* This function constructs the widgets, so it should be able to write the variables. */ friend void ApplyNWidgetPartAttribute(const struct NWidgetPart &nwid, NWidgetBase *dest);