summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2009-08-14 21:20:22 +0000
committeralberth <alberth@openttd.org>2009-08-14 21:20:22 +0000
commit2184b5db8a48c6064f387b33a3790617668df065 (patch)
tree0d601dab80621f03234ac235dff201ebee689ab4 /src
parentc4f055cc1158a50b98db5f94ed4859619f37b37b (diff)
downloadopenttd-2184b5db8a48c6064f387b33a3790617668df065.tar.xz
(svn r17173) -Codechange: Vertically align WWT_TEXT widget, generalize vertical alignment of label and text buttons.
Diffstat (limited to 'src')
-rw-r--r--src/widget.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/widget.cpp b/src/widget.cpp
index 70dd207c9..e46bb5f8b 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -301,7 +301,9 @@ static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, Strin
{
if (str == STR_NULL) return;
if ((type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
- DrawString(r.left + clicked, r.right + clicked, ((r.top + r.bottom + 1) >> 1) - (FONT_HEIGHT_NORMAL / 2) + clicked, str, TC_FROMSTRING, SA_CENTER);
+ Dimension d = GetStringBoundingBox(str);
+ int offset = max(0, ((int)(r.bottom - r.top + 1) - (int)d.height) / 2); // Offset for rendering the text vertically centered
+ DrawString(r.left + clicked, r.right + clicked, r.top + offset + clicked, str, TC_FROMSTRING, SA_CENTER);
}
/**
@@ -312,7 +314,9 @@ static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, Strin
*/
static inline void DrawText(const Rect &r, TextColour colour, StringID str)
{
- if (str != STR_NULL) DrawString(r.left, r.right, r.top, str, colour);
+ Dimension d = GetStringBoundingBox(str);
+ int offset = max(0, ((int)(r.bottom - r.top + 1) - (int)d.height) / 2); // Offset for rendering the text vertically centered
+ if (str != STR_NULL) DrawString(r.left, r.right, r.top + offset, str, colour);
}
/**