Helper class to supply a platform independent rectangle implementation. More...
#include <GUIRect.h>
Public Types | |
enum | ExpandDirection_t { EXPAND_HORIZONTAL , EXPAND_VERTICAL , EXPAND_ALL } |
enum of expansion types More... | |
Public Member Functions | |
CGUIRect () | |
CGUIRect (const CGUIPoint &kLeftUpperPt, const CGUIPoint &kRightLowerPt) | |
CGUIRect (const CGUIPoint &kOriginPt, const eC_Value &vWidth, const eC_Value &vHeight) | |
CGUIRect (const CGUIRect &srcRect) | |
CGUIRect (const eC_Value &vX1, const eC_Value &vY1, const eC_Value &vX2, const eC_Value &vY2) | |
CGUIRect & | Assign (const CGUIPoint &kOriginPt, const eC_Value &vWidth, const eC_Value &vHeight) |
CGUIRect & | Assign (const eC_Value &vX1, const eC_Value &vY1, const eC_Value &vX2, const eC_Value &vY2) |
CGUIRect & | Expand (const eC_Value vDif, const ExpandDirection_t enDirection=EXPAND_ALL) |
CGUIPoint | GetBottomRight () const |
CGUIPoint | GetCenter () const |
eC_Value | GetHeight () const |
CGUIRect | GetOriginRect () const |
CGUIPoint | GetTopLeft () const |
eC_Value | GetWidth () const |
eC_Value | GetX1 () const |
eC_Value | GetX2 () const |
eC_Value | GetY1 () const |
eC_Value | GetY2 () const |
CGUIRect & | Interpolate (const CGUIRect &kTargetRect, const eC_Value vInterpolationFactor) |
CGUIRect & | InterSect (const CGUIRect &Rect) |
eC_Bool | IsBottomOf (const CGUIRect &Rect) const |
eC_Bool | IsComprehensive () const |
eC_Bool | IsInside (const CGUIPoint &kPt) const |
eC_Bool | IsInside (const CGUIRect &kRect) const |
eC_Bool | IsInside (const eC_Value &vX, const eC_Value &vY) const |
eC_Bool | IsLeftOf (const CGUIRect &Rect) const |
eC_Bool | IsRightOf (const CGUIRect &Rect) const |
eC_Bool | IsTopOf (const CGUIRect &Rect) const |
CGUIRect & | Move (const CGUIPoint &kOffsetPt) |
CGUIRect & | Move (const eC_Value vDeltaX, const eC_Value vDeltaY) |
CGUIRect & | MoveTo (const eC_Value vAbsX, const eC_Value vAbsY) |
void | Normalise () |
eC_Bool | operator!= (const CGUIRect &rkRect) const |
CGUIRect & | operator= (const CGUIRect &srcRect) |
eC_Bool | operator== (const CGUIRect &rkRect) const |
eC_Bool | Overlaps (const CGUIRect &Rect) const |
void | ReadFromStream () |
Helper method to stream CGUIRect attributes. | |
void | SetComprehensive (const eC_Bool &bComprehensive) |
void | SetHeight (const eC_Value vHeight) |
void | SetWidth (const eC_Value vWidth) |
void | SetX1 (const eC_Value &vX1) |
void | SetX2 (const eC_Value &vX2) |
void | SetY1 (const eC_Value &vY1) |
void | SetY2 (const eC_Value &vY2) |
CGUIRect & | Union (const CGUIRect &Rect) |
void | WriteToStream () |
Helper method to write CGUIRect attributes. | |
Helper class to supply a platform independent rectangle implementation.
The CGUIRect class implements basic geometry-handling for rectangles, including functionalities such as intersection or checks for overlaps. Please note that the lower right corner of a rectangle is not considered to be "inside" of the rectangle itself. In other words, a rectangle reaching from positions (0,0) to (10,0) will have a height of zero and therefore be considered "not normalized".
If a rectangle is incomprehensive this means that it has no valid coordinates. When a rectangle is copied the comprehensive flag is always copied too. After a rectangle is created it will always be comprehensive until it is explicitly changed by m_bComprehensive = false; No function that accepts separate coordinate values will automatically normalise them internally in this class.
Speaking of normalised coordinates here means, that the X-coordinate of the top left corner is smaller than the X-coordinate of the bottom right corner AND the Y-coordinate of the top left corner is smaller than the Y-coordinate of the bottom right corner.
Whenever the coordinates of a rectangle get non-normalised then the rectangle will in turn get incomprehensive, that is, no comprehensive rectangle may be non-normalised. Incomprehensive rectangles on the other hand may have normalised or non-normalised coordinates as the coordinates are invalid anyway. No function will make an incomprehensive rectangle to be comprehensive, except when forcing this via SetComprehensive(true) or assignment or construction. Thus, no function of this class that does not alter the coordinates, needs to check whether the coordinates are normalised; for these functions it is sufficient to check for comprehensiveness.
Example:
CGUIRect::CGUIRect | ( | ) |
Standard constructor. Initializes all coordinates with 0. The rectangle will be incomprehensive as the rectangle that covers zero space is invalid.
Constructor
kLeftUpperPt | left upper point |
kRightLowerPt | right lower point |
CGUIRect::CGUIRect | ( | const CGUIPoint & | kOriginPt, |
const eC_Value & | vWidth, | ||
const eC_Value & | vHeight | ||
) |
Constructor
kOriginPt | origin point |
vWidth | width |
vHeight | height |
CGUIRect::CGUIRect | ( | const eC_Value & | vX1, |
const eC_Value & | vY1, | ||
const eC_Value & | vX2, | ||
const eC_Value & | vY2 | ||
) |
Constructs a rectangle from four coordinates. The rectangle will be comprehensive if the covered space is not zero.
vX1 | X-coordinate of the top left corner |
vY1 | Y-coordinate of the top left corner |
vX2 | X-coordinate of the bottom right corner |
vY2 | Y-coordinate of the bottom right corner |
CGUIRect::CGUIRect | ( | const CGUIRect & | srcRect | ) |
Constructs a rectangle from another rectangle / copy constructor.
srcRect | Rectangle from which a duplicate will be created. |
CGUIRect & CGUIRect::Assign | ( | const CGUIPoint & | kOriginPt, |
const eC_Value & | vWidth, | ||
const eC_Value & | vHeight | ||
) |
Assigns new coordinates to an existing rectangle. The rectangle will be comprehensive if the covered area of the new rectangle is not negative.
kOriginPt | X- and Y-coordinate of the left upper corner. |
vWidth | The width of the rectangle. |
vHeight | The height of the rectangle. |
CGUIRect & CGUIRect::Assign | ( | const eC_Value & | vX1, |
const eC_Value & | vY1, | ||
const eC_Value & | vX2, | ||
const eC_Value & | vY2 | ||
) |
Assigns new coordinates to an existing rectangle. The rectangle will be comprehensive if the covered area greater than zero.
vX1 | X-coordinate of the top left corner |
vY1 | Y-coordinate of the top left corner |
vX2 | X-coordinate of the bottom right corner |
vY2 | Y-coordinate of the bottom right corner |
|
inline |
Expand the rectangle. Depending on sign this results in expanding or shrinking the rect
vDif | value to add on all sides |
enDirection |
|
inline |
|
inline |
|
inline |
Returns the height of the rectangle. This function only returns the expected value if it is used on a comprehensive (and normalized) rectangle, so please check this. This function also only works correctly if the coordinates are not more far away from each other than eC_MAXVALUE so please be careful that your rectangles don't get too big.
|
inline |
|
inline |
|
inline |
Returns the width of the rectangle. This function only returns the expected value if it is used on a comprehensive (and normalized) rectangle, so please check this. This function also only works correctly if the coordinates are not more far away from each other than eC_MAXVALUE so please be careful that your rectangles don't get too big.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Interpolate between two rectangles.
kTargetRect | Target of interpolation |
vInterpolationFactor | Value between 0 (this rectangle stays unchanged) and 1 (identical to target rectangle) |
Calculates the area where two rectangles overlap. The resulting rectangle is stored within this object. If the rectangles do not overlap then "this" rectangle will be incomprehensive. Doing this function on an incomprehensive "this" rectangle doesn't change any rectangle. Calling this function on a comprehensive "this" rectangle and an incomprehensive argument rectangle will make "this" rectangle incomprehensive.
CGUIException | if one of the rectangles is not normalised (only in _DEBUG build) |
Rect | The rectangle to check |
|
inline |
Checks if this rectangle is fully at the bottom of 'Rect' or the relevant edges touch each other.
Rect | The rectangle to check |
|
inline |
If true then it is guaranteed that the rectangle is also normalised.
|
inline |
Checks whether a point at a given coordinate is inside a rectangle or not. Only comprehensive rectangles contain points.
kPt | The point to check |
|
inline |
Check if the given rectangle is completely within this rectangle. True is also returned for exactly same positions and sizes.
kRect | The rectangle to check |
|
inline |
Checks whether a point at a given coordinate is inside a rectangle or not. Only comprehensive rectangles contain points.
vX | X-coordinate |
vY | Y-coordinate |
|
inline |
Checks if this rectangle is fully to the left of 'Rect' or the relevant edges touch each other.
Rect | The rectangle to check |
|
inline |
Checks if this rectangle is fully to the right of 'Rect' or the relevant edges touch each other.
Rect | The rectangle to check |
|
inline |
Checks if this rectangle is fully top of 'Rect' or the relevant edges touch each other.
Rect | The rectangle to check |
Moves the rectangle.
kOffsetPt | Pixels to move in x/y direction |
CGUIRect & CGUIRect::Move | ( | const eC_Value | vDeltaX, |
const eC_Value | vDeltaY | ||
) |
Moves the rectangle.
vDeltaX | Pixels to move in x direction |
vDeltaY | Pixels to move in y direction |
CGUIRect & CGUIRect::MoveTo | ( | const eC_Value | vAbsX, |
const eC_Value | vAbsY | ||
) |
Moves the rectangle to an absolute position
vAbsX | Target position in x direction |
vAbsY | Target position in y direction |
void CGUIRect::Normalise | ( | ) |
This normalises the rectangle so that the functions and operations of this class may operate on it successfully. Only comprehensive rectangles will be made normalised as it makes no sense to normalise invalid coordinates.
|
inline |
Checks whether two rectangles are identical. They are identical if the coordinates of their upper left and lower right corners are identical.
rkRect | Rectangle to compare with. |
Assigns an existing rectangle from another rectangle.
srcRect | Rectangle from which a duplicate will be created. |
|
inline |
Checks whether two rectangles are identical. They are identical if the coordinates of their upper left and lower right corners are identical.
rkRect | Rectangle to compare with. |
eC_Bool CGUIRect::Overlaps | ( | const CGUIRect & | Rect | ) | const |
Does an overlap-check between two rectangles.
Rect | The rectangle to check |
CGUIException | if one of the rectangles is not normalised (only in _DEBUG build) |
|
inline |
If a non-normalised rectangle is forced to be comprehensive via this function, then it also gets normalised automatically.
bComprehensive | true if comprehensive |
|
inline |
Sets the new height of the rectangle. Bottom corner will be extended.
vHeight | new height of the rectangle |
|
inline |
Sets the new width of the rectangle. Right corner will be extended.
vWidth | new width of the rectangle |
|
inline |
vX1 | New X of vertex 1 |
|
inline |
vX2 | New Y of vertex 2 |
|
inline |
vY1 | New X of vertex 1 |
|
inline |
vY2 | New Y of vertex 2 |
Merges the rectangle with another rectangle. The resulting rectangle is the smallest enclosing rectangle around the two input rectangles and is stored within this object. Doing this function on an incomprehensive rectangle that is passed as an argument doesn't change any rectangle. If this rectangle is incomprehensive and the rectangle that is passed as an argument is comprehensive then the argument will be copied to this rectangle. This is because not just a usual comprehensive rectangle but also an incomprehensive rectangle should be able to get bigger when a union with a comprehensive rectangle is performed. This is especially useful for enlarging the invalidated rectangle in reset (= incomprehensive) state. A rectangle with covers zero space will have no effect for a union operation.
CGUIException | if one of the rectangles is not normalised (only in _DEBUG build) |
Rect | The rectangle to check |