diff --git a/src/aircraft_gui.cpp b/src/aircraft_gui.cpp index 1ba0a311d5..5b7d67582b 100644 --- a/src/aircraft_gui.cpp +++ b/src/aircraft_gui.cpp @@ -82,7 +82,7 @@ void DrawAircraftImage(const Vehicle *v, const Rect &r, VehicleID selection, Eng int x_offs = UnScaleGUI(rect.left); int x = rtl ? r.right - width - x_offs : r.left - x_offs; /* This magic -1 offset is related to the sprite_y_offsets in build_vehicle_gui.cpp */ - int y = ScaleSpriteTrad(-1) + CenterBounds(r.top, r.bottom, 0); + int y = ScaleSpriteTrad(-1) + CentreBounds(r.top, r.bottom, 0); bool helicopter = v->subtype == AIR_HELICOPTER; int heli_offs = 0; diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index 6954317887..5b2464e975 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -401,7 +401,7 @@ public: case WID_AP_AIRPORT_SPRITE: if (this->preview_sprite != 0) { Dimension d = GetSpriteSize(this->preview_sprite); - DrawSprite(this->preview_sprite, COMPANY_SPRITE_COLOUR(_local_company), CenterBounds(r.left, r.right, d.width), CenterBounds(r.top, r.bottom, d.height)); + DrawSprite(this->preview_sprite, COMPANY_SPRITE_COLOUR(_local_company), CentreBounds(r.left, r.right, d.width), CentreBounds(r.top, r.bottom, d.height)); } break; diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index ad0f55141e..e2a5c7cdf0 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -995,7 +995,7 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li if (lvl < item.indent) tx += level_width; } /* Draw our node in the tree. */ - int ycentre = CenterBounds(textr.top, textr.bottom, WidgetDimensions::scaled.fullbevel.top); + int ycentre = CentreBounds(textr.top, textr.bottom, WidgetDimensions::scaled.fullbevel.top); if (!HasBit(item.level_mask, item.indent)) GfxDrawLine(tx, ir.top, tx, ycentre, linecolour, WidgetDimensions::scaled.fullbevel.top); GfxDrawLine(tx, ycentre, tx + offset - (rtl ? -1 : 1), ycentre, linecolour, WidgetDimensions::scaled.fullbevel.top); } diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 0c171330e2..01544dc527 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -1127,8 +1127,8 @@ void DrawCompanyManagerFace(CompanyManagerFace cmf, Colours colour, const Rect & /* Determine offset from centre of drawing rect. */ Dimension d = GetSpriteSize(SPR_GRADIENT); - int x = CenterBounds(r.left, r.right, d.width); - int y = CenterBounds(r.top, r.bottom, d.height); + int x = CentreBounds(r.left, r.right, d.width); + int y = CentreBounds(r.top, r.bottom, d.height); bool has_moustache = !HasBit(ge, GENDER_FEMALE) && GetCompanyManagerFaceBits(cmf, CMFV_HAS_MOUSTACHE, ge) != 0; bool has_tie_earring = !HasBit(ge, GENDER_FEMALE) || GetCompanyManagerFaceBits(cmf, CMFV_HAS_TIE_EARRING, ge) != 0; @@ -2373,7 +2373,7 @@ struct CompanyWindow : Window Point offset; Dimension d = GetSpriteSize(SPR_VEH_BUS_SW_VIEW, &offset); d.height -= offset.y; - DrawSprite(SPR_VEH_BUS_SW_VIEW, COMPANY_SPRITE_COLOUR(c->index), r.left - offset.x, CenterBounds(r.top, r.bottom, d.height) - offset.y); + DrawSprite(SPR_VEH_BUS_SW_VIEW, COMPANY_SPRITE_COLOUR(c->index), r.left - offset.x, CentreBounds(r.top, r.bottom, d.height) - offset.y); break; } diff --git a/src/core/geometry_type.hpp b/src/core/geometry_type.hpp index 9149ab2c3c..ddb3398ade 100644 --- a/src/core/geometry_type.hpp +++ b/src/core/geometry_type.hpp @@ -16,6 +16,17 @@ # define Point OTTD_Point #endif /* __APPLE__ */ +/** + * Determine where to position a centred object. + * @param min The top or left coordinate. + * @param max The bottom or right coordinate. + * @param size The height or width of the object to draw. + * @return Offset of where to position the object. + */ +inline int CentreBounds(int min, int max, int size) +{ + return (min + max - size + 1) / 2; +} /** Coordinates of a point in 2D */ struct Point { diff --git a/src/dropdown_common_type.h b/src/dropdown_common_type.h index 5193348464..04cb7665f6 100644 --- a/src/dropdown_common_type.h +++ b/src/dropdown_common_type.h @@ -36,7 +36,7 @@ public: uint8_t c1 = GetColourGradient(bg_colour, SHADE_DARK); uint8_t c2 = GetColourGradient(bg_colour, SHADE_LIGHTEST); - int mid = CenterBounds(full.top, full.bottom, 0); + int mid = CentreBounds(full.top, full.bottom, 0); GfxFillRect(full.left, mid - WidgetDimensions::scaled.bevel.bottom, full.right, mid - 1, c1); GfxFillRect(full.left, mid, full.right, mid + WidgetDimensions::scaled.bevel.top - 1, c2); } @@ -126,7 +126,7 @@ public: { bool rtl = TEnd ^ (_current_text_dir == TD_RTL); Rect ir = r.WithWidth(this->dbounds.width, rtl); - DrawSprite(this->sprite, this->palette, CenterBounds(ir.left, ir.right, this->dsprite.width), CenterBounds(r.top, r.bottom, this->dsprite.height)); + DrawSprite(this->sprite, this->palette, CentreBounds(ir.left, ir.right, this->dsprite.width), CentreBounds(r.top, r.bottom, this->dsprite.height)); this->TBase::Draw(full, r.Indent(this->dbounds.width + WidgetDimensions::scaled.hsep_normal, rtl), sel, bg_colour); } }; diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index 52218c2380..a646638cff 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -1393,7 +1393,7 @@ struct GenerateProgressWindow : public Window { DrawFrameRect(r, COLOUR_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), COLOUR_MAUVE, {}); - DrawString(br.left, br.right, CenterBounds(br.top, br.bottom, GetCharacterHeight(FS_NORMAL)), + DrawString(br.left, br.right, CentreBounds(br.top, br.bottom, GetCharacterHeight(FS_NORMAL)), GetString(STR_GENERATION_PROGRESS, GenWorldStatus::percent), TC_FROMSTRING, SA_HOR_CENTER); break; } diff --git a/src/gfx.cpp b/src/gfx.cpp index f116343b00..13d9776d12 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -907,8 +907,8 @@ void DrawCharCentered(char32_t c, const Rect &r, TextColour colour) { SetColourRemap(colour); GfxMainBlitter(GetGlyph(FS_NORMAL, c), - CenterBounds(r.left, r.right, GetCharacterWidth(FS_NORMAL, c)), - CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), + CentreBounds(r.left, r.right, GetCharacterWidth(FS_NORMAL, c)), + CentreBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), BlitterMode::ColourRemap); } diff --git a/src/gfx_func.h b/src/gfx_func.h index d7febfdc74..72654a7b8c 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -156,18 +156,6 @@ inline bool FillDrawPixelInfo(DrawPixelInfo *n, const Rect &r) return FillDrawPixelInfo(n, r.left, r.top, r.Width(), r.Height()); } -/** - * Determine where to draw a centred object inside a widget. - * @param min The top or left coordinate. - * @param max The bottom or right coordinate. - * @param size The height or width of the object to draw. - * @return Offset of where to start drawing the object. - */ -inline int CenterBounds(int min, int max, int size) -{ - return (min + max - size + 1) / 2; -} - /* window.cpp */ void DrawOverlappedWindowForAll(int left, int top, int right, int bottom); diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index 7cb36d9dbe..011e1d41c2 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -73,10 +73,10 @@ struct GraphLegendWindow : Window { const Rect ir = r.Shrink(WidgetDimensions::scaled.framerect); Dimension d = GetSpriteSize(SPR_COMPANY_ICON); - DrawCompanyIcon(cid, rtl ? ir.right - d.width : ir.left, CenterBounds(ir.top, ir.bottom, d.height)); + DrawCompanyIcon(cid, rtl ? ir.right - d.width : ir.left, CentreBounds(ir.top, ir.bottom, d.height)); const Rect tr = ir.Indent(d.width + WidgetDimensions::scaled.hsep_normal, rtl); - DrawString(tr.left, tr.right, CenterBounds(tr.top, tr.bottom, GetCharacterHeight(FS_NORMAL)), GetString(STR_COMPANY_NAME_COMPANY_NUM, cid, cid), _legend_excluded_companies.Test(cid) ? TC_BLACK : TC_WHITE); + DrawString(tr.left, tr.right, CentreBounds(tr.top, tr.bottom, GetCharacterHeight(FS_NORMAL)), GetString(STR_COMPANY_NAME_COMPANY_NUM, cid, cid), _legend_excluded_companies.Test(cid) ? TC_BLACK : TC_WHITE); } void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override @@ -1385,7 +1385,7 @@ struct PerformanceRatingDetailWindow : Window { if (this->IsWidgetDisabled(widget)) return; CompanyID cid = (CompanyID)(widget - WID_PRD_COMPANY_FIRST); Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON); - DrawCompanyIcon(cid, CenterBounds(r.left, r.right, sprite_size.width), CenterBounds(r.top, r.bottom, sprite_size.height)); + DrawCompanyIcon(cid, CentreBounds(r.left, r.right, sprite_size.width), CentreBounds(r.top, r.bottom, sprite_size.height)); return; } @@ -1408,8 +1408,8 @@ struct PerformanceRatingDetailWindow : Window { needed = SCORE_MAX; } - uint bar_top = CenterBounds(r.top, r.bottom, this->bar_height); - uint text_top = CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)); + uint bar_top = CentreBounds(r.top, r.bottom, this->bar_height); + uint text_top = CentreBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)); DrawString(this->score_info_left, this->score_info_right, text_top, STR_PERFORMANCE_DETAIL_VEHICLES + score_type); diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index bbe73b9327..6beb9bdaf9 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -864,7 +864,7 @@ public: SpriteID icon = CargoSpec::Get(cargo_type)->GetCargoIcon(); Dimension d = GetSpriteSize(icon); Rect ir = r.WithWidth(this->cargo_icon_size.width, rtl).WithHeight(GetCharacterHeight(FS_NORMAL)); - DrawSprite(icon, PAL_NONE, CenterBounds(ir.left, ir.right, d.width), CenterBounds(ir.top, ir.bottom, this->cargo_icon_size.height)); + DrawSprite(icon, PAL_NONE, CentreBounds(ir.left, ir.right, d.width), CentreBounds(ir.top, ir.bottom, this->cargo_icon_size.height)); } std::string GetAcceptedCargoString(const Industry::AcceptedCargo &ac, const CargoSuffix &suffix) const diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp index 61c25550c0..57ab1dfaf0 100644 --- a/src/linkgraph/linkgraph_gui.cpp +++ b/src/linkgraph/linkgraph_gui.cpp @@ -604,7 +604,7 @@ void LinkGraphLegendWindow::DrawWidget(const Rect &r, WidgetID widget) const if (this->IsWidgetDisabled(widget)) return; CompanyID cid = (CompanyID)(widget - WID_LGL_COMPANY_FIRST); Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON); - DrawCompanyIcon(cid, CenterBounds(br.left, br.right, sprite_size.width), CenterBounds(br.top, br.bottom, sprite_size.height)); + DrawCompanyIcon(cid, CentreBounds(br.left, br.right, sprite_size.width), CentreBounds(br.top, br.bottom, sprite_size.height)); } if (IsInsideMM(widget, WID_LGL_SATURATION_FIRST, WID_LGL_SATURATION_LAST + 1)) { uint8_t colour = LinkGraphOverlay::LINK_COLOURS[_settings_client.gui.linkgraph_colours][widget - WID_LGL_SATURATION_FIRST]; @@ -618,13 +618,13 @@ void LinkGraphLegendWindow::DrawWidget(const Rect &r, WidgetID widget) const str = STR_LINKGRAPH_LEGEND_SATURATED; } if (str != STR_NULL) { - DrawString(br.left, br.right, CenterBounds(br.top, br.bottom, GetCharacterHeight(FS_SMALL)), str, GetContrastColour(colour) | TC_FORCED, SA_HOR_CENTER, false, FS_SMALL); + DrawString(br.left, br.right, CentreBounds(br.top, br.bottom, GetCharacterHeight(FS_SMALL)), str, GetContrastColour(colour) | TC_FORCED, SA_HOR_CENTER, false, FS_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, CenterBounds(br.top, br.bottom, GetCharacterHeight(FS_SMALL)), cargo->abbrev, GetContrastColour(cargo->legend_colour, 73), SA_HOR_CENTER, false, FS_SMALL); + DrawString(br.left, br.right, CentreBounds(br.top, br.bottom, GetCharacterHeight(FS_SMALL)), cargo->abbrev, GetContrastColour(cargo->legend_colour, 73), SA_HOR_CENTER, false, FS_SMALL); } } diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index bae49d57f3..eefdf37a29 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -767,14 +767,14 @@ void QueryString::DrawEditBox(const Window *w, WidgetID wid) const /* If we have a marked area, draw a background highlight. */ if (tb->marklength != 0) GfxFillRect(fr.left + tb->markxoffs, fr.top, fr.left + tb->markxoffs + tb->marklength - 1, fr.bottom, PC_GREY); - DrawString(fr.left, fr.right, CenterBounds(fr.top, fr.bottom, GetCharacterHeight(FS_NORMAL)), tb->GetText(), TC_YELLOW); + DrawString(fr.left, fr.right, CentreBounds(fr.top, fr.bottom, GetCharacterHeight(FS_NORMAL)), tb->GetText(), TC_YELLOW); bool focussed = w->IsWidgetGloballyFocused(wid) || IsOSKOpenedFor(w, wid); if (focussed && tb->caret) { int caret_width = GetCaretWidth(); if (rtl) { - DrawString(fr.right - tb->pixels + tb->caretxoffs - caret_width, fr.right - tb->pixels + tb->caretxoffs, CenterBounds(fr.top, fr.bottom, GetCharacterHeight(FS_NORMAL)), "_", TC_WHITE); + DrawString(fr.right - tb->pixels + tb->caretxoffs - caret_width, fr.right - tb->pixels + tb->caretxoffs, CentreBounds(fr.top, fr.bottom, GetCharacterHeight(FS_NORMAL)), "_", TC_WHITE); } else { - DrawString(fr.left + tb->caretxoffs, fr.left + tb->caretxoffs + caret_width, CenterBounds(fr.top, fr.bottom, GetCharacterHeight(FS_NORMAL)), "_", TC_WHITE); + DrawString(fr.left + tb->caretxoffs, fr.left + tb->caretxoffs + caret_width, CentreBounds(fr.top, fr.bottom, GetCharacterHeight(FS_NORMAL)), "_", TC_WHITE); } } } diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index de77cc6dd7..5974f0f1bb 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -145,7 +145,7 @@ void BaseNetworkContentDownloadStatusWindow::DrawWidget(const Rect &r, WidgetID DrawFrameRect(r, COLOUR_GREY, {FrameFlag::BorderOnly, FrameFlag::Lowered}); Rect ir = r.Shrink(WidgetDimensions::scaled.bevel); DrawFrameRect(ir.WithWidth((uint64_t)ir.Width() * this->downloaded_bytes / this->total_bytes, _current_text_dir == TD_RTL), COLOUR_MAUVE, {}); - DrawString(ir.left, ir.right, CenterBounds(ir.top, ir.bottom, GetCharacterHeight(FS_NORMAL)), + DrawString(ir.left, ir.right, CentreBounds(ir.top, ir.bottom, GetCharacterHeight(FS_NORMAL)), GetString(STR_CONTENT_DOWNLOAD_PROGRESS_SIZE, this->downloaded_bytes, this->total_bytes, this->downloaded_bytes * 100LL / this->total_bytes), TC_FROMSTRING, SA_HOR_CENTER); break; diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index cb5c5cb4a2..a5da3540d1 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -1900,10 +1900,10 @@ public: void DrawCompany(CompanyID company_id, const Rect &r, uint &line) const { bool rtl = _current_text_dir == TD_RTL; - int text_y_offset = CenterBounds(0, this->line_height, GetCharacterHeight(FS_NORMAL)); + int text_y_offset = CentreBounds(0, this->line_height, GetCharacterHeight(FS_NORMAL)); Dimension d = GetSpriteSize(SPR_COMPANY_ICON); - int offset = CenterBounds(0, this->line_height, d.height); + int offset = CentreBounds(0, this->line_height, d.height); uint line_start = this->vscroll->GetPosition(); uint line_end = line_start + this->vscroll->GetCapacity(); @@ -1961,7 +1961,7 @@ public: if (player_icon != 0) { Dimension d2 = GetSpriteSize(player_icon); - int offset_y = CenterBounds(0, this->line_height, d2.height); + int offset_y = CentreBounds(0, this->line_height, d2.height); DrawSprite(player_icon, PALETTE_TO_GREY, rtl ? tr.right - d2.width : tr.left, y + offset_y); tr = tr.Indent(d2.width + WidgetDimensions::scaled.hsep_normal, rtl); } @@ -2075,7 +2075,7 @@ struct NetworkJoinStatusWindow : Window { break; } DrawFrameRect(ir.WithWidth(ir.Width() * progress / 100, _current_text_dir == TD_RTL), COLOUR_MAUVE, {}); - DrawString(ir.left, ir.right, CenterBounds(ir.top, ir.bottom, GetCharacterHeight(FS_NORMAL)), STR_NETWORK_CONNECTING_1 + _network_join_status, TC_FROMSTRING, SA_HOR_CENTER); + DrawString(ir.left, ir.right, CentreBounds(ir.top, ir.bottom, GetCharacterHeight(FS_NORMAL)), STR_NETWORK_CONNECTING_1 + _network_join_status, TC_FROMSTRING, SA_HOR_CENTER); break; } diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index 40fabd2e0c..1f83160969 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -412,7 +412,7 @@ struct NewGRFInspectWindow : Window { GrfSpecFeature f = GetFeatureNum(this->window_number); int h = GetVehicleImageCellSize((VehicleType)(VEH_TRAIN + (f - GSF_TRAINS)), EIT_IN_DEPOT).height; - int y = CenterBounds(br.top, br.bottom, h); + int y = CentreBounds(br.top, br.bottom, h); DrawVehicleImage(v->First(), br, VehicleID::Invalid(), EIT_IN_DETAILS, skip); /* Highlight the articulated part (this is different to the whole-vehicle highlighting of DrawVehicleImage */ diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 2b145522d3..6c206a93fe 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 grayish rectangle at the details top. */ GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), PC_DARK_BLUE); - DrawString(r.left, r.right, CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), STR_NEWGRF_SETTINGS_INFO_TITLE, TC_FROMSTRING, SA_HOR_CENTER); + DrawString(r.left, r.right, CentreBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), STR_NEWGRF_SETTINGS_INFO_TITLE, TC_FROMSTRING, SA_HOR_CENTER); break; } @@ -2194,7 +2194,7 @@ 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), COLOUR_MAUVE, {}); - DrawString(ir.left, ir.right, CenterBounds(ir.top, ir.bottom, GetCharacterHeight(FS_NORMAL)), GetString(STR_GENERATION_PROGRESS, percent), TC_FROMSTRING, SA_HOR_CENTER); + DrawString(ir.left, ir.right, CentreBounds(ir.top, ir.bottom, GetCharacterHeight(FS_NORMAL)), GetString(STR_GENERATION_PROGRESS, percent), TC_FROMSTRING, SA_HOR_CENTER); break; } diff --git a/src/news_gui.cpp b/src/news_gui.cpp index f9ca7a3601..8445579b74 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -550,7 +550,7 @@ struct NewsWindow : Window { case WID_N_VEH_SPR: { assert(std::holds_alternative(ni->ref1)); EngineID engine = std::get(this->ni->ref1); - DrawVehicleEngine(r.left, r.right, CenterBounds(r.left, r.right, 0), CenterBounds(r.top, r.bottom, 0), engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW); + DrawVehicleEngine(r.left, r.right, CentreBounds(r.left, r.right, 0), CentreBounds(r.top, r.bottom, 0), engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW); GfxFillRect(r, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR); break; } diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 09c551a344..08d8b38d7f 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -1465,7 +1465,7 @@ private: Point offset; Dimension sprite_size = GetSpriteSize(image, &offset); Rect ir = r.Shrink(WidgetDimensions::scaled.imgbtn); - int x = CenterBounds(ir.left, ir.right, sprite_size.width - offset.x) - offset.x; // centered + int x = CentreBounds(ir.left, ir.right, sprite_size.width - offset.x) - offset.x; // centered int y = ir.top - sig_sprite_bottom_offset + (ir.Height() + sig_sprite_size.height) / 2; // aligned to bottom diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp index 4a98d58dfa..b7fedf2495 100644 --- a/src/roadveh_gui.cpp +++ b/src/roadveh_gui.cpp @@ -152,6 +152,6 @@ void DrawRoadVehImage(const Vehicle *v, const Rect &r, VehicleID selection, Engi if (v->index == selection) { int height = ScaleSpriteTrad(12); Rect hr = {(rtl ? px : 0), 0, (rtl ? max_width : px) - 1, height - 1}; - DrawFrameRect(hr.Translate(r.left, CenterBounds(r.top, r.bottom, height)).Expand(WidgetDimensions::scaled.bevel), COLOUR_WHITE, FrameFlag::BorderOnly); + DrawFrameRect(hr.Translate(r.left, CentreBounds(r.top, r.bottom, height)).Expand(WidgetDimensions::scaled.bevel), COLOUR_WHITE, FrameFlag::BorderOnly); } } diff --git a/src/script/script_gui.cpp b/src/script/script_gui.cpp index 28c9f2f379..d5353dfa82 100644 --- a/src/script/script_gui.cpp +++ b/src/script/script_gui.cpp @@ -857,7 +857,7 @@ struct ScriptDebugWindow : public Window { if (this->IsWidgetDisabled(widget)) return; CompanyID cid = (CompanyID)(widget - start); Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON); - DrawCompanyIcon(cid, CenterBounds(r.left, r.right, sprite_size.width), CenterBounds(r.top, r.bottom, sprite_size.height)); + DrawCompanyIcon(cid, CentreBounds(r.left, r.right, sprite_size.width), CentreBounds(r.top, r.bottom, sprite_size.height)); } /** diff --git a/src/ship_gui.cpp b/src/ship_gui.cpp index 7edccb0be6..7bdedb82dc 100644 --- a/src/ship_gui.cpp +++ b/src/ship_gui.cpp @@ -41,7 +41,7 @@ void DrawShipImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineI int x_offs = UnScaleGUI(rect.left); int x = rtl ? r.right - width - x_offs : r.left - x_offs; /* This magic -1 offset is related to the sprite_y_offsets in build_vehicle_gui.cpp */ - int y = ScaleSpriteTrad(-1) + CenterBounds(r.top, r.bottom, 0); + int y = ScaleSpriteTrad(-1) + CentreBounds(r.top, r.bottom, 0); seq.Draw(x, y, GetVehiclePalette(v), false); if (v->cargo_cap > 0) DrawCargoIconOverlay(x, y, v->cargo_type); diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index e73183481e..eb4521be95 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -1495,8 +1495,8 @@ public: */ Point GetStationMiddle(const Station *st) const { - int x = CenterBounds(st->rect.left, st->rect.right, 0); - int y = CenterBounds(st->rect.top, st->rect.bottom, 0); + int x = CentreBounds(st->rect.left, st->rect.right, 0); + int y = CentreBounds(st->rect.top, st->rect.bottom, 0); Point ret = this->RemapTile(x, y); /* Same magic 3 as in DrawVehicles; that's where I got it from. diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp index 7944176499..7dbde04b44 100644 --- a/src/statusbar_gui.cpp +++ b/src/statusbar_gui.cpp @@ -106,7 +106,7 @@ struct StatusBarWindow : Window { void DrawWidget(const Rect &r, WidgetID widget) const override { Rect tr = r.Shrink(WidgetDimensions::scaled.framerect, RectPadding::zero); - tr.top = CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)); + tr.top = CentreBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)); switch (widget) { case WID_S_LEFT: /* Draw the date */ @@ -155,7 +155,7 @@ struct StatusBarWindow : Window { if (!this->reminder_timeout.HasFired()) { Dimension icon_size = GetSpriteSize(SPR_UNREAD_NEWS); - DrawSprite(SPR_UNREAD_NEWS, PAL_NONE, tr.right - icon_size.width, CenterBounds(r.top, r.bottom, icon_size.height)); + DrawSprite(SPR_UNREAD_NEWS, PAL_NONE, tr.right - icon_size.width, CentreBounds(r.top, r.bottom, icon_size.height)); } break; } diff --git a/src/subsidy_gui.cpp b/src/subsidy_gui.cpp index 520063d198..5f065166ef 100644 --- a/src/subsidy_gui.cpp +++ b/src/subsidy_gui.cpp @@ -150,7 +150,7 @@ struct SubsidyListWindow : Window { SpriteID icon = CargoSpec::Get(cargo_type)->GetCargoIcon(); Dimension d = GetSpriteSize(icon); Rect ir = r.WithWidth(this->cargo_icon_size.width, rtl).WithHeight(GetCharacterHeight(FS_NORMAL)); - DrawSprite(icon, PAL_NONE, CenterBounds(ir.left, ir.right, d.width), CenterBounds(ir.top, ir.bottom, this->cargo_icon_size.height) + y_offset); + DrawSprite(icon, PAL_NONE, CentreBounds(ir.left, ir.right, d.width), CentreBounds(ir.top, ir.bottom, this->cargo_icon_size.height) + y_offset); } void DrawWidget(const Rect &r, WidgetID widget) const override diff --git a/src/train_gui.cpp b/src/train_gui.cpp index a0c5804e56..4a96056f58 100644 --- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -167,7 +167,7 @@ void DrawTrainImage(const Train *v, const Rect &r, VehicleID selection, EngineIm * the next engine after the highlight could overlap it. */ int height = ScaleSpriteTrad(12); Rect hr = {highlight_l, 0, highlight_r, height - 1}; - DrawFrameRect(hr.Translate(r.left, CenterBounds(r.top, r.bottom, height)).Expand(WidgetDimensions::scaled.bevel), COLOUR_WHITE, FrameFlag::BorderOnly); + DrawFrameRect(hr.Translate(r.left, CentreBounds(r.top, r.bottom, height)).Expand(WidgetDimensions::scaled.bevel), COLOUR_WHITE, FrameFlag::BorderOnly); } } diff --git a/src/tree_gui.cpp b/src/tree_gui.cpp index e177146cd9..109fd08e18 100644 --- a/src/tree_gui.cpp +++ b/src/tree_gui.cpp @@ -167,7 +167,7 @@ public: if (widget >= WID_BT_TYPE_BUTTON_FIRST) { const int index = widget - WID_BT_TYPE_BUTTON_FIRST; /* Trees "grow" in the centre on the bottom line of the buttons */ - DrawSprite(tree_sprites[index].sprite, tree_sprites[index].pal, CenterBounds(r.left, r.right, 0), r.bottom - ScaleGUITrad(BUTTON_BOTTOM_OFFSET)); + DrawSprite(tree_sprites[index].sprite, tree_sprites[index].pal, CentreBounds(r.left, r.right, 0), r.bottom - ScaleGUITrad(BUTTON_BOTTOM_OFFSET)); } } diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 83553cad0f..d78ba5723b 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1058,7 +1058,7 @@ struct RefitWindow : public Window { /* Determine top & bottom position of the highlight.*/ const int height = ScaleSpriteTrad(12); - const int highlight_top = CenterBounds(r.top, r.bottom, height); + const int highlight_top = CentreBounds(r.top, r.bottom, height); const int highlight_bottom = highlight_top + height - 1; for (Train *u = Train::From(v); u != nullptr; u = u->Next()) { @@ -2667,14 +2667,14 @@ struct VehicleDetailsWindow : Window { /* We're using wallclock units. Show minutes since last serviced. */ if (TimerGameEconomy::UsingWallclockUnits()) { int minutes_since_serviced = (TimerGameEconomy::date - v->date_of_last_service).base() / EconomyTime::DAYS_IN_ECONOMY_MONTH; - DrawString(tr.left, tr.right, CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), + DrawString(tr.left, tr.right, CentreBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), GetString(v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT : STR_VEHICLE_DETAILS_SERVICING_INTERVAL_MINUTES, v->GetServiceInterval(), STR_VEHICLE_DETAILS_LAST_SERVICE_MINUTES_AGO, minutes_since_serviced)); break; } /* We're using calendar dates. Show the date of last service. */ - DrawString(tr.left, tr.right, CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), + DrawString(tr.left, tr.right, CentreBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), GetString(v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT : STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS, v->GetServiceInterval(), STR_VEHICLE_DETAILS_LAST_SERVICE_DATE, v->date_of_last_service)); break; @@ -3212,7 +3212,7 @@ public: TextColour text_colour = TC_FROMSTRING; std::string str = GetVehicleStatusString(v, text_colour); - DrawString(tr.left, tr.right, CenterBounds(tr.top, tr.bottom, GetCharacterHeight(FS_NORMAL)), str, text_colour, SA_HOR_CENTER); + DrawString(tr.left, tr.right, CentreBounds(tr.top, tr.bottom, GetCharacterHeight(FS_NORMAL)), str, text_colour, SA_HOR_CENTER); } void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override diff --git a/src/widget.cpp b/src/widget.cpp index 2609362796..cde3eba7bf 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -123,13 +123,13 @@ static inline Point GetAlignedPosition(const Rect &r, const Dimension &d, String 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 = CenterBounds(r.left, r.right, d.width); 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; default: NOT_REACHED(); } switch (align & SA_VERT_MASK) { case SA_TOP: p.y = r.top; break; - case SA_VERT_CENTER: p.y = CenterBounds(r.top, r.bottom, d.height); 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; default: NOT_REACHED(); } @@ -676,7 +676,7 @@ static inline void DrawCloseBox(const Rect &r, Colours colour) d.width -= offset.x; d.height -= offset.y; int s = ScaleSpriteTrad(1); /* Offset to account for shadow of SPR_CLOSEBOX */ - DrawSprite(SPR_CLOSEBOX, (colour != COLOUR_WHITE ? TC_BLACK : TC_SILVER) | (1U << PALETTE_TEXT_RECOLOUR), CenterBounds(r.left, r.right, d.width - s) - offset.x, CenterBounds(r.top, r.bottom, d.height - s) - offset.y); + DrawSprite(SPR_CLOSEBOX, (colour != COLOUR_WHITE ? TC_BLACK : TC_SILVER) | (1U << PALETTE_TEXT_RECOLOUR), CentreBounds(r.left, r.right, d.width - s) - offset.x, CentreBounds(r.top, r.bottom, d.height - s) - offset.y); } /** @@ -727,13 +727,13 @@ static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicke DrawFrameRect(r.left, r.top, r.right - dd_width, r.bottom, colour, clicked_button ? FrameFlag::Lowered : FrameFlags{}); DrawImageButtons(r.WithWidth(dd_width, true), WWT_DROPDOWN, colour, clicked_dropdown, SPR_ARROW_DOWN, SA_CENTER); if (!str.empty()) { - DrawString(r.left + WidgetDimensions::scaled.dropdowntext.left, r.right - dd_width - WidgetDimensions::scaled.dropdowntext.right, CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), str, TC_BLACK, align); + DrawString(r.left + WidgetDimensions::scaled.dropdowntext.left, r.right - dd_width - WidgetDimensions::scaled.dropdowntext.right, CentreBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), str, TC_BLACK, align); } } else { DrawFrameRect(r.left + dd_width, r.top, r.right, r.bottom, colour, clicked_button ? FrameFlag::Lowered : FrameFlags{}); DrawImageButtons(r.WithWidth(dd_width, false), WWT_DROPDOWN, colour, clicked_dropdown, SPR_ARROW_DOWN, SA_CENTER); if (!str.empty()) { - DrawString(r.left + dd_width + WidgetDimensions::scaled.dropdowntext.left, r.right - WidgetDimensions::scaled.dropdowntext.right, CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), str, TC_BLACK, align); + DrawString(r.left + dd_width + WidgetDimensions::scaled.dropdowntext.left, r.right - WidgetDimensions::scaled.dropdowntext.right, CentreBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), str, TC_BLACK, align); } } }