Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-09-18 18:50:55 +0000
committerStijn Buys <ingar@osirion.org>2010-09-18 18:50:55 +0000
commit9c91a9767b570fdc3c3e19e1f452f9a8257f9999 (patch)
tree9ac10114a3378134ea19dac3d7f7639532c3bf5a /src/ui
parentfc4809e41bc5694231046eb2fd4c324c4daba13f (diff)
trade updates
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/listitem.cc18
-rw-r--r--src/ui/listitem.h8
-rw-r--r--src/ui/listview.cc22
-rw-r--r--src/ui/listview.h24
-rw-r--r--src/ui/widget.h6
5 files changed, 72 insertions, 6 deletions
diff --git a/src/ui/listitem.cc b/src/ui/listitem.cc
index 3ff108f..dcd4e2a 100644
--- a/src/ui/listitem.cc
+++ b/src/ui/listitem.cc
@@ -22,8 +22,6 @@ ListItem::~ListItem() {
void ListItem::draw_border()
{
- // FIXME glow if selected, not on_mouseover
-
if (has_mouse_focus()) {
math::Color color(palette()->foreground());
float t = core::application()->time();
@@ -33,7 +31,23 @@ void ListItem::draw_border()
color.a = 0.5f + t;
paint::color(color);
paint::border(global_location(), size());
+ } else if ((static_cast<ListView *>(parent()))->selected() == this) {
+ paint::color(palette()->border());
+ paint::border(global_location(), size());
+ }
+}
+
+void ListItem::draw()
+{
+ if (!text().size())
+ return;
+
+ if ( has_mouse_focus() || ((static_cast<ListView *>(parent()))->selected() == this)) {
+ paint::color(palette()->highlight());
+ } else {
+ paint::color(palette()->foreground());
}
+ paint::label(global_location(), size(), font(), text(), alignment());
}
bool ListItem::on_keypress(const int key, const unsigned int modifier)
diff --git a/src/ui/listitem.h b/src/ui/listitem.h
index a107ed5..cc03621 100644
--- a/src/ui/listitem.h
+++ b/src/ui/listitem.h
@@ -11,6 +11,12 @@
#include "core/info.h"
#include "ui/label.h"
+
+namespace ui
+{
+class ListItem;
+}
+
#include "ui/listview.h"
namespace ui
@@ -34,6 +40,8 @@ protected:
/// draw the button border
virtual void draw_border();
+
+ virtual void draw();
private:
const core::Info *listitem_info;
diff --git a/src/ui/listview.cc b/src/ui/listview.cc
index da320c5..646b168 100644
--- a/src/ui/listview.cc
+++ b/src/ui/listview.cc
@@ -15,6 +15,7 @@ ListView::ListView(Widget *parent) : Widget(parent)
set_border(true);
listview_scroll = 0.0f;
+ listview_selecteditem = 0;
}
ListView::~ListView()
@@ -66,5 +67,26 @@ void ListView::resize()
content_top += (*it)->height();
}
}
+
+void ListView::deselect()
+{
+ listview_selecteditem = 0;
+}
+
+void ListView::clear()
+{
+ listview_selecteditem = 0;
+ remove_children();
+}
+
+bool ListView::on_emit(Widget *sender, const Event event, void *data)
+{
+ if ((sender->parent() == this) && (event == Widget::EventListItemClicked)) {
+ listview_selecteditem = static_cast<ListItem *>(sender);
+ return false; // return false because parent widgets might want to handle this event
+ }
+ return ui::Widget::on_emit(sender, event, data);
+}
+
}
diff --git a/src/ui/listview.h b/src/ui/listview.h
index 25fd07c..a650348 100644
--- a/src/ui/listview.h
+++ b/src/ui/listview.h
@@ -12,6 +12,13 @@
namespace ui
{
+class ListView;
+}
+
+#include "ui/listitem.h"
+
+namespace ui
+{
/**
* @brief a list of selectable items
@@ -27,6 +34,11 @@ public:
return listview_scroll;
}
+ /// return last selected listitem
+ inline ListItem *selected() const {
+ return listview_selecteditem;
+ }
+
/* -- mutators --------------------------------------------- */
/// set scroll
@@ -38,11 +50,21 @@ public:
/// scroll up
void dec_scroll(float scroll);
+ /// clear all listitems
+ void clear();
+
+ /// set selection to nothing
+ void deselect();
+
protected:
virtual void resize();
+ /// emit event handler
+ virtual bool on_emit(Widget *sender, const Event event, void *data);
+
private:
- float listview_scroll;
+ float listview_scroll;
+ ListItem *listview_selecteditem;
};
} // namespacd ui
diff --git a/src/ui/widget.h b/src/ui/widget.h
index 856fca0..880b71c 100644
--- a/src/ui/widget.h
+++ b/src/ui/widget.h
@@ -241,9 +241,6 @@ public:
event_emit(this, event, data);
}
- /// remove all child widgets
- virtual void remove_children();
-
protected:
/// type definition for child widgets
typedef std::list<Widget *> Children;
@@ -343,6 +340,9 @@ protected:
/// remove a child widget
virtual void remove_child(Widget *child);
+
+ /// remove all child widgets
+ virtual void remove_children();
private:
void draw_debug_border();