From b492615fb68e5c97fce87bcc946e92f115cfc3a2 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 30 Jul 2011 13:36:45 +0000 Subject: Added support for tiled ui materials, changed default widget backgrounds to use ui materials. --- src/ui/paint.cc | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'src/ui/paint.cc') 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) -- cgit v1.2.3