Sleipnir
Public Member Functions | Static Public Member Functions | Static Public Attributes
Sleipnir::CColor Class Reference

Simple representation of a color triple in RGB space. More...

#include <color.h>

Inheritance diagram for Sleipnir::CColor:
Sleipnir::CColorImpl

Public Member Functions

 CColor (const unsigned char *abRGB)
 Construct a new color with the given red, green, and blue values.
 CColor (unsigned char bRed, unsigned char bGreen, unsigned char bBlue)
 Construct a new color with the given red, green, and blue values.
CColor operator+ (const CColor &Color) const
 Blend two colors equally.
CColor operator* (float dValue) const
 Scale the current color by the requested amount.
CColoroperator= (const CColor &Color)
 Copies the given color into the current color.
std::string ToRGB () const
 Constructs a standard hexadecimal string encoding the current color.
bool IsDark () const
 Returns true if the current color is dark enough to warrant a light foreground.

Static Public Member Functions

static CColor Interpolate (float dValue, const CColor &ColorMinimum, const CColor &ColorMedium, const CColor &ColorMaximum)
 Given a fractional value, interpolate between three colors.

Static Public Attributes

static const CColor c_Black = CColor( 0x00, 0x00, 0x00 )
 Black.
static const CColor c_Cyan = CColor( 0x00, 0xFF, 0xFF )
 Cyan.
static const CColor c_Green = CColor( 0x00, 0xFF, 0x00 )
 Green.
static const CColor c_Red = CColor( 0xFF, 0x00, 0x00 )
 Red.
static const CColor c_White = CColor( 0xFF, 0xFF, 0xFF )
 White.
static const CColor c_Yellow = CColor( 0xFF, 0xFF, 0x00 )
 Yellow.
static const CColor c_Blue = CColor( 0x00, 0x00, 0xFF )
static const CColor c_DarkGreen = CColor( 0x00, 0x64, 0x00 )
static const CColor c_Orange = CColor( 0xFF, 0xA5, 0x00 )

Detailed Description

Simple representation of a color triple in RGB space.

Definition at line 33 of file color.h.


Constructor & Destructor Documentation

Sleipnir::CColor::CColor ( const unsigned char *  abRGB)

Construct a new color with the given red, green, and blue values.

Parameters:
abRGBArray of three bytes representing red, green, and blue values between 0 and 255.

Definition at line 89 of file color.cpp.

Referenced by operator*(), and operator+().

Sleipnir::CColor::CColor ( unsigned char  bRed,
unsigned char  bGreen,
unsigned char  bBlue 
)

Construct a new color with the given red, green, and blue values.

Parameters:
bRedRed value between 0 and 255.
bGreenGreen value between 0 and 255.
bBlueBlue value between 0 and 255.

Definition at line 108 of file color.cpp.


Member Function Documentation

CColor Sleipnir::CColor::Interpolate ( float  dValue,
const CColor ColorMinimum,
const CColor ColorMedium,
const CColor ColorMaximum 
) [static]

Given a fractional value, interpolate between three colors.

Parameters:
dValueFractional value between 0 and 1.
ColorMinimumMinimum color (corresponding to value zero).
ColorMediumMidpoint color (corresponding to value 0.5).
ColorMaximumMaximum color (corresponding to value one).
Returns:
A new color blending the minimum/midpoint or midpoint/maximum.

Blend continuously between three colors given a value between 0 and 1. Given 0, the minimum color is returned. Given 0.5, the midpoint color is returned. Between 0 and 0.5, the minimum and midpoint colors are mixed; between 0.5 and 1, the midpoint and maximum colors are mixed. Given 1, the maximum color is returned.

Definition at line 63 of file color.cpp.

Referenced by Sleipnir::CDat::SaveDOT().

bool Sleipnir::CColor::IsDark ( ) const

Returns true if the current color is dark enough to warrant a light foreground.

Returns:
True if the current color is perceptibly dark.

If this method returns true, it is generally safe to assume that the current color is dark enough to warrant a white foreground; if it returns false, a black foreground is appropriate. This calculation is performed heuristically by testing whether the color's value is low or its hue is extreme in HSV space.

Definition at line 236 of file color.cpp.

CColor Sleipnir::CColor::operator* ( float  dValue) const

Scale the current color by the requested amount.

Parameters:
dValueScalar by which the channels of the current color are multiplied.
Returns:
New color scaling the current color by the requested amount.

Definition at line 146 of file color.cpp.

References CColor(), and Sleipnir::CMath::Round().

CColor Sleipnir::CColor::operator+ ( const CColor Color) const

Blend two colors equally.

Parameters:
ColorColor to which the current color is added.
Returns:
New color blending the current and given colors.

Definition at line 124 of file color.cpp.

References CColor().

CColor & Sleipnir::CColor::operator= ( const CColor Color)

Copies the given color into the current color.

Parameters:
ColorColor whose channel values are copied into the current color.
Returns:
Reference to the current color with values copied from the given color.

Definition at line 168 of file color.cpp.

string Sleipnir::CColor::ToRGB ( ) const

Constructs a standard hexadecimal string encoding the current color.

Returns:
Hexadecimal string encoding the current colors RGB values.
Remarks:
String does not include an initial # mark.

Definition at line 186 of file color.cpp.

Referenced by Sleipnir::CDat::SaveDOT().


The documentation for this class was generated from the following files: