aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti2008-07-10 20:36:02 +0000
committerVicent Marti2008-07-10 20:36:02 +0000
commita90be07c3e93014174a3b4f3fa0be25aad227859 (patch)
tree72b41efdbe6245167332d35908110d63ecb2183b
parente0aad7f4be66a9e30f0226c17c9d2bd0a8138898 (diff)
downloadscummvm-rg350-a90be07c3e93014174a3b4f3fa0be25aad227859.tar.gz
scummvm-rg350-a90be07c3e93014174a3b4f3fa0be25aad227859.tar.bz2
scummvm-rg350-a90be07c3e93014174a3b4f3fa0be25aad227859.zip
Support for Vertical text alignement.
svn-id: r32995
-rw-r--r--graphics/VectorRenderer.cpp22
-rw-r--r--graphics/VectorRenderer.h9
-rw-r--r--gui/ThemeDefaultXML.cpp6
-rw-r--r--gui/ThemeParser.cpp23
-rw-r--r--gui/ThemeRenderer.cpp5
-rw-r--r--gui/theme.h7
6 files changed, 51 insertions, 21 deletions
diff --git a/graphics/VectorRenderer.cpp b/graphics/VectorRenderer.cpp
index 0c1d01213d..8856386819 100644
--- a/graphics/VectorRenderer.cpp
+++ b/graphics/VectorRenderer.cpp
@@ -75,7 +75,7 @@ void VectorRenderer::textStep(const Common::String &text, const Common::Rect &ar
if (step.color.set)
setFgColor(step.color.r, step.color.g, step.color.b);
- drawString(step.font, text.c_str(), area, step.align);
+ drawString(step.font, text.c_str(), area, step.alignHorizontal, step.alignVertical);
}
/********************************************************************
@@ -185,8 +185,24 @@ inline uint32 fp_sqroot(uint32 x) {
********************************************************************/
template <typename PixelType, typename PixelFormat>
void VectorRendererSpec<PixelType, PixelFormat>::
-drawString(const Graphics::Font *font, const Common::String &text, const Common::Rect &area, GUI::Theme::TextAlign align) {
- font->drawString(_activeSurface, text, area.left, area.top, area.width(), _fgColor, (Graphics::TextAlignment)align, 0, false);
+drawString(const Graphics::Font *font, const Common::String &text, const Common::Rect &area,
+ GUI::Theme::TextAlign alignH, GUI::Theme::TextAlignVertical alignV) {
+
+ int offset = 0;
+
+ switch (alignV) {
+ case GUI::Theme::kTextAlignVCenter:
+ offset = area.top + (area.height() - font->getFontHeight()) / 2;
+ break;
+ case GUI::Theme::kTextAlignVBottom:
+ offset = area.bottom - font->getFontHeight();
+ break;
+ case GUI::Theme::kTextAlignVTop:
+ offset = area.top;
+ break;
+ }
+
+ font->drawString(_activeSurface, text, area.left, offset, area.width(), _fgColor, (Graphics::TextAlignment)alignH, 0, false);
}
/** LINES **/
diff --git a/graphics/VectorRenderer.h b/graphics/VectorRenderer.h
index 9b5481cddf..01fccb8c30 100644
--- a/graphics/VectorRenderer.h
+++ b/graphics/VectorRenderer.h
@@ -46,7 +46,8 @@ struct TextStep {
}
color; /** text color */
- GUI::Theme::TextAlign align;
+ GUI::Theme::TextAlign alignHorizontal;
+ GUI::Theme::TextAlignVertical alignVertical;
char *text;
const Graphics::Font *font;
};
@@ -446,7 +447,7 @@ public:
*/
virtual void blitSurface(Graphics::Surface *source, const Common::Rect &r) = 0;
- virtual void drawString(const Graphics::Font *font, const Common::String &text, const Common::Rect &area, GUI::Theme::TextAlign align) = 0;
+ virtual void drawString(const Graphics::Font *font, const Common::String &text, const Common::Rect &area, GUI::Theme::TextAlign alignH, GUI::Theme::TextAlignVertical alignV) = 0;
protected:
Surface *_activeSurface; /** Pointer to the surface currently being drawn */
@@ -513,7 +514,9 @@ public:
drawBevelSquareAlg(x, y, w, h, bevel, _fgColor, _bgColor);
}
- void drawString(const Graphics::Font *font, const Common::String &text, const Common::Rect &area, GUI::Theme::TextAlign align);
+ void drawString(const Graphics::Font *font, const Common::String &text,
+ const Common::Rect &area, GUI::Theme::TextAlign alignH,
+ GUI::Theme::TextAlignVertical alignV);
/**
* @see VectorRenderer::setFgColor()
diff --git a/gui/ThemeDefaultXML.cpp b/gui/ThemeDefaultXML.cpp
index 3793fcc82b..da40d64731 100644
--- a/gui/ThemeDefaultXML.cpp
+++ b/gui/ThemeDefaultXML.cpp
@@ -51,17 +51,17 @@ bool ThemeRenderer::loadDefaultXML() {
"</drawdata>"
"<drawdata id = 'button_idle' cache = false>"
- "<text align = 'center' color = '255, 0, 0' />"
+ "<text vertical_align = 'center' horizontal_align = 'center' color = '255, 255, 255' />"
"<drawstep func = 'roundedsq' radius = '8' stroke = 0 fill = 'gradient' gradient_start = '206, 121, 99' gradient_end = '173, 40, 8' size = 'auto' shadow = 3 />"
"</drawdata>"
"<drawdata id = 'button_hover' cache = false>"
- "<text align = 'center' color = '255, 0, 0' />"
+ "<text vertical_align = 'center' horizontal_align = 'center' color = '255, 255, 255' />"
"<drawstep func = 'roundedsq' radius = '8' fill = 'gradient' gradient_start = '206, 121, 99' gradient_end = '173, 40, 8' size = 'auto' shadow = 3 />"
"</drawdata>"
"<drawdata id = 'checkbox_disabled' cache = false>"
- "<text align = 'center' color = '255, 0, 0' />"
+ "<text vertical_align = 'center' horizontal_align = 'center' color = '255, 0, 0' />"
"<drawstep func = 'square' fill = 'gradient' gradient_start = '206, 121, 99' gradient_end = '173, 40, 8' size = 'auto' shadow = 0 />"
"</drawdata>"
diff --git a/gui/ThemeParser.cpp b/gui/ThemeParser.cpp
index eae131af50..7f02c1eb57 100644
--- a/gui/ThemeParser.cpp
+++ b/gui/ThemeParser.cpp
@@ -146,17 +146,24 @@ bool ThemeParser::parserCallback_text() {
Graphics::TextStep step;
- if (tNode->values.contains("align") == false)
- return parserError("Text inside widgets requires an alignement key.");
+ if (tNode->values.contains("horizontal_align") == false || tNode->values.contains("vertical_align") == false)
+ return parserError("Text inside widgets requires proper alignment keys.");
- if (tNode->values["align"] == "left")
- step.align = GUI::Theme::kTextAlignLeft;
- else if (tNode->values["align"] == "right")
- step.align = GUI::Theme::kTextAlignRight;
- else if (tNode->values["align"] == "center")
- step.align = GUI::Theme::kTextAlignCenter;
+ if (tNode->values["horizontal_align"] == "left")
+ step.alignHorizontal = GUI::Theme::kTextAlignLeft;
+ else if (tNode->values["horizontal_align"] == "right")
+ step.alignHorizontal = GUI::Theme::kTextAlignRight;
+ else if (tNode->values["horizontal_align"] == "center")
+ step.alignHorizontal = GUI::Theme::kTextAlignCenter;
else return parserError("Invalid value for text alignment.");
+ if (tNode->values["vertical_align"] == "top")
+ step.alignVertical = GUI::Theme::kTextAlignVTop;
+ else if (tNode->values["vertical_align"] == "center")
+ step.alignVertical = GUI::Theme::kTextAlignVCenter;
+ else if (tNode->values["vertical_align"] == "bottom")
+ step.alignVertical = GUI::Theme::kTextAlignVBottom;
+ else return parserError("Invalid value for text alignment.");
if (tNode->values.contains("color")) {
int red, green, blue;
diff --git a/gui/ThemeRenderer.cpp b/gui/ThemeRenderer.cpp
index ca686b8583..0fd7afbaf5 100644
--- a/gui/ThemeRenderer.cpp
+++ b/gui/ThemeRenderer.cpp
@@ -302,10 +302,7 @@ void ThemeRenderer::drawButton(const Common::Rect &r, const Common::String &str,
dd = kDDButtonDisabled;
drawDD(dd, r);
- drawDDText(dd, r, str);
- if (hasWidgetText(dd))
- _vectorRenderer->textStep(str, r, _widgets[dd]->_textStep);
-
+ drawDDText(dd, r, str);
addDirtyRect(r);
debugWidgetPosition(r);
diff --git a/gui/theme.h b/gui/theme.h
index 320d2544e0..e9ce8bb01d 100644
--- a/gui/theme.h
+++ b/gui/theme.h
@@ -92,6 +92,13 @@ public:
kTextAlignCenter, //! Text should be centered
kTextAlignRight //! Text should be aligned to the right
};
+
+ //! Vertical alignment of the text.
+ enum TextAlignVertical {
+ kTextAlignVBottom,
+ kTextAlignVCenter,
+ kTextAlignVTop
+ };
//! Widget background type
enum WidgetBackground {