From 02fcd22d8cde355aa898a8c6bb4773d9434b8e9a Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 10 Oct 2008 16:41:38 +0000 Subject: adds KeyPress, DevInfo and Stats widgets --- src/ui/paint.cc | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'src/ui/paint.cc') 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); + +} + } } -- cgit v1.2.3