Foundation classes for a basic GUI implementing simple widgets and events
Dependents: TouchScreenGUIDemo
Diff: Core/Rectangle.h
- Revision:
- 12:63db16fea709
- Child:
- 13:6714534e7974
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Core/Rectangle.h Sun May 08 14:42:08 2016 +0000 @@ -0,0 +1,43 @@ +#ifndef SIMPLEGUI_RECTANGLE_H +#define SIMPLEGUI_RECTANGLE_H + +#include <algorithm> + +class Rectangle +{ + +public: + + Rectangle(int _x, int _y, int _w, int _h) : + x(_x), y(_y), width(_w), height(_h) {} + + void resize(const Rectangle &outer, int padding) { + x = outer.x+padding; + y = outer.y+padding; + width = outer.width - 2 * padding; + height = outer.height - 2 * padding; + } + + bool contains(int pointX, int pointY) { + return pointX >= x + && pointX <= (x+width) + && pointY >= y + && pointY <= (y+height); + } + + bool intersects(const Rectangle &r) { + int x1 = std::max(x, r.x); + int x2 = std::min(x+width, r.x + r.width); + int y1 = std::max(y, r.y); + int y2 = std::min(y+height, r.y + r.height); + if((x2 < x1) || (y2 < y1)) { + return false; + } + return true; + } + + + int x, y, width, height; +}; + +#endif \ No newline at end of file