From 02fcd22d8cde355aa898a8c6bb4773d9434b8e9a Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 10 Oct 2008 16:41:38 +0000 Subject: adds KeyPress, DevInfo and Stats widgets --- src/ui/widget.cc | 92 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 32 deletions(-) (limited to 'src/ui/widget.cc') diff --git a/src/ui/widget.cc b/src/ui/widget.cc index 4ff577c..b2c436d 100644 --- a/src/ui/widget.cc +++ b/src/ui/widget.cc @@ -71,6 +71,30 @@ Font const *Widget::font() const { } } +void Widget::lower() +{ + if (!parent()) + return; + + Children::iterator it = parent()->find_child(this); + if (it != parent()->children().end()) { + parent()->children().erase(it); + parent()->children().push_front(this); + } +} + +void Widget::raise() +{ + if (!parent()) + return; + + Children::iterator it = parent()->find_child(this); + if (it != parent()->children().end()) { + parent()->children().erase(it); + parent()->children().push_back(this); + } +} + void Widget::show() { widget_visible = true; @@ -81,6 +105,12 @@ void Widget::hide() widget_visible = false; } + +void Widget::set_visible(bool visible) +{ + widget_visible = visible; +} + void Widget::set_border(bool border) { widget_border = border; @@ -122,6 +152,11 @@ void Widget::set_size(float const w, float const h) widget_size.assign(w, h); } +void Widget::set_size(math::Vector2f const &size) +{ + widget_size.assign(size); +} + void Widget::set_width(float const w) { widget_size.x = w; @@ -159,30 +194,6 @@ void Widget::remove_child(Widget *child) } } -void Widget::raise() -{ - if (!parent()) - return; - - Children::iterator it = find_child(this); - if (it != parent()->children().end()) { - parent()->children().erase(it); - parent()->children().push_front(this); - } -} - -void Widget::lower() -{ - if (!parent()) - return; - - Children::iterator it = find_child(this); - if (it != parent()->children().end()) { - parent()->children().erase(it); - parent()->children().push_back(this); - } -} - void Widget::event_resize() { resize(); @@ -231,7 +242,7 @@ void Widget::draw_border() paint::border(global_location(), size()); } -Widget *Widget::find_focus(math::Vector2f const & pos) +Widget *Widget::event_focus(math::Vector2f const & pos) { // this widget is not visible if (!visible()) @@ -245,7 +256,7 @@ Widget *Widget::find_focus(math::Vector2f const & pos) for (Children::reverse_iterator rit = widget_children.rbegin(); rit != widget_children.rend(); ++rit) { Widget *w = (*rit); if (w->visible()) { - Widget *f = w->find_focus(pos - w->location()); + Widget *f = w->event_focus(pos - w->location()); if (f) return f; } @@ -261,13 +272,30 @@ bool Widget::has_focus() const return (root()->focus() == this); } -void Widget::mousemove(float x, float y) -{} +bool Widget::event_key(bool pressed, unsigned int key, unsigned int modifier) +{ + bool handled; + + if (pressed) { + handled = keypress(key, modifier); + } else { + handled = keyrelease(key, modifier); + } -void Widget::keypress(unsigned int key, unsigned int modifier) -{} + if (!handled && parent()) + handled = parent()->event_key(pressed, key, modifier); -void Widget::keyrelease(unsigned int key, unsigned int modifier) -{} + return handled; +} + +bool Widget::keypress(unsigned int key, unsigned int modifier) +{ + return false; +} + +bool Widget::keyrelease(unsigned int key, unsigned int modifier) +{ + return false; +} } -- cgit v1.2.3