5 #ifndef BPP_GRAPHICS_RGBCOLOR_H 6 #define BPP_GRAPHICS_RGBCOLOR_H 12 #include "../Text/TextTools.h" 13 #include "../Exceptions.h" 14 #include "../Clonable.h" 30 RGBColor(
unsigned int red,
unsigned int green,
unsigned int blue) : red_(red), green_(green), blue_(blue) {}
39 return red_ == color.
red_ && green_ == color.
green_ && blue_ == color.
blue_;
59 std::string hex =
"#";
71 if (i == 0)
return red_;
73 if (i == 2)
return blue_;
82 if (i == 0)
return red_;
84 if (i == 2)
return blue_;
99 std::string hexa =
"0123456789ABCDEF";
100 std::string hex =
"";
103 unsigned int tmp = dec -
static_cast<unsigned int>(floor(static_cast<double>(dec) / 16.) * 16);
104 hex = hexa[tmp] + hex;
105 dec =
static_cast<unsigned int>(floor(static_cast<double>(dec) / 16.));
107 hex = hexa[dec] + hex;
108 if (hex.size() == 1) hex =
"0" + hex;
113 #endif // BPP_GRAPHICS_RGBCOLOR_H std::string toString() const
Get a string description of the color, e.g. [R255,G0,B255].
bool operator<(const RGBColor &color) const
Comparison operator (for sorting purposes).
std::string toHex() const
Get the HTML-like, hexadecimal description of this color.
static std::string decToHex(unsigned int dec)
bool operator==(const RGBColor &color) const
Describe a color according to its red, green and blue componants.
const unsigned int & operator[](unsigned int i) const
Access to each color componant: 0=red, 1=green, 2=blue.
RGBColor(unsigned int red, unsigned int green, unsigned int blue)
RGBColor * clone() const
Create a copy of this object and send a pointer to it.
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
The Clonable interface (allow an object to be cloned).
std::string toString(T t)
General template method to convert to a string.
unsigned int & operator[](unsigned int i)
Access to each color componant: 0=red, 1=green, 2=blue.