Foundation classes for a basic GUI implementing simple widgets and events
Dependents: TouchScreenGUIDemo
Widgets/Widget.h
- Committer:
- duncanFrance
- Date:
- 2016-04-10
- Revision:
- 7:303850a4b30c
- Parent:
- 5:b7ce5721a0b5
- Child:
- 8:a460cabc85ac
File content as of revision 7:303850a4b30c:
#ifndef SIMPLEGUI_WIDGET_H #define SIMPLEGUI_WIDGET_H #include "EventListener.h" #include "GraphicsDisplay.h" /** * A basic widget draws itself in a rectangular area **/ class Widget : public EventListener { public: Widget(GraphicsDisplay& display) : _display(display), _fg(White), _bg(Black), _x(0), _y(0), _width(0), _height(0) {} virtual bool isEventTarget(Event e) { return e.screenX >= _x && e.screenX <= (_x+_width) && e.screenY >= _y && e.screenY <= (_y+_height); } virtual void setLocation(int x, int y) { _x = x; _y = y; } virtual void setSize(int width, int height) { _width = width; _height = height; } virtual int x() { return _x; } virtual int y() { return _y; } virtual int height() { return _height; } virtual int width() { return _width; } virtual void setForeground(uint16_t color) { _fg = color; } virtual void setBackground(uint16_t color) { _bg = color; } virtual void draw() = 0; void setHidden(bool hidden) { _hidden = hidden; } bool isHidden() { return _hidden; } protected: GraphicsDisplay& _display; uint16_t _fg, _bg; int _x,_y,_width,_height; bool _hidden; }; #endif