Shape Operations

A graphics context provides line and shape drawing graphics operations for points, lines, and fillable shapes.

Lines

There are three line primitives - straight line, polyline and arc. These are drawn with the pen, with all its current settings. Straight lines can be drawn between two given points, to a single given point from the current internal drawing position, or by moving the internal drawing position by a given vector. They are constructed with the help of a linear DDA.

Fillable shapes

There are five shape drawing primitives - pie slice, ellipse, rectangle, rounded rectangle, and polygon. All may be drawn with or without an outline.

Outlines are drawn with the pen, and thus subject to pen color, pen size and pen style settings. The effective outline color depends on the drawing mode. If the pen size has been set to greater than or equal to half the size of the shape, then the shape will be filled with solid pen color. The pen style should be set to null if no outline is required.

Shapes are filled using the brush, and thus subject to the brush style (color, hash or pattern) and brush pattern origin. The effective fill color depends on the drawing mode. The brush style should be set to null if no fill is required.

Pen size

Note that when the pen is a single pixel wide:

  • There is a guarantee that each pixel will be written only once on the display. This allows shapes to be drawn in exclusive-or mode, without the risk that multiple writes will cancel each other out.

  • When straight lines are drawn, their last point is not included. This allows a polyline to be constructed without the pixels at the joins being written twice. The single write guarantee can thus be maintained for multiple consecutive primitives. However, the last point of an arc is always drawn.

If the pen size is greater than one pixel, a straight line is drawn as a rectangular shaped region of pixels, with rounded ends that extend beyond the start and end points. See CGraphicsContext::SetPenSize() for details.

Rectangles

All the fillable shape drawing primitives, (except DrawPolygon() ), either use a rectangle directly or to define the position of an ellipse that is used in the construction of the shape. This rectangle is passed as an argument of type TRect .

Care is needed when specifying rectangles. The TRect class is defined to include the pixel at its top left corner, but to exclude the pixel at its bottom right corner. Thus, a rectangle specified as:

       
        
       
       TRect(TPoint(100,50),TPoint(300,150))
      

includes the point (100,50) but not the point (300,150). No pixels will be written to column 300, nor to row 150, on the display. The rectangle drawn on the screen will be 300-100=200 pixels wide, and 150-50=100 pixels high.

Ellipses

Ellipses whose axes are aligned with the x and y axes of the co-ordinate system, are supported; other ellipses are not. Ellipses are defined with reference to their bounding rectangle. The comments above on the behavior of TRect also need to be observed when drawing ellipses. Arcs, pie slices and the corners of rounded rectangles are all defined as sections of an ellipse.