- Main Page
- Classes
- Files
- Examples

- File List
- File Members

# include/board/Color.h

Go to the documentation of this file.

    00001 /* -*- mode: c++ -*- */
    00010 #ifndef _BOARD_COLOR_H_
    00011 #define _BOARD_COLOR_H_
    00012
    00013 #include <ostream>
    00014 #include <string>
    00015
    00016 namespace LibBoard {
    00017
    00022 class Color {
    00023
    00024 public:
    00025
    00026   Color( const unsigned int rgb, unsigned char alpha = 255 );
    00027
    00028   Color( unsigned char red, unsigned char  green, unsigned char  blue, unsigned char alpha = 255 )
    00029     :_red(red),_green(green),_blue(blue),_alpha(alpha) { }
    00030
    00031   Color( unsigned char gray, unsigned char alpha = 255 )
    00032     :_red(gray),_green(gray),_blue(gray),_alpha(alpha) { }
    00033
    00034   Color( const bool valid = true )
    00035     :_red(-1),_green(-1),_blue(-1),_alpha(255)
    00036   {
    00037     if ( valid ) {
    00038       _red = _green = _blue = 0;
    00039     }
    00040   }
    00041
    00042   inline void red( unsigned char red );
    00043   inline void green( unsigned char green );
    00044   inline void blue( unsigned char blue );
    00045   inline void alpha( unsigned char alpha );
    00046
    00047   inline unsigned char red() const;
    00048   inline unsigned char green() const;
    00049   inline unsigned char blue() const;
    00050   inline unsigned char alpha() const;
    00051
    00052   inline Color & setRGBi( const unsigned char red,
    00053                           const unsigned char green,
    00054                           const unsigned char blue,
    00055                           const unsigned char alpha = 255 );
    00056
    00057   Color & setRGBf( float red,
    00058                    float green,
    00059                    float blue,
    00060                    float alpha = 1.0 );
    00061
    00062   bool operator==( const Color & other ) const;
    00063
    00064   bool operator!=( const Color & other ) const;
    00065
    00066   bool operator<( const Color & other ) const;
    00067
    00068   void flushPostscript( std::ostream & ) const;
    00069
    00070   std::string svg() const;
    00071
    00080   std::string svgAlpha( const char * prefix ) const;
    00081
    00082   std::string postscript() const;
    00083
    00084   inline bool valid() const { return (*this) != Color::None; }
    00085
    00086
    00087 public:
    00088   static const Color None;
    00089   static const Color Black;
    00090   static const Color Gray;
    00091   static const Color White;
    00092   static const Color Red;
    00093   static const Color Green;
    00094   static const Color Lime;
    00095   static const Color Blue;
    00096   static const Color Cyan;
    00097   static const Color Magenta;
    00098   static const Color Yellow;
    00099   static const Color Silver;
    00100   static const Color Purple;
    00101   static const Color Navy;
    00102   static const Color Aqua;
    00103
    00104 private:
    00105   int _red;
    00106   int _green;
    00107   int _blue;
    00108   int _alpha;
    00109 };
    00110
    00111 inline Color &
    00112 Color::setRGBi( const unsigned char red,
    00113                 const unsigned char green,
    00114                 const unsigned char blue,
    00115                 const unsigned char alpha ) {
    00116   _red = red;
    00117   _green = green;
    00118   _blue = blue;
    00119   _alpha = alpha;
    00120   return *this;
    00121 }
    00122
    00123
    00124 inline void
    00125 Color::red( const unsigned char red )
    00126 {
    00127   _red = red;
    00128 }
    00129
    00130 inline void
    00131 Color::green( unsigned char green )
    00132 {
    00133   _green = green;
    00134 }
    00135
    00136 inline void
    00137 Color::blue( unsigned char blue )
    00138 {
    00139   _blue = blue;
    00140 }
    00141
    00142 inline void
    00143 Color::alpha( unsigned char alpha )
    00144 {
    00145   _alpha = alpha;
    00146 }
    00147
    00148 inline unsigned char Color::red() const { return _red; }
    00149 inline unsigned char Color::green() const { return _green; }
    00150 inline unsigned char Color::blue() const { return _blue; }
    00151 inline unsigned char Color::alpha() const { return _alpha; }
    00152
    00153 }
    00154
    00155 #endif // _COLOR_H_