diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2012-03-25 21:40:45 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2013-01-13 22:40:52 +0100 |
commit | 231a5c0d8dfc6d5b0fd2cbbdbd10cea582562f85 (patch) | |
tree | 10c217ed3e7137dc8bedf15cc00a45413656983c /src/menu/text.cpp | |
parent | 443d35771754821fbcf205005c7f5a632bdfbbd2 (diff) | |
download | usdx-231a5c0d8dfc6d5b0fd2cbbdbd10cea582562f85.tar.gz usdx-231a5c0d8dfc6d5b0fd2cbbdbd10cea582562f85.tar.xz usdx-231a5c0d8dfc6d5b0fd2cbbdbd10cea582562f85.zip |
menu/text: added variable vertical alignment in the box of the control
Diffstat (limited to '')
-rw-r--r-- | src/menu/text.cpp | 29 |
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 |