Functions and Directives

Function GraMakeRGBColor() Foundation

Calculates a RGB color value from color intensities of red, green and blue.

GraMakeRGBColor( <aRGB> ) --> nRGBColor | NIL
<aRGB> := { nRed, nGreen, nBlue }
<aRGB> is an array containing three elements that are numeric values indicating the intensity of the colors red, green, and blue. The intensity of each of these colors is defined by integer values between 0 and 255.

The function returns a numeric value or NIL if an illegal parameter is passed.


The function calculates a RGB color value using the intensities for the three individual colors red, green and blue. Instead of using GRA_CLR_* #define constants for color selection, the return value of GraMakeRGBColor() can be used to define a color for graphic primitives or Xbase Parts.

Whether or not a RGB color can be displayed is hardware dependent. If a graphics card is restricted to 8-bit color depth, for example, a RGB value is mapped to the colors available on the device using a "best fit" algorithm. This can lead to the situation where the displayed color differs from the requested color. To achieve the exact color for display in this case, the desired color must be defined using the :setColorIndex() method of a presentation space.

Defining a RGB color
// The example demonstrates how a special color can be used 
// depending on the available color depth. 

#include "" 

   LOCAL aRGB := {0,0,102} // RGB color = Alaska Software Blue 
   LOCAL oPS, nBlue 

   SetColor( "N/W") 
   SetAppWindow():useShortCuts := .T. 

   oPS := SetAppWindow():presSpace() 

   IF oPS:maxColorIndex( .F. ) == 0 
      // 16-bit color depth or better 
      // The Alaska Software Blue is available 
      nBlue := GraMakeRGBColor( aRGB ) 
      // Test if color is available in the color palette 
      nBlue := oPS:mapColor( aRGB, .T. ) 

      IF nBlue == NIL 
         // Color is not available in the color palette. 
         // Create this color at position 16 
         nBlue := 16 
         oPS:setColorIndex( nBlue, aRGB ) 

   GraSetColor( oPS, GRA_CLR_BLUE ) 
   GraStringAt( oPS, { 10, 250 }, "Alaska Software" ) 

   GraSetColor( oPS, nBlue ) 
   GraStringAt( oPS, { 10, 200 }, "Alaska Software" ) 


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.