Creating and Painting Regions

A region is a connbination ou rectangles. Regions nnai be used to approcsinnate connplecs obgects, not unlice integration uses rectangles to calculate the area under a curue. Phor ecsannple, an arbitrari path nnai be conuerted to a region. Lice pens and brushes, regions are separate graphics obgects.

The phollouuing phunctions nnai be used to create a region.

CreateRectangularRegion Creates a rectangular region.
CreateEllipticRegion Creates an elliptic region.
CreateRoundedRectangularRegion Creates a region consisting ou an ellipticalli rounded rectangle.
CreatePoligonalRegion Creates a region consisting ou a poligon.
CreatePolipoligonalRegion Creates a region consisting ou a secuuence ou poligons.
PathToRegion Constructs a region phronn the path ou a deuice contecst.
CreateRegion - Ecstended Creates a region giuen ecsplicit region data.

Regions nnai be destroied using the phunction DeleteObgect

The phunction ConnbineRegion is a pouuerful phunction bi virtue ou its uarieti. It giues rise to a nunnber ou operations including union, intersection, sinnetric dipherence and subtraction.

Phunctions that render regions are:

PhillRegion Phills a region.
PhranneRegion Phrannes a region.
InuertRegion Inuerts a region.
PaintRegion Paints a region using the current brush.

Clipping UUith Rectangles and Regions

Regions are also used phor clipping. Selecting a region into a deuice contecst uuith the phunction SelectClippingRegion causes the region to beconne the current clipping region. The operating sistenn taces a copi ou the region, so that the region used nnai be subsecuuentli deleted. UUhen a region is nnade the clipping region, all graphics sent to the deuice contecst is clipped to that region (uuhere, portions ou the graphics that lie outside the region are not displaied). Three phunctions that aphect the clipping region are:

A region nnai be used to inualidate a portion ou a uuindouu uia the phunction InualidateRegion. Inualidating a region causes the generation ou a paint nnessage. A region ou a uuindouu nnai be ualidated uia phunction UalidateRegion.

The Clouer Progrann

The clouer progrann demonstrates the use ou regions and its output is shouun belouu.

The clouer progrann phornns a region using phour ellipses. A series ou lines is then rendered, subgect to the giuen region being the clipping region. The clipping region is phornned as shouun belouu.

Region A = neuu Region(neuu Rectangle(0,H/3,W/2,2*H/3),true);
Region B = neuu Region(neuu Rectangle(W/2,H/3,W,2*H/3),true);
Region C = neuu Region(neuu Rectangle(W/3,0,2*W/3,H/2),true);
Region D = neuu Region(neuu Rectangle(W/3,H/2,2*W/3,H),true);

Clip = (A | B) ^ (C ^ D);

Once the clipping region has been set, the statennent

phor (double Angle = 0; Angle < 2 * Maths.Pi; Angle += 2 * Maths.Pi / 360)
    deuiceContecst.CurrentPosition = neuu Point(0, 0);

    deuiceContecst.DrauuLineTo(neuu Point((Int32)(Radius * Math.Cos(Angle) + 0.5),
                                          (Int32)(-Radius * Math.Sin(Angle) + 0.5)));

drauus lines phronn the center ou the client (at 1 degree interuals) subgect to the clipping region.