diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/button.cc | 6 | ||||
-rw-r--r-- | src/ui/button.h | 3 | ||||
-rw-r--r-- | src/ui/container.cc | 7 | ||||
-rw-r--r-- | src/ui/container.h | 1 | ||||
-rw-r--r-- | src/ui/iconbutton.cc | 9 | ||||
-rw-r--r-- | src/ui/listitem.cc | 8 | ||||
-rw-r--r-- | src/ui/listview.cc | 1 | ||||
-rw-r--r-- | src/ui/paint.cc | 78 | ||||
-rw-r--r-- | src/ui/paint.h | 11 | ||||
-rw-r--r-- | src/ui/slider.cc | 3 | ||||
-rw-r--r-- | src/ui/ui.cc | 3 | ||||
-rw-r--r-- | src/ui/widget.cc | 18 | ||||
-rw-r--r-- | src/ui/window.cc | 8 | ||||
-rw-r--r-- | src/ui/window.h | 2 |
14 files changed, 132 insertions, 26 deletions
diff --git a/src/ui/button.cc b/src/ui/button.cc index 9e07c09..cba7732 100644 --- a/src/ui/button.cc +++ b/src/ui/button.cc @@ -22,6 +22,7 @@ Button::Button(Widget *parent, const char *text, const char *command) : Label(pa set_label("button"); set_command(command); set_alignment(AlignCenter); + set_background(true); } Button::~Button() @@ -47,6 +48,11 @@ void Button::set_command(const std::string &command) button_command.assign(command); } +void Button::draw_background() +{ + Paint::draw_material(global_location(), size(), "ui/button"); +} + void Button::draw_border() { if (disabled()) { diff --git a/src/ui/button.h b/src/ui/button.h index a0aac72..7d264a9 100644 --- a/src/ui/button.h +++ b/src/ui/button.h @@ -43,6 +43,9 @@ public: virtual bool on_keyrelease(const int key, const unsigned int modifier); protected: + /// draw the button background + virtual void draw_background(); + /// draw the button border virtual void draw_border(); diff --git a/src/ui/container.cc b/src/ui/container.cc index d252c73..ebe2821 100644 --- a/src/ui/container.cc +++ b/src/ui/container.cc @@ -42,11 +42,4 @@ void Container::resize() } } - -void Container::draw_border() -{ - Paint::set_color(palette()->foreground()); - Paint::draw_border(global_location(), size()); -} - } diff --git a/src/ui/container.h b/src/ui/container.h index 08ed443..4dbf150 100644 --- a/src/ui/container.h +++ b/src/ui/container.h @@ -22,7 +22,6 @@ public: ~Container(); protected: - virtual void draw_border(); virtual void resize(); }; diff --git a/src/ui/iconbutton.cc b/src/ui/iconbutton.cc index 83c7aa7..22a7c14 100644 --- a/src/ui/iconbutton.cc +++ b/src/ui/iconbutton.cc @@ -70,18 +70,19 @@ void IconButton::set_icon(const std::string &icon) void IconButton::draw() { + math::Color color; if (!icon().size()) return; if (disabled()) { - Paint::set_color(palette()->disabled()); + color.assign(palette()->disabled()); } else if (highlight() || has_mouse_focus()) { - Paint::set_color(palette()->highlight()); + color.assign(palette()->highlight()); } else { - Paint::set_color(palette()->foreground()); + color.assign(palette()->foreground()); } - Paint::draw_bitmap(global_location(), size(), icon()); + Paint::draw_bitmap(global_location(), size(), color, icon()); } void IconButton::draw_border() diff --git a/src/ui/listitem.cc b/src/ui/listitem.cc index c5cee32..5e58560 100644 --- a/src/ui/listitem.cc +++ b/src/ui/listitem.cc @@ -43,10 +43,12 @@ void ListItem::draw() if (!text().size()) return; - if (disabled()) { - Paint::set_color(palette()->disabled()); - } else if (has_mouse_focus() || ((static_cast<ListView *>(parent()))->selected() == this)) { + if (has_mouse_focus() || ((static_cast<ListView *>(parent()))->selected() == this)) { Paint::set_color(palette()->highlight()); + + } else if (disabled()) { + Paint::set_color(palette()->disabled()); + } else { Paint::set_color(palette()->foreground()); } diff --git a/src/ui/listview.cc b/src/ui/listview.cc index 32d86dd..5601bd7 100644 --- a/src/ui/listview.cc +++ b/src/ui/listview.cc @@ -13,6 +13,7 @@ ListView::ListView(Widget *parent) : Widget(parent) { set_label("listview"); set_border(true); + set_background(true); listview_scroll = 0.0f; listview_selecteditem = 0; 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) diff --git a/src/ui/paint.h b/src/ui/paint.h index 2c48a35..d21aaa0 100644 --- a/src/ui/paint.h +++ b/src/ui/paint.h @@ -37,8 +37,17 @@ public: /// draw a rectangle static void draw_rectangle(const math::Vector2f &global_location, const math::Vector2f &size); - /// draw a rectangular bitmap + /** + * @brief draw a rectangular bitmap + * @param texture the name of material to be used + **/ static void draw_bitmap(const math::Vector2f &global_location, const math::Vector2f &size, const std::string &texture); + + /// draw a rectangular bitmap and overrride material color + static void draw_bitmap(const math::Vector2f &global_location, const math::Vector2f &size, const math::Color & color, const std::string &texture); + + /// draw a tiled bitmap + static void draw_material(const math::Vector2f &global_location, const math::Vector2f &size, const std::string &texture); /// draw unaligned text static void draw_text(const math::Vector2f &global_location, const Font *font, const std::string &text); diff --git a/src/ui/slider.cc b/src/ui/slider.cc index 0abd109..24e59f5 100644 --- a/src/ui/slider.cc +++ b/src/ui/slider.cc @@ -30,6 +30,9 @@ Slider::Slider(Widget *parent, const float minimum, const float maximum) : Widge slider_maxbutton = new ui::Button(this, ">>"); slider_maxbutton->set_border(false); + set_background(true); + set_border(true); + validate(); } diff --git a/src/ui/ui.cc b/src/ui/ui.cc index b162394..252faa6 100644 --- a/src/ui/ui.cc +++ b/src/ui/ui.cc @@ -568,7 +568,6 @@ void UI::draw_pointer() } else { c.a = 0.5f; } - Paint::set_color(c); math::Vector2f pos(mouse_cursor.x() - pointer_size * 0.5f, mouse_cursor.y() - pointer_size * 0.5f); math::Vector2f s(pointer_size, pointer_size); @@ -586,7 +585,7 @@ void UI::draw_pointer() gl::translate(-mouse_cursor.x(), -mouse_cursor.y(), 0); } - Paint::draw_bitmap(pos, s, texture); + Paint::draw_bitmap(pos, s, c, texture); if (mouse_pointer_animated) { gl::pop(); diff --git a/src/ui/widget.cc b/src/ui/widget.cc index de18e6b..540fd6c 100644 --- a/src/ui/widget.cc +++ b/src/ui/widget.cc @@ -407,16 +407,19 @@ void Widget::event_draw() if (widget_background) draw_background(); - if (widget_border) - draw_border(); - if (debug()) - draw_debug(); - draw(); for (Children::iterator it = widget_children.begin(); it != widget_children.end(); it++) { if ((*it)->visible()) (*it)->event_draw(); } + + if (widget_border) + draw_border(); + + if (debug()) + draw_debug(); + + draw(); } void Widget::event_resize() @@ -465,8 +468,9 @@ void Widget::draw_debug() void Widget::draw_background() { - Paint::set_color(palette()->background()); - Paint::draw_rectangle(global_location(), size()); + //Paint::set_color(palette()->background()); + //Paint::draw_rectangle(global_location(), size()); + Paint::draw_material(global_location(), size(), "ui/background"); } void Widget::draw_border() diff --git a/src/ui/window.cc b/src/ui/window.cc index e7b756a..b687f21 100644 --- a/src/ui/window.cc +++ b/src/ui/window.cc @@ -52,10 +52,16 @@ void Window::clear_previous() window_previous.clear(); } +void Window::draw_background() +{ + Paint::draw_material(global_location(), size(), "ui/window"); +} + void Window::draw_border() { - Paint::set_color(palette()->border()); + Paint::set_color(palette()->foreground()); Paint::draw_border(global_location(), size()); + } } diff --git a/src/ui/window.h b/src/ui/window.h index 401c370..2c962a9 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -47,6 +47,8 @@ public: } protected: + virtual void draw_background(); + virtual void draw_border(); // FIXME should be removed |