Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

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



Location: e32std.h
Link against: euser.lib

Class TRegion

TRegion

Support

Supported from 5.0

Description

Clipping region — abstract base class.

This abstract base class represents a 2-dimensional area which is used by Graphics, the graphics window server, and the text window server to define regions of the display which need to be updated, or regions within which all operations must occur.

A TRegion is defined in terms of an array of TRects and the more complex the region, the more TRects are required to represent it.

A clipping region initially has space allocated for five rectangles. If manipulations result in a region which requires more than this, an attempt is made to allocate more rectangles. If this cannot be done, an error flag is set, and all subsequent operations involving the region have no effect (except possibly to propagate the error flag to other regions). The CheckError() member function allows the error flag to be tested; Clear() can be used to clear it.

Application programs’ redraw logic may use the TRegion in various ways:

Application programs may also manipulate clipping regions in order to constrain parts of their redrawing to narrower areas of the screen than the clipping region offered by the window server. To do this, functions that allow clipping region manipulation may be used; for example, adding or removing rectangles or finding the intersection or union of two regions.

Defined in TRegion:
AddRect(), BoundingRect(), CheckError(), Clear(), ClipRect(), Contains(), Copy(), Count(), ForceError(), Intersect(), Intersection(), IsContainedBy(), IsEmpty(), Offset(), RectangleList(), Sort(), SubRect(), SubRegion(), Tidy(), Union(), operator[]()


Manipulate a region


SubRegion()

void SubRegion(const TRegion& aRegion,TRegion* aSubtractedRegion=NULL);

Description

Subtracts a region.

If there is no area of intersection between the two regions, this region is unaffected.

Parameters

const TRegion& aRegion

The region to be removed from this region. If aRegion's error flag is set, then this region is cleared, freeing up any allocated memory, and the error flag is set.

TRegion* aSubtractedRegion=NULL

If specified, on return contains the area removed from this region.


BoundingRect()

TRect BoundingRect() const;

Description

Gets the minimal rectangle which bounds the entire region.

Return value

TRect

The region’s minimal bounding rectangle.


Offset()

void Offset(TInt aXoffset,TInt aYoffset);

Description

Moves the region by adding X and Y offsets to the co-ordinates of its corners.

The size of the region is not changed.

Parameters

TInt aXoffset

The number of pixels by which to move the region horizontally. If negative, the region moves leftwards.

TInt aYoffset

The number of pixels by which to move the region vertically. If negative, the region moves upwards.


Offset()

void Offset(const TPoint& aOffset);

Description

Moves the region by adding a TPoint offset to the co-ordinates of its corners.

The size of the region is not changed.

Parameters

const TPoint& aOffset

The offset by which the region is moved. The region is moved horizontally by aOffset.iX pixels and vertically by aOffset.iY pixels.


ClipRect()

void ClipRect(const TRect& aRect);

Description

Clips the region to a rectangle.

The resulting region is the area of overlap between the region and the rectangle. If there is no overlap, all rectangles within this region are deleted and the resulting region is empty.

Parameters

const TRect& aRect

The rectangle to which this region is to be clipped

[Top]


Get components of a region


operator[]()

const TRect& operator[](TInt aIndex) const;

Description

Gets a rectangle from the region.

Parameters

TInt aIndex

The index of a rectangle within the region's array of rectangles. Indexes are relative to zero. This value must be strictly less than the number of rectangles in the region, otherwise the function raises a USER 81 panic.

Return value

TRect&

The specified rectangle.


Count()

TInt Count() const;

Description

Gets the number of rectangles in this region.

Return value

TInt

The number of rectangles.

[Top]


RectangleList()

const TRect* RectangleList() const;

Description

Gets a pointer to the array of rectangles defining this region.

Return value

TRect*

Pointer to the array of rectangles. Note that array is a standard C++ array, i.e. a concatenated set of TRect objects. Use Count() to get the number of rectangles.

[Top]


Add or remove a region


AddRect()

void AddRect(const TRect& aRect);

Description

Adds a rectangle to this region.

Notes:

Parameters

const TRect& aRect

The rectangle to be added to this region.


SubRect()

void SubRect(const TRect& aRect,TRegion* aSubtractedRegion=NULL);

Description

Removes a rectangle from this region.

If there is no intersection between the rectangle and this region, then this region is unaffected.

Parameters

const TRect& aRect

The rectangular area to be removed from this region

TRegion* aSubtractedRegion

A pointer to a region. If this is supplied, the removed rectangle is added to it. By default this pointer is NULL.

[Top]


Query functions


IsEmpty()

TBool IsEmpty() const;

Description

Tests whether the region is empty.

Return value

TBool

True, if the region is empty and its error flag is unset; false, otherwise.


IsContainedBy()

TBool IsContainedBy(const TRect& aRect) const;

Description

Tests whether the region is fully enclosed within a specified rectangle.

Parameters

const TRect& aRect

The specified rectangle.

Return value

TBool

True, if the region is fully enclosed within the rectangle (their sides may touch); false, otherwise.


Contains()

TBool Contains(const TPoint& aPoint) const;

Description

Tests whether a point is located within the region.

If the point is located on the top or left hand side of any rectangle in the region, it is considered to be within that rectangle and within the region.

If the point is located on the right hand side or bottom of a rectangle, it is considered to be outside that rectangle, and may be outside the region.

Parameters

const TPoint& aPoint

The specified point.

Return value

TBool

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


CheckError()

TBool CheckError() const;

Description

Tests whether the region’s error flag is set.

The error flag may be set:

Use Clear() to unset the error flag, clear the region and free all allocated memory.

Return value

TBool

True, if the error flag is set; false, otherwise.

See also:

[Top]


Operations with other regions


Copy()

void Copy(const TRegion& aRegion);

Description

Copies another region to this region.

The state of the specified region’s error flag is also copied.

Parameters

const TRegion& aRegion

The region to be copied.


Union()

void Union(const TRegion& aRegion);

Description

Replaces this region with the union of it and the specified region.

Note:

Parameters

const TRegion& aRegion

The region to be joined to this region


Intersection()

void Intersection(const TRegion& aRegion,const TRegion& aRegion2);

Description

Replaces this region with the area of intersection between two specified regions.

Notes:

Parameters

const TRegion& aRegion

The first region.

const TRegion& aRegion2

The second region.


Intersect()

void Intersect(const TRegion& aRegion);

Description

Replaces this region with the area of intersection between it and the specified region.

Note:

Parameters

const TRegion& aRegion

The region to be intersected with this region.

[Top]


Region maintenance


Clear()

void Clear();

Description

Clears this region.

This frees up any memory which has been allocated and unsets the error flag.


Tidy()

void Tidy();

Description

Merges all rectangles within this region which share an adjacent edge of the same length.

The function subsequently frees up any allocated but unused memory.


Sort()

TInt Sort();

Description

Sorts the region’s array of rectangles according to their vertical position on the screen.

The co-ordinates used in the sort are those of the rectangles’ bottom right hand corner. The co-ordinates of the top and left hand sides are irrelevant to the sort.

Higher rectangles take precedence over lower ones. For rectangles at the same vertical position, the leftmost takes priority.

Notes:

Return value

TInt

KErrNone, if the operation is successful; KErrGeneral, otherwise.


Sort()

TInt Sort(const TPoint& aOffset);

Description

Sorts the region’s array of rectangles according to a specified sort order.

The co-ordinates used in the sort are those of the rectangles’ bottom right hand corner. The co-ordinates of the top and left hand sides are irrelevant to the sort.

The order of the sort is determined by whether the iX and iY members of aOffset are positive, or zero or less. If aOffset.iY is greater than zero, lower rectangles take precedence over higher rectangles in the list order. Otherwise, higher rectangles take precedence. For rectangles of equal height, aOffset.iX becomes relevant to the sort. If is greater than zero, rightmost rectangles take precedence. Otherwise, leftmost rectangles take precedence.

Note:

Parameters

const TPoint& aOffset

A point whose iX and iY members determine the order of the sort.

Return value

TInt

KErrNone, if the operation is successful; KErrGeneral, otherwise.


ForceError()

void ForceError();

Description

Sets the error flag, and clears the region.

This frees up memory allocated to the region.