Foundation classes for a basic GUI implementing simple widgets and events
Dependents: TouchScreenGUIDemo
Widgets/Window.cpp
- Committer:
- duncanFrance
- Date:
- 2016-05-21
- Revision:
- 15:e69fd74d42e4
- Parent:
- 12:63db16fea709
- Child:
- 17:5184762fda6c
File content as of revision 15:e69fd74d42e4:
#include "Window.h" Window::Window(GraphicsContext* context) : Widget(context) { } void Window::attach(Widget *widget) { _widgets.append(widget); widget->setParent(this); dirtyAll(); damage(); } void Window::detach(Widget *widget) { widget->clear(); _widgets.remove(widget); widget->setParent(NULL); dirty(); } void Window::dirtyAll() { if(!_dirtying) { _dirtying = true; _dirty(); Widget *w; _widgets.reset(); while((w = _widgets.next()) != NULL) { w->dirtyAll(); } _dirtying = false; } } void Window::_draw() { Widget::_draw(); Widget* w; // Draw only the damaged widgets first LinkedList<Widget> _damaged; _widgets.reset(); while((w = _widgets.next()) != NULL) { if(w->isDamaged()) { _damaged.appendOnce(w); w->adjust(); w->draw(); } } _damaged.reset(); while((w = _damaged.next()) != NULL) { _dirtyIntersected(w); } _damaged.clear(); _widgets.reset(); while((w = _widgets.next()) != NULL) { w->draw(); } } void Window::_dirtyIntersected(Widget *w) { Widget *o; _widgets.reset(); while((o = _widgets.next()) != NULL) { if((o != w) && o->intersects(w)) { o->dirtyAll(); } } }