Changeset - r12700:a0d471f4a901
[Not reviewed]
master
0 1 0
alberth - 15 years ago 2009-08-14 21:20:22
alberth@openttd.org
(svn r17173) -Codechange: Vertically align WWT_TEXT widget, generalize vertical alignment of label and text buttons.
1 file changed with 6 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/widget.cpp
Show inline comments
 
@@ -298,24 +298,28 @@ static inline void DrawImageButtons(cons
 
 * @param str     Text to draw.
 
 */
 
static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, StringID str)
 
{
 
	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);
 
}
 

	
 
/**
 
 * Draw text.
 
 * @param r      Rectangle of the background.
 
 * @param colour Colour of the text.
 
 * @param str    Text to draw.
 
 */
 
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);
 
}
 

	
 
/**
 
 * Draw an inset widget.
 
 * @param r      Rectangle of the background.
 
 * @param colour Colour of the inset.
0 comments (0 inline, 0 general)