23 #ifndef __MYGUI_COLOUR_H__
24 #define __MYGUI_COLOUR_H__
34 float red, green, blue, alpha;
43 Colour() : red( 1 ), green( 1 ), blue( 1 ), alpha( 1 ) { }
44 Colour(
float _red,
float _green,
float _blue,
float _alpha = 1 ) : red( _red ), green( _green ), blue( _blue ), alpha( _alpha ) { }
45 explicit Colour(
const std::string& _value) { *
this = parse(_value); }
59 return ((red == _value.
red) && (green == _value.
green) && (blue == _value.
blue) && (alpha == _value.
alpha));
64 return ! (*
this == _value);
67 void set(
float _red,
float _green,
float _blue,
float _alpha = 1 )
77 red = green = blue = alpha = 0;
80 std::string print()
const
82 std::ostringstream stream;
87 static Colour parse(
const std::string& _value)
93 std::istringstream stream(_value.substr(1));
95 stream >> std::hex >> result;
98 return Colour( (
unsigned char)( result >> 16 ) / 256.0f, (
unsigned char)( result >> 8 ) / 256.0f, (
unsigned char)( result ) / 256.0f );
103 float red, green, blue, alpha = 1;
104 std::istringstream stream(_value);
105 stream >> red >> green >> blue;
110 return Colour(red, green, blue, alpha);
117 friend std::ostream& operator << ( std::ostream& _stream,
const Colour& _value )
119 _stream << _value.
red <<
" " << _value.
green <<
" " << _value.
blue <<
" " << _value.
alpha;
123 friend std::istream& operator >> ( std::istream& _stream,
Colour& _value )
139 std::istringstream stream(value);
140 stream >> _value.
red;
147 _stream >> _value.
alpha;
163 #endif // __MYGUI_COLOUR_H__