Foundation classes for a basic GUI implementing simple widgets and events
Dependents: TouchScreenGUIDemo
Diff: Widgets/Window.cpp
- Revision:
- 18:d849f3ada858
- Parent:
- 17:5184762fda6c
--- a/Widgets/Window.cpp Sun May 22 16:35:23 2016 +0000 +++ b/Widgets/Window.cpp Sat May 28 14:50:14 2016 +0000 @@ -1,6 +1,6 @@ #include "Window.h" -Window::Window(GraphicsContext* context) : Widget(context) +Window::Window(GraphicsContext* context) : Widget(context), _childHandledEvents(0) { setSize(context->display()->width(), context->display()->height()); } @@ -9,6 +9,7 @@ { _widgets.append(widget); widget->setParent(this); + _reenumerateEvents(); widget->show(); dirtyAll(); damage(); @@ -20,6 +21,7 @@ widget->hide(); _widgets.remove(widget); widget->setParent(NULL); + _reenumerateEvents(); dirty(); } @@ -74,11 +76,41 @@ void Window::_dirtyIntersected(Widget *w) { Widget *o; - _widgets.reset(); - while((o = _widgets.next()) != NULL) { + LinkedListIterator<Widget> it = _widgets.getIterator(); + while((o = it.next()) != NULL) { if((o != w) && o->intersects(w)) { o->dirtyAll(); } } } +void Window::handleEvent(Event e) { + Widget::handleEvent(e); + // At this point we can do bubbling, cancelling etc. One day + if(_childHandledEvents & e.type) { + LinkedListIterator<Widget> it = _widgets.getIterator(); + Widget *w; + while((w = it.next()) != NULL) { + w->handleEvent(e); + } + } +} + +void Window::_reenumerateHandledEvents() { + + Widget::_reenumerateHandledEvents(); + + _childHandledEvents = 0; + Widget *w; + LinkedListIterator<Widget> wit = _widgets.getIterator(); + while((w = wit.next()) != NULL) { + _childHandledEvents |= w->_getHandledEvents(); + w = _widgets.next(); + } +} + +uint16_t Window::_getHandledEvents() { + uint16_t m = Widget::_getHandledEvents(); + m |= _childHandledEvents; + return m; +}