13 const Colour Colour::Zero = Colour(0, 0, 0, 0);
14 const Colour Colour::Black = Colour(0, 0, 0, 1);
15 const Colour Colour::White = Colour(1, 1, 1, 1);
16 const Colour Colour::Red = Colour(1, 0, 0, 1);
17 const Colour Colour::Green = Colour(0, 1, 0, 1);
18 const Colour Colour::Blue = Colour(0, 0, 1, 1);
20 Colour::Colour(
float _red,
float _green,
float _blue,
float _alpha) :
28 Colour::Colour(std::string_view _value)
30 *
this = parse(_value);
33 bool Colour::operator==(Colour
const& _value)
const
35 return ((red == _value.red) && (green == _value.green) && (blue == _value.blue) && (alpha == _value.alpha));
38 bool Colour::operator!=(Colour
const& _value)
const
40 return !(*
this == _value);
43 void Colour::set(
float _red,
float _green,
float _blue,
float _alpha)
53 red = green = blue = alpha = 0;
56 std::string Colour::print()
const
58 std::ostringstream stream;
63 Colour Colour::parse(std::string_view _value)
69 std::stringstream stream{std::string{_value.substr(1)}};
71 stream >> std::hex >> result;
75 (
unsigned char)(result >> 16) / 256.0f,
76 (
unsigned char)(result >> 8) / 256.0f,
77 (
unsigned char)(result) / 256.0f};
85 std::stringstream stream{std::string{_value}};
86 stream >> red >> green >> blue;
92 return {red, green, blue, alpha};
99 std::ostream& Colour::operatorShiftLeft(std::ostream& _stream,
const Colour& _value)
101 _stream << _value.red <<
" " << _value.green <<
" " << _value.blue <<
" " << _value.alpha;
105 std::istream& Colour::operatorShiftRight(std::istream& _stream, Colour& _value)
117 _value = parse(value);
121 std::istringstream stream(value);
122 stream >> _value.red;
127 _stream >> _value.green >> _value.blue;
129 _stream >> _value.alpha;
constexpr float ALPHA_MAX