Foundation classes for a basic GUI implementing simple widgets and events
Dependents: TouchScreenGUIDemo
Core/Rectangle.h
- Committer:
- duncanFrance
- Date:
- 2016-05-28
- Revision:
- 18:d849f3ada858
- Parent:
- 13:6714534e7974
File content as of revision 18:d849f3ada858:
#ifndef SIMPLEGUI_RECTANGLE_H #define SIMPLEGUI_RECTANGLE_H #include <algorithm> #include "Point.h" 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; } bool isLocatedAt(Point *p) { return p->x() == x && p->y() == y; } int x, y, width, height; }; #endif