neoWidgets
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
Rect.h
1 #ifndef NEO_RECT_H
2 #define NEO_RECT_H
3 
4 namespace neo
5 {
6 
10 struct Point : public POINT
11 {
12  Point(LONG px = 0, LONG py = 0)
13  {
14  x = px;
15  y = py;
16  }
17 
18  Point(const POINT& other)
19  {
20  x = other.x;
21  y = other.y;
22  }
23 
24  void operator=(const POINT& other)
25  {
26  x = other.x;
27  y = other.y;
28  }
29 
30  bool operator==(const POINT& other) const
31  {
32  return x == other.x && y == other.y;
33  }
34 
35  Point& ClientToScreen(HWND window)
36  {
37  ::ClientToScreen(window, this);
38  return *this;
39  }
40 
41  Point& ScreenToClient(HWND window)
42  {
43  ::ScreenToClient(window, this);
44  return *this;
45  }
46 
48  Point operator+(const POINT& other)
49  {
50  return Point(x + other.x, y + other.y);
51  }
52 
54  Point operator-(const POINT& other)
55  {
56  return Point(x - other.x, y - other.y);
57  }
58 
60  Point& operator+=(const POINT& other)
61  {
62  x += other.x;
63  y += other.y;
64  return *this;
65  }
66 
68  Point& operator-=(const POINT& other)
69  {
70  x -= other.x;
71  y -= other.y;
72  return *this;
73  }
74 };
75 
79 struct Size : public SIZE
80 {
81  Size(LONG width = 0, LONG height = 0)
82  {
83  cx = width;
84  cy = height;
85  }
86 
87  Size(const SIZE& other)
88  {
89  cx = other.cx;
90  cy = other.cy;
91  }
92 
93  void operator=(const SIZE& other)
94  {
95  cx = other.cx;
96  cy = other.cy;
97  }
98 
99  bool operator==(const SIZE& other) const
100  {
101  return cx == other.cx && cy == other.cy;
102  }
103 };
104 
108 struct Rect : public RECT
109 {
110  Rect()
111  {
112  left = top = right = bottom = 0;
113  }
114 
115  Rect(LONG x, LONG y, LONG width, LONG height)
116  {
117  left = x;
118  top = y;
119  right = left + width;
120  bottom = top + height;
121  }
122 
123  Rect(const POINT& topleft, const SIZE& size)
124  {
125  Set(topleft, size);
126  }
127 
128  Rect(const POINT& topleft, const POINT& bottomright)
129  {
130  Set(topleft, bottomright);
131  }
132 
133  Rect(const RECT& other)
134  {
135  left = other.left;
136  top = other.top;
137  right = other.right;
138  bottom = other.bottom;
139  }
140 
141  void operator=(const RECT& other)
142  {
143  left = other.left;
144  top = other.top;
145  right = other.right;
146  bottom = other.bottom;
147  }
148 
149  void Set(const POINT& topleft, const SIZE& size)
150  {
151  left = topleft.x;
152  top = topleft.y;
153  right = left + size.cx;
154  bottom = top + size.cy;
155  }
156 
157  void Set(const POINT& topleft, const POINT& bottomright)
158  {
159  left = topleft.x;
160  top = topleft.y;
161  right = bottomright.x;
162  bottom = bottomright.y;
163  }
164 
165  bool operator==(const RECT& other) const
166  {
167  return EqualRect(this, &other) != FALSE;
168  }
169 
170  Point TopLeft() const
171  {
172  return Point(left, top);
173  }
174 
175  LONG Width() const
176  {
177  return right - left;
178  }
179 
180  LONG Height() const
181  {
182  return bottom - top;
183  }
184 
185  Size GetSize() const
186  {
187  return Size(Width(), Height());
188  }
189 
190  bool IsEmpty() const
191  {
192  return IsRectEmpty(this) != FALSE;
193  }
194 
195  bool PtInRect(const POINT& p) const
196  {
197  return ::PtInRect(this, p) != FALSE;
198  }
199 
200  Rect& Offset(int dx, int dy)
201  {
202  OffsetRect(this, dx, dy);
203  return *this;
204  }
205 
206  Rect& Inflate(int dx, int dy)
207  {
208  InflateRect(this, dx, dy);
209  return *this;
210  }
211 
212  bool Intersect(const RECT& r1, const RECT& r2)
213  {
214  return IntersectRect(this, &r1, &r2) != FALSE;
215  }
216 
217  Rect Intersect(const RECT& other) const
218  {
219  Rect r;
220  IntersectRect(&r, this, &other);
221  return r;
222  }
223 
224  bool Union(const RECT& r1, const RECT& r2)
225  {
226  return UnionRect(this, &r1, &r2) != FALSE;
227  }
228 
229  Rect Union(const RECT& other) const
230  {
231  Rect r;
232  UnionRect(&r, this, &other);
233  return r;
234  }
235 
236  Rect& ClientToScreen(HWND window)
237  {
238  Set(Point(left, top).ClientToScreen(window), GetSize());
239  return *this;
240  }
241 
242  Rect& ScreenToClient(HWND window)
243  {
244  Set(Point(left, top).ScreenToClient(window), GetSize());
245  return *this;
246  }
247 
249  static Rect DesktopRect()
250  {
251  return Rect(
252  GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_XVIRTUALSCREEN),
253  GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN));
254  }
255 };
256 
257 } // namespace neo
258 
259 #endif
Windows POINT structure with constructor.
Definition: Rect.h:10
Point operator+(const POINT &other)
Definition: Rect.h:48
Point & operator-=(const POINT &other)
Definition: Rect.h:68
Point & operator+=(const POINT &other)
Definition: Rect.h:60
Windows SIZE structure with constructor.
Definition: Rect.h:79
static Rect DesktopRect()
Definition: Rect.h:249
Windows RECT structure with constructor.
Definition: Rect.h:108
Point operator-(const POINT &other)
Definition: Rect.h:54