14 #include <argos3/core/utility/datatypes/datatypes.h>
15 #include <argos3/core/utility/string_utilities.h>
61 UInt8 un_alpha = 255) throw() :
62 m_tChannels(un_red, un_green, un_blue, un_alpha) {}
70 0.299f * m_tChannels.m_unRed +
71 0.587f * m_tChannels.m_unGreen +
72 0.114f * m_tChannels.m_unBlue;
79 inline UInt8 GetRed()
const throw() {
return m_tChannels.m_unRed; }
84 inline void SetRed(
UInt8 un_red)
throw() { m_tChannels.m_unRed = un_red; }
95 inline void SetGreen(
UInt8 un_green)
throw() { m_tChannels.m_unGreen = un_green; }
106 inline void SetBlue(
UInt8 un_blue)
throw() { m_tChannels.m_unBlue = un_blue; }
117 inline void SetAlpha(
UInt8 un_alpha)
throw() { m_tChannels.m_unAlpha = un_alpha; }
129 UInt8 un_alpha = 255) throw() {
145 Real fAlpha = m_tChannels.m_unAlpha / 255.0;
147 static_cast<UInt8>(fAlpha *
GetRed() + (1.0-fAlpha) * c_background.GetRed()),
148 static_cast<UInt8>(fAlpha *
GetGreen() + (1.0-fAlpha) * c_background.GetGreen()),
149 static_cast<UInt8>(fAlpha *
GetBlue() + (1.0-fAlpha) * c_background.GetBlue())
160 inline void Set(
const std::string& str_color) {
184 ParseValues<UInt16>(str_color, 4, unValues,
',');
185 for(
UInt16 i = 0; i < 4; ++i) {
186 if(unValues[i] > 255) {
190 Set(unValues[0], unValues[1], unValues[2], unValues[3]);
203 return *
reinterpret_cast<UInt32*
>(&m_tChannels);
212 return m_tChannels == c_color2.m_tChannels;
221 return m_tChannels != c_color2.m_tChannels;
258 os << c_color.m_tChannels.m_unRed
259 <<
"," << c_color.m_tChannels.m_unGreen
260 <<
"," << c_color.m_tChannels.m_unBlue
261 <<
"," << c_color.m_tChannels.m_unAlpha;
277 std::string strColor;
279 c_color.
Set(strColor);
298 TChannels(
const UInt8 un_red,
299 const UInt8 un_green,
301 const UInt8 un_alpha = 255) :
305 m_unAlpha(un_alpha) {}
307 inline bool operator==(
const TChannels& t_channels)
const {
309 (m_unRed == t_channels.m_unRed) &&
310 (m_unGreen == t_channels.m_unGreen) &&
311 (m_unBlue == t_channels.m_unBlue) &&
312 (m_unAlpha == t_channels.m_unAlpha);
315 inline bool operator!=(
const TChannels& t_channels)
const {
317 (m_unRed != t_channels.m_unRed) ||
318 (m_unGreen != t_channels.m_unGreen) ||
319 (m_unBlue != t_channels.m_unBlue) ||
320 (m_unAlpha != t_channels.m_unAlpha);
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
unsigned int UInt32
32-bit unsigned integer.
unsigned char UInt8
8-bit unsigned integer.
float Real
Collects all ARGoS code.
unsigned short UInt16
16-bit unsigned integer.
The namespace containing all the ARGoS related code.
The exception that wraps all errors in ARGoS.
CColor()
Class constructor.
Real ToGrayScale() const
Returns the color in grayscale.
void Set(UInt8 un_red, UInt8 un_green, UInt8 un_blue, UInt8 un_alpha=255)
Sets the RGBA values of the color.
void Set(const std::string &str_color)
Sets the RGBA values of the color from a string.
friend std::ostream & operator<<(std::ostream &os, const CColor &c_color)
Output stream operator.
bool operator==(const CColor &c_color2) const
Returns true if the given color is identical to the current.
bool operator!=(const CColor &c_color2) const
Returns true if the given color is different from the current.
void SetGreen(UInt8 un_green)
Sets the green channel of the color.
UInt8 GetBlue() const
Returns the blue channel of the color.
void SetBlue(UInt8 un_blue)
Sets the blue channel of the color.
void SetAlpha(UInt8 un_alpha)
Sets the alpha channel of the color.
friend std::istream & operator>>(std::istream &is, CColor &c_color)
Input stream operator.
UInt8 GetGreen() const
Returns the green channel of the color.
CColor Blend(const CColor &c_background) const
Blends the current color with a background color.
UInt8 GetRed() const
Returns the red channel of the color.
UInt8 GetAlpha() const
Returns the alpha channel of the color.
CColor(UInt8 un_red, UInt8 un_green, UInt8 un_blue, UInt8 un_alpha=255)
Class constructor.
void SetRed(UInt8 un_red)
Sets the red channel of the color.