|Century Embedded Technologies Nano-X SDK and Developer's Guide|
|Prev||Chapter 5. Fundamental Concepts of Nano-X||Next|
When drawing objects such as lines, there are many parameters that can be specified for the function call that affect the operation. Besides the minimum information needed for the function such as the endpoint coordinates, there are extra parameters that are less important and less variable. Examples of these extra parameters are color, width (thin or thick), style (dashed, dotted), and drawing operation (setting, XORing). Instead of requiring the specifying of each of these extra parameters for every function call, graphics contexts are used. Graphics contexts are just a collection of specific combinations of these extra parameters. The many possible extra parameters to each function are replaced by just one extra parameter, which is the graphics context.
For example, instead of a function call like:
drawline(window, x1, y1, x2, y2, color, width, style, operation);
you have instead
drawline(window, gc, x1, y1, x2, y2),
where the graphics context contains within itself the parameters color, width, style, and operation.
Graphics contexts are stored in the graphics server, and are identified by unique numbers in a way similar to window ids. Your program must allocate graphic contexts, which then can be used in drawing functions. A newly allocated graphics context is supplied with default parameters, such as a foreground color of white, drawing operation of setting, and width of 0. You can modify the parameters associated with the graphics context one by one, by for example, setting the foreground color to black.
A single graphics context could be used for every drawing operation by constantly setting the parameters associated with it to the values needed for each drawing call. But this is inefficient. The reason that multiple graphics contexts can be allocated is so that you can minimize the setting of their parameters. By presetting the parameters of several graphics contexts to commonly used values in your program, you can avoid changing them later. For example, you can call one graphics context white_gc, and another graphics context black_gc, and then use the correct graphics context in the drawing functions to draw in either black or white.
The parameters contained within a graphics context are currently the following:
Drawing mode. Specifies the operation performed when drawing each pixel. One of:
GR_MODE_SET draw pixels as given (default) GR_MODE_XOR draw pixels using XOR GR_MODE_OR draw pixels using OR GR_MODE_AND draw pixels using AND
Text font. A small integer identifying the font for drawing text. The first few are built-in to the device driver, others must be loaded by the graphics server. The default font is 0.
Foreground color. The color that is used to draw almost all objects with, such as lines, points, ellipses, text, bitmaps, and filled areas. Default is white.
Background color. The color used for some functions in addition to the foreground color. For bitmaps and text, this is the color used for the zero bits. The default background color is black. The drawing of this color can be disabled by the next parameter.
UseBackground flag. This is a boolean value which indicates whether or not the background color is actually to be drawn for bitmaps, text, and the GrArea8 function. The default is GR_TRUE.