summaryrefslogtreecommitdiff
path: root/src/town_gui.cpp
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2009-07-18 10:46:55 +0000
committeralberth <alberth@openttd.org>2009-07-18 10:46:55 +0000
commit36576371c05edf9a3498196d7ebdb8824a6910d1 (patch)
tree0b847859d28abe6988089bd80682f0d9b0f40412 /src/town_gui.cpp
parent2b374824dcd55fef5cf6afe727f1ab914b19a1d2 (diff)
downloadopenttd-36576371c05edf9a3498196d7ebdb8824a6910d1.tar.xz
(svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
Diffstat (limited to 'src/town_gui.cpp')
-rw-r--r--src/town_gui.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index b8dfe4fcf..d017c04a7 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -643,18 +643,19 @@ public:
}
}
- virtual Dimension GetWidgetContentSize(int widget)
+ virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *resize)
{
- Dimension d = {0, 0};
switch (widget) {
case TDW_SORTNAME:
case TDW_SORTPOPULATION: {
- d = GetStringBoundingBox(this->nested_array[widget]->widget_data);
- d.width += WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the word is centered, also looks nice.
+ Dimension d = GetStringBoundingBox(this->nested_array[widget]->widget_data);
+ d.width += padding.width + WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the word is centered, also looks nice.
+ d.height += padding.height;
+ *size = maxdim(*size, d);
break;
}
-
- case TDW_CENTERTOWN:
+ case TDW_CENTERTOWN: {
+ Dimension d = {0, 0};
for (uint i = 0; i < this->towns.Length(); i++) {
const Town *t = this->towns[i];
@@ -664,15 +665,21 @@ public:
SetDParam(1, 10000000); // 10^7
d = maxdim(d, GetStringBoundingBox(STR_TOWN_DIRECTORY_TOWN));
}
- d.width += 2 + 2; // Text is rendered with 2 pixel offset at both sides.
+ d.width += padding.width + 2 + 2; // Text is rendered with 2 pixel offset at both sides.
+ d.height += padding.height;
+ *size = maxdim(*size, d);
+ resize->height = d.height;
break;
-
- case TDW_EMPTYBOTTOM:
+ }
+ case TDW_EMPTYBOTTOM: {
SetDParam(0, 1000000000); // 10^9
- d = GetStringBoundingBox(STR_TOWN_POPULATION);
+ Dimension d = GetStringBoundingBox(STR_TOWN_POPULATION);
+ d.width += padding.width;
+ d.height += padding.height;
+ *size = maxdim(*size, d);
break;
+ }
}
- return d;
}
virtual void OnClick(Point pt, int widget)