diff options
author | Stijn Buys <ingar@osirion.org> | 2010-09-15 21:29:18 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2010-09-15 21:29:18 +0000 |
commit | e55638d081e2e1ff6fbc06e0e8ac0381a04308e7 (patch) | |
tree | 511ccb478adf2acd3cc93f66d217b09f3e3a06dc /src/ui | |
parent | f612f19e095b8d0ba49f5bcdec6a582824315d69 (diff) |
updated comments, updated buy menu, info support for map window, added const to target selection
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/container.cc | 6 | ||||
-rw-r--r-- | src/ui/widget.cc | 19 | ||||
-rw-r--r-- | src/ui/widget.h | 51 |
3 files changed, 60 insertions, 16 deletions
diff --git a/src/ui/container.cc b/src/ui/container.cc index 04e1ec2..31d7549 100644 --- a/src/ui/container.cc +++ b/src/ui/container.cc @@ -45,11 +45,7 @@ void Container::resize() void Container::draw_border() { - if (focus()) { - paint::color(palette()->foreground()); - } else { - paint::color(palette()->border()); - } + paint::color(palette()->foreground()); paint::border(global_location(), size()); } diff --git a/src/ui/widget.cc b/src/ui/widget.cc index 2e2f291..39fbe98 100644 --- a/src/ui/widget.cc +++ b/src/ui/widget.cc @@ -321,7 +321,21 @@ bool Widget::has_input_focus() const /* -- event distributors ------------------------------------------- */ +bool Widget::event_emit(Widget *sender, const Event event, void *data) +// Unhandled events are sent to the parent widget +{ + if (on_emit(sender, event, data)) { + return true; + } else if (parent()) { + return (parent()->on_emit(sender, event, data)); + } else { + return false; + } +} + + bool Widget::event_key(const bool pressed, const int key, const unsigned int modifier) +// Unhandled key events are sent to the parent widget { bool handled = false; @@ -400,6 +414,11 @@ bool Widget::on_keyrelease(const int key, const unsigned int modifier) return false; } +bool Widget::on_emit(Widget *sender, const Event event, void *data) +{ + return false; +} + /* -- draw functions ----------------------------------------------- */ void Widget::draw_debug_border() diff --git a/src/ui/widget.h b/src/ui/widget.h index 1f87695..50678fa 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h @@ -27,6 +27,9 @@ class Widget { public: + /// types of custom events a widget can emit + enum Event {EventNone = 0, EventSelected = 1}; + /// create a new widget Widget(Widget *parent = 0); @@ -196,22 +199,45 @@ public: /// enable or disable widget border void set_border(bool border = true); - ///enable or disable widget background + /// enable or disable widget background void set_background(bool background = true); + + /// emit a custom event + void emit(const Event event, const void *data=0); - /* -- event distributors ----------------------------------- */ + /* -- event distributors --------------------------------------- */ - /// distribute resize event - virtual void event_resize(); - - /// distribute draw event - virtual void event_draw(); + /** + * @brief calls the resize event handler and sends the event to all child widgets + * @see resize + **/ + void event_resize(); + + /** + * @brief calls the draw event handler and sends the event to all child widgets + * @see draw + **/ + void event_draw(); - /// distribute keyboard events - virtual bool event_key(const bool pressed, const int key, const unsigned int modifier); + /** + * @brief calls the key event handlers and sends unhandled keys to the parent widget + * @see on_keypress + * @see on_keyrelease + **/ + bool event_key(const bool pressed, const int key, const unsigned int modifier); - /// distribute mouse movement events - virtual bool event_mouse(const math::Vector2f &cursor); + /** + * @brief calls the mouse event handlers and sends unhandled keys to the parent widget + * @see on_mousemove + * @see on_mouseover + **/ + bool event_mouse(const math::Vector2f &cursor); + + /** + * @brief calls the custom event handler and sends unhandled events to the parent widget + * @see on_event + **/ + bool event_emit(Widget *sender, const Event event, void *data = 0); protected: /// type definition for child widgets @@ -289,6 +315,9 @@ protected: /// called when the widget receives a key release virtual bool on_keyrelease(const int key, const unsigned int modifier); + + /// called when the widget receives a custom event + virtual bool on_emit(Widget *sender, const Event event, void *data=0); /* -- draw functions --------------------------------------- */ |