Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SimpleGUI by
Core/Rectangle.h@13:6714534e7974, 2016-05-21 (annotated)
- Committer:
- duncanFrance
- Date:
- Sat May 21 14:40:09 2016 +0000
- Revision:
- 13:6714534e7974
- Parent:
- 12:63db16fea709
Cleaned up SpinnerWidget; Started on SpinnerDialog - will extract Dialog later
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| duncanFrance | 12:63db16fea709 | 1 | #ifndef SIMPLEGUI_RECTANGLE_H |
| duncanFrance | 12:63db16fea709 | 2 | #define SIMPLEGUI_RECTANGLE_H |
| duncanFrance | 12:63db16fea709 | 3 | |
| duncanFrance | 12:63db16fea709 | 4 | #include <algorithm> |
| duncanFrance | 13:6714534e7974 | 5 | #include "Point.h" |
| duncanFrance | 12:63db16fea709 | 6 | |
| duncanFrance | 12:63db16fea709 | 7 | class Rectangle |
| duncanFrance | 12:63db16fea709 | 8 | { |
| duncanFrance | 12:63db16fea709 | 9 | |
| duncanFrance | 12:63db16fea709 | 10 | public: |
| duncanFrance | 12:63db16fea709 | 11 | |
| duncanFrance | 12:63db16fea709 | 12 | Rectangle(int _x, int _y, int _w, int _h) : |
| duncanFrance | 12:63db16fea709 | 13 | x(_x), y(_y), width(_w), height(_h) {} |
| duncanFrance | 12:63db16fea709 | 14 | |
| duncanFrance | 12:63db16fea709 | 15 | void resize(const Rectangle &outer, int padding) { |
| duncanFrance | 12:63db16fea709 | 16 | x = outer.x+padding; |
| duncanFrance | 12:63db16fea709 | 17 | y = outer.y+padding; |
| duncanFrance | 12:63db16fea709 | 18 | width = outer.width - 2 * padding; |
| duncanFrance | 12:63db16fea709 | 19 | height = outer.height - 2 * padding; |
| duncanFrance | 12:63db16fea709 | 20 | } |
| duncanFrance | 12:63db16fea709 | 21 | |
| duncanFrance | 12:63db16fea709 | 22 | bool contains(int pointX, int pointY) { |
| duncanFrance | 12:63db16fea709 | 23 | return pointX >= x |
| duncanFrance | 12:63db16fea709 | 24 | && pointX <= (x+width) |
| duncanFrance | 12:63db16fea709 | 25 | && pointY >= y |
| duncanFrance | 12:63db16fea709 | 26 | && pointY <= (y+height); |
| duncanFrance | 12:63db16fea709 | 27 | } |
| duncanFrance | 12:63db16fea709 | 28 | |
| duncanFrance | 12:63db16fea709 | 29 | bool intersects(const Rectangle &r) { |
| duncanFrance | 12:63db16fea709 | 30 | int x1 = std::max(x, r.x); |
| duncanFrance | 12:63db16fea709 | 31 | int x2 = std::min(x+width, r.x + r.width); |
| duncanFrance | 12:63db16fea709 | 32 | int y1 = std::max(y, r.y); |
| duncanFrance | 12:63db16fea709 | 33 | int y2 = std::min(y+height, r.y + r.height); |
| duncanFrance | 12:63db16fea709 | 34 | if((x2 < x1) || (y2 < y1)) { |
| duncanFrance | 12:63db16fea709 | 35 | return false; |
| duncanFrance | 12:63db16fea709 | 36 | } |
| duncanFrance | 12:63db16fea709 | 37 | return true; |
| duncanFrance | 12:63db16fea709 | 38 | } |
| duncanFrance | 13:6714534e7974 | 39 | |
| duncanFrance | 13:6714534e7974 | 40 | bool isLocatedAt(Point *p) { |
| duncanFrance | 13:6714534e7974 | 41 | return p->x() == x && p->y() == y; |
| duncanFrance | 13:6714534e7974 | 42 | } |
| duncanFrance | 12:63db16fea709 | 43 | |
| duncanFrance | 12:63db16fea709 | 44 | int x, y, width, height; |
| duncanFrance | 12:63db16fea709 | 45 | }; |
| duncanFrance | 12:63db16fea709 | 46 | |
| duncanFrance | 12:63db16fea709 | 47 | #endif |
