Accounting Software
Small Business Software Estimating Software
Project Management SoftwareProject Estimating SoftwareProject Tracking SoftwareInventory Tracking SoftwareCustomer Tracking SoftwareCustomer Management SoftwareBusiness Management Software

Color Palette (Source Code)

Link to: header | other interface directory

Copyright Turtle Creek Software 1996-2006. All Rights Reserved.

Comments

TCS_ColorPalette

This class manages color palettes for the
Goldenseal small business estimating software,
project management software, construction estimating software
and construction software.

It's a class for implementing a color palette. This is not a view for displaying
the palette, it is just a wrapper for the palette data.

Related class-- CColorPickerPane is the pane with color blocks to choose from

Constructor

/*********************************************************************************
default constructor
*********************************************************************************/
CTCS_ColorPalette::CTCS_ColorPalette()
{
mPalette = nil;
mOwnsPalette = false;
}
/*********************************************************************************
destructor
*********************************************************************************/
CTCS_ColorPalette::~CTCS_ColorPalette()
{
DisposeIfOwnsPalette();
}

Source Code

/*********************************************************************************

LoadAppropriatePalette

load in a palette for the current depth, and return the depth as well

*********************************************************************************/
void CTCS_ColorPalette::LoadAppropriatePalette(CTCS_ColorPalette *palette)
{
switch (CTCS_Environment::ScreenDepth())
{
case 1:
// clear the palette, leaving b&w
palette->Clear();

case 2:
case 3:
palette->LoadFromResource(/*cPalette4*/2);
break;

case 4:
case 5:
case 6:
case 7:
palette->LoadFromResource(/*cPalette16*/4);
break;

default:
palette->LoadFromResource(/*cPalette256*/8);
break;
}
}
/*********************************************************************************

LoadFromResource

load in the palette from a resource

*********************************************************************************/
void CTCS_ColorPalette::LoadFromResource(const ResIDT resID)
{
#if TCS_CANUSE_QUICKTIME
DisposeIfOwnsPalette();
mPalette = ::GetCTable(resID);
TCS_FailNILMsg(mPalette, TCS_GetErrString(errID_BadWindow));
mOwnsPalette = true;
#else
NeoUsed(resID);
TCS_NYI("CTCS_ColorPalette::LoadFromResource");
#endif
}
/*********************************************************************************

DisposeIfOwnsPalette

dispose the palette, if we own it

*********************************************************************************/
void CTCS_ColorPalette::DisposeIfOwnsPalette()
{
if (mOwnsPalette && mPalette)
{
#if TCS_CANUSE_QUICKTIME
::DisposeCTable(mPalette);
#endif
mPalette = nil;
}
}
/*********************************************************************************

SetPaletteHandle

set this palette's handle to the given palette handle

*********************************************************************************/
void CTCS_ColorPalette::SetPaletteHandle(const TCS_PaletteHandle aPalette,
Boolean ownsPalette)
{
mPalette = aPalette;
mOwnsPalette = ownsPalette;
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************

GetColorCount

return the number of colors in the palette

*********************************************************************************/
UInt32 CTCS_ColorPalette::GetColorCount() const
{
#if TCS_CANUSE_QUICKTIME
return mPalette ?(**mPalette).ctSize+1 : 0;
#else
TCS_NYI("CTCS_ColorPalette::GetColorCount");
return 0;
#endif
}
/*********************************************************************************

GetNthColor

return the nth color in the palette. If the palette has not been
initialized or the color is out of range, this returns white.
Note that index is a 1-based index, wherease the Mac ColorTable
structure index is zero-based (a C array)

*********************************************************************************/
void CTCS_ColorPalette::GetNthColor(const UInt32 index,
CTCS_RGBColor *inColor) const
{
TCS_FailNILMsg(inColor, TCS_GetErrString(errID_BadPane));

#if TCS_CANUSE_QUICKTIME
if ((!mPalette) || ((index-1) >(**mPalette).ctSize) || (index <= 0) )
{
*inColor = CTCS_RGBColor::GetWhiteColor();
}
else
*inColor = (**mPalette).ctTable[index-1].rgb;
#else
NeoUsed(index);
NeoUsed(inColor);
TCS_NYI("CTCS_ColorPalette::GetNthColor");
#endif
}