Function GraMakeRGBColor() Foundation

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

Syntax
GraMakeRGBColor( <aRGB> ) --> nRGBColor | NIL
Parameters
<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.
Return

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

Description

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.

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

#include "Gra.ch" 

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

   SetColor( "N/W") 
   CLS 
   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 ) 
   ELSE 
      // 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 ) 
      ENDIF 
   ENDIF 

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

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

   WAIT 
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.