19 #ifdef GOSU_IS_LITTLE_ENDIAN 20 enum { RED_OFFSET = 0, GREEN_OFFSET = 8, BLUE_OFFSET = 16, ALPHA_OFFSET = 24 };
22 enum { RED_OFFSET = 24, GREEN_OFFSET = 16, BLUE_OFFSET = 8, ALPHA_OFFSET = 0 };
36 :
Color((argb >> 24) & 0xff, (argb >> 16) & 0xff, (argb >> 8) & 0xff, (argb >> 0) & 0xff)
41 :
Color(0xff, red, green, blue)
47 rep = (alpha << ALPHA_OFFSET) | (red << RED_OFFSET) |
48 (green << GREEN_OFFSET) | (blue << BLUE_OFFSET);
61 return static_cast<Channel
>(rep >> RED_OFFSET);
66 return static_cast<Channel
>(rep >> GREEN_OFFSET);
71 return static_cast<Channel
>(rep >> BLUE_OFFSET);
76 return static_cast<Channel
>(rep >> ALPHA_OFFSET);
81 rep &= ~(0xff << RED_OFFSET);
82 rep |= value << RED_OFFSET;
87 rep &= ~(0xff << GREEN_OFFSET);
88 rep |= value << GREEN_OFFSET;
93 rep &= ~(0xff << BLUE_OFFSET);
94 rep |= value << BLUE_OFFSET;
99 rep &= ~(0xff << ALPHA_OFFSET);
100 rep |= value << ALPHA_OFFSET;
116 double value()
const;
131 std::uint32_t
gl()
const {
return rep; }
std::uint32_t bgr() const
Returns the color in 0x00bbggrr representation. Useful for Win32 programming.
void set_alpha(Channel value)
Color()
The default constructor does not initialize the color to any value.
void set_red(Channel value)
Represents an RGBA color value with 8 bits for each channel.
static const Color YELLOW
void set_saturation(double s)
Changes the current color so saturation() will return s.
void set_blue(Channel value)
static Color from_hsv(double h, double s, double v)
Constructs a color from the given hue/saturation/value triple.
std::uint32_t gl() const
Returns the internal representation of the color (RGBA in memory).
double saturation() const
Returns the saturation of the color, in the range of 0..1.
bool operator!=(Color a, Color b)
static Color from_ahsv(Channel alpha, double h, double s, double v)
Constructs a color from the given hue/saturation/value triple.
Color interpolate(Color a, Color b, double weight=0.5)
Interpolates linearly between two colors, with a given weight towards the second color.
Color(unsigned argb)
Conversion constructor for literals of the form 0xaarrggbb.
bool operator==(Color a, Color b)
std::uint32_t argb() const
Returns the color in 0xaarrggbb representation.
void set_hue(double h)
Changes the current color so hue() will return h.
Color(Channel alpha, Channel red, Channel green, Channel blue)
static const unsigned GL_FORMAT
double hue() const
Returns the hue of the color, in the usual range of 0..360.
double value() const
Returns the value (brightness) of the color, in the range of 0..1.
Color(Channel red, Channel green, Channel blue)
void set_value(double v)
Changes the current color so value() will return v.
std::uint32_t abgr() const
Returns the color in 0xaabbggrr representation.
Color multiply(Color a, Color b)
Combines two colors as if their channels were mapped to the 0..1 range and then multiplied with each ...
void set_green(Channel value)
static const Color FUCHSIA
bool operator<(Color a, Color b)