Location:
e32std.h
Link against: euser.lib
TRegion
Supported from 5.0
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
TRect
s and the more complex the region, the more
TRect
s 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:
minimally, they pass it to the graphics context as the clipping region; when a graphics context is activated to a window, the clipping region is set up automatically
if they wish to avoid redrawing objects which are outside the
general area of the region, they may use TRegion::BoundingRect()
to return the rectangle which bounds the clipping region, and draw only
primitives that lie within that rectangle
if they wish to exercise finer control, they may extract the
individual rectangles that comprise the clipping region using
Operator[]()
.
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[]()
void SubRegion(const TRegion& aRegion,TRegion* aSubtractedRegion=NULL);
Subtracts a region.
If there is no area of intersection between the two regions, this region is unaffected.
|
TRect BoundingRect() const;
Gets the minimal rectangle which bounds the entire region.
|
void Offset(TInt aXoffset,TInt aYoffset);
Moves the region by adding X and Y offsets to the co-ordinates of its corners.
The size of the region is not changed.
|
void Offset(const TPoint& aOffset);
Moves the region by adding a TPoint
offset to the
co-ordinates of its corners.
The size of the region is not changed.
|
void ClipRect(const TRect& aRect);
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.
|
const TRect& operator[](TInt aIndex) const;
Gets a rectangle from the region.
|
|
TInt Count() const;
Gets the number of rectangles in this region.
|
const TRect* RectangleList() const;
Gets a pointer to the array of rectangles defining this region.
|
void AddRect(const TRect& aRect);
Adds a rectangle to this region.
Notes:
If this region’s error flag is already set, this function has no effect.
If the operation causes the capacity of this region to be exceeded, or if memory allocation fails, the region is cleared, freeing up any memory which has been allocated; its error flag is also set.
|
void SubRect(const TRect& aRect,TRegion* aSubtractedRegion=NULL);
Removes a rectangle from this region.
If there is no intersection between the rectangle and this region, then this region is unaffected.
|
TBool IsEmpty() const;
Tests whether the region
is empty.
|
TBool IsContainedBy(const TRect& aRect) const;
Tests whether the region is fully enclosed within a specified rectangle.
|
|
TBool Contains(const TPoint& aPoint) const;
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.
|
|
TBool CheckError() const;
Tests whether the region’s error flag is set.
The error flag may be set:
when an attempt to allocate more memory for the region fails
if an attempt is made to expand a fixed size region beyond its allocated size
if ForceError()
has been called.
Use Clear()
to unset the error flag, clear the
region and free all allocated memory.
|
void Copy(const TRegion& aRegion);
Copies another region to this region.
The state of the specified region’s error flag is also copied.
|
void Union(const TRegion& aRegion);
Replaces this region with the union of it and the specified region.
Note:
If the error flag of either this region or the specified region is set, then this region is cleared and its error flag is set. This frees up allocated memory.
|
void Intersection(const TRegion& aRegion,const TRegion& aRegion2);
Replaces this region with the area of intersection between two specified regions.
Notes:
If the error flag of either of the two specified regions is set, then this region is cleared and its error flag is set. This frees up allocated memory.
If this region’s error flag is already set, then the function has no effect.
|
void Intersect(const TRegion& aRegion);
Replaces this region with the area of intersection between it and the specified region.
Note:
If the error flag of either this region or the specified region is set, then this region is cleared and its error flag is set. This frees up allocated memory.
|
void Clear();
Clears this region.
This frees up any memory which has been allocated and unsets the error flag.
void Tidy();
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.
TInt Sort();
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:
The sort order may need to be different from the default if, for example, a region is moved downwards so that lower non-overlapping rectangles need to be redrawn (and sorted) before higher ones. In this case, use the second overload of this function.
|
TInt Sort(const TPoint& aOffset);
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:
The sort order may need to be different from the default if, for example, a region is moved downwards so that lower non-overlapping rectangles need to be redrawn (and sorted) before higher ones.
|
|
void ForceError();
Sets the error flag, and clears the region.
This frees up memory allocated to the region.