TQRegion Class

Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# TQRegion Class Reference

The TQRegion class specifies a clip region for a painter. More...

`#include <ntqregion.h>`

List of all member functions.

## Public Members

- enum RegionType { Rectangle, Ellipse }
- TQRegion ()
- TQRegion ( int x, int y, int w, int h, RegionType t = Rectangle )
- TQRegion ( const TQRect & r, RegionType t = Rectangle )
- TQRegion ( const TQPointArray & a, bool winding = FALSE )
- TQRegion ( const TQRegion & r )
- TQRegion ( const TQBitmap & bm )
- ~TQRegion ()
- TQRegion & operator= ( const TQRegion & r )
- bool isNull () const
- bool isEmpty () const
- bool contains ( const TQPoint & p ) const
- bool contains ( const TQRect & r ) const
- void translate ( int dx, int dy )
- TQRegion unite ( const TQRegion & r ) const
- TQRegion intersect ( const TQRegion & r ) const
- TQRegion subtract ( const TQRegion & r ) const
- TQRegion eor ( const TQRegion & r ) const
- TQRect boundingRect () const
- TQMemArray<TQRect> rects () const
- const TQRegion operator| ( const TQRegion & r ) const
- const TQRegion operator+ ( const TQRegion & r ) const
- const TQRegion operator& ( const TQRegion & r ) const
- const TQRegion operator- ( const TQRegion & r ) const
- const TQRegion operator^ ( const TQRegion & r ) const
- TQRegion & operator|= ( const TQRegion & r )
- TQRegion & operator+= ( const TQRegion & r )
- TQRegion & operator&= ( const TQRegion & r )
- TQRegion & operator-= ( const TQRegion & r )
- TQRegion & operator^= ( const TQRegion & r )
- bool operator== ( const TQRegion & r ) const
- bool operator!= ( const TQRegion & r ) const
- HRGN handle () const

## Related Functions

- TQDataStream & operator<< ( TQDataStream & s, const TQRegion & r )
- TQDataStream & operator>> ( TQDataStream & s, TQRegion & r )

## Detailed Description

The TQRegion class specifies a clip region for a painter.

TQRegion is used with TQPainter::setClipRegion() to limit the paint area to what needs to be painted. There is also a TQWidget::repaint() that takes a TQRegion parameter. TQRegion is the best tool for reducing flicker.

A region can be created from a rectangle, an ellipse, a polygon or a bitmap. Complex regions may be created by combining simple regions using unite(), intersect(), subtract() or eor() (exclusive or). You can move a region using translate().

You can test whether a region isNull(), isEmpty() or if it contains() a TQPoint or TQRect. The bounding rectangle is given by boundingRect().

The function rects() gives a decomposition of the region into rectangles.

Example of using complex regions:

            void MyWidget::paintEvent( TQPaintEvent * )
            {
                TQPainter p;                         // our painter
                TQRegion r1( TQRect(100,100,200,80),  // r1 = elliptic region
                            TQRegion::Ellipse );
                TQRegion r2( TQRect(100,120,90,30) ); // r2 = rectangular region
                TQRegion r3 = r1.intersect( r2 );    // r3 = intersection
                p.begin( this );                    // start painting widget
                p.setClipRegion( r3 );              // set clip region
                ...                                 // paint clipped graphics
                p.end();                            // painting done
            }

TQRegion is an implicitly shared class.

Warning: Due to window system limitations, the whole coordinate space for a region is limited to the points between -32767 and 32767 on Mac OS X and Windows 95/98/ME.

See also TQPainter::setClipRegion(), TQPainter::setClipRect(), Graphics Classes, and Image Processing Classes.

## Member Type Documentation

### TQRegion::RegionType

Specifies the shape of the region to be created.

- `TQRegion::Rectangle` - the region covers the entire rectangle.
- `TQRegion::Ellipse` - the region is an ellipse inside the rectangle.

## Member Function Documentation

### TQRegion::TQRegion ()

Constructs a null region.

See also isNull().

### TQRegion::TQRegion ( int x, int y, int w, int h, RegionType t = Rectangle )

Constructs a rectangular or elliptic region.

If t is Rectangle, the region is the filled rectangle (x, y, w, h). If t is Ellipse, the region is the filled ellipse with center at (x + w / 2, y + h / 2) and size (w ,h ).

### TQRegion::TQRegion ( const TQRect & r, RegionType t = Rectangle )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Create a region based on the rectange r with region type t.

If the rectangle is invalid a null region will be created.

See also TQRegion::RegionType.

### TQRegion::TQRegion ( const TQPointArray & a, bool winding = FALSE )

Constructs a polygon region from the point array a.

If winding is TRUE, the polygon region is filled using the winding algorithm, otherwise the default even-odd fill algorithm is used.

This constructor may create complex regions that will slow down painting when used.

### TQRegion::TQRegion ( const TQRegion & r )

Constructs a new region which is equal to region r.

### TQRegion::TQRegion ( const TQBitmap & bm )

Constructs a region from the bitmap bm.

The resulting region consists of the pixels in bitmap bm that are `color1`, as if each pixel was a 1 by 1 rectangle.

This constructor may create complex regions that will slow down painting when used. Note that drawing masked pixmaps can be done much faster using TQPixmap::setMask().

### TQRegion::~TQRegion ()

Destroys the region.

### TQRect TQRegion::boundingRect () const

Returns the bounding rectangle of this region. An empty region gives a rectangle that is TQRect::isNull().

### bool TQRegion::contains ( const TQPoint & p ) const

Returns TRUE if the region contains the point p; otherwise returns FALSE.

### bool TQRegion::contains ( const TQRect & r ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns TRUE if the region overlaps the rectangle r; otherwise returns FALSE.

### TQRegion TQRegion::eor ( const TQRegion & r ) const

Returns a region which is the exclusive or (XOR) of this region and r.

The figure shows the exclusive or of two elliptical regions.

### HRGN TQRegion::handle () const

Returns the region's handle.

### TQRegion TQRegion::intersect ( const TQRegion & r ) const

Returns a region which is the intersection of this region and r.

The figure shows the intersection of two elliptical regions.

### bool TQRegion::isEmpty () const

Returns TRUE if the region is empty; otherwise returns FALSE. An empty region is a region that contains no points.

Example:

            TQRegion r1( 10, 10, 20, 20 );
            TQRegion r2( 40, 40, 20, 20 );
            TQRegion r3;
            r1.isNull();             // FALSE
            r1.isEmpty();            // FALSE
            r3.isNull();             // TRUE
            r3.isEmpty();            // TRUE
            r3 = r1.intersect( r2 ); // r3 = intersection of r1 and r2
            r3.isNull();             // FALSE
            r3.isEmpty();            // TRUE
            r3 = r1.unite( r2 );     // r3 = union of r1 and r2
            r3.isNull();             // FALSE
            r3.isEmpty();            // FALSE

See also isNull().

### bool TQRegion::isNull () const

Returns TRUE if the region is a null region; otherwise returns FALSE.

A null region is a region that has not been initialized. A null region is always empty.

See also isEmpty().

### bool TQRegion::operator!= ( const TQRegion & r ) const

Returns TRUE if the region is different from r; otherwise returns FALSE.

### const TQRegion TQRegion::operator& ( const TQRegion & r ) const

Applies the intersect() function to this region and r. `r1&r2` is equivalent to `r1.intersect(r2)`

See also intersect().

### TQRegion & TQRegion::operator&= ( const TQRegion & r )

Applies the intersect() function to this region and r and assigns the result to this region. `r1&=r2` is equivalent to `r1=r1.intersect(r2)`

See also intersect().

### const TQRegion TQRegion::operator+ ( const TQRegion & r ) const

Applies the unite() function to this region and r. `r1+r2` is equivalent to `r1.unite(r2)`

See also unite() and operator|().

### TQRegion & TQRegion::operator+= ( const TQRegion & r )

Applies the unite() function to this region and r and assigns the result to this region. `r1+=r2` is equivalent to `r1=r1.unite(r2)`

See also intersect().

### const TQRegion TQRegion::operator- ( const TQRegion & r ) const

Applies the subtract() function to this region and r. `r1-r2` is equivalent to `r1.subtract(r2)`

See also subtract().

### TQRegion & TQRegion::operator-= ( const TQRegion & r )

Applies the subtract() function to this region and r and assigns the result to this region. `r1-=r2` is equivalent to `r1=r1.subtract(r2)`

See also subtract().

### TQRegion & TQRegion::operator= ( const TQRegion & r )

Assigns r to this region and returns a reference to the region.

### bool TQRegion::operator== ( const TQRegion & r ) const

Returns TRUE if the region is equal to r; otherwise returns FALSE.

### const TQRegion TQRegion::operator^ ( const TQRegion & r ) const

Applies the eor() function to this region and r. `r1^r2` is equivalent to `r1.eor(r2)`

See also eor().

### TQRegion & TQRegion::operator^= ( const TQRegion & r )

Applies the eor() function to this region and r and assigns the result to this region. `r1^=r2` is equivalent to `r1=r1.eor(r2)`

See also eor().

### const TQRegion TQRegion::operator| ( const TQRegion & r ) const

Applies the unite() function to this region and r. `r1|r2` is equivalent to `r1.unite(r2)`

See also unite() and operator+().

### TQRegion & TQRegion::operator|= ( const TQRegion & r )

Applies the unite() function to this region and r and assigns the result to this region. `r1|=r2` is equivalent to `r1=r1.unite(r2)`

See also unite().

### TQMemArray<TQRect> TQRegion::rects () const

Returns an array of non-overlapping rectangles that make up the region.

The union of all the rectangles is equal to the original region.

### TQRegion TQRegion::subtract ( const TQRegion & r ) const

Returns a region which is r subtracted from this region.

The figure shows the result when the ellipse on the right is subtracted from the ellipse on the left. (`left-right` )

### void TQRegion::translate ( int dx, int dy )

Translates (moves) the region dx along the X axis and dy along the Y axis.

### TQRegion TQRegion::unite ( const TQRegion & r ) const

Returns a region which is the union of this region and r.

The figure shows the union of two elliptical regions.

## Related Functions

### TQDataStream & operator<< ( TQDataStream & s, const TQRegion & r )

Writes the region r to the stream s and returns a reference to the stream.

See also Format of the TQDataStream operators.

### TQDataStream & operator>> ( TQDataStream & s, TQRegion & r )

Reads a region from the stream s into r and returns a reference to the stream.

See also Format of the TQDataStream operators.

This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.