summaryrefslogtreecommitdiff
path: root/src/town_gui.cpp
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2009-07-04 15:35:36 +0000
committeralberth <alberth@openttd.org>2009-07-04 15:35:36 +0000
commitd65c6cae545f36e7f25efcee0b28bbfac7d64769 (patch)
tree88411cfe473c05b2abb2c6afdce7932f660312cd /src/town_gui.cpp
parent2385aeae3c3b065fac37724334469f1ed9ea29f3 (diff)
downloadopenttd-d65c6cae545f36e7f25efcee0b28bbfac7d64769.tar.xz
(svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
Diffstat (limited to 'src/town_gui.cpp')
-rw-r--r--src/town_gui.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index bbc03ea61..fd2eb949a 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -643,6 +643,43 @@ public:
}
}
+ virtual Dimension GetWidgetContentSize(int widget)
+ {
+ Dimension d = {0, 0};
+ switch (widget) {
+ case TDW_SORTNAME: {
+ d = GetStringBoundingBox(STR_SORT_BY_NAME);
+ d.width += WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the word is centered, also looks nice.
+ break;
+ }
+
+ case TDW_SORTPOPULATION: {
+ d = GetStringBoundingBox(STR_SORT_BY_POPULATION);
+ d.width += WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the word is centered, also looks nice.
+ break;
+ }
+
+ case TDW_CENTERTOWN:
+ for (uint i = 0; i < this->towns.Length(); i++) {
+ const Town *t = this->towns[i];
+
+ assert(t != NULL);
+
+ SetDParam(0, t->index);
+ 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.
+ break;
+
+ case TDW_EMPTYBOTTOM:
+ SetDParam(0, 1000000000); // 10^9
+ d = GetStringBoundingBox(STR_TOWN_POPULATION);
+ break;
+ }
+ return d;
+ }
+
virtual void OnClick(Point pt, int widget)
{
switch (widget) {
@@ -676,7 +713,7 @@ public:
if (id_v >= this->towns.Length()) return; // click out of town bounds
const Town *t = this->towns[id_v];
- assert(t->xy != INVALID_TILE);
+ assert(t != NULL);
if (_ctrl_pressed) {
ShowExtraViewPortWindow(t->xy);
} else {