Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]


How to draw polylines and polygons

The example code shown here demonstrates how to:

The example code assumes the array of points used when drawing these shapes is defined as follows:

...
// set up an array of points for drawing a polyline and a polygon etc.
// will be used relative to top left of rectangle
TPoint point1(20,20);
TPoint point2(100,190);
TPoint point3(110,90);
TPoint point4(50,150);
TPoint point5(200,150);
CArrayFix<TPoint>* mypoints = new CArrayFixFlat<TPoint>(5);
CleanupStack::PushL(mypoints);
mypoints->AppendL(point1);
mypoints->AppendL(point2);
mypoints->AppendL(point3);
mypoints->AppendL(point4);
mypoints->AppendL(point5);
...
// switch statement with example cases
...
CleanupStack::PopAndDestroy(); // mypoints

[Top]


Drawing a polyline

You can draw a polyline using DrawPolyLine() from an array of points.

...
// draw a polyline
gc.DrawPolyLine(mypoints);
...

[Top]


Drawing a polygon

The following example code illustrates how to draw a filled polygon from an array of points. The polygon is self-crossing. Self-crossing polygons can be filled according to one of two rules, TFillRule::EAlternate (the default), or TFillRule::EWinding. These rules work with the concept of a winding number, as shown in the following figure:

Winding numbers


Winding numbers

EWinding fills all areas, while EAlternate only fills areas with odd winding numbers.


Drawing a polygon using the EWinding fill rule

  1. Use SetBrushStyle() to set a cross-hatched brush style.

  2. Use DrawPolygon() to draw the polygon with the EWinding fill rule.

...
// draw self-crossing polygon using the winding fill rule
gc.SetBrushStyle(CGraphicsContext::ESquareCrossHatchBrush);
gc.SetBrushColor(black);
gc.DrawPolygon(mypoints,CGraphicsContext::EWinding);
...

Drawing a polygon using the EAlternate fill rule

  1. Use SetBrushStyle() to set a diamond cross-hatched brush style.

  2. Use DrawPolygon() to draw the polygon with the EAlternate fill rule.

...
// draw self-crossing polygon using the alternate fill rule
gc.SetBrushStyle(CGraphicsContext::EDiamondCrossHatchBrush);
gc.SetBrushColor(black);
gc.DrawPolygon(mypoints,CGraphicsContext::EAlternate);
...