FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
color.hpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4// Copyright 2020 Arthur Sonzogni. 無断複写・転載を禁じます。
5// このソースコードの使用は、LICENSEファイルにあるMITライセンスによって管理されています。
6#ifndef FTXUI_SCREEN_COLOR_HPP
7#define FTXUI_SCREEN_COLOR_HPP
8
9#include <cstdint> // for uint8_t
10#include <string> // for string
11
12#ifdef RGB
13// Workaround for wingdi.h (via Windows.h) defining macros that break things.
14// https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-rgb
15// wingdi.h (Windows.h経由) が問題を発生させるマクロを定義する事への回避策。
16// https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-rgb
17#undef RGB
18#endif
19
20namespace ftxui {
21
22/// @brief Colorは、ターミナルユーザーインターフェースにおける色を表すクラスです。
23///
24/// @ingroup screen
25class Color {
26 public:
27 enum Palette1 : uint8_t;
28 enum Palette16 : uint8_t;
29 enum Palette256 : uint8_t;
30
31 // NOLINTBEGIN
32 Color(); // 透明
33 Color(Palette1 index); // 透明
34 Color(Palette16 index); // インデックスからColorへの暗黙的な変換
35 Color(Palette256 index); // インデックスからColorへの暗黙的な変換
36 // NOLINTEND
37 Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
38 static Color RGB(uint8_t red, uint8_t green, uint8_t blue);
39 static Color HSV(uint8_t hue, uint8_t saturation, uint8_t value);
40 static Color RGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha);
41 static Color HSVA(uint8_t hue,
42 uint8_t saturation,
43 uint8_t value,
44 uint8_t alpha);
45 static Color Interpolate(float t, const Color& a, const Color& b);
46 static Color Blend(const Color& lhs, const Color& rhs);
47
48 //---------------------------
49 // 色のリスト:
50 //---------------------------
51 // clang-format off
52 enum Palette1 : uint8_t{
53 Default, // 透明
54 };
55
56 enum Palette16 : uint8_t {
57 Black = 0,
58 Red = 1,
59 Green = 2,
60 Yellow = 3,
61 Blue = 4,
63 Cyan = 6,
72 White = 15,
73 };
74
75 enum Palette256 : uint8_t {
79 Blue1 = 21,
80 Blue3 = 19,
92 Cornsilk1 = 230,
93 Cyan1 = 51,
94 Cyan2 = 50,
95 Cyan3 = 43,
147 Gold1 = 220,
148 Gold3 = 142,
149 Gold3Bis = 178,
150 Green1 = 46,
151 Green3 = 34,
153 Green4 = 28,
155 Grey0 = 16,
156 Grey100 = 231,
157 Grey11 = 234,
158 Grey15 = 235,
159 Grey19 = 236,
160 Grey23 = 237,
161 Grey27 = 238,
162 Grey3 = 232,
163 Grey30 = 239,
164 Grey35 = 240,
165 Grey37 = 59,
166 Grey39 = 241,
167 Grey42 = 242,
168 Grey46 = 243,
169 Grey50 = 244,
170 Grey53 = 102,
171 Grey54 = 245,
172 Grey58 = 246,
173 Grey62 = 247,
174 Grey63 = 139,
175 Grey66 = 248,
176 Grey69 = 145,
177 Grey7 = 233,
178 Grey70 = 249,
179 Grey74 = 250,
180 Grey78 = 251,
181 Grey82 = 252,
182 Grey84 = 188,
183 Grey85 = 253,
184 Grey89 = 254,
185 Grey93 = 255,
187 HotPink = 205,
188 HotPink2 = 169,
189 HotPink3 = 132,
196 Khaki1 = 228,
197 Khaki3 = 185,
224 Magenta1 = 201,
225 Magenta2 = 165,
227 Magenta3 = 127,
249 Orange1 = 214,
250 Orange3 = 172,
254 Orchid = 170,
255 Orchid1 = 213,
256 Orchid2 = 212,
264 Pink1 = 218,
265 Pink3 = 175,
266 Plum1 = 219,
267 Plum2 = 183,
268 Plum3 = 176,
269 Plum4 = 96,
270 Purple = 129,
275 Red1 = 196,
276 Red3 = 124,
277 Red3Bis = 160,
280 Salmon1 = 209,
286 SkyBlue1 = 117,
287 SkyBlue2 = 111,
302 Tan = 180,
303 Thistle1 = 225,
304 Thistle3 = 182,
307 Violet = 177,
308 Wheat1 = 229,
309 Wheat4 = 101,
310 Yellow1 = 226,
311 Yellow2 = 190,
312 Yellow3 = 148,
314 Yellow4 = 100,
316 };
317 // clang-format on
318
319 // --- Operators ------
320 bool operator==(const Color& rhs) const;
321 bool operator!=(const Color& rhs) const;
322
323 std::string Print(bool is_background_color) const;
324 bool IsOpaque() const { return alpha_ == 255; }
325
326 private:
327 enum class ColorType : uint8_t {
328 Palette1,
329 Palette16,
331 TrueColor,
332 };
333 ColorType type_ = ColorType::Palette1;
334 uint8_t red_ = 0;
335 uint8_t green_ = 0;
336 uint8_t blue_ = 0;
337 uint8_t alpha_ = 0;
338};
339
340inline namespace literals {
341
342/// @brief 結合された16進数RGB表現から色を作成します。
343/// 例: 0x808000_rgb
344Color operator""_rgb(unsigned long long int combined);
345
346} // namespace literals
347
348} // namespace ftxui
349
350#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)
アルファチャンネルを使用して2つの色をブレンドします。
bool operator!=(const Color &rhs) const
bool operator==(const Color &rhs) const
bool IsOpaque() const
Definition color.hpp:324
static Color RGB(uint8_t red, uint8_t green, uint8_t blue)
RGB表現から色を構築します。 https://en.wikipedia.org/wiki/RGB_color_model.
@ LightGoldenrod2
Definition color.hpp:202
@ MediumOrchid1Bis
Definition color.hpp:232
@ Chartreuse3Bis
Definition color.hpp:89
@ LightGoldenrod1
Definition color.hpp:201
@ MediumPurple3Bis
Definition color.hpp:239
@ LightGoldenrod3
Definition color.hpp:205
@ DarkSeaGreen4Bis
Definition color.hpp:122
@ LightSkyBlue3Bis
Definition color.hpp:217
@ DarkOliveGreen1
Definition color.hpp:103
@ Aquamarine1Bis
Definition color.hpp:77
@ DarkOliveGreen1Bis
Definition color.hpp:104
@ MediumPurple2Bis
Definition color.hpp:237
@ Chartreuse2Bis
Definition color.hpp:87
@ DarkSeaGreen1Bis
Definition color.hpp:116
@ MediumTurquoise
Definition color.hpp:242
@ DarkOliveGreen3Ter
Definition color.hpp:108
@ DarkSeaGreen3Bis
Definition color.hpp:120
@ LightSteelBlue1
Definition color.hpp:221
@ DeepSkyBlue3Bis
Definition color.hpp:140
@ MediumVioletRed
Definition color.hpp:243
@ LightGoldenrod2Ter
Definition color.hpp:204
@ DeepSkyBlue4Ter
Definition color.hpp:143
@ DarkOliveGreen2
Definition color.hpp:105
@ CornflowerBlue
Definition color.hpp:91
@ DarkGoldenrod
Definition color.hpp:98
@ LightGoldenrod2Bis
Definition color.hpp:203
@ DarkSeaGreen2Bis
Definition color.hpp:118
@ LightSalmon3Bis
Definition color.hpp:213
@ SpringGreen2Bis
Definition color.hpp:294
@ DeepSkyBlue4Bis
Definition color.hpp:142
@ DarkOliveGreen3Bis
Definition color.hpp:107
@ MediumSpringGreen
Definition color.hpp:241
@ DarkOliveGreen3
Definition color.hpp:106
@ SpringGreen3Bis
Definition color.hpp:296
@ LightSteelBlue3
Definition color.hpp:222
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は、ターミナルユーザーインターフェースにおける色を表すクラスです。
Definition color.hpp:25
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
FTXUI ftxui::literals::名前空間