Optibits
Loading...
Searching...
No Matches
Color.hpp
1#pragma once
2
3#include <compare>
4#include <cstdint>
5#include <ostream>
6
7namespace Optibits
8{
9
10 struct Color
11 {
12 using Channel = std::uint8_t;
13 Channel red = 0, green = 0, blue = 0, alpha = 0;
14
15 Color() = default;
16
17 Color(std::uint32_t argb)
18 : red(argb >> 16),
19 green(argb >> 8),
20 blue(argb >> 0),
21 alpha(argb >> 24)
22 {
23 }
24
25 Color(Channel red, Channel green, Channel blue)
26 : red(red),
27 green(green),
28 blue(blue),
29 alpha(255)
30 {
31 }
32
33 Color withAlpha(Channel newAlpha) const
34 {
35 Color result = *this;
36 result.alpha = newAlpha;
37 return result;
38 }
39
40 static Color fromHSV(double h, double s, double v);
41
42 double hue() const;
43
44 void setHue(double h);
45
46 double saturation() const;
47
48 void setSaturation(double s);
49
50 double value() const;
51
52 void setValue(double v);
53
54 std::uint32_t argb() const { return alpha << 24 | red << 16 | green << 8 | blue; }
55 std::uint32_t bgr() const { return blue << 16 | green << 8 | red; }
56 std::uint32_t abgr() const { return alpha << 24 | blue << 16 | green << 8 | red; }
57
58 std::uint32_t gl() const { return *reinterpret_cast<const std::uint32_t*>(this); }
59
60 static const Color NONE;
61 static const Color BLACK;
62 static const Color GRAY;
63 static const Color WHITE;
64
65 static const Color AQUA;
66 static const Color CYAN;
67
68 static const Color RED;
69 static const Color GREEN;
70 static const Color BLUE;
71 static const Color YELLOW;
72 static const Color FUCHSIA;
73
74 std::strong_ordering operator<=>(const Color&) const = default;
75 };
76
77}
Definition Color.hpp:11