Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-10-12 14:55:10 +0000
committerStijn Buys <ingar@osirion.org>2008-10-12 14:55:10 +0000
commitb417df720584c101f3799874a0c836a543a8d0a8 (patch)
treefb7105ed662f13753a6ab8d3efb047bad04f2316 /src/ui/paint.cc
parent18383a5fc596bf9546f14d7393ee66c57720b116 (diff)
user interface updates, work-in-progress
Diffstat (limited to 'src/ui/paint.cc')
-rw-r--r--src/ui/paint.cc66
1 files changed, 36 insertions, 30 deletions
diff --git a/src/ui/paint.cc b/src/ui/paint.cc
index ce5a5c2..33ee54f 100644
--- a/src/ui/paint.cc
+++ b/src/ui/paint.cc
@@ -11,7 +11,8 @@
#include "render/textures.h"
#include "ui/paint.h"
-namespace ui {
+namespace ui
+{
// contains the interface between the user interface and the render library
namespace paint {
@@ -26,10 +27,15 @@ void color(math::Color const & color)
render::gl::color(color);
}
+void color_code(const char *c)
+{
+ render::Text::setcolor(*c);
+}
+
void border(math::Vector2f const &location, math::Vector2f const &size)
{
using namespace render::gl;
-
+
begin(LineLoop);
vertex(location.x +1 , location.y);
vertex(location.x + size.x, location.y);
@@ -41,7 +47,7 @@ void border(math::Vector2f const &location, math::Vector2f const &size)
void rectangle(math::Vector2f const &location, math::Vector2f const &size)
{
using namespace render::gl;
-
+
begin(Quads);
vertex(location.x +1 , location.y);
vertex(location.x + size.x, location.y);
@@ -57,39 +63,39 @@ void bitmap(math::Vector2f const &location, math::Vector2f const &size, std::str
render::Textures::bind("bitmaps/" + texture);
enable(GL_TEXTURE_2D);
-
+
begin(Quads);
-
+
glTexCoord2f(0.0f, 0.0f);
vertex(location.x +1 , location.y);
-
+
glTexCoord2f(1.0f, 0.0f);
vertex(location.x + size.x, location.y);
-
+
glTexCoord2f(1.0f, 1.0f);
vertex(location.x + size.x, location.y + size.y -1);
-
+
glTexCoord2f(0.0f, 1.0f);
vertex(location.x +1, location.y + size.y - 1);
end();
-
+
disable(GL_TEXTURE_2D);
}
void text_centered(math::Vector2f const &location, math::Vector2f const &size, std::string const &text, Font const *font)
{
using namespace render::gl;
-
+
render::Text::setfont(font->name().c_str(), font->width(), font->height());
enable(GL_TEXTURE_2D);
math::Vector2f v(location);
-
+
v.x += (size.x - aux::text_strip(text).size() * font->width()) /2.0f;
v.y += (size.y - font->height()) / 2.0f;
-
+
render::Text::draw(v.x, v.y, text);
-
+
disable(GL_TEXTURE_2D);
}
@@ -97,45 +103,45 @@ void text(math::Vector2f const &location, Font const *font, std::stringstream &
{
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)
+ 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) {
+
+ switch (align_horizontal) {
case AlignLeft:
v.x += font->width();
break;
@@ -147,7 +153,7 @@ void text(math::Vector2f const &location, math::Vector2f const &size,
break;
}
- switch(align_vertical) {
+ switch (align_vertical) {
case AlignTop:
v.y += font->height()*0.5f;
break;
@@ -158,12 +164,12 @@ void text(math::Vector2f const &location, math::Vector2f const &size,
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);
-
+
}
}