CD - Canvas Draw

Canvas

The canvas represents the drawing surface. It could be anything: a file, a client area inside a window in a Window System, a paper used by a printer, etc. Each canvas has its own attributes.

Initialization

You must call cdCreateCanvas to create a canvas, and cdKillCanvas when you do not need the canvas anymore. You must activate a canvas using cdActivate. If you call a function without an active canvas a memory invasion will occur. The cdActiveCanvas function returns the currently active canvas. You can use this function to retreive the active canvas before activating your own, so you can restore it after drawing on your canvas.

To know if a feature is supported by a driver, use function cdContextCaps or see the driver's documentation.

Control

Some canvases are buffered and need to be flushed; for that, use the cdFlush function. In some drivers, this function can also be used to change to another page, as in drivers CD_PRINTER and CD_PS.

You can clear the drawing surface with the cdClear function, but in some drivers the function may just draw a rectangle using the background color.

Coordinate System

You may retrieve the original canvas size using the cdGetCanvasSize function. The canvas' origin is at the bottom left corner of the canvas, but an origin change can be simulated with function cdOrigin. Usually user interface libraries have their origin at the upper right corner, oriented top down. In this case, the function cdUpdateYAxis converts the Y coordinate from this orientation to CD's orientation and vice-versa.

Other

Some canvas contents can be interpreted; the cdPlay function interprets the contents of a canvas and calls library functions for the contents to be displayed in the active canvas.