mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-08 15:30:00 +00:00
Change: Scale bridge GUI by interface scale. (#11152)
This commit is contained in:
parent
96e937c6cd
commit
fd155dfb40
@ -85,7 +85,7 @@ private:
|
||||
TransportType transport_type;
|
||||
byte road_rail_type;
|
||||
GUIBridgeList bridges;
|
||||
int bridgetext_offset; ///< Horizontal offset of the text describing the bridge properties in #WID_BBS_BRIDGE_LIST relative to the left edge.
|
||||
int icon_width; ///< Scaled width of the the bridge icon sprite.
|
||||
Scrollbar *vscroll;
|
||||
|
||||
/** Sort the bridges by their index */
|
||||
@ -159,7 +159,7 @@ public:
|
||||
this->vscroll = this->GetScrollbar(WID_BBS_SCROLLBAR);
|
||||
/* Change the data, or the caption of the gui. Set it to road or rail, accordingly. */
|
||||
this->GetWidget<NWidgetCore>(WID_BBS_CAPTION)->widget_data = (transport_type == TRANSPORT_ROAD) ? STR_SELECT_ROAD_BRIDGE_CAPTION : STR_SELECT_RAIL_BRIDGE_CAPTION;
|
||||
this->FinishInitNested(transport_type); // Initializes 'this->bridgetext_offset'.
|
||||
this->FinishInitNested(transport_type); // Initializes 'this->icon_width'.
|
||||
|
||||
this->parent = FindWindowById(WC_BUILD_TOOLBAR, transport_type);
|
||||
this->bridges.SetListing(this->last_sorting);
|
||||
@ -199,15 +199,13 @@ public:
|
||||
Dimension sprite_dim = {0, 0}; // Biggest bridge sprite dimension
|
||||
Dimension text_dim = {0, 0}; // Biggest text dimension
|
||||
for (const BuildBridgeData &bridge_data : this->bridges) {
|
||||
sprite_dim = maxdim(sprite_dim, GetSpriteSize(bridge_data.spec->sprite));
|
||||
sprite_dim = maxdim(sprite_dim, GetScaledSpriteSize(bridge_data.spec->sprite));
|
||||
text_dim = maxdim(text_dim, GetStringBoundingBox(GetBridgeSelectString(bridge_data)));
|
||||
}
|
||||
sprite_dim.height++; // Sprite is rendered one pixel down in the matrix field.
|
||||
text_dim.height++; // Allowing the bottom row pixels to be rendered on the edge of the matrix field.
|
||||
resize->height = std::max(sprite_dim.height, text_dim.height) + padding.height; // Max of both sizes + account for matrix edges.
|
||||
|
||||
this->bridgetext_offset = sprite_dim.width + WidgetDimensions::scaled.hsep_normal; // Left edge of text, 1 pixel distance from the sprite.
|
||||
size->width = this->bridgetext_offset + text_dim.width + padding.width;
|
||||
this->icon_width = sprite_dim.width; // Width of bridge icon.
|
||||
size->width = this->icon_width + WidgetDimensions::scaled.hsep_normal + text_dim.width + padding.width;
|
||||
size->height = 4 * resize->height; // Smallest bridge gui is 4 entries high in the matrix.
|
||||
break;
|
||||
}
|
||||
@ -233,11 +231,12 @@ public:
|
||||
|
||||
case WID_BBS_BRIDGE_LIST: {
|
||||
Rect tr = r.WithHeight(this->resize.step_height).Shrink(WidgetDimensions::scaled.matrix);
|
||||
bool rtl = _current_text_dir == TD_RTL;
|
||||
for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < (int)this->bridges.size(); i++) {
|
||||
const BuildBridgeData &bridge_data = this->bridges.at(i);
|
||||
const BridgeSpec *b = bridge_data.spec;
|
||||
DrawSprite(b->sprite, b->pal, tr.left, tr.bottom - GetSpriteSize(b->sprite).height);
|
||||
DrawStringMultiLine(tr.Indent(this->bridgetext_offset, false), GetBridgeSelectString(bridge_data));
|
||||
DrawSpriteIgnorePadding(b->sprite, b->pal, tr.WithWidth(this->icon_width, rtl), false, SA_HOR_CENTER | SA_BOTTOM);
|
||||
DrawStringMultiLine(tr.Indent(this->icon_width + WidgetDimensions::scaled.hsep_normal, rtl), GetBridgeSelectString(bridge_data));
|
||||
tr = tr.Translate(0, this->resize.step_height);
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user