Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



Location: e32std.h
Link against: euser.lib

Class TRect

TRect

Support

Supported from 5.0

Description

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.

Defined in TRect:
BoundingRect(), Center(), Contains(), Grow(), Height(), Intersection(), Intersects(), IsEmpty(), IsNormalized(), Move(), Normalize(), Resize(), SetHeight(), SetRect(), SetSize(), SetWidth(), Shrink(), Size(), TRect(), Width(), iBr, iTl, operator!=(), operator==()

See also:


Construction and destruction


TRect()

TRect();

Description

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


TRect()

TRect(TInt aAx,TInt aAy,TInt aBx,TInt aBy);

Description

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

Parameters

TInt aAx

The horizontal co-ordinate of the left hand side of the rectangle.

TInt aAy

The vertical co-ordinate of the top of the rectangle.

TInt aBx

The horizontal co-ordinate of the right hand side of the rectangle.

TInt aBy

The vertical co-ordinate of the bottom of the rectangle.


TRect()

TRect(const TPoint& aPointA,const TPoint& aPointB);

Description

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

Parameters

const TPoint& aPointA

The co-ordinates of the rectangle’s top left hand corner.

const TPoint& aPointB

The co-ordinates of the rectangle’s bottom right hand corner.


TRect()

TRect(const TPoint& aPoint,const TSize& aSize);

Description

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

Parameters

const TPoint& aPoint

The rectangle’s top left hand corner.

const TSize& aSize

The rectangle’s width and height.


TRect()

TRect(const TSize& aSize);

Description

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& aSize

The width and height of the rectangle.

[Top]


Set co-ordinates


SetRect()

void SetRect(TInt aAx,TInt aAy,TInt aBx,TInt aBy);

Description

Sets the rectangle’s position using four TInts.

Parameters

TInt aAx

The horizontal co-ordinate of the left hand side of the rectangle.

TInt aAy

The vertical co-ordinate of the top of the rectangle.

TInt aBx

The horizontal co-ordinate of the right hand side of the rectangle.

TInt aBy

The vertical co-ordinate of the bottom of the rectangle.


SetRect()

void SetRect(const TPoint& aPointTL,const TPoint& aPointBR);

Description

Sets the rectangle’s position using two TPoints.

Parameters

const TPoint& aPointTL

The co-ordinates of the rectangle’s top left hand corner.

const TPoint& aPointBR

The co-ordinates of the rectangle’s bottom right hand corner.


SetRect()

void SetRect(const TPoint& aPoint,const TSize& aSize);

Description

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

Parameters

const TPoint& aPoint

The co-ordinates of the rectangle’s top left hand corner.

const TSize& aSize

The rectangle’s width and height.

[Top]


Operators


operator==()

TInt operator==(const TRect& aRect) const;

Description

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& aRect

The rectangle to compare with this rectangle.

Return value

TInt

True, if the rectangles have the same co-ordinates; false, otherwise.


operator!=()

TInt operator!=(const TRect& aRect) const;

Description

Compares two rectangles for inequality.

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

Parameters

const TRect& aRect

The rectangle to compare with this rectangle.

Return value

TInt

True, if the rectangles do not have the same co-ordinates; false, if all co-ordinates are equal.

[Top]


Manipulate rectangles


Normalize()

void Normalize();

Description

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.


Move()

void Move(TInt aDx,TInt aDy);

Description

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 aDx

The number of pixels to move the rectangle horizontally. If negative, the rectangle moves leftwards.

TInt aDy

The number of pixels to move the rectangle vertically. If negative, the rectangle moves upwards.


Move()

void Move(const TPoint& aOffset);

Description

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& aOffset

The number of pixels to move the rectangle; horizontally by aOffset.iX and vertically by aOffset.iY.


Resize()

void Resize(TInt aDx,TInt aDy);

Description

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 aDx

The number of pixels by which to move the right hand side of the rectangle.

TInt aDy

The number of pixels by which to move the bottom of the rectangle.


Resize()

void Resize(const TSize& aSize);

Description

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& aSize

The number of pixels by which to move the rectangle; the right hand side by aSize.iWidth and the bottom by aSize.iHeight.


Shrink()

void Shrink(TInt aDx,TInt aDy);

Description

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 aDx

The 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 aDy

The 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()

void Shrink(const TSize& aSize);

Description

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& aSize

The 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).


Grow()

void Grow(TInt aDx,TInt aDy);

Description

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 aDx

The 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 aDy

The 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()

void Grow(const TSize& aSize);

Description

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& aSize

The 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).

[Top]


Assign dimensions


SetSize()

void SetSize(const TSize& aSize);

Description

Sets the size of the rectangle.

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

Parameters

const TSize& aSize

The new width is aSize.iWidth. The new height is aSize.iHeight.


SetWidth()

void SetWidth(TInt aWidth);

Description

Sets the width of the rectangle.

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

Parameters

TInt aWidth

The new width of the rectangle.


SetHeight()

void SetHeight(TInt aHeight);

Description

Sets the height of the rectangle.

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

Parameters

TInt aHeight

The new height of the rectangle.

[Top]


Extracting information


Size()

TSize Size() const;

Description

Gets the size of the rectangle.

Return value

TSize

The size of the rectangle.


Width()

TInt Width() const;

Description

Gets the width of the rectangle.

Return value

TInt

The width of the rectangle.


Height()

TInt Height() const;

Description

Gets the height of the rectangle.

Return value

TInt

The height of the rectangle.


IsNormalized()

TBool IsNormalized() const;

Description

Tests whether the rectangle is normalised.

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

Return value

TBool

True, if normalised; false, if not.


IsEmpty()

TBool IsEmpty() const;

Description

Tests whether the rectangle is empty.

Return value

TBool

True, if empty; false, if not.


Center()

TPoint Center() const;

Description

Gets the point at the centre of the rectangle.

Return value

TPoint

The point at the centre of the rectangle.


Contains()

TBool Contains(const TPoint& aPoint) const;

Description

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& aPoint

The point to be tested.

Return value

TBool

True, if the point is within the rectangle; false, otherwise.

[Top]


Operations with other rectangles


BoundingRect()

void BoundingRect(const TRect& aRect);

Description

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

Parameters

const TRect& aRect

The rectangle to use with this rectangle to get the minimal bounding rectangle.


Intersection()

void Intersection(const TRect& aRect);

Description

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.

Parameters

const TRect& aRect

The rectangle to use with this rectangle to get the area of intersection.


Intersects()

TBool Intersects(const TRect& aRect) const;

Description

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& aRect

The rectangle to compare with this rectangle for an intersection.

Return value

TBool

True, if the two rectangles overlap; false, if there is no overlap.

[Top]


Public data members


iBr

TPoint iBr

Description

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


iTl

TPoint iTl

Description

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