Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
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
parent3a28abfa64d02b8d530689c425f6ed476a14fe9c (diff)
Added support for tiled ui materials, changed default widget backgrounds to use ui materials.
Diffstat (limited to 'src')
-rw-r--r--src/client/inventorywindow.cc4
-rw-r--r--src/client/trademenu.cc20
-rw-r--r--src/client/trademenu.h2
-rw-r--r--src/ui/button.cc6
-rw-r--r--src/ui/button.h3
-rw-r--r--src/ui/container.cc7
-rw-r--r--src/ui/container.h1
-rw-r--r--src/ui/iconbutton.cc9
-rw-r--r--src/ui/listitem.cc8
-rw-r--r--src/ui/listview.cc1
-rw-r--r--src/ui/paint.cc78
-rw-r--r--src/ui/paint.h11
-rw-r--r--src/ui/slider.cc3
-rw-r--r--src/ui/ui.cc3
-rw-r--r--src/ui/widget.cc18
-rw-r--r--src/ui/window.cc8
-rw-r--r--src/ui/window.h2
17 files changed, 145 insertions, 39 deletions
diff --git a/src/client/inventorywindow.cc b/src/client/inventorywindow.cc
index 6698565..396c449 100644
--- a/src/client/inventorywindow.cc
+++ b/src/client/inventorywindow.cc
@@ -49,8 +49,8 @@ InventoryWindow::InventoryWindow(ui::Widget *parent) : ui::Window(parent)
inventorywindow_listview = new ui::ListView(this);
inventorywindow_listview->set_label("listview");
- inventorywindow_listview->set_background(false);
- inventorywindow_listview->set_border(true);
+ //inventorywindow_listview->set_background(true);
+ //inventorywindow_listview->set_border(true);
inventorywindow_inventorytext = new ui::PlainText(this);
inventorywindow_inventorytext->set_label("inventorytext");
diff --git a/src/client/trademenu.cc b/src/client/trademenu.cc
index f4a5653..20117c7 100644
--- a/src/client/trademenu.cc
+++ b/src/client/trademenu.cc
@@ -26,7 +26,7 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
else
set_label("trademenu");
- menu_tradewindow = new ui::Widget(this);
+ menu_tradewindow = new ui::Window(this);
menu_tradewindow->set_label("tradewindow");
menu_tradewindow->set_border(true);
menu_tradewindow->set_background(true);
@@ -37,8 +37,8 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
menu_modelview->set_border(false);
menu_slider = new ui::Slider(menu_tradewindow);
- menu_slider->set_background(false);
- menu_slider->set_border(true);
+ //menu_slider->set_background(false);
+ //menu_slider->set_border(true);
menu_msgtext = new ui::Label(menu_tradewindow);
menu_msgtext->set_label("label");
@@ -56,8 +56,8 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
menu_inventorylistview = new InventoryListView(menu_tradewindow);
menu_inventorylistview->set_label("inventorylistview");
- menu_inventorylistview->set_background(false);
- menu_inventorylistview->set_border(true);
+ //menu_inventorylistview->set_background(false);
+ //menu_inventorylistview->set_border(true);
menu_inventorytext = new ui::PlainText(menu_tradewindow);
menu_inventorytext->set_label("inventorytext");
@@ -72,8 +72,8 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
menu_traderlistview = new InventoryListView(menu_tradewindow);
menu_traderlistview->set_label("traderlistview");
- menu_traderlistview->set_background(false);
- menu_traderlistview->set_border(true);
+ //menu_traderlistview->set_background(false);
+ //menu_traderlistview->set_border(true);
menu_traderlistview->set_showempty(true);
menu_tradertext = new ui::PlainText(menu_tradewindow);
@@ -341,7 +341,7 @@ bool TradeMenu::on_emit(Widget *sender, const Event event, void *data)
return true;
}
- return ui::Widget::on_emit(sender, event, data);
+ return ui::Window::on_emit(sender, event, data);
}
void TradeMenu::draw()
@@ -369,7 +369,7 @@ void TradeMenu::draw()
}
menu_inventorytext->set_text(str.str());
- Widget::draw();
+ Window::draw();
}
bool TradeMenu::on_keypress(const int key, const unsigned int modifier)
@@ -385,7 +385,7 @@ bool TradeMenu::on_keypress(const int key, const unsigned int modifier)
break;
}
- return Widget::on_keypress(key, modifier);
+ return Window::on_keypress(key, modifier);
}
} // namespace client
diff --git a/src/client/trademenu.h b/src/client/trademenu.h
index c882287..61609e2 100644
--- a/src/client/trademenu.h
+++ b/src/client/trademenu.h
@@ -49,7 +49,7 @@ protected:
private:
void set_item(ui::ListItem *item);
- ui::Widget *menu_tradewindow;
+ ui::Window *menu_tradewindow;
ui::Label *menu_namelabel;
ui::PlainText *menu_inventorytext;
ui::PlainText *menu_tradertext;
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