Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Static Private Member Functions | Private Attributes | Static Private Attributes
Color Class Reference

A Color class for creating the color object following the standard RGB color space. More...

#include <Color.h>

Collaboration diagram for Color:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Value {
  red, green, blue, yellow,
  orange, cyan, magenta, black,
  darkgray, lightgray, white
}
 A few common colors. More...

Public Member Functions

 Color (int red=0, int green=0, int blue=0)
 The following constructor takes red, green, and blue components as arguments.
 Color (Color::Value value)
 A constructor using Color::Value to set the color.
 Color (const std::string &name)
 A constructor using a name to set the color.
int getBlue () const
int getGreen () const
int getRed () const
bool operator== (Color c)
void setColor (const std::string &)
 Sets the color.
void setColor (int red=0, int green=0, int blue=0)
 Sets the color.
void setColor (Color::Value value)
 Sets the color.

Static Public Member Functions

static void addColor (const char *name, const Color &color)
 Adds a named color to the color by name map.
static const std::vector
< std::string > & 
colorNames ()
 Returns the list of color names.
static Color::Value getColor ()
 Instead of getting a random color, this static method loop over the 5 common colors: red, green, blue, magenta and orange.
static bool isValid (const std::string &name)
 Returns true if name is a valid color.

Static Public Attributes

static int colorIndex = 0
 Color index for composite plotter.

Private Types

typedef std::map< std::string,
Color
ColorMapByName_t
 The type of container mapping string to Color object.

Static Private Member Functions

static void initColorByNameMap ()
 Initializes the mapping of a name to Color object.

Private Attributes

int m_blue
 The blue component of the color.
int m_green
 The green component of the color.
int m_red
 The red component of the color.

Static Private Attributes

static ColorMapByName_t s_color_by_name
 The color by name map.
static std::vector< std::string > s_color_names
 The list of available color names.

Detailed Description

A Color class for creating the color object following the standard RGB color space.

This class represents color in a way similar to color classes of GUI tool kits such as Java and Qt. It should, thus, be straight-forward to convert from one to the other.

The compiler-generated copy constructor, destructor, and assignment operator are all valid and, thus, not explicitly implemented.

See also:
http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html .
Author:
Stephane Bonneaud ganda.nosp@m.lf@s.nosp@m.lac.s.nosp@m.tanf.nosp@m.ord.e.nosp@m.du

Definition at line 37 of file Color.h.


Member Typedef Documentation

typedef std::map< std::string, Color > ColorMapByName_t [private]

The type of container mapping string to Color object.

Definition at line 58 of file Color.h.


Member Enumeration Documentation

enum Value

A few common colors.

A few common colors for use by clients.

Note:
A few common colors are provided as a convenience to the programmer. They are better to use than constructing a Color by name because they are typed checked and take up less space. At one point, it took over 5K byte more space in the core library if colors were created by name.
Enumerator:
red 
green 
blue 
yellow 
orange 
cyan 
magenta 
black 
darkgray 
lightgray 
white 

Definition at line 51 of file Color.h.


Constructor & Destructor Documentation

Color ( int  red = 0,
int  green = 0,
int  blue = 0 
) [explicit]

The following constructor takes red, green, and blue components as arguments.

The range of the values is 0 to 255. If the default values are taken, then the color will be black.

Definition at line 24 of file Color.cxx.

Color ( Color::Value  value) [explicit]

A constructor using Color::Value to set the color.

Definition at line 30 of file Color.cxx.

References Color::setColor().

Color ( const std::string &  name) [explicit]

A constructor using a name to set the color.

A constructor using a name to set the color. The name must match one of the values of the Color::Value enumeration, otherwise the color is set to Color::black.

Definition at line 105 of file Color.cxx.

References Color::setColor().


Member Function Documentation

void addColor ( const char *  name,
const Color color 
) [static]

Adds a named color to the color by name map.

Definition at line 37 of file Color.cxx.

References Color::s_color_by_name.

Referenced by Color::initColorByNameMap().

const std::vector< std::string > & colorNames ( ) [static]

Returns the list of color names.

Definition at line 144 of file Color.cxx.

References Color::s_color_by_name, and Color::s_color_names.

int getBlue ( ) const
Color::Value getColor ( ) [static]

Instead of getting a random color, this static method loop over the 5 common colors: red, green, blue, magenta and orange.

Definition at line 181 of file Color.cxx.

References Color::blue, Color::colorIndex, Color::green, Color::magenta, Color::orange, and Color::red.

Referenced by Inspector::addDataRepButton_clicked().

int getGreen ( ) const
int getRed ( ) const
void initColorByNameMap ( ) [static, private]

Initializes the mapping of a name to Color object.

Definition at line 89 of file Color.cxx.

References Color::addColor().

Referenced by Color::isValid().

bool isValid ( const std::string &  name) [static]

Returns true if name is a valid color.

Definition at line 131 of file Color.cxx.

References Color::initColorByNameMap(), and Color::s_color_by_name.

Referenced by Color::setColor().

bool operator== ( Color  c)
void setColor ( const std::string &  name)
void setColor ( int  red = 0,
int  green = 0,
int  blue = 0 
)

Sets the color.

Definition at line 157 of file Color.cxx.

References Color::blue, Color::green, Color::m_blue, Color::m_green, Color::m_red, and Color::red.

void setColor ( Color::Value  value)

Member Data Documentation

int colorIndex = 0 [static]

Color index for composite plotter.

Definition at line 137 of file Color.h.

Referenced by Color::getColor().

int m_blue [private]

The blue component of the color.

Definition at line 75 of file Color.h.

Referenced by Color::getBlue(), Color::operator==(), and Color::setColor().

int m_green [private]

The green component of the color.

Definition at line 72 of file Color.h.

Referenced by Color::getGreen(), Color::operator==(), and Color::setColor().

int m_red [private]

The red component of the color.

Definition at line 69 of file Color.h.

Referenced by Color::getRed(), Color::operator==(), and Color::setColor().

The color by name map.

Definition at line 62 of file Color.h.

Referenced by Color::addColor(), Color::colorNames(), Color::isValid(), and Color::setColor().

std::vector< std::string > s_color_names [static, private]

The list of available color names.

Definition at line 66 of file Color.h.

Referenced by Color::colorNames().


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

Generated for HippoDraw Class Library by doxygen