Guiliani  Version 2.6 revision 7293 (documentation build 12)
GUIRect.h
1/*
2* Copyright (C) TES Electronic Solutions GmbH,
3* All Rights Reserved.
4* Contact: info@guiliani.de
5*
6* This file is part of the Guiliani HMI framework
7* for the development of graphical user interfaces on embedded systems.
8*/
9
10#ifndef GUIRECT__H_
11#define GUIRECT__H_
12
13#include "GUIPoint.h"
14#include "eC_Math.h"
15
17
63{
64public:
69
74 CGUIRect(const CGUIPoint &kLeftUpperPt, const CGUIPoint &kRightLowerPt);
75
81 CGUIRect(const CGUIPoint &kOriginPt, const eC_Value& vWidth, const eC_Value& vHeight);
82
90 CGUIRect(const eC_Value& vX1, const eC_Value& vY1, const eC_Value& vX2, const eC_Value& vY2);
91
97 eC_Bool IsRightOf(const CGUIRect &Rect) const
98 {
99 return m_vX1 >= Rect.GetX2();
100 }
101
107 eC_Bool IsLeftOf(const CGUIRect &Rect) const
108 {
109 return m_vX2 <= Rect.GetX1();
110 }
111
117 eC_Bool IsTopOf(const CGUIRect &Rect) const
118 {
119 return m_vY2 <= Rect.GetY1();
120 }
121
127 eC_Bool IsBottomOf(const CGUIRect &Rect) const
128 {
129 return m_vY1 >= Rect.GetY2();
130 }
131
133 inline CGUIRect GetOriginRect() const
134 {
135 return CGUIRect(eC_FromInt(0), eC_FromInt(0), GetWidth(), GetHeight());
136 }
137
139 inline CGUIPoint GetCenter() const
140 {
141 return CGUIPoint(
142 m_vX1 + eC_Div(m_vX2 - m_vX1, eC_FromInt(2)),
143 m_vY1 + eC_Div(m_vY2 - m_vY1, eC_FromInt(2)));
144 }
145
147 inline CGUIPoint GetTopLeft() const
148 {
149 return CGUIPoint(m_vX1, m_vY1);
150 }
151
154 {
155 return CGUIPoint(m_vX2, m_vY2);
156 }
157
164 inline eC_Value GetWidth() const
165 {
166 return m_vX2 - m_vX1;
167 }
168
175 inline eC_Value GetHeight() const
176 {
177 return m_vY2 - m_vY1;
178 }
179
183 inline void SetWidth(const eC_Value vWidth)
184 {
185 m_vX2 = m_vX1 + vWidth;
186 }
187
191 inline void SetHeight(const eC_Value vHeight)
192 {
193 m_vY2 = m_vY1 + vHeight;
194 }
195
196 inline eC_Value GetX1() const { return m_vX1; }
197 inline eC_Value GetY1() const { return m_vY1; }
198 inline eC_Value GetX2() const { return m_vX2; }
199 inline eC_Value GetY2() const { return m_vY2; }
200 inline void SetX1(const eC_Value& vX1) { m_vX1 = vX1; }
201 inline void SetY1(const eC_Value& vY1) { m_vY1 = vY1; }
202 inline void SetX2(const eC_Value& vX2) { m_vX2 = vX2; }
203 inline void SetY2(const eC_Value& vY2) { m_vY2 = vY2; }
204
208 inline eC_Bool IsComprehensive() const { return m_bComprehensive; }
209
214 inline void SetComprehensive(const eC_Bool &bComprehensive)
215 {
216 if (!IsNormalised() && bComprehensive)
217 {
218 m_bComprehensive = true;
219 Normalise(); // only normalised rectangles may be comprehensive
220 }
221 else
222 {
223 m_bComprehensive = bComprehensive;
224 }
225 }
226
230 CGUIRect(const CGUIRect &srcRect);
231
236 CGUIRect& operator=(const CGUIRect& srcRect);
237
243 inline eC_Bool operator==(const CGUIRect& rkRect) const
244 {
245 return (m_vX1 == rkRect.GetX1()) &&
246 (m_vY1 == rkRect.GetY1()) &&
247 (m_vX2 == rkRect.GetX2()) &&
248 (m_vY2 == rkRect.GetY2());
249 }
250
256 inline eC_Bool operator!=(const CGUIRect& rkRect) const
257 {
258 return !operator==(rkRect);
259 }
260
269 CGUIRect& Assign(const CGUIPoint &kOriginPt, const eC_Value& vWidth, const eC_Value& vHeight);
270
279 CGUIRect& Assign(const eC_Value& vX1, const eC_Value& vY1, const eC_Value& vX2, const eC_Value& vY2);
280
287 eC_Bool Overlaps(const CGUIRect &Rect) const;
288
304 CGUIRect& Union(const CGUIRect &Rect);
305
316
323 inline eC_Bool IsInside(const eC_Value& vX, const eC_Value& vY) const
324 {
325 if (m_bComprehensive)
326 {
327 return ((vX >= m_vX1) && (vX < m_vX2) && (vY >= m_vY1) && (vY < m_vY2));
328 }
329 else
330 {
331 return false;
332 }
333 }
334
340 inline eC_Bool IsInside(const CGUIPoint &kPt) const
341 {
342 return IsInside(kPt.m_vX, kPt.m_vY);
343 }
344
350 inline eC_Bool IsInside(const CGUIRect &kRect) const
351 {
352 return kRect.IsComprehensive() && IsInside(kRect.GetTopLeft()) && (kRect.GetY2() <= m_vY2) && (kRect.GetX2() <= m_vX2);
353 }
354
357 {
361 };
362
368 inline CGUIRect& Expand(const eC_Value vDif, const ExpandDirection_t enDirection = EXPAND_ALL)
369 {
370 if ((enDirection == EXPAND_ALL) || (enDirection == EXPAND_HORIZONTAL))
371 {
372 m_vX1 = m_vX1 - vDif;
373 m_vX2 = m_vX2 + vDif;
374 }
375
376 if ((enDirection == EXPAND_ALL) || (enDirection == EXPAND_VERTICAL))
377 {
378 m_vY1 = m_vY1 - vDif;
379 m_vY2 = m_vY2 + vDif;
380 }
381
382 if ((vDif < eC_FromInt(0)) && (!IsNormalised()))
383 {
384 // avoid non-normalised state of "this" rectangle,
385 // alternatively we could call Normalise() here but the calculated coordinates make no sense
386 // anyway -> "this" rectangle is now invalid
387 m_bComprehensive = false;
388 }
389 return *this;
390 }
391
396 CGUIRect& Move(const CGUIPoint &kOffsetPt);
397
403 CGUIRect& Move(const eC_Value vDeltaX, const eC_Value vDeltaY);
404
410 CGUIRect& MoveTo(const eC_Value vAbsX, const eC_Value vAbsY);
411
418 inline CGUIRect& Interpolate(const CGUIRect& kTargetRect, const eC_Value vInterpolationFactor)
419 {
420 m_vX1 = m_vX1 + eC_Mul(vInterpolationFactor, (kTargetRect.GetX1() - m_vX1));
421 m_vY1 = m_vY1 + eC_Mul(vInterpolationFactor, (kTargetRect.GetY1() - m_vY1));
422 m_vX2 = m_vX2 + eC_Mul(vInterpolationFactor, (kTargetRect.GetX2() - m_vX2));
423 m_vY2 = m_vY2 + eC_Mul(vInterpolationFactor, (kTargetRect.GetY2() - m_vY2));
424 if (vInterpolationFactor < eC_FromInt(0) && !IsNormalised())
425 {
426 // avoid non-normalised state of "this" rectangle,
427 // alternatively we could call Normalise() here but the calculated coordinates make no sense
428 // anyway -> "this" rectangle is now invalid
429 m_bComprehensive = false;
430 }
431 return *this;
432 }
433
440 void Normalise();
441
442#ifdef GUILIANI_STREAM_GUI
445#endif
446
447#ifdef GUILIANI_WRITE_GUI
450#endif
451
452private:
457 inline eC_Bool IsNormalised() const
458 {
459 //@todo: is a rectangle with width or height of 0 normalized???
460 return !((m_vX1 >= m_vX2) || (m_vY1 >= m_vY2));
461 }
462
463 // Member variables
464 eC_Bool m_bComprehensive;
465 eC_Value m_vX1, m_vY1, m_vX2, m_vY2;
466};
467#endif
CGUIPoint class to hold two values (x, y) like a vector.
Definition: GUIPoint.h:18
eC_Value m_vY
Y-Value.
Definition: GUIPoint.h:55
eC_Value m_vX
X-Value.
Definition: GUIPoint.h:54
Helper class to supply a platform independent rectangle implementation.
Definition: GUIRect.h:63
CGUIRect & Interpolate(const CGUIRect &kTargetRect, const eC_Value vInterpolationFactor)
Definition: GUIRect.h:418
CGUIRect & InterSect(const CGUIRect &Rect)
eC_Value GetY2() const
Definition: GUIRect.h:199
ExpandDirection_t
enum of expansion types
Definition: GUIRect.h:357
@ EXPAND_VERTICAL
vertical only
Definition: GUIRect.h:359
@ EXPAND_HORIZONTAL
horizontal only
Definition: GUIRect.h:358
@ EXPAND_ALL
both horizontal and vertical (default)
Definition: GUIRect.h:360
eC_Bool IsInside(const eC_Value &vX, const eC_Value &vY) const
Definition: GUIRect.h:323
eC_Value GetX2() const
Definition: GUIRect.h:198
CGUIRect & Assign(const eC_Value &vX1, const eC_Value &vY1, const eC_Value &vX2, const eC_Value &vY2)
eC_Bool IsRightOf(const CGUIRect &Rect) const
Definition: GUIRect.h:97
eC_Bool IsTopOf(const CGUIRect &Rect) const
Definition: GUIRect.h:117
eC_Bool IsInside(const CGUIRect &kRect) const
Definition: GUIRect.h:350
eC_Value GetX1() const
Definition: GUIRect.h:196
CGUIRect & MoveTo(const eC_Value vAbsX, const eC_Value vAbsY)
void SetX2(const eC_Value &vX2)
Definition: GUIRect.h:202
CGUIPoint GetBottomRight() const
Definition: GUIRect.h:153
CGUIRect & Expand(const eC_Value vDif, const ExpandDirection_t enDirection=EXPAND_ALL)
Definition: GUIRect.h:368
eC_Value GetY1() const
Definition: GUIRect.h:197
CGUIPoint GetTopLeft() const
Definition: GUIRect.h:147
eC_Bool Overlaps(const CGUIRect &Rect) const
void Normalise()
eC_Bool operator!=(const CGUIRect &rkRect) const
Definition: GUIRect.h:256
eC_Value GetWidth() const
Definition: GUIRect.h:164
void SetComprehensive(const eC_Bool &bComprehensive)
Definition: GUIRect.h:214
CGUIRect(const CGUIRect &srcRect)
void SetHeight(const eC_Value vHeight)
Definition: GUIRect.h:191
CGUIPoint GetCenter() const
Definition: GUIRect.h:139
eC_Bool IsInside(const CGUIPoint &kPt) const
Definition: GUIRect.h:340
void SetX1(const eC_Value &vX1)
Definition: GUIRect.h:200
CGUIRect & Union(const CGUIRect &Rect)
CGUIRect & operator=(const CGUIRect &srcRect)
void SetWidth(const eC_Value vWidth)
Definition: GUIRect.h:183
void SetY1(const eC_Value &vY1)
Definition: GUIRect.h:201
void ReadFromStream()
Helper method to stream CGUIRect attributes.
eC_Bool IsLeftOf(const CGUIRect &Rect) const
Definition: GUIRect.h:107
eC_Bool IsComprehensive() const
Definition: GUIRect.h:208
CGUIRect(const eC_Value &vX1, const eC_Value &vY1, const eC_Value &vX2, const eC_Value &vY2)
CGUIRect GetOriginRect() const
Definition: GUIRect.h:133
void WriteToStream()
Helper method to write CGUIRect attributes.
CGUIRect & Assign(const CGUIPoint &kOriginPt, const eC_Value &vWidth, const eC_Value &vHeight)
eC_Bool operator==(const CGUIRect &rkRect) const
Definition: GUIRect.h:243
eC_Bool IsBottomOf(const CGUIRect &Rect) const
Definition: GUIRect.h:127
CGUIRect(const CGUIPoint &kLeftUpperPt, const CGUIPoint &kRightLowerPt)
CGUIRect & Move(const eC_Value vDeltaX, const eC_Value vDeltaY)
CGUIRect(const CGUIPoint &kOriginPt, const eC_Value &vWidth, const eC_Value &vHeight)
CGUIRect & Move(const CGUIPoint &kOffsetPt)
void SetY2(const eC_Value &vY2)
Definition: GUIRect.h:203
eC_Value GetHeight() const
Definition: GUIRect.h:175