Graphics contexts are created by sending the createGC:values: message to a
CgDrawable. The GC attributes are initialized to preset values, listed in
Table 16. The two arguments of the message specify modifications to the preset values. The first argument,
valuemask, specifies which components of the second argument,
values, should override the preset values.
In the following example, a CgGCValues object is created, the
function: message sets the desired raster operation (
GXhighlight), and the
lineWidth: message sets a line width value (2 pixels) in the
CgGCValues object. The
CgGCValues object is then passed to the drawable using the
createGC:values: message. The valuemasks
GCFunction and
GCLineWidth are ORed together to create a mask that identifies which attributes are being modified. The
gcValues variable contains the new values for the attributes.
You can also use a CgGCValues object to retrieve attribute values from a graphics context. In the following example, the
GCLineWidth valuemask is used to retrieve the current line width. The information is returned in a new
CgGCValues object.
Table 16 contains the complete list of attributes that can be initialized or modified. In most cases, the attribute is either an integer value or a constant from the
CgConstants pool dictionary. For a detailed explanation, consult the method comment for the
createGC:values: method of
CgDrawable.