libtcod
Loading...
Searching...
No Matches
TCODColor Class Reference

#include <color.hpp>

Public Member Functions

constexpr TCODColor (uint8_t r_, uint8_t g_, uint8_t b_) noexcept
 You can create your own colours using a set of constructors, both for RGB and HSV values.
constexpr TCODColor (int r_, int g_, int b_) noexcept
constexpr TCODColor (const TCOD_color_t &col) noexcept
 TCODColor (float h, float s, float v) noexcept
constexpr bool operator== (const TCODColor &c) const noexcept
 if (myColor == TCODColor::yellow) { ... } if (myColor != TCODColor::white) { ... }if (TCOD_color_equals(my_color,TCOD_yellow)) { ... } if (!TCOD_color_equals(my_color,TCOD_white)) { ... }if my_color == libtcod.yellow : ... if my_color != libtcod.white : ...if (myColor.Equal(TCODColor.yellow)) { ... } if (myColor.NotEqual(TCODColor.white)) { ... }if myColor == tcod.color.yellow then ... end
constexpr bool operator!= (const TCODColor &c) const noexcept
constexpr TCODColor operator* (const TCODColor &rhs) const noexcept
 c1 = c2 * c3 => c1.r = c2.r * c3.r / 255 c1.g = c2.g * c3.g / 255 c1.b = c2.b * c3.b / 255 darkishRed = darkGrey * red
constexpr TCODColor operator* (float value) const noexcept
 c1 = c2 * v => c1.r = TCOD_CLAMP(0, 255, c2.r * v) c1.g = TCOD_CLAMP(0, 255, c2.g * v) c1.b = TCOD_CLAMP(0, 255, c2.b * v) darkishRed = red * 0.5
constexpr TCODColor operator+ (const TCODColor &rhs) const noexcept
 c1 = c1 + c2 => c1.r = TCOD_MIN(255, c1.r + c2.r) c1.g = TCOD_MIN(255, c1.g + c2.g) c1.b = TCOD_MIN(255, c1.b + c2.b) lightishRed = red + darkGrey
constexpr TCODColor operator- (const TCODColor &rhs) const noexcept
 c1 = c1 - c2 => c1.r = TCOD_MAX(0, c1.r - c2.r) c1.g = TCOD_MAX(0, c1.g - c2.g) c1.b = TCOD_MAX(0, c1.b - c2.b) redish = red - darkGrey
void setHSV (float h, float s, float v) noexcept
 After this function is called, the r,g,b fields of the color are calculated according to the h,s,v parameters.
void setHue (float h) noexcept
 These functions set only a single component in the HSV color space.
void setSaturation (float s) noexcept
void setValue (float v) noexcept
void getHSV (float *h, float *s, float *v) const noexcept
float getHue () noexcept
 Should you need to extract only one of the HSV components, these functions are what you should call.
float getSaturation () noexcept
float getValue () noexcept
void shiftHue (float hshift) noexcept
 The hue shift value is the number of grades the color's hue will be shifted.
void scaleHSV (float sscale, float vscale) noexcept
constexpr operator TCOD_ColorRGB () const noexcept
 Allow explicit conversions to TCOD_ColorRGB.
constexpr operator TCOD_ColorRGBA () const noexcept
 Allow explicit conversions to TCOD_ColorRGBA.
constexpr operator tcod::ColorRGB () const noexcept
 Allow explicit conversions to tcod::ColorRGB.
constexpr operator tcod::ColorRGBA () const noexcept
 Allow explicit conversions to tcod::ColorRGBA.

Static Public Member Functions

static constexpr TCODColor lerp (const TCODColor &c1, const TCODColor &c2, float coef) noexcept
 c1 = lerp (c2, c3, coef) => c1.r = c2.r + (c3.r - c2.r ) * coef c1.g = c2.g + (c3.g - c2.g ) * coef c1.b = c2.b + (c3.b - c2.b ) * coef coef should be between 0.0 and 1.0 but you can as well use other values
static void genMap (TCODColor *map, int nbKey, TCODColor const *keyColor, int const *keyIndex)
 You can define a color map from an array of color keys.
template<int OutSize, typename KeyColors, typename KeyIndexes>
static constexpr auto genMap (const KeyColors &key_colors, const KeyIndexes &key_indexes) -> std::array< tcod::ColorRGB, OutSize >
 Generate a gradient of colors.

Public Attributes

uint8_t r {}
uint8_t g {}
uint8_t b {}

Friends

TCODLIB_API_INLINE_EXPORT friend TCODColor operator* (float value, const TCODColor &color) noexcept

Detailed Description

The Doryen library uses 32bits colors. Thus, your OS desktop must use 32bits colors. A color is defined by its red, green and blue component between 0 and 255. You can use the following predefined colors (hover over a color to see its full name and R,G,B values):

TCODColor::desaturatedRed TCODColor::lightestRed TCODColor::lighterRed TCODColor::lightRed TCODColor::red TCODColor::darkRed TCODColor::darkerRed TCODColor::darkestRed

TCOD_desaturated_red TCOD_lightest_red TCOD_lighter_red TCOD_light_red TCOD_red TCOD_dark_red TCOD_darker_red TCOD_darkest_red

libtcod.desaturated_red libtcod.lightest_red libtcod.lighter_red libtcod.light_red libtcod.red libtcod.dark_red libtcod.darker_red libtcod.darkest_red

TCODColor::desaturatedRed TCODColor::lightestRed TCODColor::lighterRed TCODColor::lightRed TCODColor::red TCODColor::darkRed TCODColor::darkerRed TCODColor::darkestRed

tcod.color.desaturatedRed tcod.color.lightestRed tcod.color.lighterRed tcod.color.lightRed tcod.color.red tcod.color.darkRed tcod.color.darkerRed tcod.color.darkestRed

Constructor & Destructor Documentation

◆ TCODColor()

TCODColor::TCODColor ( uint8_t r_,
uint8_t g_,
uint8_t b_ )
inlineconstexprnoexcept

You can create your own colours using a set of constructors, both for RGB and HSV values.

TCODColor myColor(24,64,255); //RGB TCODColor myOtherColor(321.0f,0.7f,1.0f); //HSV

TCOD_color_t my_color={24,64,255}; /* RGB */ TCOD_color_t my_other_color = TCOD_color_RGB(24,64,255); /* RGB too */ TCOD_color_t my_yet_another_color = TCOD_color_HSV(321.0f,0.7f,1.0f); /* HSV */

TCODColor myColor = new TCODColor(321.0f,0.7f,1.0f); //HSV

Member Function Documentation

◆ genMap() [1/2]

template<int OutSize, typename KeyColors, typename KeyIndexes>
constexpr auto TCODColor::genMap ( const KeyColors & key_colors,
const KeyIndexes & key_indexes )->std::array< tcod::ColorRGB, OutSize >
inlinestaticnodiscardconstexpr

Generate a gradient of colors.

Template Parameters
OutSizeThe size of the output array.
KeyColorsA key color container of tcod::ColorRGB-like objects.
KeyIndexesThe key index container of integers.
Parameters
key_colorsAn array of which colors belong in sequence.
key_indexesAn ascending array of indexes of the output to map the respective color from key_colors. First index must always be 0, last index must always be KeyColors - 1.
Returns
std::array<tcod::ColorRGB, OutSize>
// Generate an array of 16 colors, with black=0, red=8, white=15.
static constexpr auto gradient = TCODColor::genMap<16>(
std::array{tcod::ColorRGB{0, 0, 0}, tcod::ColorRGB{255, 0, 0}, tcod::ColorRGB{255, 255, 255}},
std::array{0, 8, 15});
static void genMap(TCODColor *map, int nbKey, TCODColor const *keyColor, int const *keyIndex)
You can define a color map from an array of color keys.
A C++ RGB color, used to handle conversions between color types.
Definition color.hpp:53
Exceptions
std::invalid_argumentIssues with the key arrays will throw an error.
embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ genMap() [2/2]

void TCODColor::genMap ( TCODColor * map,
int nbKey,
TCODColor const * keyColor,
int const * keyIndex )
static

You can define a color map from an array of color keys.

Colors will be interpolated between the keys. 0 -> black 4 -> red 8 -> white Result :

map[0]
 black
map[1]
 
map[2]
 
map[3]
 
map[4]
 red
map[5]
 
map[6]
 
map[7]
 
map[8]
 white
Parameters
mapAn array of colors to be filled by the function.
nbKeyNumber of color keys
keyColorArray of nbKey colors containing the color of each key
keyIndexArray of nbKey integers containing the index of each key. If you want to fill the map array, keyIndex[0] must be 0 and keyIndex[nbKey-1] is the number of elements in map minus 1 but you can also use the function to fill only a part of the map array.

int idx[] = { 0, 4, 8 }; // indexes of the keys TCODColor col[] = { TCODColor( 0,0,0 ), TCODColor(255,0,0), TCODColor(255,255,255) }; // colors : black, red, white TCODColor map[9]; TCODColor::genMap(map,3,col,idx);

int idx[] = { 0, 4, 8 }; // indexes of the keys TCOD_color_t col[] = { { 0,0,0 }, {255,0,0}, {255,255,255} }; // colors : black, red, white TCOD_color_t map[9]; TCOD_color_gen_map(map,3,col,idx);

idx = [ 0, 4, 8 ] # indexes of the keys col = [ libtcod.Color( 0,0,0 ), libtcod.Color( 255,0,0 ), libtcod.Color(255,255,255) ] # colors : black, red, white map=libtcod.color_gen_map(col,idx)

◆ getHSV()

void TCODColor::getHSV ( float * h,
float * s,
float * v ) const
noexcept
Parameters
cIn the C and Python versions, the TCOD_color_t from which to read.
h,s,vColor components in the HSV space 0.0 <= h < 360.0 0.0 <= s <= 1.0 0.0 <= v <= 1.0

◆ getHue()

float TCODColor::getHue ( )
nodiscardnoexcept

Should you need to extract only one of the HSV components, these functions are what you should call.

Note that if you need all three values, it's way less burdensome for the CPU to call TCODColor::getHSV().

float TCODColor::getHue () float TCODColor::getSaturation () float TCODColor::getValue ()

float TCOD_color_get_hue (TCOD_color_t c) float TCOD_color_get_saturation (TCOD_color_t c) float TCOD_color_get_value (TCOD_color_t c)

Color:getHue() Color:getSaturation() Color:getValue()

float TCODColor::getHue() float TCODColor::getSaturation() float TCODColor::getValue()

Parameters
cthe TCOD_color_t from which to read

◆ lerp()

constexpr TCODColor TCODColor::lerp ( const TCODColor & c1,
const TCODColor & c2,
float coef )
inlinestaticnodiscardconstexprnoexcept

c1 = lerp (c2, c3, coef) => c1.r = c2.r + (c3.r - c2.r ) * coef c1.g = c2.g + (c3.g - c2.g ) * coef c1.b = c2.b + (c3.b - c2.b ) * coef coef should be between 0.0 and 1.0 but you can as well use other values

coef == 0.0f
coef == 0.25f
coef == 0.5f
coef == 0.75f
coef == 1.0f

◆ operator tcod::ColorRGB()

TCODColor::operator tcod::ColorRGB ( ) const
inlineexplicitnodiscardconstexprnoexcept

Allow explicit conversions to tcod::ColorRGB.

embed:rst:leading-asterisk 
.. versionadded:: 1.19

◆ operator tcod::ColorRGBA()

TCODColor::operator tcod::ColorRGBA ( ) const
inlineexplicitnodiscardconstexprnoexcept

Allow explicit conversions to tcod::ColorRGBA.

embed:rst:leading-asterisk 
.. versionadded:: 1.19

◆ operator TCOD_ColorRGB()

TCODColor::operator TCOD_ColorRGB ( ) const
inlineexplicitnodiscardconstexprnoexcept

Allow explicit conversions to TCOD_ColorRGB.

embed:rst:leading-asterisk 
.. versionadded:: 1.19

◆ operator TCOD_ColorRGBA()

TCODColor::operator TCOD_ColorRGBA ( ) const
inlineexplicitnodiscardconstexprnoexcept

Allow explicit conversions to TCOD_ColorRGBA.

embed:rst:leading-asterisk 
.. versionadded:: 1.19

◆ operator*() [1/2]

TCODColor TCODColor::operator* ( const TCODColor & rhs) const
inlinenodiscardconstexprnoexcept

c1 = c2 * c3 => c1.r = c2.r * c3.r / 255 c1.g = c2.g * c3.g / 255 c1.b = c2.b * c3.b / 255 darkishRed = darkGrey * red

◆ operator*() [2/2]

TCODColor TCODColor::operator* ( float value) const
inlinenodiscardconstexprnoexcept

c1 = c2 * v => c1.r = TCOD_CLAMP(0, 255, c2.r * v) c1.g = TCOD_CLAMP(0, 255, c2.g * v) c1.b = TCOD_CLAMP(0, 255, c2.b * v) darkishRed = red * 0.5

◆ operator+()

TCODColor TCODColor::operator+ ( const TCODColor & rhs) const
inlinenodiscardconstexprnoexcept

c1 = c1 + c2 => c1.r = TCOD_MIN(255, c1.r + c2.r) c1.g = TCOD_MIN(255, c1.g + c2.g) c1.b = TCOD_MIN(255, c1.b + c2.b) lightishRed = red + darkGrey

◆ operator-()

TCODColor TCODColor::operator- ( const TCODColor & rhs) const
inlinenodiscardconstexprnoexcept

c1 = c1 - c2 => c1.r = TCOD_MAX(0, c1.r - c2.r) c1.g = TCOD_MAX(0, c1.g - c2.g) c1.b = TCOD_MAX(0, c1.b - c2.b) redish = red - darkGrey

◆ scaleHSV()

void TCODColor::scaleHSV ( float sscale,
float vscale )
noexcept
Parameters
cThe color to modify
sscalesaturation multiplier (1.0f for no change)
vscalevalue multiplier (1.0f for no change)

◆ setHSV()

void TCODColor::setHSV ( float h,
float s,
float v )
noexcept

After this function is called, the r,g,b fields of the color are calculated according to the h,s,v parameters.

Parameters
cIn the C and Python versions, the color to modify
h,s,vColor components in the HSV space 0.0 <= h < 360.0 0.0 <= s <= 1.0 0.0 <= v <= 1.0

◆ setHue()

void TCODColor::setHue ( float h)
noexcept

These functions set only a single component in the HSV color space.

void TCODColor::setHue (float h) void TCODColor::setSaturation (float s) void TCODColor::setValue (float v)

void TCOD_color_set_hue (TCOD_color_t *c, float h) void TCOD_color_set_saturation (TCOD_color_t *c, float s) void TCOD_color_set_value (TCOD_color_t *c, float v)

Color:setHue(h) Color:setSaturation(s) Color:setValue(v)

Parameters
h,s,vColor components in the HSV space
cIn the C and Python versions, the color to modify

◆ shiftHue()

void TCODColor::shiftHue ( float hshift)
noexcept

The hue shift value is the number of grades the color's hue will be shifted.

The value can be negative for shift left, or positive for shift right. Resulting values H < 0 and H >= 360 are handled automatically.

Parameters
cThe color to modify
hshiftThe hue shift value

The documentation for this class was generated from the following file:
  • C:/Users/4b796/Projects/libtcod/src/libtcod/color.hpp