el h / SimpleGUI

Fork of SimpleGUI by Duncan McIntyre

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Widget.h Source File

Widget.h

00001 #ifndef SIMPLEGUI_WIDGET_H
00002 #define SIMPLEGUI_WIDGET_H
00003 
00004 class Widget;
00005 
00006 #include "GraphicsContext.h"
00007 #include "EventListener.h"
00008 #include "Rectangle.h"
00009 #include "Point.h"
00010 
00011 /**
00012 * A basic widget draws itself in a rectangular area
00013 **/
00014 
00015 class Widget : public EventListener
00016 {
00017 
00018 public:
00019 
00020     Widget(GraphicsContext* context);
00021     
00022     virtual void setParent(Widget* parent);
00023     virtual Widget *getParent();
00024     
00025     /********************************************************
00026     * Methods relating to containment
00027     * In the base class these methods do nothing.
00028     * They are implemented in container classes
00029     ********************************************************/
00030     virtual void attach(Widget *widget) {}
00031     virtual void detach(Widget *widget) {}
00032     
00033     /********************************************************
00034     * Common Widget methods
00035     ********************************************************/    
00036     virtual void setLocation(int x, int y);
00037     virtual void setSize(int width, int height);
00038     virtual void setWidth(int width);
00039     virtual void setHeight(int height);
00040     virtual int x();
00041     virtual int y();
00042     virtual int height();
00043     virtual int width();
00044     
00045     virtual void setOffset(int x, int y);
00046     virtual int offsetX();
00047     virtual int offsetY();
00048     
00049     virtual void setForeground(uint16_t color);
00050     virtual void setBackground(uint16_t color);
00051     
00052     virtual void setPadding(int pixels);
00053     virtual void setBorder(int width, uint16_t colour);    
00054    
00055     /**
00056     * Cause the widget to redraw itself if is is dirty or damaged
00057     **/
00058     virtual void draw();
00059     virtual void clear();
00060     
00061     void show();
00062     void hide();
00063     bool isHidden();
00064     
00065     /**
00066     * Implementation of EventListener
00067     **/
00068     virtual void handleEvent(Event e);
00069     virtual void setEventHandler(EventHandler *handler);
00070     virtual void unsetEventHandler(EventHandler *handler);
00071     
00072     bool intersects(Widget *widget);
00073 
00074     /**
00075     * Mark the widget as needing to be redrawn
00076     **/
00077     void dirty();
00078     bool isDirty();
00079     /**
00080     * Mark the widget and all its children as dirty
00081     **/
00082     virtual void dirtyAll();
00083     
00084     /**
00085     * Mark the widget as having changed dimensions or location
00086     **/
00087     void damage();
00088     bool isDamaged();
00089 
00090     void adjust();
00091 
00092     /**
00093     * Convenience method
00094     **/
00095     GraphicsDisplay *display();
00096     virtual void _reenumerateEvents();
00097     virtual void _reenumerateHandledEvents();
00098     virtual uint16_t _getHandledEvents();
00099     
00100 protected:
00101 
00102     virtual void _draw();
00103     virtual void _clear();
00104     
00105     virtual void _dirty();
00106     virtual void _damage();
00107     virtual void _adjust();
00108     
00109     /**
00110     * Methods to help with event handling
00111     **/
00112     bool _isEventTarget(Event e);
00113     
00114     uint16_t _handledEvents;
00115     
00116     Widget* _parent;
00117     GraphicsContext* _context;
00118     uint16_t _fg, _bg;
00119     
00120     Point _offset;
00121     Rectangle _outer;
00122     Rectangle _inner;
00123     
00124     bool _hidden;
00125     int _padding;
00126     int _borderWidth;
00127     uint16_t _borderColour;
00128 
00129     bool _adjusting;
00130 
00131     bool _dirtied;
00132     bool _dirtying;
00133 
00134     bool _damaged;
00135     bool _damaging;
00136     
00137     LinkedList<EventHandler> _handlers;
00138 };
00139 
00140 #endif