Sources/ColorPicker.cp

/*
    File:       ColorPicker.cp
 
    Contains:   TColorPicker is a simple color picker utility class 
                TColorPicker.cp contains the TColorPicker member function definitions. 
 
    Written by: Kent Sandvik    
 
    Copyright:  Copyright © 1993-1999 by Apple Computer, Inc., All Rights Reserved.
 
                You may incorporate this Apple sample source code into your program(s) without
                restriction. This Apple sample source code has been provided "AS IS" and the
                responsibility for its operation is yours. You are not permitted to redistribute
                this Apple sample source code as "Apple sample source code" after having made
                changes. If you're going to re-distribute the source, we require that you make
                it clear in the source that the code was descended from Apple sample source
                code, but that you've made changes.
 
    Change History (most recent first):
                8/18/1999   Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
                
 
*/
#ifndef _COLORPICKER_
#include "ColorPicker.h"
#endif
 
// CONSTRUCTORS AND DESTRUCTORS
#pragma segment Color
TColorPicker::TColorPicker(Boolean keepTrack)
{
    fKeepTrack = keepTrack;
 
    // define the starting color scheme as white (arbitrary selection)
    fInitialColor.red = fInitialColor.green = fInitialColor.blue = 0xFFFF;
 
    // Define the dialog point for the color picker, default setting.
    // Note that -1,-1 indicates that the color picker will be placed on what
    // the picker considers to be the best screen, optimizing depth and color.
    // In addition, it centers the dialog box nicely. If you want to change this, change
    // the lines, but I wouldn't :-).
    fDialogPoint.v = -1;
    fDialogPoint.h = -1;
}
 
 
#pragma segment Color
TColorPicker::~TColorPicker()
// Default constructor -- empty for the time being.
{
}
 
 
// MAIN INTERFACE
#pragma segment Color
Boolean TColorPicker::Select(Str255 string)
// Select a color from the picker.
{
    Boolean result = ::GetColor(fDialogPoint, string, &fInitialColor, &fSelectedColor);
    if (fKeepTrack && result)                   // we want to keep track of selected color?
        fInitialColor = fSelectedColor;         // then save it for later use
    return result;
}
 
 
#pragma segment Color
void TColorPicker::Reset()
// Reset any initial color setting to 'white'.
{
    fInitialColor.red = fInitialColor.green = fInitialColor.blue = 0xFFFF;
}
 
 
#pragma segment Color
RGBColor TColorPicker::GetSelectedColor() const
// Return the selected color.
{
    return fSelectedColor;
}
 
 
#pragma segment Color
CMYColor TColorPicker::GetSelectedCMYColor()
// Return the selected color in CMY values.
{
    CMYColor temp;
    ::RGB2CMY(&fSelectedColor, &temp);
 
    return temp;
}
 
 
#pragma segment Color
HSLColor TColorPicker::GetSelectedHSLColor()
// Return the selected color in HSL values.
{
    HSLColor temp;
    ::RGB2HSL(&fSelectedColor, &temp);
 
    return temp;
}
 
 
#pragma segment Color
HSVColor TColorPicker::GetSelectedHSVColor()
// Return the selected color in HSV values.
{
    HSVColor temp;
    ::RGB2HSV(&fSelectedColor, &temp);
 
    return temp;
}
 
// _________________________________________________________________________________________________________ //
 
/*  Change History (most recent last):
  No        Init.   Date        Comment
  1         khs     1/3/93      New file
  2         khs     1/5/93      Cleanup
*/