NShape Concepts

Drawing a Shape

<< Click to Display Table of Contents >>

Navigation:  Concepts > Shapes >

NShape Concepts

Drawing a Shape

Previous pageReturn to chapter overviewNext page

Multiple steps are involved until a shape can be drawn via its Draw method, at least if the shape derives from ShapeBase, which is the normal case. ShapeBase drawing is based on a draw cache, which stores a drawable representation of the shape in its current layout, i.e. with its current position, size, rotation angle etc. When anything about those property changes, the draw cache must be invalidated and recalculated. ShapeBase itself does not implement the draw cache because this storage must be optimized for the actual way the shape is to be drawn. For example, PathBasedPlanarShape uses a Path object as its draw cache, while LinearShapeBase contains an array of Points. ImageBasedShape uses yet an other draw cache implementation.

In order to support the draw cache management, ShapeBase defines abstract methods that must be implemented in the concrete classes:

RecalcDrawCache performs the actual recalculation of the draw cache, e.g. the recalculation of points for a LinearShapeBase or the recalculation of the Path in path based shapes. This method creates the form of the shape taking size, colors etc into account but neglecting position and rotation.

TransformDrawCache applies a matrix transformation on the draw cache to move the shape to the correct position and display it with the correct angle.

InvalidateDrawCache makes the draw cache invalid, i.e. it must be recalculated before it can be used the next time. E.g. when the shape is resized or moved, the draw cache must be invalidated.

UpdateDrawCache makes sure the draw cache is up-to-date.

Draw uses the draw cache and paint it to the drawing surface.