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>2011-07-30 13:36:45 +0000
committerStijn Buys <ingar@osirion.org>2011-07-30 13:36:45 +0000
commitb492615fb68e5c97fce87bcc946e92f115cfc3a2 (patch)
treeeb90e46894bd351332f64874babc5cef3959a2bd /src/ui/paint.cc
parent3a28abfa64d02b8d530689c425f6ed476a14fe9c (diff)
Added support for tiled ui materials, changed default widget backgrounds to use ui materials.
Diffstat (limited to 'src/ui/paint.cc')
-rw-r--r--src/ui/paint.cc78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/ui/paint.cc b/src/ui/paint.cc
index 1745e1f..c257022 100644
--- a/src/ui/paint.cc
+++ b/src/ui/paint.cc
@@ -94,6 +94,84 @@ void Paint::draw_bitmap(const math::Vector2f &global_location, const math::Vecto
render::State::reset();
}
+// draw a bitmap and override material color
+void Paint::draw_bitmap(const math::Vector2f &global_location, const math::Vector2f &size, const math::Color & color, const std::string &texture)
+{
+ // find the material
+ model::Material *material = model::Material::find(texture);
+ if (!material) {
+ material = new model::Material(texture);
+ model::Material::add(material);
+ material->set_texture(material->name());
+ // ui btimaps are fullbright
+ material->set_flags(model::Material::Bright);
+ }
+
+ render::State::use_material(material);
+
+ // this overrides material color
+ gl::color(color);
+
+ gl::begin(gl::Quads);
+
+ glTexCoord2f(0.0f, 0.0f);
+ gl::vertex(global_location.x(), global_location.y());
+
+ glTexCoord2f(1.0f, 0.0f);
+ gl::vertex(global_location.x() + size.width(), global_location.y());
+
+ glTexCoord2f(1.0f, 1.0f);
+ gl::vertex(global_location.x() + size.width(), global_location.y() + size.height());
+
+ glTexCoord2f(0.0f, 1.0f);
+ gl::vertex(global_location.x(), global_location.y() + size.height());
+
+ gl::end();
+
+ render::State::reset();
+}
+
+void Paint::draw_material(const math::Vector2f &global_location, const math::Vector2f &size, const std::string &texture)
+{
+ // find the material
+ model::Material *material = model::Material::find(texture);
+ if (!material) {
+ material = new model::Material(texture);
+ model::Material::add(material);
+ material->set_texture(material->name());
+ // ui btimaps are fullbright
+ material->set_flags(model::Material::Bright);
+ }
+
+ // use global coordinates
+ const float w0 = global_location.x() / material->size().width();
+ const float h0 = global_location.y() / material->size().height();
+
+ const float w1 = (global_location.x() + size.width()) / material->size().width();
+ const float h1 = (global_location.y() + size.height()) / material->size().height();
+
+ render::State::set_color(math::Color());
+ render::State::set_color_second(math::Color());
+ render::State::use_material(material);
+
+ gl::begin(gl::Quads);
+
+ glTexCoord2f(w0, h0);
+ gl::vertex(global_location.x(), global_location.y());
+
+ glTexCoord2f(w1, h0);
+ gl::vertex(global_location.x() + size.width(), global_location.y());
+
+ glTexCoord2f(w1, h1);
+ gl::vertex(global_location.x() + size.width(), global_location.y() + size.height());
+
+ glTexCoord2f(w0, h1);
+ gl::vertex(global_location.x(), global_location.y() + size.height());
+
+ gl::end();
+
+ render::State::reset();
+}
// draw unaligned text
void Paint::draw_text(const math::Vector2f &global_location, const Font *font, const std::string &text)