Color Class Reference

#include <Color.h>

Collaboration diagram for Color:

Collaboration graph
[legend]

List of all members.


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 <gandalf@slac.stanford.edu>

Definition at line 37 of file Color.h.


Public Types

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

Public Member Functions

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

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.

Referenced by PyDataRep::colorNames().

int getBlue (  )  const

Definition at line 174 of file Color.cxx.

References Color::m_blue.

Referenced by Inspector::colorSelect_clicked(), ColorXML::createElement(), QtViewImp::createPen(), BinToLineStyle::doubleToColor(), BinToGreyScale::doubleToColor(), BinToGamma::doubleToColor(), BinToBlack::doubleToColor(), QtViewImp::drawColorLines(), OpenGLView::drawColorLines(), AxisRepColor::drawColorScale(), CutRangeRep::drawInvertedRange1D(), CutRangeRep::drawInvertedRange2D(), OpenGLView::drawLines(), CutRangeRep::drawNormalRange(), QtViewImp::drawPoints(), OpenGLView::drawPoints(), QtViewImp::drawPolygon(), OpenGLView::drawPolyLine(), ColorBoxPointRep::drawProjectedValues(), QtViewImp::drawText(), FilledColumnPointRep::drawValues(), OpenGLView::drawViewLines(), Color::operator==(), EpsView::setRgbColor(), and Inspector::updatePlotTab().

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

Definition at line 169 of file Color.cxx.

References Color::m_green.

Referenced by Inspector::colorSelect_clicked(), ColorXML::createElement(), QtViewImp::createPen(), BinToLineStyle::doubleToColor(), BinToGreyScale::doubleToColor(), BinToGamma::doubleToColor(), BinToBlack::doubleToColor(), QtViewImp::drawColorLines(), OpenGLView::drawColorLines(), AxisRepColor::drawColorScale(), CutRangeRep::drawInvertedRange1D(), CutRangeRep::drawInvertedRange2D(), OpenGLView::drawLines(), CutRangeRep::drawNormalRange(), QtViewImp::drawPoints(), OpenGLView::drawPoints(), QtViewImp::drawPolygon(), OpenGLView::drawPolyLine(), ColorBoxPointRep::drawProjectedValues(), QtViewImp::drawText(), FilledColumnPointRep::drawValues(), OpenGLView::drawViewLines(), Color::operator==(), EpsView::setRgbColor(), and Inspector::updatePlotTab().

int getRed (  )  const

Definition at line 164 of file Color.cxx.

References Color::m_red.

Referenced by Inspector::colorSelect_clicked(), ColorXML::createElement(), QtViewImp::createPen(), BinToLineStyle::doubleToColor(), BinToGreyScale::doubleToColor(), BinToGamma::doubleToColor(), BinToBlack::doubleToColor(), QtViewImp::drawColorLines(), OpenGLView::drawColorLines(), AxisRepColor::drawColorScale(), CutRangeRep::drawInvertedRange1D(), CutRangeRep::drawInvertedRange2D(), OpenGLView::drawLines(), CutRangeRep::drawNormalRange(), QtViewImp::drawPoints(), OpenGLView::drawPoints(), QtViewImp::drawPolygon(), OpenGLView::drawPolyLine(), ColorBoxPointRep::drawProjectedValues(), QtViewImp::drawText(), FilledColumnPointRep::drawValues(), OpenGLView::drawViewLines(), Color::operator==(), EpsView::setRgbColor(), and Inspector::updatePlotTab().

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 PyDataRep::setColor(), and Color::setColor().

bool operator== ( Color  c  ) 

Definition at line 202 of file Color.cxx.

References Color::getBlue(), Color::getGreen(), Color::getRed(), Color::m_blue, Color::m_green, and Color::m_red.

void setColor ( Color::Value  value  ) 

Sets the color.

Definition at line 45 of file Color.cxx.

References Color::black, Color::blue, Color::cyan, Color::darkgray, Color::green, Color::lightgray, Color::magenta, Color::orange, Color::red, Color::setColor(), Color::white, and Color::yellow.

void setColor ( int  red = 0,
int  green = 0,
int  blue = 0 
)

Sets the color.

Definition at line 157 of file Color.cxx.

References Color::m_blue, Color::m_green, and Color::m_red.

void setColor ( const std::string &  name  ) 

Sets the color.

Sets the color by one of the known color names. If the name is not found in the color map, then sets the color to black.

Definition at line 112 of file Color.cxx.

References Color::isValid(), Color::m_blue, Color::m_green, Color::m_red, and Color::s_color_by_name.

Referenced by Color::Color(), ColorXML::createObject(), BinToUsrDefinedScale::doubleToColor(), BinToMovingBrkPt::doubleToColor(), BinToLineStyle::doubleToColor(), BinToKamaeScale::doubleToColor(), BinToGreyScale::doubleToColor(), BinToGamma::doubleToColor(), BinToFullColorScale::doubleToColor(), BinToColorScaleMovingBrkPt::doubleToColor(), BinToColorMap::doubleToColor(), BinToBlack::doubleToColor(), BinTo3ColorScale::doubleToColor(), and Color::setColor().


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().

Color::ColorMapByName_t s_color_by_name [static, private]

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