TermOx
color.hpp
1 #ifndef TERMOX_PAINTER_COLOR_HPP
2 #define TERMOX_PAINTER_COLOR_HPP
3 #include <chrono>
4 #include <cstdint>
5 #include <functional>
6 #include <string>
7 #include <variant>
8 #include <vector>
9 
10 #include <esc/color_index.hpp>
11 #include <esc/true_color.hpp>
12 
13 namespace ox {
14 
16 class Color {
17  public:
18  using Value_t = std::uint8_t;
19  Value_t value;
20 
21  public:
22  enum Name : Value_t {
23  Background = 0,
24  Black = 0,
25  Dark_red = 1,
26  Green = 2,
27  Brown = 3,
28  Dark_blue = 4,
29  Violet = 5,
30  Light_blue = 6,
31  Light_gray = 7,
32  Dark_gray = 8,
33  Red = 9,
34  Light_green = 10,
35  Yellow = 11,
36  Blue = 12,
37  Orange = 13,
38  Gray = 14,
39  White = 15,
40  Foreground = 15,
41  };
42 
43  public:
44  constexpr Color(Name n) : value{static_cast<Value_t>(n)} {}
45 
46  explicit constexpr Color(Value_t v) : value{v} {}
47 };
48 
49 [[nodiscard]] auto constexpr operator==(Color x, Color y) -> bool
50 {
51  return x.value == y.value;
52 }
53 
54 [[nodiscard]] auto constexpr operator!=(Color x, Color y) -> bool
55 {
56  return !(x == y);
57 }
58 
59 [[nodiscard]] auto constexpr operator<(Color x, Color y) -> bool
60 {
61  return x.value < y.value;
62 }
63 
65  Color::Value_t value;
66 };
67 
69  Color::Value_t value;
70 };
71 
73 [[nodiscard]] auto constexpr bg(Color c) -> Background_color
74 {
75  return {c.value};
76 }
77 
79 [[nodiscard]] auto constexpr fg(Color c) -> Foreground_color
80 {
81  return {c.value};
82 }
83 
84 /* --------------------------- Color_index -----------------------------------*/
85 
87 using Color_index = ::esc::Color_index;
88 
89 /* ------------------------------- True Color --------------------------------*/
90 
92 using RGB = ::esc::RGB;
93 
95 using HSL = ::esc::HSL;
96 
98 
99 using True_color = ::esc::True_color;
100 
101 /* ----------------------------- Dynamic Color -------------------------------*/
102 
104 
106  using Period_t = std::chrono::milliseconds;
107  Period_t interval;
108  std::function<True_color()> get_value;
109 };
110 
111 /* ----------------------------- Color Palette -------------------------------*/
112 
115  public:
116  using Value_t = std::variant<Color_index, True_color, Dynamic_color>;
117 
118  public:
119  Color color;
120  Value_t value;
121 };
122 
124 
126 using Palette = std::vector<Color_definition>;
127 
129 
131 template <typename... ColorValues>
132 [[nodiscard]] static auto make_palette(ColorValues... values) -> Palette
133 {
134  auto c = Color::Value_t{0};
135  return {Color_definition{Color{c++}, values}...};
136 }
137 
138 /* ---------------------------------------------------------------------------*/
139 
141 [[nodiscard]] auto color_to_string(Color c) -> std::string;
142 
143 } // namespace ox
144 #endif // TERMOX_PAINTER_COLOR_HPP
Color numbers [0 - 180] are valid.
Definition: color.hpp:16
Definition: color.hpp:64
Used to define a single color for a Palette.
Definition: color.hpp:114
Defines an animated color.
Definition: color.hpp:105
Definition: color.hpp:68