1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
|
.. _ZColor:
ZColor
======
Color handling in terminals works in distinct color kinds:
* default color
* named colors
* indexed colors
* rgb/direct colors
The default color further has the special property that it is displayed differently when uses as foreground color
versus background color.
That is using the default color as both foreground and background color usually yields readable high contrast text.
The default color is often configurable separatly for the user of the terminal.
The named colors are 8 basic colors plus their bright variants.
Terminal usually allow users to configure these colors and many users make use of that configability.
The indexed colors are divided into 3 parts.
Color indicies 0-15 often correspond to the named colors, possible with some differences in handling
(i.e. bright named colors might default to bold, while the same indicies might not use auto bold).
The following color indicies are usually divided into a color cube and a ramp of grey tones.
The rgb colors allow direct usage of given rgb color values.
The colors use 8 bit resolution for each color channel.
But of course some terminals internally use lower resolution.
If Tui Widgets knows the terminal does not support rgb color it internally translates them to indexed colors, because
most terminals support those.
Of course terminals differ in support for color kinds.
Also in some situations users expect the application to use named colors to fit with their selected color theming.
Thus Tui Widgets exposes all color kinds discussed above and lets the application select which colors to use.
Although the default palette uses rgb colors and the automatic conversion.
If the application uses RGB colors, it can additionally use the :cpp:class:`Tui::ZColorHSV` class to ease calculation of
related colors.
.. cpp:enum:: Tui::TerminalColor
The ``TerminalColor`` enum represents the named terminal colors.
.. rst-class:: tw-invisible
.. cpp:enumerator:: black
.. rst-class:: tw-invisible
.. cpp:enumerator:: darkGray
.. rst-class:: tw-invisible
.. cpp:enumerator:: lightGray
.. rst-class:: tw-invisible
.. cpp:enumerator:: brightWhite
.. rst-class:: tw-invisible
.. cpp:enumerator:: blue
.. rst-class:: tw-invisible
.. cpp:enumerator:: green
.. rst-class:: tw-invisible
.. cpp:enumerator:: cyan
.. rst-class:: tw-invisible
.. cpp:enumerator:: red
.. rst-class:: tw-invisible
.. cpp:enumerator:: magenta
.. rst-class:: tw-invisible
.. cpp:enumerator:: yellow
.. rst-class:: tw-invisible
.. cpp:enumerator:: brightBlue
.. rst-class:: tw-invisible
.. cpp:enumerator:: brightGreen
.. rst-class:: tw-invisible
.. cpp:enumerator:: brightCyan
.. rst-class:: tw-invisible
.. cpp:enumerator:: brightRed
.. rst-class:: tw-invisible
.. cpp:enumerator:: brightMagenta
.. rst-class:: tw-invisible
.. cpp:enumerator:: brightYellow
.. list-table:: named colors
:header-rows: 1
:align: left
* - enum
- description
- enum (bright)
- description
* - black (0)
- black
- darkGray (8)
- dark grey
* - red (1)
- red
- brightRed (9)
- bright red
* - green (2)
- green
- brightGreen (10)
- bright green
* - yellow (3)
- yellow
- brightYellow (11)
- bright yellow
* - blue (4)
- blue
- brightBlue (12)
- bright blue
* - magenta (5)
- magenta
- brightMagenta (13)
- bright magenta
* - cyan (6)
- cyan
- brightCyan (14)
- bright cyan
* - lightGray (7)
- light gray
- brightWhite (15)
- white
The following RGB colors are predefined as constants for application use in ``Tui::Colors``:
.. list-table:: predefined rgb values
:header-rows: 1
:align: left
* - name
- description
- name (bright)
- description
* - black
- :colorchip:`#000000` black (#000000)
- darkGray
- :colorchip:`#555555` dark grey (#555555)
* - red
- :colorchip:`#aa0000` red (#aa0000)
- brightRed
- :colorchip:`#ff5555` bright red (#ff5555)
* - green
- :colorchip:`#00aa00` green (#00aa00)
- brightGreen
- :colorchip:`#55ff55` bright green (#55ff55)
* - yellow
- :colorchip:`#aaaa00` yellow (#aaaa00)
- brightYellow
- :colorchip:`#ffff55` bright yellow (#ffff55)
* - blue
- :colorchip:`#0000aa` blue (#0000aa)
- brightBlue
- :colorchip:`#5555ff` bright blue (#5555ff)
* - magenta
- :colorchip:`#aa00aa` magenta (#aa00aa)
- brightMagenta
- :colorchip:`#ff55ff` bright magenta (#ff55ff)
* - cyan
- :colorchip:`#00aaaa` cyan (#00aaaa)
- brightCyan
- :colorchip:`#55ffff` bright cyan (#55ffff)
* - lightGray
- :colorchip:`#aaaaaa` light gray (#aaaaaa)
- brightWhite
- :colorchip:`#ffffff` white (#ffffff)
.. cpp:class:: Tui::ZColor
This class represents colors in Tui Widgets.
It's copyable, assignable and supports equality comparasion.
.. cpp:enum:: ColorType
.. cpp:enumerator:: RGB
.. cpp:enumerator:: Default
.. cpp:enumerator:: Terminal
.. cpp:enumerator:: TerminalIndexed
**constructors**
| :cpp:func:`Tui::ZColor::ZColor(int r, int g, int b) <void Tui::ZColor::ZColor(int r, int g, int b)>`
**static functions**
| :cpp:func:`~Tui::ZColor Tui::ZColor::defaultColor()`
| :cpp:func:`fromHsv(const Tui::ZColorHSV &hsv) <Tui::ZColor Tui::ZColor::fromHsv(const Tui::ZColorHSV &hsv)>`
| :cpp:func:`~Tui::ZColor Tui::ZColor::fromHsv(double hue, double saturation, double value)`
| :cpp:func:`~Tui::ZColor Tui::ZColor::fromHsvStrict(double hue, double saturation, double value)`
| :cpp:func:`fromHsvStrict(const Tui::ZColorHSV &hsv) <Tui::ZColor Tui::ZColor::fromHsvStrict(const Tui::ZColorHSV &hsv)>`
| :cpp:func:`~Tui::ZColor Tui::ZColor::fromRgb(int r, int g, int b)`
| :cpp:func:`~Tui::ZColor Tui::ZColor::fromTerminalColor(TerminalColor color)`
| :cpp:func:`~Tui::ZColor Tui::ZColor::fromTerminalColor(int color)`
| :cpp:func:`~Tui::ZColor Tui::ZColor::fromTerminalColorIndexed(int color)`
**functions**
| :cpp:func:`~int Tui::ZColor::blue() const`
| :cpp:func:`~int Tui::ZColor::blueOrGuess() const`
| :cpp:func:`~int Tui::ZColor::green() const`
| :cpp:func:`~int Tui::ZColor::greenOrGuess() const`
| :cpp:func:`~uint32_t Tui::ZColor::nativeValue() const`
| :cpp:func:`~int Tui::ZColor::red() const`
| :cpp:func:`~int Tui::ZColor::redOrGuess() const`
| :cpp:func:`~void Tui::ZColor::setBlue(int blue)`
| :cpp:func:`~void Tui::ZColor::setGreen(int green)`
| :cpp:func:`~void Tui::ZColor::setRed(int red)`
| :cpp:func:`~Tui::TerminalColor Tui::ZColor::terminalColor() const`
| :cpp:func:`~int Tui::ZColor::terminalColorIndexed() const`
| :cpp:func:`~Tui::ZColorHSV Tui::ZColor::toHsv() const`
|
.. cpp:namespace:: Tui::ZColor
.. cpp:function:: ZColor(int r, int g, int b)
Creates an ZColor instance of type RGB using ``r``, ``g`` and ``b`` as the color values.
.. cpp:function:: Tui::ZColor::ColorType colorType() const
Returns the type of color the instance represents.
.. cpp:function:: int red() const
.. cpp:function:: void setRed(int red)
.. cpp:function:: int green() const
.. cpp:function:: void setGreen(int green)
.. cpp:function:: int blue() const
.. cpp:function:: void setBlue(int blue)
Only for :cpp:expr:`colorType() == ColorType::RGB`.
Getters and setters for RGB values.
If the setters are used on a color of another type the type will be changed to RGB and all other channels are set to
zero.
Use :cpp:func:`Tui::ZColor fromRgb(int r, int g, int b)` to create a new instance with a specific rgb color.
.. cpp:function:: int terminalColorIndexed() const
Only for :cpp:expr:`colorType() == ColorType::TerminalIndexed`.
Returns the index of the indexed color.
Use :cpp:func:`Tui::ZColor fromTerminalColorIndexed(int color)` to create a new instance with a specific indexed color.
.. cpp:function:: Tui::TerminalColor terminalColor() const
Only for :cpp:expr:`colorType() == ColorType::Terminal`.
Returns the enum value of the named color.
Use :cpp:func:`Tui::ZColor fromTerminalColor(TerminalColor color)` to create a new instance with a specific named color.
.. cpp:function:: int redOrGuess() const
.. cpp:function:: int greenOrGuess() const
.. cpp:function:: int blueOrGuess() const
Returns the color component for RGB type colors or a guess of the color component for other color types.
.. cpp:function:: Tui::ZColorHSV toHsv() const
Returns the color converted to HSV.
For non RGB type colors it uses guesses for the color like :cpp:func:`~int Tui::ZColor::redOrGuess() const` and co.
.. cpp:function:: uint32_t nativeValue() const
Returns the color as a termpaint color value.
.. rst-class:: tw-static
.. cpp:function:: Tui::ZColor defaultColor()
Returns a ``ZColor`` with the default color.
.. rst-class:: tw-static
.. cpp:function:: Tui::ZColor fromRgb(int r, int g, int b)
Returns a ``ZColor`` with the RGB color with components ``r``, ``g`` and ``b``.
.. rst-class:: tw-static
.. cpp:function:: Tui::ZColor fromTerminalColor(TerminalColor color)
Returns a ``ZColor`` with the terminal color ``color``.
.. rst-class:: tw-static
.. cpp:function:: Tui::ZColor fromTerminalColor(int color)
Returns a ``ZColor`` with the terminal color ``static_cast<Tui::TerminalColor>(color)``.
.. rst-class:: tw-static
.. cpp:function:: Tui::ZColor fromTerminalColorIndexed(int color)
Returns a ``ZColor`` with the indexed color ``color``.
.. rst-class:: tw-static
.. cpp:function:: Tui::ZColor fromHsv(const Tui::ZColorHSV &hsv)
Returns a ``ZColor`` with RGB type converted from the HSV color ``hsv``.
.. rst-class:: tw-static
.. cpp:function:: Tui::ZColor fromHsv(double hue, double saturation, double value)
Returns a ``ZColor`` with RGB type converted from the HSV color components ``hue``, ``saturation`` and ``value``.
The ranges for the components are:
* 0 <= hue <= 360
* 0 <= saturation <= 1
* 0 <= value <= 1
Values outside are clipped for saturation and value. Values outside for hue are wrapped back into the allowed range.
.. rst-class:: tw-static
.. cpp:function:: Tui::ZColor fromHsvStrict(double hue, double saturation, double value)
Like :cpp:func:`~Tui::ZColor Tui::ZColor::fromHsv(double hue, double saturation, double value)` but only valid if
the parameters are in the allowed range.
.. rst-class:: tw-static
.. cpp:function:: Tui::ZColor fromHsvStrict(const Tui::ZColorHSV &hsv)
Like :cpp:func:`~Tui::ZColor Tui::ZColor::fromHsv(const Tui::ZColorHSV &hsv)` but only valid if the components in
``hsv`` are in the allowed range.
.. cpp:namespace:: NULL
HSV
---
.. cpp:class:: Tui::ZColorHSV
``ZColorHSV`` is a simple class to store a color as hue, saturation and value.
It's copyable, assignable and supports equality comparasion.
.. cpp:function:: double hue() const
.. cpp:function:: void setHue(double hue)
.. cpp:function:: double saturation() const
.. cpp:function:: void setSaturation(double saturation)
.. cpp:function:: double value() const
.. cpp:function:: void setValue(double value)
All components have getters and setters.
|