Presentation graphics also maintains a pool of “fill patterns” that determine the fill design for column, bar, and pie charts. The third member of the palette structure holds the fill pattern. The pattern member is an array:
_fillmap fill;
where _fillmap is type-defined as
typedef unsigned char _fillmap[8];
Each fill pattern array holds an 8-by-8 bit map that defines the fill pattern for the data series associated with the palette. Table 10.3 shows how a fill pattern of diagonal stripes is created with the fill pattern array.
The bit map in Table 10.3 corresponds to screen pixels. Each of the eight layers of the map is a binary number, where a solid circle signifies 1 and an open circle signifies 0. Thus the first layer of the map—that is, the first byte—represents the binary number 10011001, which is the decimal number 153.
Table 10.3 Fill Patterns
Bit Map | Value in Fill |
1 0 0 1 1 0 0 l | fill[0] = 153 |
1 1 0 0 1 1 0 0 | fill[1] = 204 |
0 1 1 0 0 1 1 0 | fill[2] = 102 |
0 0 1 1 0 0 1 l | fill[3] = 51 |
1 0 0 1 1 0 0 l | fill[4] = 153 |
1 1 0 0 1 1 0 0 | fill[5] = 204 |
0 1 1 0 0 1 1 0 | fill[6] = 102 |
0 0 1 1 0 0 1 l | fill[7] = 51 |
For example, if you want to create the pattern in Table 10.3 for your chart's first data series, you must reset the fill array for the first palette structure. You can do this in five steps:
1.Declare a structure of type _palettetype to hold the palette parameters.
2.Call _pg_initchart to initialize the palettes with default values.
3.Call the presentation graphics function _pg_getpalette to retrieve a copy of the current palette data.
4.Assign the values given in Table 10.3 to the array fill for the first palette.
5.Call the presentation graphics function _pg_setpalette to load the modified palette values.
The following lines of code demonstrate these five steps:
/* Declare a structure array for palette data. */
_palettetype palette_struct;
.
.
.
/* Initialize chart library */
.
.
.
/* Copy current palette data into palette_struct */
_pg_getpalette( palette_struct );
/* Reinitialize fill pattern for first palette using
values in Table 10.3 */
palette_struct[1].fill[0] = 153;
palette_struct[1].fill[1] = 204;
palette_struct[1].fill[2] = 102;
palette_struct[1].fill[3] = 51;
palette_struct[1].fill[4] = 153;
palette_struct[1].fill[5] = 204;
palette_struct[1].fill[6] = 102;
palette_struct[1].fill[7] = 51;
/* Load new palette data */
_pg_setpalette( palette_struct );
Now when you display your bar or column chart, the first series appears filled with the striped pattern shown in Table 10.3.
Palette structures are used differently with pie charts. Instead of clarifying multiple series, fill patterns, line styles, and colors, palette structures are used to distinguish individual slices in a pie chart. Palettes are recycled if the number of slices exceeds _PG_PALETTELEN. Thus, the first palette dictates not only the appearance of the first slice, but of slice number _PG_PALETTELEN as well. The second palette determines the appearance of both the second slice and of slice number _PG_PALETTELEN + 1, and so forth.