diff options
author | Stijn Buys <ingar@osirion.org> | 2008-10-08 18:28:21 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-10-08 18:28:21 +0000 |
commit | 4331f5c17901f46693dcb5c2df96276f6851be25 (patch) | |
tree | 903f70d18c7842121c5409a5ec121e0a565fd5ef /src/ui/paint.cc | |
parent | e3b810e1fe8ced1e0245f8d999bdc9136cfcdc70 (diff) |
libui updates, paint namespace, font and palette fixes, button sound
Diffstat (limited to 'src/ui/paint.cc')
-rw-r--r-- | src/ui/paint.cc | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/ui/paint.cc b/src/ui/paint.cc new file mode 100644 index 0000000..935cf92 --- /dev/null +++ b/src/ui/paint.cc @@ -0,0 +1,98 @@ +/* + ui/paint.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "auxiliary/functions.h" +#include "math/vector2f.h" +#include "render/gl.h" +#include "render/text.h" +#include "render/textures.h" +#include "ui/paint.h" + +namespace ui { + +// contains the interface between the user interface and the render library +namespace paint { + +void color(float r, float g, float b, float a) +{ + render::gl::color(r, g, b, a); +} + +void color(math::Color const & color) +{ + render::gl::color(color); +} + +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); + vertex(location.x + size.x, location.y + size.y -1); + vertex(location.x +1, location.y + size.y - 1); + end(); +} + +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); + vertex(location.x + size.x, location.y + size.y -1); + vertex(location.x +1, location.y + size.y - 1); + end(); +} + +void bitmap(math::Vector2f const &location, math::Vector2f const &size, std::string const &texture) +{ + + using namespace render::gl; + + 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); +} + +} + +} |