Boost.UI
User Interface Boost library
color.hpp
Go to the documentation of this file.
1 // Copyright (c) 2017 Kolya Kosenko
2 
3 // Distributed under the Boost Software License, Version 1.0.
4 // See http://www.boost.org/LICENSE_1_0.txt
5 
7 
8 #ifndef BOOST_UI_COLOR_HPP
9 #define BOOST_UI_COLOR_HPP
10 
11 #include <boost/ui/config.hpp>
12 
13 #ifdef BOOST_HAS_PRAGMA_ONCE
14 #pragma once
15 #endif
16 
17 #include <boost/cstdint.hpp>
18 
19 namespace boost {
20 namespace ui {
21 
30 
31 class BOOST_UI_DECL color
32 {
33 public:
35  color() BOOST_NOEXCEPT : m_red(0), m_green(0), m_blue(0), m_alpha(0) {}
36 
38  typedef boost::uint_least8_t channel255_type;
39 
41  static color rgba255(channel255_type red, channel255_type green,
42  channel255_type blue, channel255_type alpha);
43 
47  { return rgba255(red, green, blue, 255); }
48 
50  channel255_type red255() const BOOST_NOEXCEPT { return m_red; }
51  channel255_type green255() const BOOST_NOEXCEPT { return m_green; }
52  channel255_type blue255() const BOOST_NOEXCEPT { return m_blue; }
53  channel255_type alpha255() const BOOST_NOEXCEPT { return m_alpha; }
55 
57  typedef double channel1_type;
58 
61  static color rgba1(channel1_type red, channel1_type green,
62  channel1_type blue, channel1_type alpha);
63 
66  { return rgba1(red, green, blue, 1); }
67 
69  channel1_type red1() const BOOST_NOEXCEPT { return static_cast<channel1_type>(m_red) / 255; }
70  channel1_type green1() const BOOST_NOEXCEPT { return static_cast<channel1_type>(m_green) / 255; }
71  channel1_type blue1() const BOOST_NOEXCEPT { return static_cast<channel1_type>(m_blue) / 255; }
72  channel1_type alpha1() const BOOST_NOEXCEPT { return static_cast<channel1_type>(m_alpha) / 255; }
74 
76  static const color alice_blue;
77  static const color antique_white;
78  static const color aqua;
79  static const color aquamarine;
80  static const color azure;
81  static const color beige;
82  static const color bisque;
83  static const color black;
84  static const color blanched_almond;
85  static const color blue;
86  static const color blue_violet;
87  static const color brown;
88  static const color burly_wood;
89  static const color cadet_blue;
90  static const color chartreuse;
91  static const color chocolate;
92  static const color coral;
93  static const color cornflower_blue;
94  static const color cornsilk;
95  static const color crimson;
96  static const color cyan;
97  static const color dark_blue;
98  static const color dark_cyan;
99  static const color dark_goldenrod;
100  static const color dark_gray;
101  static const color dark_green;
102  static const color dark_grey;
103  static const color dark_khaki;
104  static const color dark_magenta;
105  static const color dark_olive_green;
106  static const color dark_orange;
107  static const color dark_orchid;
108  static const color dark_red;
109  static const color dark_salmon;
110  static const color dark_sea_green;
111  static const color dark_slate_blue;
112  static const color dark_slate_gray;
113  static const color dark_slate_grey;
114  static const color dark_turquoise;
115  static const color dark_violet;
116  static const color deep_pink;
117  static const color deep_sky_blue;
118  static const color dim_gray;
119  static const color dim_grey;
120  static const color dodger_blue;
121  static const color firebrick;
122  static const color floral_white;
123  static const color forest_green;
124  static const color fuchsia;
125  static const color gainsboro;
126  static const color ghost_white;
127  static const color gold;
128  static const color goldenrod;
129  static const color gray;
130  static const color green;
131  static const color green_yellow;
132  static const color grey;
133  static const color honeydew;
134  static const color hot_pink;
135  static const color indian_red;
136  static const color indigo;
137  static const color ivory;
138  static const color khaki;
139  static const color lavender;
140  static const color lavender_blush;
141  static const color lawn_green;
142  static const color lemon_chiffon;
143  static const color light_blue;
144  static const color light_coral;
145  static const color light_cyan;
147  static const color light_gray;
148  static const color light_green;
149  static const color light_grey;
150  static const color light_pink;
151  static const color light_salmon;
152  static const color light_sea_green;
153  static const color light_sky_blue;
154  static const color light_slate_gray;
155  static const color light_slate_grey;
156  static const color light_steel_blue;
157  static const color light_yellow;
158  static const color lime;
159  static const color lime_green;
160  static const color linen;
161  static const color magenta;
162  static const color maroon;
163  static const color medium_aquamarine;
164  static const color medium_blue;
165  static const color medium_orchid;
166  static const color medium_purple;
167  static const color medium_sea_green;
168  static const color medium_slate_blue;
170  static const color medium_turquoise;
171  static const color medium_violet_red;
172  static const color midnight_blue;
173  static const color mint_cream;
174  static const color misty_rose;
175  static const color moccasin;
176  static const color navajo_white;
177  static const color navy;
178  static const color old_lace;
179  static const color olive;
180  static const color olive_drab;
181  static const color orange;
182  static const color orange_red;
183  static const color orchid;
184  static const color pale_goldenrod;
185  static const color pale_green;
186  static const color pale_turquoise;
187  static const color pale_violet_red;
188  static const color papaya_whip;
189  static const color peach_puff;
190  static const color peru;
191  static const color pink;
192  static const color plum;
193  static const color powder_blue;
194  static const color purple;
195  static const color red;
196  static const color rosy_brown;
197  static const color royal_blue;
198  static const color saddle_brown;
199  static const color salmon;
200  static const color sandy_brown;
201  static const color sea_green;
202  static const color sea_shell;
203  static const color sienna;
204  static const color silver;
205  static const color sky_blue;
206  static const color slate_blue;
207  static const color slate_gray;
208  static const color slate_grey;
209  static const color snow;
210  static const color spring_green;
211  static const color steel_blue;
212  static const color tan;
213  static const color teal;
214  static const color thistle;
215  static const color tomato;
216  static const color turquoise;
217  static const color violet;
218  static const color wheat;
219  static const color white;
220  static const color white_smoke;
221  static const color yellow;
222  static const color yellow_green;
224 
225 private:
226  channel255_type m_red;
227  channel255_type m_green;
228  channel255_type m_blue;
229  channel255_type m_alpha;
230 };
231 
234 inline bool operator==(const color& lhs, const color& rhs) BOOST_NOEXCEPT
235 {
236  return lhs.red255() == rhs.red255() && lhs.green255() == rhs.green255() &&
237  lhs.blue255() == rhs.blue255() && lhs.alpha255() == rhs.alpha255();
238 }
239 inline bool operator!=(const color& lhs, const color& rhs) BOOST_NOEXCEPT
240  { return !operator==(lhs, rhs); }
242 
243 } // namespace ui
244 } // namespace boost
245 
246 #endif // BOOST_UI_COLOR_HPP
boost::ui::color::gainsboro
static const color gainsboro
Predefined color.
Definition: color.hpp:125
boost::ui::color::orange
static const color orange
Predefined color.
Definition: color.hpp:181
boost::ui::color::sienna
static const color sienna
Predefined color.
Definition: color.hpp:203
boost::ui::color::rgb255
static color rgb255(channel255_type red, channel255_type green, channel255_type blue)
Creates opaque color from channels in [0, 255] ragne.
Definition: color.hpp:46
boost::ui::color::blue_violet
static const color blue_violet
Predefined color.
Definition: color.hpp:86
boost::ui::color::lavender
static const color lavender
Predefined color.
Definition: color.hpp:139
boost::ui::color::medium_orchid
static const color medium_orchid
Predefined color.
Definition: color.hpp:165
boost::ui::color::salmon
static const color salmon
Predefined color.
Definition: color.hpp:199
boost::ui::color::mint_cream
static const color mint_cream
Predefined color.
Definition: color.hpp:173
boost::ui::color::light_slate_grey
static const color light_slate_grey
Predefined color.
Definition: color.hpp:155
boost::ui::color::lavender_blush
static const color lavender_blush
Predefined color.
Definition: color.hpp:140
boost::ui::color::light_sky_blue
static const color light_sky_blue
Predefined color.
Definition: color.hpp:153
boost::ui::color::royal_blue
static const color royal_blue
Predefined color.
Definition: color.hpp:197
boost::ui::color::old_lace
static const color old_lace
Predefined color.
Definition: color.hpp:178
boost::ui::color::orange_red
static const color orange_red
Predefined color.
Definition: color.hpp:182
boost::ui::color::alpha255
channel255_type alpha255() const noexcept
Returns color value in [0, 255] range.
Definition: color.hpp:53
boost::ui::color::medium_aquamarine
static const color medium_aquamarine
Predefined color.
Definition: color.hpp:163
boost::ui::color::powder_blue
static const color powder_blue
Predefined color.
Definition: color.hpp:193
boost::ui::color::light_green
static const color light_green
Predefined color.
Definition: color.hpp:148
boost::ui::color::navajo_white
static const color navajo_white
Predefined color.
Definition: color.hpp:176
boost::ui::color::channel1_type
double channel1_type
Channel type with values in [0, 1] range.
Definition: color.hpp:57
boost::ui::color::pale_turquoise
static const color pale_turquoise
Predefined color.
Definition: color.hpp:186
boost::ui::color::plum
static const color plum
Predefined color.
Definition: color.hpp:192
boost::ui::color::grey
static const color grey
Predefined color.
Definition: color.hpp:132
config.hpp
Configuration options.
boost::ui::color::dark_green
static const color dark_green
Predefined color.
Definition: color.hpp:101
boost::ui::color::azure
static const color azure
Predefined color.
Definition: color.hpp:80
boost::ui::color::color
color() noexcept
Create transparent black color.
Definition: color.hpp:35
boost::ui::color::black
static const color black
Predefined color.
Definition: color.hpp:83
boost::ui::color::chartreuse
static const color chartreuse
Predefined color.
Definition: color.hpp:90
boost::ui::color::misty_rose
static const color misty_rose
Predefined color.
Definition: color.hpp:174
boost::ui::color::medium_blue
static const color medium_blue
Predefined color.
Definition: color.hpp:164
boost::ui::color::khaki
static const color khaki
Predefined color.
Definition: color.hpp:138
boost::ui::operator==
bool operator==(const color &lhs, const color &rhs) noexcept
Compares two colors.
Definition: color.hpp:234
boost::ui::color::coral
static const color coral
Predefined color.
Definition: color.hpp:92
boost::ui::color::red1
channel1_type red1() const noexcept
Returns color value in [0, 1] range.
Definition: color.hpp:69
boost::ui::color::midnight_blue
static const color midnight_blue
Predefined color.
Definition: color.hpp:172
boost::ui::color::dark_magenta
static const color dark_magenta
Predefined color.
Definition: color.hpp:104
boost::ui::color::green1
channel1_type green1() const noexcept
Returns color value in [0, 1] range.
Definition: color.hpp:70
boost::ui::color::channel255_type
boost::uint_least8_t channel255_type
Channel type with values in [0, 255] range.
Definition: color.hpp:38
boost::ui::color::dark_olive_green
static const color dark_olive_green
Predefined color.
Definition: color.hpp:105
boost::ui::color::linen
static const color linen
Predefined color.
Definition: color.hpp:160
boost::ui::color::sandy_brown
static const color sandy_brown
Predefined color.
Definition: color.hpp:200
boost::ui::color::green255
channel255_type green255() const noexcept
Returns color value in [0, 255] range.
Definition: color.hpp:51
boost::ui::color::deep_pink
static const color deep_pink
Predefined color.
Definition: color.hpp:116
boost::ui::color::tomato
static const color tomato
Predefined color.
Definition: color.hpp:215
boost::ui::color::light_blue
static const color light_blue
Predefined color.
Definition: color.hpp:143
boost::ui::color::magenta
static const color magenta
Predefined color.
Definition: color.hpp:161
boost::ui::color::sea_shell
static const color sea_shell
Predefined color.
Definition: color.hpp:202
boost::ui::color::violet
static const color violet
Predefined color.
Definition: color.hpp:217
boost::ui::color::cornsilk
static const color cornsilk
Predefined color.
Definition: color.hpp:94
boost::ui::color::slate_grey
static const color slate_grey
Predefined color.
Definition: color.hpp:208
boost::ui::color::pale_goldenrod
static const color pale_goldenrod
Predefined color.
Definition: color.hpp:184
boost::ui::color::indian_red
static const color indian_red
Predefined color.
Definition: color.hpp:135
boost::ui::color::light_cyan
static const color light_cyan
Predefined color.
Definition: color.hpp:145
boost::ui::color::light_grey
static const color light_grey
Predefined color.
Definition: color.hpp:149
boost::ui::color::light_salmon
static const color light_salmon
Predefined color.
Definition: color.hpp:151
boost
Boost C++ libraries namespace.
Definition: window.hpp:19
boost::ui::color::alpha1
channel1_type alpha1() const noexcept
Returns color value in [0, 1] range.
Definition: color.hpp:72
boost::ui::color::bisque
static const color bisque
Predefined color.
Definition: color.hpp:82
boost::ui::color::red
static const color red
Predefined color.
Definition: color.hpp:195
boost::ui::color::pale_green
static const color pale_green
Predefined color.
Definition: color.hpp:185
boost::ui::color::dark_gray
static const color dark_gray
Predefined color.
Definition: color.hpp:100
boost::ui::color::maroon
static const color maroon
Predefined color.
Definition: color.hpp:162
boost::ui::color::light_slate_gray
static const color light_slate_gray
Predefined color.
Definition: color.hpp:154
boost::ui::color::rosy_brown
static const color rosy_brown
Predefined color.
Definition: color.hpp:196
boost::ui::color::yellow
static const color yellow
Predefined color.
Definition: color.hpp:221
boost::ui::color::dim_grey
static const color dim_grey
Predefined color.
Definition: color.hpp:119
boost::ui::color::antique_white
static const color antique_white
Predefined color.
Definition: color.hpp:77
boost::ui::color::light_sea_green
static const color light_sea_green
Predefined color.
Definition: color.hpp:152
boost::ui::color::dark_blue
static const color dark_blue
Predefined color.
Definition: color.hpp:97
boost::ui::color::red255
channel255_type red255() const noexcept
Returns color value in [0, 255] range.
Definition: color.hpp:50
boost::ui::color::blue
static const color blue
Predefined color.
Definition: color.hpp:85
boost::ui::color::blanched_almond
static const color blanched_almond
Predefined color.
Definition: color.hpp:84
boost::ui::color::goldenrod
static const color goldenrod
Predefined color.
Definition: color.hpp:128
boost::ui::color::lemon_chiffon
static const color lemon_chiffon
Predefined color.
Definition: color.hpp:142
boost::ui::color::light_pink
static const color light_pink
Predefined color.
Definition: color.hpp:150
boost::ui::color::aquamarine
static const color aquamarine
Predefined color.
Definition: color.hpp:79
boost::ui::color::dark_orange
static const color dark_orange
Predefined color.
Definition: color.hpp:106
boost::ui::color::spring_green
static const color spring_green
Predefined color.
Definition: color.hpp:210
boost::ui::color::aqua
static const color aqua
Predefined color.
Definition: color.hpp:78
boost::ui::color::dark_grey
static const color dark_grey
Predefined color.
Definition: color.hpp:102
boost::ui::color::turquoise
static const color turquoise
Predefined color.
Definition: color.hpp:216
boost::ui::operator!=
bool operator!=(const color &lhs, const color &rhs) noexcept
Compares two colors.
Definition: color.hpp:239
boost::ui::color::light_gray
static const color light_gray
Predefined color.
Definition: color.hpp:147
boost::ui::color::brown
static const color brown
Predefined color.
Definition: color.hpp:87
boost::ui::color::steel_blue
static const color steel_blue
Predefined color.
Definition: color.hpp:211
boost::ui::color::forest_green
static const color forest_green
Predefined color.
Definition: color.hpp:123
boost::ui::color::orchid
static const color orchid
Predefined color.
Definition: color.hpp:183
boost::ui::color::dark_khaki
static const color dark_khaki
Predefined color.
Definition: color.hpp:103
boost::ui::color::dark_turquoise
static const color dark_turquoise
Predefined color.
Definition: color.hpp:114
boost::ui::color::olive_drab
static const color olive_drab
Predefined color.
Definition: color.hpp:180
boost::ui::color::papaya_whip
static const color papaya_whip
Predefined color.
Definition: color.hpp:188
boost::ui::color::honeydew
static const color honeydew
Predefined color.
Definition: color.hpp:133
boost::ui::color::medium_sea_green
static const color medium_sea_green
Predefined color.
Definition: color.hpp:167
boost::ui::color::green
static const color green
Predefined color.
Definition: color.hpp:130
boost::ui::color::ivory
static const color ivory
Predefined color.
Definition: color.hpp:137
boost::ui::color::dim_gray
static const color dim_gray
Predefined color.
Definition: color.hpp:118
boost::ui::color::medium_turquoise
static const color medium_turquoise
Predefined color.
Definition: color.hpp:170
boost::ui::color::fuchsia
static const color fuchsia
Predefined color.
Definition: color.hpp:124
boost::ui::color::navy
static const color navy
Predefined color.
Definition: color.hpp:177
boost::ui::color::green_yellow
static const color green_yellow
Predefined color.
Definition: color.hpp:131
boost::ui::color::lime_green
static const color lime_green
Predefined color.
Definition: color.hpp:159
boost::ui::color::saddle_brown
static const color saddle_brown
Predefined color.
Definition: color.hpp:198
boost::ui::color::deep_sky_blue
static const color deep_sky_blue
Predefined color.
Definition: color.hpp:117
boost::ui::color::yellow_green
static const color yellow_green
Predefined color.
Definition: color.hpp:222
boost::ui::color::light_yellow
static const color light_yellow
Predefined color.
Definition: color.hpp:157
boost::ui::color::dark_salmon
static const color dark_salmon
Predefined color.
Definition: color.hpp:109
boost::ui::color::medium_violet_red
static const color medium_violet_red
Predefined color.
Definition: color.hpp:171
boost::ui::color::hot_pink
static const color hot_pink
Predefined color.
Definition: color.hpp:134
boost::ui::color::purple
static const color purple
Predefined color.
Definition: color.hpp:194
boost::ui::color::dark_slate_blue
static const color dark_slate_blue
Predefined color.
Definition: color.hpp:111
boost::ui::color::dodger_blue
static const color dodger_blue
Predefined color.
Definition: color.hpp:120
boost::ui::color::thistle
static const color thistle
Predefined color.
Definition: color.hpp:214
boost::ui::color::dark_goldenrod
static const color dark_goldenrod
Predefined color.
Definition: color.hpp:99
boost::ui::color::dark_sea_green
static const color dark_sea_green
Predefined color.
Definition: color.hpp:110
boost::ui::color::rgb1
static color rgb1(channel1_type red, channel1_type green, channel1_type blue)
Creates opaque color from channels in [0, 1] ragne.
Definition: color.hpp:65
boost::ui::color::dark_slate_grey
static const color dark_slate_grey
Predefined color.
Definition: color.hpp:113
boost::ui::color::peru
static const color peru
Predefined color.
Definition: color.hpp:190
boost::ui::color::moccasin
static const color moccasin
Predefined color.
Definition: color.hpp:175
boost::ui::color::snow
static const color snow
Predefined color.
Definition: color.hpp:209
boost::ui::color::floral_white
static const color floral_white
Predefined color.
Definition: color.hpp:122
boost::ui::color::crimson
static const color crimson
Predefined color.
Definition: color.hpp:95
boost::ui::color::light_goldenrod_yellow
static const color light_goldenrod_yellow
Predefined color.
Definition: color.hpp:146
boost::ui::color::indigo
static const color indigo
Predefined color.
Definition: color.hpp:136
boost::ui::color::pink
static const color pink
Predefined color.
Definition: color.hpp:191
boost::ui::color::blue1
channel1_type blue1() const noexcept
Returns color value in [0, 1] range.
Definition: color.hpp:71
boost::ui::color::pale_violet_red
static const color pale_violet_red
Predefined color.
Definition: color.hpp:187
boost::ui::color::lawn_green
static const color lawn_green
Predefined color.
Definition: color.hpp:141
boost::ui::color::light_coral
static const color light_coral
Predefined color.
Definition: color.hpp:144
boost::ui::color::slate_gray
static const color slate_gray
Predefined color.
Definition: color.hpp:207
boost::ui::color::tan
static const color tan
Predefined color.
Definition: color.hpp:212
boost::ui::color::ghost_white
static const color ghost_white
Predefined color.
Definition: color.hpp:126
boost::ui::color::medium_spring_green
static const color medium_spring_green
Predefined color.
Definition: color.hpp:169
boost::ui::color::wheat
static const color wheat
Predefined color.
Definition: color.hpp:218
boost::ui::color::dark_violet
static const color dark_violet
Predefined color.
Definition: color.hpp:115
boost::ui::color::firebrick
static const color firebrick
Predefined color.
Definition: color.hpp:121
boost::ui::color::cadet_blue
static const color cadet_blue
Predefined color.
Definition: color.hpp:89
boost::ui::color::dark_slate_gray
static const color dark_slate_gray
Predefined color.
Definition: color.hpp:112
boost::ui::color
Color class.
Definition: color.hpp:31
boost::ui::color::dark_orchid
static const color dark_orchid
Predefined color.
Definition: color.hpp:107
boost::ui::color::dark_cyan
static const color dark_cyan
Predefined color.
Definition: color.hpp:98
boost::ui::color::dark_red
static const color dark_red
Predefined color.
Definition: color.hpp:108
boost::ui::color::peach_puff
static const color peach_puff
Predefined color.
Definition: color.hpp:189
boost::ui::color::cyan
static const color cyan
Predefined color.
Definition: color.hpp:96
boost::ui::color::medium_purple
static const color medium_purple
Predefined color.
Definition: color.hpp:166
boost::ui::color::chocolate
static const color chocolate
Predefined color.
Definition: color.hpp:91
boost::ui::color::light_steel_blue
static const color light_steel_blue
Predefined color.
Definition: color.hpp:156
boost::ui::color::slate_blue
static const color slate_blue
Predefined color.
Definition: color.hpp:206
boost::ui::color::white_smoke
static const color white_smoke
Predefined color.
Definition: color.hpp:220
boost::ui::color::silver
static const color silver
Predefined color.
Definition: color.hpp:204
boost::ui::color::gray
static const color gray
Predefined color.
Definition: color.hpp:129
boost::ui::color::beige
static const color beige
Predefined color.
Definition: color.hpp:81
boost::ui::color::blue255
channel255_type blue255() const noexcept
Returns color value in [0, 255] range.
Definition: color.hpp:52
boost::ui::color::olive
static const color olive
Predefined color.
Definition: color.hpp:179
boost::ui::color::alice_blue
static const color alice_blue
Predefined color.
Definition: color.hpp:76
boost::ui::color::cornflower_blue
static const color cornflower_blue
Predefined color.
Definition: color.hpp:93
boost::ui::color::lime
static const color lime
Predefined color.
Definition: color.hpp:158
boost::ui::color::white
static const color white
Predefined color.
Definition: color.hpp:219
boost::ui::color::teal
static const color teal
Predefined color.
Definition: color.hpp:213
boost::ui::color::medium_slate_blue
static const color medium_slate_blue
Predefined color.
Definition: color.hpp:168
boost::ui::color::gold
static const color gold
Predefined color.
Definition: color.hpp:127
boost::ui::color::sea_green
static const color sea_green
Predefined color.
Definition: color.hpp:201
boost::ui::color::burly_wood
static const color burly_wood
Predefined color.
Definition: color.hpp:88
boost::ui::color::sky_blue
static const color sky_blue
Predefined color.
Definition: color.hpp:205