• Main Page
  • Namespaces
  • Classes
  • Files
  • File List

widget.cpp

Go to the documentation of this file.
00001 #include "widget.h"
00002 #include "event.h"
00003 #include "application.h"
00004 
00005 namespace wit {
00006 
00024 struct WidgetPrivate {
00025     unsigned char hasFocus : 4;
00026     bool autoFocus : 1;
00027 };
00028 
00032 Widget::Widget() : EventHandler(), Hotspot(), Renderer()
00033 {
00034     d = new WidgetPrivate;
00035     d->autoFocus = true;
00036     d->hasFocus = 0;
00037     setEventHandler(this);
00038 }
00039 
00045 bool Widget::autoFocus() const
00046 {
00047     return d->autoFocus;
00048 }
00049 
00059 void Widget::setAutoFocus(bool on)
00060 {
00061     d->autoFocus = on;
00062 }
00063 
00070 bool Widget::hasPointer(int controllerID) const
00071 {
00072     if(controllerID == -1)
00073         return d->hasFocus;
00074     return d->hasFocus & (1 << controllerID);
00075 }
00076 
00083 bool Widget::pointerEvent(PointerEvent* event)
00084 {
00085     unsigned char bit = (1 << event->controllerNumber);
00086     if(d->autoFocus && !(d->hasFocus & bit)) {
00087         d->hasFocus |= bit;
00088         Application::instance()->pushFocus(this, event->controllerNumber);
00089         focusEvent(event);
00090     }
00091     return true;
00092 }
00093 
00101 void Widget::focusEvent(PointerEvent* event)
00102 {
00103     // do nothing
00104     (void)event;
00105 }
00106 
00113 bool Widget::pointerLeaveEvent(PointerLeaveEvent* event)
00114 {
00115     unsigned char bit = (1 << event->controllerNumber);
00116     if(d->autoFocus && (d->hasFocus & bit)) {
00117         d->hasFocus &= ~bit;
00118         Application::instance()->removeFromFocusStack(this, event->controllerNumber);
00119     }
00120     return true;
00121 }
00122 
00123 }

Generated on Sat Sep 3 2011 10:25:00 for wit by  doxygen 1.7.2