Foundation classes for a basic GUI implementing simple widgets and events
Dependents: TouchScreenGUIDemo
Core/Rectangle.h
- Committer:
- duncanFrance
- Date:
- 2016-05-08
- Revision:
- 12:63db16fea709
- Child:
- 13:6714534e7974
File content as of revision 12:63db16fea709:
#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