Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/paint.cc')
-rw-r--r--src/ui/paint.cc73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/ui/paint.cc b/src/ui/paint.cc
index 935cf92..ce5a5c2 100644
--- a/src/ui/paint.cc
+++ b/src/ui/paint.cc
@@ -93,6 +93,79 @@ void text_centered(math::Vector2f const &location, math::Vector2f const &size, s
disable(GL_TEXTURE_2D);
}
+void text(math::Vector2f const &location, Font const *font, std::stringstream & textstream)
+{
+ using namespace render::gl;
+ render::Text::setfont(font->name().c_str(), font->width(), font->height());
+
+ // enable OpenGL textures
+ enable(GL_TEXTURE_2D);
+
+ render::Text::draw(location.x, location.y, textstream);
+
+ // disable texturing
+ disable(GL_TEXTURE_2D);
+}
+
+void text(math::Vector2f const &location, math::Vector2f const &size,
+ Font const *font,
+ std::string const &text,
+ unsigned int align)
+{
+ unsigned int align_horizontal = (align & 0x000F);
+ if (!align_horizontal)
+ align_horizontal = AlignLeft;
+
+ unsigned int align_vertical = (align & 0x00F0);
+ if (!align_vertical)
+ align_vertical = AlignTop;
+
+ // apply text font
+ using namespace render::gl;
+ render::Text::setfont(font->name().c_str(), font->width(), font->height());
+
+ // enable OpenGL textures
+ enable(GL_TEXTURE_2D);
+
+ // determine the width and height of the text
+ // FIXME support multiline text
+ float text_height = 1.0f * font->height();
+ float text_width = (float) aux::text_strip(text).size() * font->width();
+
+ // calculate drawing position
+ math::Vector2f v(location);
+
+ switch(align_horizontal) {
+ case AlignLeft:
+ v.x += font->width();
+ break;
+ case AlignHCenter:
+ v.x += (size.x - text_width) / 2.0f;
+ break;
+ case AlignRight:
+ v.x += size.x - text_width - font->width();
+ break;
+ }
+
+ switch(align_vertical) {
+ case AlignTop:
+ v.y += font->height()*0.5f;
+ break;
+ case AlignVCenter:
+ v.y += (size.y - text_height) / 2.0f;
+ break;
+ case AlignBottom:
+ v.y += size.y - text_height - font->height()*0.5f;
+ break;
+ }
+
+ render::Text::draw(v.x, v.y, text);
+
+ // disable texturing
+ disable(GL_TEXTURE_2D);
+
+}
+
}
}