diff options
author | Stijn Buys <ingar@osirion.org> | 2012-01-29 13:51:31 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2012-01-29 13:51:31 +0000 |
commit | 398f3df8af02047a76ab7172c69d93313250260c (patch) | |
tree | 0a4925510726d74b23d84115c56de0ca4042643e | |
parent | f320ee25c74b6f24db58d97c0129de6e94db3345 (diff) |
FS#80 Have mouse focus stick to the widget when the mouse button is down.
-rw-r--r-- | src/ui/ui.cc | 15 | ||||
-rw-r--r-- | src/ui/ui.h | 1 | ||||
-rw-r--r-- | src/ui/widget.cc | 18 | ||||
-rw-r--r-- | src/ui/widget.h | 10 | ||||
-rw-r--r-- | src/ui/window.cc | 2 |
5 files changed, 40 insertions, 6 deletions
diff --git a/src/ui/ui.cc b/src/ui/ui.cc index 4977d03..e10d77a 100644 --- a/src/ui/ui.cc +++ b/src/ui/ui.cc @@ -87,6 +87,8 @@ UI::UI() : Window(0) mouse_pointer_color = Palette::Pointer; mouse_pointer_bitmap.assign("pointer"); + + mouse_buttonleft_pressed = false; } UI::~UI() @@ -249,12 +251,18 @@ void UI::list_visible() const void UI::frame() { ui_input_focus = find_input_focus(); - Widget *f = find_mouse_focus(mouse_cursor); + + Widget *f = 0; + if (!mouse_buttonleft_pressed) { + f = find_mouse_focus(mouse_cursor); + } else { + f = find_visible_child(ui_mouse_focus); + } if (f) { f->event_mouse(mouse_cursor); } ui_mouse_focus = f; - + // reset mouse pointer ui::root()->set_pointer("pointer"); @@ -288,6 +296,9 @@ bool UI::input_key(const bool pressed, const int key, const unsigned int modifie ui_input_focus = f; } else if (key < 564) { + if ( key == 512 + SDL_BUTTON_LEFT) { + mouse_buttonleft_pressed = pressed; + } // mouse buttons Widget *f = find_mouse_focus(mouse_cursor); if (f) { diff --git a/src/ui/ui.h b/src/ui/ui.h index cd2e38c..77b04f5 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -117,6 +117,7 @@ private: std::string mouse_pointer_bitmap; Palette::Color mouse_pointer_color; bool mouse_pointer_animated; + bool mouse_buttonleft_pressed; }; /// initialize the user interface diff --git a/src/ui/widget.cc b/src/ui/widget.cc index 6d0fb84..7cde03b 100644 --- a/src/ui/widget.cc +++ b/src/ui/widget.cc @@ -366,6 +366,24 @@ Widget *Widget::find_input_focus() return this; } +Widget *Widget::find_visible_child(const Widget *widget) +{ + if (!visible()) + return 0; + + if (this == widget) + return this; + + // search in reverse drawing order + for (Children::reverse_iterator rit = widget_children.rbegin(); rit != widget_children.rend(); ++rit) { + Widget *f = (*rit)->find_visible_child(widget); + if (f) { + return f; + } + } + return 0; +} + Widget *Widget::find_mouse_focus(const math::Vector2f & pos) { // this widget is not visible diff --git a/src/ui/widget.h b/src/ui/widget.h index 77a84c2..ada1f5b 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h @@ -38,8 +38,9 @@ public: EventListItemClicked = 2, EventListViewChanged = 3, EventSliderChanged = 4, - EventWindowShow = 5, - EventWindowHide = 6 + EventScrollBarChanged = 5, + EventWindowShow = 6, + EventWindowHide = 7 }; /// create a new widget @@ -287,7 +288,7 @@ public: } protected: - + /// find the widget that has input focus virtual Widget *find_input_focus(); @@ -295,6 +296,9 @@ protected: /** @param cursor mouse cursor position relative to this widget's location */ Widget *find_mouse_focus(const math::Vector2f & cursor); + + /// find a visible widget + Widget *find_visible_child(const Widget *widget); /// list widget content size_t list(const size_t indent, const bool visible_only = false) const; diff --git a/src/ui/window.cc b/src/ui/window.cc index 97792bc..325f974 100644 --- a/src/ui/window.cc +++ b/src/ui/window.cc @@ -25,7 +25,7 @@ Window::~Window() void Window::show() { - resize(); + event_resize(); Widget::show(); //raise(); Widget *w = this; |