V-ART
color.h
Go to the documentation of this file.
1 
5 #ifndef VART_COLOR_H
6 #define VART_COLOR_H
7 
8 #include <iostream>
9 
10 namespace VART {
24  class Color {
25  friend std::ostream& operator<<(std::ostream& output, const Color& c);
26  public:
28  Color();
29  Color(const Color& color);
30  Color(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255);
31  void SetR(unsigned char r) { rgba[0] = r; }
32  void SetG(unsigned char g) { rgba[1] = g; }
33  void SetB(unsigned char b) { rgba[2] = b; }
34  void SetA(unsigned char a) { rgba[3] = a; }
35  void SetRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
36  unsigned char GetR() const { return rgba[0]; }
37  unsigned char GetG() const { return rgba[1]; }
38  unsigned char GetB() const { return rgba[2]; }
39  unsigned char GetA() const { return rgba[3]; }
40  void GetRGBA(unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a) const;
42  void Get(float rgbaVec[4]) const;
43  Color& operator=(const Color& color);
44  Color operator+(const Color& color) const;
45  Color operator-(const Color& color) const;
46  bool operator==(const Color& color) const;
47  bool operator!=(const Color& color) const;
48 
50 
58  void GetScaled(float escalar, float result[4]) const;
59 
61 
69  void GetScaled(float escalar, Color* result) const;
70  // PUBLIC STATIC METHODS
72  static Color HSV(unsigned char h_, unsigned char s_, unsigned char v_);
74  static const Color& BLACK();
76  static const Color& RED();
78  static const Color& GREEN();
80  static const Color& BLUE();
82  static const Color& MAGENTA();
84  static const Color& CYAN();
86  static const Color& YELLOW();
88  static const Color& WHITE();
89 
91 
94  static Color RANDOM();
95  private:
96  // PRIVATE ATTRIBUTES
98  unsigned char rgba[4];
99  // Note: OpenGL's glLight... and glMaterial... only have int/float versions.
100  // PRIVATE STATIC METHODS
101  }; // end class declaration
102 } // end namespace
103 #endif // _COLOR_H
static const Color & YELLOW()
Yellow opaque color.
Definition: color.cpp:100
static const Color & RED()
Red opaque color.
Definition: color.cpp:75
static const Color & BLUE()
Blue opaque color.
Definition: color.cpp:85
Color operator-(const Color &color) const
Definition: color.cpp:158
void GetRGBA(unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) const
Definition: color.cpp:130
Color()
Creates a black, opaque color.
Definition: color.cpp:15
void SetR(unsigned char r)
Definition: color.h:31
void SetG(unsigned char g)
Definition: color.h:32
static const Color & GREEN()
Green opaque color.
Definition: color.cpp:80
bool operator==(const Color &color) const
Definition: color.cpp:164
unsigned char GetA() const
Definition: color.h:39
RGBA color representation.
Definition: color.h:24
static const Color & MAGENTA()
Magenta opaque color.
Definition: color.cpp:90
static Color HSV(unsigned char h_, unsigned char s_, unsigned char v_)
HSV named Constructor.
Definition: color.cpp:37
void SetRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Definition: color.cpp:123
void SetB(unsigned char b)
Definition: color.h:33
unsigned char GetR() const
Definition: color.h:36
static const Color & CYAN()
Cyan opaque color.
Definition: color.cpp:95
void GetScaled(float escalar, float result[4]) const
Multiplies RGB components, keeps A component.
Definition: color.cpp:178
bool operator!=(const Color &color) const
Definition: color.cpp:171
static const Color & BLACK()
Black opaque color.
Definition: color.cpp:70
void Get(float rgbaVec[4]) const
Returns RGBA componts as a vector of floats.
Definition: color.cpp:138
static Color RANDOM()
Returns a randomly chosen color.
Definition: color.cpp:110
Color operator+(const Color &color) const
Definition: color.cpp:152
unsigned char GetG() const
Definition: color.h:37
Color & operator=(const Color &color)
Definition: color.cpp:144
static const Color & WHITE()
White opaque color.
Definition: color.cpp:105
friend std::ostream & operator<<(std::ostream &output, const Color &c)
void SetA(unsigned char a)
Definition: color.h:34
unsigned char GetB() const
Definition: color.h:38