Function GraSetColor() Foundation

Determines default colors for all graphic functions.

Syntax
GraSetColor( [<oPS>], ;
             [<nForeground>], [<nBackground>] ) --> aOldColor
Parameters
<oPS>
The argument <oPS> specifies the presentation space where the foreground and background colors are set. If the current window is an XbpCrt window, <oPS>is optional. If it is NIL, the return value of SetAppWindow():presSpace() is used. In all other cases <oPS> is not optional. It must be created either using XbpPresSpace():new() or a "Micro PS" must be requested from an Xbase Part using the method:lockPS(). After graphic output the Micro PS must be released with :unlockPS().
<nForeground>
<nForeground> is a numeric value which determines the foreground color for all graphic functions (Gra..() functions) which support a foreground color. Symbolic constants are defined in the #include file GRA.CH for use in specifying various colors for <nForeground>. Constants for colors all begin with GRA_CLR_.
<nBackground>
<nBackground> is a numeric value which determines the background color for all graphic functions which support a background color.
Return

The function GraSetColor() returns an array containing the currently set foreground and background colors { nForegroundColor, nBackgroundColor }. If new colors are specified, the function returns an array containing the previous colors.

Description

The function GraSetColor() determines the colors for all graphic primitives. In contrast to the function SetColor(), a numeric value is specified for the foreground and/or background with GraSetColor(). SetColor() defines colors for the VIO- or hybrid mode. For output using the graphic function in the hybrid or GUI mode, the color must be set using GraSetColor(). The function SetColor() has no effect on graphic functions.

The following table lists #define constants used to set the foreground and/or background colors:

#define constants for colors with Gra functions
Constant Color
GRA_CLR_WHITE White
GRA_CLR_BLACK Black
GRA_CLR_BLUE Blue
GRA_CLR_RED Red
GRA_CLR_PINK Pink
GRA_CLR_GREEN Green
GRA_CLR_CYAN Cyan
GRA_CLR_YELLOW Yellow
GRA_CLR_DARKGRAY Dark gray
GRA_CLR_DARKBLUE Dark blue
GRA_CLR_DARKRED Dark red
GRA_CLR_DARKPINK Dark pink
GRA_CLR_DARKGREEN Dark green
GRA_CLR_DARKCYAN Dark cyan
GRA_CLR_BROWN Dark brown
GRA_CLR_PALEGRAY Pale gray
GRA_CLR_BACKGROUND Background color of the presentation space
GRA_CLR_NEUTRAL Contrast color to GRA_CLR_BACKGROUND

Instead of #define constants listed in the table, a RGB color value may be used to define a color for graphic primitives. RGB colors are calculated by the function GraMakeRGBColor(). Note, however, that the display of RGB colors is hardware dependent. The color definition via #define constants is hardware independent.

GraSetColor() defines the colors for the display of all graphic primitives. Any colors defined for specific graphic primitives before the call to GraSetColor() are removed.

The foreground color is the color used when drawing lines with graphic primitives. The background color is only visible when the color mix attribute has been changed for the background color (when it has a value other than GRA_BGMIX_LEAVEALONE).

If areas are filled with a pattern, the lines of the fill pattern are output in the foreground color and the space in between is in the background color. For characters, the character cell (GRA_AS_BOX) is output in the background color and the character itself in the foreground color. The exception is outline fonts where a character is drawn only as an outline. The areas within a character using such fonts are displayed in the background color.

Examples
Sets colors for graphic output
// The example program demonstrates the use of the function 
// GraSetColor() and illustrates the effect of the color mix attribute. 
// Two squares and two circles are drawn in different colors. 
// The intersecting areas of circle and square receive their own colors 
// on the basis of the mix attribute. 

#include "Gra.ch" 

PROCEDURE Main 
   LOCAL aAttr 

   aAttr := Array( GRA_AA_COUNT ) 
   aAttr[ GRA_AA_SYMBOL ]    := GRA_SYM_DIAG1 // intersecting areas 
   aAttr[ GRA_AA_MIXMODE ]   := GRA_FGMIX_OR  // are enhanced 
   aAttr[ GRA_AA_BGMIXMODE ] := GRA_BGMIX_OVERPAINT 
   GraSetAttrArea( NIL, aAttr ) 
                                              // color: red/blue 
   GraSetColor( NIL, GRA_CLR_RED, GRA_CLR_BLUE ) 
                                              // draw circle 
   GraArc( NIL, { 145,215}, 65,,,, GRA_OUTLINEFILL ) 

   aAttr[ GRA_AA_SYMBOL ] := GRA_SYM_DIAG3 
   GraSetAttrArea( NIL, aAttr ) 
                                              // color: yellow/brown 
   GraSetColor( NIL, GRA_CLR_YELLOW, GRA_CLR_BROWN ) 
                                              // draw square 
   GraBox( NIL, { 90,160}, {200,270}, GRA_OUTLINEFILL ) 

   aAttr[ GRA_AA_SYMBOL ] := GRA_SYM_DIAG1 
   GraSetAttrArea( NIL, aAttr) 
                                              // color: green/red 
   GraSetColor( NIL, GRA_CLR_GREEN, GRA_CLR_RED ) 
                                              // draw circle 
   GraArc( NIL, {440,215}, 110,,,, GRA_OUTLINEFILL ) 

   aAttr[ GRA_AA_SYMBOL ] := GRA_SYM_DIAG3 
   GraSetAttrArea( NIL, aAttr ) 
                                              // color: yellow/blue 
   GraSetColor( NIL, GRA_CLR_YELLOW, GRA_CLR_BLUE ) 
                                              // draw square 
   GraBox( NIL, {350,120}, {530,310}, GRA_OUTLINEFILL ) 

   Inkey(0) 

RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.