The drawing area (CwDrawingArea) widget provides an application with an area in which application-defined graphics can be drawn using Common Graphics operations such as
fillRectangle:,
drawArc:, and
drawString:. Consult the Common Graphics chapter for an explanation of drawing and other graphics operations.
Drawing is actually done on the CgWindow associated with the
CwDrawingArea. Every
CwWidget has a corresponding
CgWindow, obtained by sending
window to a widget, that can be used for drawing. Although any widget can be drawn on in this manner,
CwDrawingArea widgets are typically used because they provide additional drawing-related functionality. Create
CwDrawingArea widgets using the
createDrawingArea:argBlock: convenience method.
A CwDrawingArea can be told to notify the application with an
expose callback whenever a part of the drawing area needs to be redrawn. The expose callback contains an expose event with a rectangle describing the damaged area of the widget's
CgWindow.
The resize callback is called when the drawing area changes size, usually due to a change in the size of a parent widget. If an expose callback is triggered as a result of a resize, the resize callback is always sent before the expose callback. It is possible for the resize callback to be run before the window has been realized. The resize callback handler should handle the case where the
window message returns
nil.
The input callback is called when a mouse button is pressed or released inside the widget or a key on the keyboard has been pressed or released. The
destroy callback, run when the widget is about to be destroyed, is a good place to free any graphics resources that have been allocated for drawing.