Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Grumpfish Library 3.2 - <b>colorpal()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
COLORPAL()

    Allowing users the flexibility to select their own color
    combinations is an important plus.  There are undoubtedly many ways
    to implement such a feature, most of them quite cumbersome both for
    you and your users.  To simplify matters, I offer you COLORPAL(),
    the interactive color palette that is as easy to implement as it is
    to use.

    Syntax

    COLORPAL([<start color>] [, <top>] [, <left>], [, <redraw>][, <egavga>])

    Required Parameters

    None

    Optional Parameter

    <start color> is a character string representing the initial color
    combination to highlight on the palette.  For example, if you wanted
    to start off with bright white on magenta as the highlighted color,
    you would call "Colorpal('W+/BR')". Important Caveat: if you choose
    to pass this parameter, you must adhere to the following color
    naming conventions:

    - magenta must be "BR" rather than "RB";
    - cyan must be "BG" rather than "GB"; and
    - the plus sign (+) for high intensity foreground colors must follow
      the letters rather than precede them (e.g., "W+" and "BR+" instead
      of "+W" and "+BR").

    If this parameter is not passed, the initial color will match the
    current color setting.

    <top> is a numeric expression representing the row at which to begin
    displaying the color palette.  You may pass any value between 6 and
    16.  If you do not use this parameter, the default will be row 16.

    <left> is a numeric expression representing the leftmost at which to
    begin displaying the color palette.  You may pass any value between
    0 and 64.  If you do not use this parameter, the default will be
    column 64.

    <redraw> is a character string that holds the name of a User-Defined
    Function that you have written to redraw a specific object(s) each time
    the user changes colors in the palette.  If you pass this parameter,
    your UDF will be called each time the color is changed.  Please see the
    example below for an illustration of how you may wish to write such a
    function.  If you do not use this parameter, COLORPAL() will display a
    small box containing a sample of the current color.  This box will be
    redrawn each time the user changes the color.  I felt that it was
    redundant to provide this color sample if you are using a custom redraw
    function.

    Note: if you pass the <redraw> parameter, COLORPAL() will save the
    entire screen and restore it upon exit.  If you do not pass this
    parameter, COLORPAL() will only save the area covered by the palette
    and sample color box.

    <egavga> is a parameter of any type.  If you pass this parameter,
    COLORPAL() will assume that you want to use EGA/VGA enhanced
    background colors and, accordingly, will turn off the blink bit to
    enable these colors.  Do not pass this parameter if you do not
    want to use enhanced background colors.  Bear in mind that if you
    use <egavga>, COLORPAL() will not reset the blinkbit!  If you
    need to do this, you can call BlinkBit(.T.) at the exit point of
    your program.  (Summer '87 version only -- see below)

    Return Value

    COLORPAL() returns a character string representing the last color
    shown on the color palette.  However, if Esc is pressed to exit
    the palette, the return value will be the color setting that was
    in effect prior to calling COLORPAL().

    COLORPAL() allows you to change colors by pressing arrow keys.  When
    you have arrived at the desired color, press Enter to select it. You
    may escape at any time by pressing the Esc key.  If you press Esc,
    however, the return value will be the same as the previous color
    setting.  Therefore, if the standard color setting was white on blue
    when you called COLORPAL(), pressing Esc will return the string 'W/B'.

    EGA/VGA support

    EGA/VGA monitors allow you to toggle the blink bit on and off.  If
    it is on, you can display blinking colors.  If it is off, you can
    display enhanced background colors (such as a dazzling bright yellow).

    COLORPAL() directly supports enhanced EGA/VGA background colors.  If
    you are using an EGA/VGA, COLORPAL() will detect this automatically
    and switch to enhanced background colors (thus disabling blinking).  It
    will then display 256 color combinations instead of 128, to accommodate
    for the additional possibilities presented by the enhanced background
    colors. Try it, you'll love it!

    Example

    SETCOLOR('+W/B')                                     
    IF YES_NO('Would you like to change the main color') 
       newcolor = COLORPAL(SETCOLOR(), 6, 64, 'redraw()')
       SETCOLOR(newcolor)                                
    ENDIF                                                
                                                         
    FUNCTION redraw                                      
    @ 0, 0, 24, 79 BOX REPLICATE(CHR(178), 80)           
    RETURN .T.                                           

    Usage Tips

    To avoid having to redraw the palette each time COLORPAL() is
    called, you may wish to save the palette variable to a memory (.mem)
    file and restoring it each time you run your program.  This will
    save time over redrawing the palette each time COLORPAL() is called.
    If you wish to do this, add the following line of code after line
    62: "SAVE ALL LIKE thepalette TO colors".  Thus, you could add the
    line "RESTORE FROM colors ADDITIVE" at the top of your program to
    keep the palette from having to be redrawn.

    Clipper 5.0 Notes

    - The palette variable is now STATIC, which circumvents the need for
      a .MEM file.
    - You may pass a code block as the <redraw> parameter, which opens
      up an interesting new set of possibilities.
    - EGAVGA() support is totally transparent, thanks to the new Clipper
      native function SETBLINK().  You do not need to pass the <egavga>
      parameter when using 5.0.

See Also: POPCALC() POPSTOP() COLORMOD()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson