FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
color.hpp
浏览该文件的文档.
1// Copyright 2020 Arthur Sonzogni. 保留所有权利。
2// 本源代码的使用受 MIT 许可协议的约束,该协议可在 LICENSE 文件中找到。
3#ifndef FTXUI_SCREEN_COLOR_HPP
4#define FTXUI_SCREEN_COLOR_HPP
5
6#include <cstdint> // for uint8_t
7#include <string> // for string
8
9#ifdef RGB
10// 解决 wingdi.h(通过 Windows.h)定义破坏性宏的问题。
11// https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-rgb
12#undef RGB
13#endif
14
15namespace ftxui {
16
17/// @brief Color 是一个表示终端用户界面中颜色的类。
18///
19/// @ingroup screen
20class Color {
21 public:
22 enum Palette1 : uint8_t;
23 enum Palette16 : uint8_t;
24 enum Palette256 : uint8_t;
25
26 // NOLINTBEGIN
27 Color(); // 透明。
28 Color(Palette1 index); // Transparent.
29 Color(Palette16 index); // 从索引到颜色的隐式转换。
30 Color(Palette256 index); // 从索引到颜色的隐式转换。
31 // NOLINTEND
32 Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
33 static Color RGB(uint8_t red, uint8_t green, uint8_t blue);
34 static Color HSV(uint8_t hue, uint8_t saturation, uint8_t value);
35 static Color RGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha);
36 static Color HSVA(uint8_t hue,
37 uint8_t saturation,
38 uint8_t value,
39 uint8_t alpha);
40 static Color Interpolate(float t, const Color& a, const Color& b);
41 static Color Blend(const Color& lhs, const Color& rhs);
42
43 //---------------------------
44 // 颜色列表:
45 //---------------------------
46 // clang-format off
47 enum Palette1 : uint8_t{
48 Default, // 透明
49 };
50
51 enum Palette16 : uint8_t {
52 Black = 0,
53 Red = 1,
54 Green = 2,
55 Yellow = 3,
56 Blue = 4,
58 Cyan = 6,
67 White = 15,
68 };
69
70 enum Palette256 : uint8_t {
74 Blue1 = 21,
75 Blue3 = 19,
87 Cornsilk1 = 230,
88 Cyan1 = 51,
89 Cyan2 = 50,
90 Cyan3 = 43,
95 DarkKhaki = 143,
142 Gold1 = 220,
143 Gold3 = 142,
144 Gold3Bis = 178,
145 Green1 = 46,
146 Green3 = 34,
148 Green4 = 28,
150 Grey0 = 16,
151 Grey100 = 231,
152 Grey11 = 234,
153 Grey15 = 235,
154 Grey19 = 236,
155 Grey23 = 237,
156 Grey27 = 238,
157 Grey3 = 232,
158 Grey30 = 239,
159 Grey35 = 240,
160 Grey37 = 59,
161 Grey39 = 241,
162 Grey42 = 242,
163 Grey46 = 243,
164 Grey50 = 244,
165 Grey53 = 102,
166 Grey54 = 245,
167 Grey58 = 246,
168 Grey62 = 247,
169 Grey63 = 139,
170 Grey66 = 248,
171 Grey69 = 145,
172 Grey7 = 233,
173 Grey70 = 249,
174 Grey74 = 250,
175 Grey78 = 251,
176 Grey82 = 252,
177 Grey84 = 188,
178 Grey85 = 253,
179 Grey89 = 254,
180 Grey93 = 255,
182 HotPink = 205,
183 HotPink2 = 169,
184 HotPink3 = 132,
191 Khaki1 = 228,
192 Khaki3 = 185,
219 Magenta1 = 201,
220 Magenta2 = 165,
222 Magenta3 = 127,
244 Orange1 = 214,
245 Orange3 = 172,
249 Orchid = 170,
250 Orchid1 = 213,
251 Orchid2 = 212,
259 Pink1 = 218,
260 Pink3 = 175,
261 Plum1 = 219,
262 Plum2 = 183,
263 Plum3 = 176,
264 Plum4 = 96,
265 Purple = 129,
270 Red1 = 196,
271 Red3 = 124,
272 Red3Bis = 160,
275 Salmon1 = 209,
281 SkyBlue1 = 117,
282 SkyBlue2 = 111,
297 Tan = 180,
298 Thistle1 = 225,
299 Thistle3 = 182,
302 Violet = 177,
303 Wheat1 = 229,
304 Wheat4 = 101,
305 Yellow1 = 226,
306 Yellow2 = 190,
307 Yellow3 = 148,
309 Yellow4 = 100,
311 };
312 // clang-format on
313
314 // --- Operators ------
315 bool operator==(const Color& rhs) const;
316 bool operator!=(const Color& rhs) const;
317
318 std::string Print(bool is_background_color) const;
319 bool IsOpaque() const { return alpha_ == 255; }
320
321 private:
322 enum class ColorType : uint8_t {
323 Palette1,
324 Palette16,
326 TrueColor,
327 };
328 ColorType type_ = ColorType::Palette1;
329 uint8_t red_ = 0;
330 uint8_t green_ = 0;
331 uint8_t blue_ = 0;
332 uint8_t alpha_ = 0;
333};
334
335inline namespace literals {
336
337/// @brief 从组合的十六进制 RGB 表示创建颜色,
338/// 例如 0x808000_rgb
339Color operator""_rgb(unsigned long long int combined);
340
341} // namespace literals
342
343} // namespace ftxui
344
345#endif // FTXUI_SCREEN_COLOR_HPP
Color()
构建一个透明颜色。
static Color HSV(uint8_t hue, uint8_t saturation, uint8_t value)
从其 HSV 表示构建一个颜色。 https://en.wikipedia.org/wiki/HSL_and_HSV
static Color RGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
从其 RGBA 表示构建一个颜色。 https://en.wikipedia.org/wiki/RGB_color_model
static Color Blend(const Color &lhs, const Color &rhs)
使用 alpha 通道混合两种颜色。
bool operator!=(const Color &rhs) const
bool operator==(const Color &rhs) const
bool IsOpaque() const
static Color RGB(uint8_t red, uint8_t green, uint8_t blue)
从其 RGB 表示构建一个颜色。 https://en.wikipedia.org/wiki/RGB_color_model
std::string Print(bool is_background_color) const
static Color Interpolate(float t, const Color &a, const Color &b)
static Color HSVA(uint8_t hue, uint8_t saturation, uint8_t value, uint8_t alpha)
从其 HSV 表示构建一个颜色。 https://en.wikipedia.org/wiki/HSL_and_HSV
Color 是一个表示终端用户界面中颜色的类。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
FTXUI ftxui::literals:: 命名空间