TRect Class Reference

class TRect

Geometric rectangle.

The class represents a rectangle whose sides are parallel with the axes of the co-ordinate system.

The co-ordinates of the top-left and bottom-right corners are used to set the dimensions of the rectangle. The bottom right co-ordinate is outside the rectangle. Thus TRect(TPoint(2,2),TSize(4,4)) is equal to TRect(TPoint(2,2),TPoint(6,6)), and in both cases you get a 4x4 pixel rectangle on the screen.

Functions are provided to initialise and manipulate the rectangle and to extract information about it.

Public Member Functions
TRect(TUninitialized)
TRect()
TRect(TInt, TInt, TInt, TInt)
TRect(const TPoint &, const TPoint &)
TRect(const TPoint &, const TSize &)
TRect(const TSize &)
IMPORT_C voidBoundingRect(const TRect &)
IMPORT_C TPointCenter()
IMPORT_C TBoolContains(const TPoint &)
IMPORT_C voidGrow(TInt, TInt)
IMPORT_C voidGrow(const TSize &)
IMPORT_C TIntHeight()
IMPORT_C voidIntersection(const TRect &)
IMPORT_C TBoolIntersects(const TRect &)
IMPORT_C TBoolIsEmpty()
IMPORT_C TBoolIsNormalized()
IMPORT_C voidMove(TInt, TInt)
IMPORT_C voidMove(const TPoint &)
IMPORT_C voidNormalize()
IMPORT_C voidResize(TInt, TInt)
IMPORT_C voidResize(const TSize &)
IMPORT_C voidSetHeight(TInt)
IMPORT_C voidSetRect(TInt, TInt, TInt, TInt)
IMPORT_C voidSetRect(const TPoint &, const TPoint &)
IMPORT_C voidSetRect(const TPoint &, const TSize &)
IMPORT_C voidSetSize(const TSize &)
IMPORT_C voidSetWidth(TInt)
IMPORT_C voidShrink(TInt, TInt)
IMPORT_C voidShrink(const TSize &)
IMPORT_C TSizeSize()
IMPORT_C TIntWidth()
IMPORT_C TBooloperator!=(const TRect &)
IMPORT_C TBooloperator==(const TRect &)
Private Member Functions
voidAdjust(TInt, TInt)
Public Member Enumerations
enumTUninitialized { EUninitialized }
Public Attributes
TPoint iBr
TPoint iTl

Constructor & Destructor Documentation

TRect(TUninitialized)

TRect(TUninitialized)[inline]

Constructs a default rectangle.

This initialises the co-ordinates of its top left and bottom right corners to (0,0).

Parameters

TUninitialized

TRect()

IMPORT_CTRect()

Constructs a default rectangle.

This initialises the co-ordinates of its top left and bottom right corners to (0,0).

TRect(TInt, TInt, TInt, TInt)

IMPORT_CTRect(TIntaAx,
TIntaAy,
TIntaBx,
TIntaBy
)

Constructs the rectangle, initialising its top left and bottom right hand corners with four TInt values.

Parameters

TInt aAxThe horizontal co-ordinate of the left hand side of the rectangle.
TInt aAyThe vertical co-ordinate of the top of the rectangle.
TInt aBxThe horizontal co-ordinate of the right hand side of the rectangle.
TInt aByThe vertical co-ordinate of the bottom of the rectangle.

TRect(const TPoint &, const TPoint &)

IMPORT_CTRect(const TPoint &aPointA,
const TPoint &aPointB
)

Constructs the rectangle with two TPoints, corresponding to its top left and bottom right hand corners.

Parameters

const TPoint & aPointAThe co-ordinates of the rectangle's top left hand corner.
const TPoint & aPointBThe co-ordinates of the rectangle's bottom right hand corner.

TRect(const TPoint &, const TSize &)

IMPORT_CTRect(const TPoint &aPoint,
const TSize &aSize
)

Constructs the rectangle with a TPoint for its top left corner, and a TSize for its width and height.

Parameters

const TPoint & aPointThe rectangle's top left hand corner.
const TSize & aSizeThe rectangle's width and height.

TRect(const TSize &)

IMPORT_CTRect(const TSize &aSize)

Constructs the rectangle with a TSize.

The co-ordinates of its top left hand corner are initialised to (0,0) and its width and height are initialised to the values contained in the argument.

Parameters

const TSize & aSizeThe width and height of the rectangle.

Member Functions Documentation

Adjust(TInt, TInt)

voidAdjust(TIntaDx,
TIntaDy
)[private]

Parameters

TInt aDx
TInt aDy

BoundingRect(const TRect &)

IMPORT_C voidBoundingRect(const TRect &aRect)

Gets the minimal rectangle which bounds both this rectangle and the specified rectangle, and assigns it to this rectangle.

Parameters

const TRect & aRectThe rectangle to use with this rectangle to get the minimal bounding rectangle.

Center()

IMPORT_C TPointCenter()const

Gets the point at the centre of the rectangle.

Contains(const TPoint &)

IMPORT_C TBoolContains(const TPoint &aPoint)const

Tests whether a point is located within the rectangle.

Note that a point located on the top or left hand side of the rectangle is within the rectangle. A point located on the right hand side or bottom is considered to be outside the rectangle.

Parameters

const TPoint & aPointThe point to be tested.

Grow(TInt, TInt)

IMPORT_C voidGrow(TIntaDx,
TIntaDy
)

Grows the rectangle using the specified horizontal and vertical offsets.

The offset values are subtracted from the co-ordinates of its top left hand corner, and the same values are added to the co-ordinates of its bottom right hand corner. The co-ordinates of the centre of the rectangle remain unchanged. If either value is negative, the rectangle shrinks in the corresponding direction.

Parameters

TInt aDxThe number of pixels by which to move the left and right hand sides of the rectangle. A positive value increases the width, a negative value reduces it.
TInt aDyThe number of pixels by which to move the top and bottom of the rectangle. A positive value increases the height, a negative value reduces it.

Grow(const TSize &)

IMPORT_C voidGrow(const TSize &aSize)

Grows a rectangle using the specified TSize offset.

The rectangle grows by twice the value of the height and width specified in the TSize. The co-ordinates of the centre of the rectangle remain unchanged. If either value is negative, the rectangle shrinks in the corresponding direction.

Parameters

const TSize & aSizeThe number of pixels by which to move the left and right hand sides of the rectangle (by aSize.iWidth) and the top and bottom (by aSize.iHeight).

Height()

IMPORT_C TIntHeight()const

Gets the height of the rectangle.

Intersection(const TRect &)

IMPORT_C voidIntersection(const TRect &aRect)

Gets the area of intersection between this rectangle and the specified rectangle, and assigns it to this rectangle.

It is usual to call TRect::Intersects() first to verify whether the two rectangles intersect. If the two rectangles do not intersect, then, on return, this rectangle is set to be empty.

TRect::Intersects

Parameters

const TRect & aRectThe rectangle to be used with this rectangle to get the area of intersection.

Intersects(const TRect &)

IMPORT_C TBoolIntersects(const TRect &aRect)const

Tests whether this rectangle overlaps with the specified rectangle.

Two rectangles overlap if any point is located within both rectangles. There is no intersection if two adjacent sides touch without overlapping, or if either rectangle is empty.

Parameters

const TRect & aRectThe rectangle to compare with this rectangle for an intersection.

IsEmpty()

IMPORT_C TBoolIsEmpty()const

Tests whether the rectangle is empty.

IsNormalized()

IMPORT_C TBoolIsNormalized()const

Tests whether the rectangle is normalised.

A rectangle is normalised when its width and height are both zero or greater.

Move(TInt, TInt)

IMPORT_C voidMove(TIntaDx,
TIntaDy
)

Moves the rectangle by adding an x, y offset.

The offset is added to the co-ordinates of both its top left and bottom right hand corners. The size of the rectangle is unchanged.

Parameters

TInt aDxThe number of pixels to move the rectangle horizontally. If negative, the rectangle moves leftwards.
TInt aDyThe number of pixels to move the rectangle vertically. If negative, the rectangle moves upwards.

Move(const TPoint &)

IMPORT_C voidMove(const TPoint &aOffset)

Moves the rectangle by adding a TPoint offset.

The offset is added to the co-ordinates of both its top left and bottom right hand corners. The size of the rectangle is unchanged.

Parameters

const TPoint & aOffsetThe number of pixels to move the rectangle; horizontally by aOffset.iX and vertically by aOffset.iY.

Normalize()

IMPORT_C voidNormalize()

Ensures that the rectangle's width and height have positive values.

For example, if the rectangle's co-ordinates are such that the top is below the bottom, or the right hand side is to the left of the left hand side, normalisation swaps the co-ordinates of the top and bottom or of the left and right.

Resize(TInt, TInt)

IMPORT_C voidResize(TIntaDx,
TIntaDy
)

Resizes a rectangle by adding a horizontal and vertical offset.

The offset is added to the co-ordinates of its bottom right hand corner. If either value is negative, the rectangle shrinks in the corresponding direction. The co-ordinates of the rectangle's top left hand corner are unaffected.

Parameters

TInt aDxThe number of pixels by which to move the right hand side of the rectangle.
TInt aDyThe number of pixels by which to move the bottom of the rectangle.

Resize(const TSize &)

IMPORT_C voidResize(const TSize &aSize)

Resizes a rectangle by adding a TSize offset.

The offset is added to the co-ordinates of its bottom right hand corner. If either value in the TSize is negative, the rectangle shrinks in the corresponding direction. The co-ordinates of the rectangle's top left hand corner are unaffected.

Parameters

const TSize & aSizeThe number of pixels by which to move the rectangle; the right hand side by aSize.iWidth and the bottom by aSize.iHeight.

SetHeight(TInt)

IMPORT_C voidSetHeight(TIntaHeight)

Sets the height of the rectangle.

Only the position of the bottom of the rectangle is affected.

Parameters

TInt aHeightThe new height of the rectangle.

SetRect(TInt, TInt, TInt, TInt)

IMPORT_C voidSetRect(TIntaAx,
TIntaAy,
TIntaBx,
TIntaBy
)

Sets the rectangle's position using four TInts.

Parameters

TInt aAxThe horizontal co-ordinate of the left hand side of the rectangle.
TInt aAyThe vertical co-ordinate of the top of the rectangle.
TInt aBxThe horizontal co-ordinate of the right hand side of the rectangle.
TInt aByThe vertical co-ordinate of the bottom of the rectangle.

SetRect(const TPoint &, const TPoint &)

IMPORT_C voidSetRect(const TPoint &aPointTL,
const TPoint &aPointBR
)

Sets the rectangle's position using two TPoints.

Parameters

const TPoint & aPointTLThe co-ordinates of the rectangle's top left hand corner.
const TPoint & aPointBRThe co-ordinates of the rectangle's bottom right hand corner.

SetRect(const TPoint &, const TSize &)

IMPORT_C voidSetRect(const TPoint &aPoint,
const TSize &aSize
)

Sets the rectangle's position using a TPoint and a TSize.

Parameters

const TPoint & aPointThe co-ordinates of the rectangle's top left hand corner.
const TSize & aSizeThe rectangle's width and height.

SetSize(const TSize &)

IMPORT_C voidSetSize(const TSize &aSize)

Sets the size of the rectangle.

Only the co-ordinates of the bottom right hand corner of the rectangle are affected.

Parameters

const TSize & aSizeThe new width is aSize.iWidth. The new height is aSize.iHeight.

SetWidth(TInt)

IMPORT_C voidSetWidth(TIntaWidth)

Sets the width of the rectangle.

Only the position of the rectangle's right hand side is affected.

Parameters

TInt aWidthThe new width of the rectangle.

Shrink(TInt, TInt)

IMPORT_C voidShrink(TIntaDx,
TIntaDy
)

Shrinks a rectangle using specified horizontal and vertical offsets.

The offset values are added to the co-ordinates of its top left hand corner, and the same values are subtracted from the co-ordinates of its bottom right hand corner. The co-ordinates of the centre of the rectangle remain unchanged. If either value is negative, the rectangle expands in the corresponding direction.

Parameters

TInt aDxThe number of pixels by which to move the left and right hand sides of the rectangle. A positive value reduces the width, a negative value increases it.
TInt aDyThe number of pixels by which to move the top and bottom of the rectangle. A positive value reduces the height, a negative value increases it.

Shrink(const TSize &)

IMPORT_C voidShrink(const TSize &aSize)

Shrinks a rectangle using a specified TSize offset.

The rectangle shrinks by twice the value of the height and width specified in the TSize. The co-ordinates of the centre of the rectangle remain unchanged. If either value is negative, the rectangle expands in the corresponding direction.

Parameters

const TSize & aSizeThe number of pixels by which to move the left and right hand sides of the rectangle (by aSize.iWidth) and the top and bottom (by aSize.iHeight).

Size()

IMPORT_C TSizeSize()const

Gets the size of the rectangle.

Width()

IMPORT_C TIntWidth()const

Gets the width of the rectangle.

operator!=(const TRect &)

IMPORT_C TBooloperator!=(const TRect &aRect)const

Compares two rectangles for inequality.

Two rectangles are unequal if any of their co-ordinates differ.

Parameters

const TRect & aRectThe rectangle to compare with this rectangle.

operator==(const TRect &)

IMPORT_C TBooloperator==(const TRect &aRect)const

Compares two rectangles for equality.

For two rectangles to be equal, the co-ordinates of both their top left and bottom right hand corners must be equal.

Parameters

const TRect & aRectThe rectangle to compare with this rectangle.

Member Enumerations Documentation

Enum TUninitialized

Enumerators

EUninitialized

Member Data Documentation

TPoint iBr

TPoint iBr

The x and y co-ordinates of the bottom right hand corner of the rectangle.

TPoint iTl

TPoint iTl

The x and y co-ordinates of the top left hand corner of the rectangle.