aboutsummaryrefslogtreecommitdiffstats
path: root/src/menu/text.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/menu/text.cpp')
-rw-r--r--src/menu/text.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/menu/text.cpp b/src/menu/text.cpp
index d5e658e1..301cc62b 100644
--- a/src/menu/text.cpp
+++ b/src/menu/text.cpp
@@ -34,8 +34,10 @@ namespace usdx
log4cpp::Category& Text::log =
log4cpp::Category::getInstance("usdx.menu.text");
- Text::Text(Container *parent, const std::string text, const unsigned int size) :
- DrawableControl(parent), text(text), auto_size(true), stretch(false)
+ Text::Text(Container *parent, const std::string text,
+ const unsigned int size, const VerticalTextAlignment* valign) :
+ DrawableControl(parent), text(text), auto_size(true),
+ stretch(false), offset(Point<int>(0, 0)), valign(valign)
{
font = new FTBufferFont("DejaVuSans.ttf");
font->FaceSize(size);
@@ -44,22 +46,39 @@ namespace usdx
throw new std::exception();
}
+ realign();
}
Text::~Text()
{
+ if (valign) {
+ delete valign;
+ valign = NULL;
+ }
+
if (font) {
delete font;
font = NULL;
}
}
- void Text::draw(void)
+ void Text::realign(void)
{
- glScalef(1, -1, 1);
+ Rectangle<int> bbox(font->BBox(text.c_str()));
+ bbox.get_point1().set_y(font->Ascender());
+ bbox.get_point2().set_y(font->Descender());
+ valign->align(offset, bbox, get_size());
+ }
+ void Text::draw(void)
+ {
{
boost::mutex::scoped_lock lock(font_mutex);
+ glTranslatef(offset.get_x(), offset.get_y(), 0.0f);
+
+ // invert y axis, text is drawn using window orientation (origin is
+ // bottom left)
+ glScalef(1, -1, 1);
font->Render(text.c_str());
}
}
@@ -68,6 +87,7 @@ namespace usdx
{
boost::mutex::scoped_lock lock(font_mutex);
font->FaceSize(value);
+ realign();
}
unsigned int Text::get_font_size(void) const
@@ -79,6 +99,7 @@ namespace usdx
{
boost::mutex::scoped_lock lock(font_mutex);
text = value;
+ realign();
}
std::string Text::get_text(void) const