Test for STM32F4

Dependents:   Nucleo_SSD1331

Fork of RGB_OLED_SSD1331 by Juergen M

Committer:
kkado
Date:
Wed Aug 02 22:12:49 2017 +0000
Revision:
18:47cbbfc890a8
Parent:
15:c49040bf0e1d
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
messi1 15:c49040bf0e1d 1 #ifndef __RECT_H_
messi1 15:c49040bf0e1d 2 #define __RECT_H_
messi1 15:c49040bf0e1d 3
messi1 15:c49040bf0e1d 4 #include "Point.h"
messi1 15:c49040bf0e1d 5
messi1 15:c49040bf0e1d 6 template <class T>
messi1 15:c49040bf0e1d 7 class Rect {
messi1 15:c49040bf0e1d 8
messi1 15:c49040bf0e1d 9 public:
messi1 15:c49040bf0e1d 10 Rect():
messi1 15:c49040bf0e1d 11 _x(0),
messi1 15:c49040bf0e1d 12 _y(0),
messi1 15:c49040bf0e1d 13 _width(0),
messi1 15:c49040bf0e1d 14 _height(0)
messi1 15:c49040bf0e1d 15 {}
messi1 15:c49040bf0e1d 16
messi1 15:c49040bf0e1d 17 Rect(T x, T y, T width, T height):
messi1 15:c49040bf0e1d 18 _x(x),
messi1 15:c49040bf0e1d 19 _y(y),
messi1 15:c49040bf0e1d 20 _width(width),
messi1 15:c49040bf0e1d 21 _height(height)
messi1 15:c49040bf0e1d 22 {}
messi1 15:c49040bf0e1d 23
messi1 15:c49040bf0e1d 24 T x() const {return _x;}
messi1 15:c49040bf0e1d 25 T y() const {return _y;}
messi1 15:c49040bf0e1d 26 void setX(T x){_x = x;}
messi1 15:c49040bf0e1d 27 void setY(T y){_y = y;}
messi1 15:c49040bf0e1d 28
messi1 15:c49040bf0e1d 29 T width() const {return _width;}
messi1 15:c49040bf0e1d 30 T height() const {return _height;}
messi1 15:c49040bf0e1d 31 void setWidth(T w) {_width = w;}
messi1 15:c49040bf0e1d 32 void setHeight(T h) {_height = h;}
messi1 15:c49040bf0e1d 33
messi1 15:c49040bf0e1d 34 Point<T> topLeft() const { return Point<T>(_x, _y); }
messi1 15:c49040bf0e1d 35 Point<T> topRight() const { return Point<T>(_x+_width, _y); }
messi1 15:c49040bf0e1d 36 Point<T> bottomLeft() const { return Point<T>(_x, _y+_height); }
messi1 15:c49040bf0e1d 37 Point<T> bottomRight() const { return Point<T>(_x+_width, _y+_height); }
messi1 15:c49040bf0e1d 38
messi1 15:c49040bf0e1d 39 void moveTo(T x, T y)
messi1 15:c49040bf0e1d 40 {
messi1 15:c49040bf0e1d 41 _x = x;
messi1 15:c49040bf0e1d 42 _y = y;
messi1 15:c49040bf0e1d 43 }
messi1 15:c49040bf0e1d 44
messi1 15:c49040bf0e1d 45 void moveTo( const Point<T> &p)
messi1 15:c49040bf0e1d 46 {
messi1 15:c49040bf0e1d 47 _x = p.x();
messi1 15:c49040bf0e1d 48 _y = p.y();
messi1 15:c49040bf0e1d 49 }
messi1 15:c49040bf0e1d 50
messi1 15:c49040bf0e1d 51 bool isNull() const {return (_x == 0 && _y == 0 && _width == 0 && _height == 0);}
messi1 15:c49040bf0e1d 52
messi1 15:c49040bf0e1d 53 friend inline bool operator==(const Rect &r1, const Rect &r2){return (r1._x==r2._x && r1._width==r2._width && r1._y==r2._y && r1._height==r2._height);}
messi1 15:c49040bf0e1d 54 friend inline bool operator!=(const Rect &r1, const Rect &r2){return (r1._x!=r2._x || r1._width!=r2._width || r1._y!=r2._y || r1._height!=r2._height);}
messi1 15:c49040bf0e1d 55
messi1 15:c49040bf0e1d 56 bool contains(const Point<T> &p) const
messi1 15:c49040bf0e1d 57 {
messi1 15:c49040bf0e1d 58 T l = xp;
messi1 15:c49040bf0e1d 59 T r = xp;
messi1 15:c49040bf0e1d 60 if (w < 0)
messi1 15:c49040bf0e1d 61 l += w;
messi1 15:c49040bf0e1d 62 else
messi1 15:c49040bf0e1d 63 r += w;
messi1 15:c49040bf0e1d 64 if (l == r) // null rect
messi1 15:c49040bf0e1d 65 return false;
messi1 15:c49040bf0e1d 66
messi1 15:c49040bf0e1d 67 if (p.x() < l || p.x() > r)
messi1 15:c49040bf0e1d 68 return false;
messi1 15:c49040bf0e1d 69
messi1 15:c49040bf0e1d 70 T t = yp;
messi1 15:c49040bf0e1d 71 T b = yp;
messi1 15:c49040bf0e1d 72 if (h < 0)
messi1 15:c49040bf0e1d 73 t += h;
messi1 15:c49040bf0e1d 74 else
messi1 15:c49040bf0e1d 75 b += h;
messi1 15:c49040bf0e1d 76 if (t == b) // null rect
messi1 15:c49040bf0e1d 77 return false;
messi1 15:c49040bf0e1d 78
messi1 15:c49040bf0e1d 79 if (p.y() < t || p.y() > b)
messi1 15:c49040bf0e1d 80 return false;
messi1 15:c49040bf0e1d 81
messi1 15:c49040bf0e1d 82 return true;
messi1 15:c49040bf0e1d 83 }
messi1 15:c49040bf0e1d 84
messi1 15:c49040bf0e1d 85 private:
messi1 15:c49040bf0e1d 86 T _x; // Left xpos
messi1 15:c49040bf0e1d 87 T _y; // Top ypos
messi1 15:c49040bf0e1d 88 T _width;
messi1 15:c49040bf0e1d 89 T _height;
messi1 15:c49040bf0e1d 90 };
messi1 15:c49040bf0e1d 91
messi1 15:c49040bf0e1d 92
messi1 15:c49040bf0e1d 93 #endif // __RECT_H_