summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-12-20 16:42:35 +0000
committerrubidium <rubidium@openttd.org>2009-12-20 16:42:35 +0000
commit90b7f0f3cb6e42e62a445e43407e4c543f55306f (patch)
tree57d843ce04871e058c4aeb9653cdb2a007963247
parentf2785ae24d369b68f246a162ff7619e61d8a380a (diff)
downloadopenttd-90b7f0f3cb6e42e62a445e43407e4c543f55306f.tar.xz
(svn r18575) -Fix [FS#3393]: unit numbers weren't always fully shown in the depot
-rw-r--r--src/depot_gui.cpp5
-rw-r--r--src/gfx.cpp14
-rw-r--r--src/gfx_func.h1
3 files changed, 17 insertions, 3 deletions
diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp
index 7c265489e..c053fffc4 100644
--- a/src/depot_gui.cpp
+++ b/src/depot_gui.cpp
@@ -631,15 +631,14 @@ struct DepotWindow : Window {
this->count_width = 0;
}
- SetDParam(0, 999);
- Dimension unumber = GetStringBoundingBox(STR_BLACK_COMMA);
+ Dimension unumber = { GetDigitWidth() * 4, FONT_HEIGHT_NORMAL };
const Sprite *spr = GetSprite(SPR_FLAG_VEH_STOPPED, ST_NORMAL);
this->flag_width = spr->width + WD_FRAMERECT_RIGHT;
this->flag_height = spr->height;
if (this->type == VEH_TRAIN || this->type == VEH_ROAD) {
min_height = max<uint>(unumber.height + WD_MATRIX_TOP, spr->height);
- this->header_width = unumber.width + this->flag_width;
+ this->header_width = unumber.width + this->flag_width + WD_FRAMERECT_LEFT;
} else {
min_height = unumber.height + spr->height + WD_MATRIX_TOP + WD_PAR_VSEP_NORMAL + WD_MATRIX_BOTTOM;
this->header_width = max<uint>(unumber.width, this->flag_width) + WD_FRAMERECT_RIGHT;
diff --git a/src/gfx.cpp b/src/gfx.cpp
index 5247daccb..4fddd1fba 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -1306,6 +1306,20 @@ byte GetCharacterWidth(FontSize size, WChar key)
return GetGlyphWidth(size, key);
}
+/**
+ * Return the maximum width of single digit.
+ * @param size Font of the digit
+ * @return Width of the digit.
+ */
+byte GetDigitWidth(FontSize size)
+{
+ byte width = 0;
+ for (char c = '0'; c <= '9'; c++) {
+ width = max(GetCharacterWidth(size, c), width);
+ }
+ return width;
+}
+
void ScreenSizeChanged()
{
diff --git a/src/gfx_func.h b/src/gfx_func.h
index 6fe86ca68..ca583fbc9 100644
--- a/src/gfx_func.h
+++ b/src/gfx_func.h
@@ -160,6 +160,7 @@ bool ToggleFullScreen(bool fs);
extern FontSize _cur_fontsize; ///< Currently selected font.
byte GetCharacterWidth(FontSize size, uint32 key);
+byte GetDigitWidth(FontSize size = FS_NORMAL);
/**
* Get height of a character for a given font size.