[GRASS5] New display color code summary

Cedric Shock cedricgrass at shockfamily.net
Tue Apr 18 12:51:00 EDT 2006


> > I added some more D_ commands to make working with colors easier and
> > eliminate the need for including colors.h and working with MAXCOLORS
> > in display modules. I've updated a couple modules to use this
> > simplified code.
> > These modules also now have gisprompts for color.
> Please post summaries of such changes to grass5 as it's hard to keep up
> with, understand, and vet all changes in CVS. I'm going to try and
> finish the symbol plotting function(s) in the next few days, no point in
> doing things twice or "the old way".

The "new way" isn't very much different from the "old way". Colors are still 
being handled as integers, not as RGB structures, but the programmer can 
ignore the gritty details of this.

1. On options for colors do not use, for example:
optfgcolor->options   = D_list_colors() ;  /* Don't use this anymore */
Instead use a color gisprompt:
optfgcolor->gisprompt = GISPROMPT_COLOR ;
It's a good idea to specify the default too:
optfgcolor->answer    = DEFAULT_FG_COLOR ;

2. Use D_parse_color to interpret these options. The second argument is 0 if 
none is not an acceptable color, 1 if it is.

int fgcolor, bgcolor;
bgcolor = D_parse_color (optbgcolor->answer, 1);
fgcolor = D_parse_color (optfgcolor->answer, 0);

This command will G_fatal_error if the color is no good.

3. Use D_raster_use_color to select colors for drawing. It returns false if 
the color can't be drawn with, such as "none". (This replaces use of R_color 
and R_standard_color). 

if (D_raster_use_color (bgcolor) ) {
    R_box_abs(...) ;

D_raster_use_color (fgcolor) ;

R_polyline_rel (...

4. Remove colors.h from the included files. This will help make sure the code 
is cleaner.


More information about the grass-dev mailing list