Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Classes | Static Public Member Functions | Static Public Attributes | List of all members
gf::ColorBase< T > Struct Template Reference

Predefined colors and utilities. More...

#include <gf/Color.h>

Static Public Member Functions

static constexpr Color4< T > Opaque (T value=T(0.5))
 Opaque predefined color. More...
 
static constexpr Color4< T > Gray (T value=T(0.5))
 Gray predefined color. More...
 
static constexpr Color4< T > lighter (Color4< T > color, T percent=T(0.5))
 Compute a lighter color. More...
 
static constexpr Color4< T > darker (Color4< T > color, T percent=T(0.5))
 Compute a darker color. More...
 
static constexpr Color4< T > fromRgb (T r, T g, T b)
 Get an opaque color from 3 RGB floats in \( [0, 1] \). More...
 
static constexpr Color4< T > fromRgba32 (uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
 Get a color from 4 8-bit channels. More...
 
static constexpr Color4< T > fromRgba32 (uint32_t color)
 Get a color from 32-bit value. More...
 
static constexpr Color4< T > fromRgba32 (Color4u color)
 Get a color from a 32-bit color. More...
 
static constexpr Color4u toRgba32 (Color4< T > color)
 Convert a color to a 32-bit color. More...
 

Static Public Attributes

static constexpr Color4< T > Black {T(0), T(0), T(0), T(1)}
 Black predefined color. More...
 
static constexpr Color4< T > White {T(1), T(1), T(1), T(1)}
 White predefined color. More...
 
static constexpr Color4< T > Red {T(1), T(0), T(0), T(1)}
 Red predefined color. More...
 
static constexpr Color4< T > Green {T(0), T(1), T(0), T(1)}
 Green predefined color. More...
 
static constexpr Color4< T > Blue {T(0), T(0), T(1), T(1)}
 Blue predefined color. More...
 
static constexpr Color4< T > Cyan {T(0), T(1), T(1), T(1)}
 Cyan predefined color. More...
 
static constexpr Color4< T > Magenta {T(1), T(0), T(1), T(1)}
 Magenta predefined color. More...
 
static constexpr Color4< T > Yellow {T(1), T(1), T(0), T(1)}
 Yellow predefined color. More...
 
static constexpr Color4< T > Transparent {T(0), T(0), T(0), T(0)}
 Transparent (black) predefined color. More...
 
static constexpr Color4< T > Orange {T(1), T(0.5), T(0), T(1)}
 Orange predefined color. More...
 
static constexpr Color4< T > Rose {T(1), T(0), T(0.5), T(1)}
 Rose predefined color. More...
 
static constexpr Color4< T > Chartreuse {T(0.5), T(1), T(0), T(1)}
 Chartreuse predefined color. More...
 
static constexpr Color4< T > Spring {T(0), T(1), T(0.5), T(1)}
 Spring (green) predefined color. More...
 
static constexpr Color4< T > Violet {T(0.5), T(0), T(1), T(1)}
 Violet predefined color. More...
 
static constexpr Color4< T > Azure {T(0), T(0.5), T(1), T(1)}
 Azure predefined color. More...
 

Detailed Description

template<typename T>
struct gf::ColorBase< T >

Predefined colors and utilities.

This class does not contain anything but predefined colors. All the primary, secondary and tertiary colors are defined by their usual names.

If you want to define a color, you should use gf::Color4f.

If you want to use the functions of this class, you can use:

See also
gf::ColorRampBase, gf::Color4f

Member Function Documentation

◆ darker()

template<typename T >
static constexpr Color4< T > gf::ColorBase< T >::darker ( Color4< T >  color,
percent = T(0.5) 
)
inlinestaticconstexpr

Compute a darker color.

This function takes a color and gives a darker color based on a percentage. If this percentage is 0, the same color is returned. If this percentage is 1, the black color is returned.

Parameters
colorThe color
percentThe percentage, must be in \( [0, 1] \)

◆ fromRgb()

template<typename T >
static constexpr Color4< T > gf::ColorBase< T >::fromRgb ( r,
g,
b 
)
inlinestaticconstexpr

Get an opaque color from 3 RGB floats in \( [0, 1] \).

Parameters
rThe red channel
gThe green channel
bThe blue channel
Returns
The corresponding color

◆ fromRgba32() [1/3]

template<typename T >
static constexpr Color4< T > gf::ColorBase< T >::fromRgba32 ( Color4u  color)
inlinestaticconstexpr

Get a color from a 32-bit color.

Parameters
colorA 32-bit color
Returns
The corresponding color

◆ fromRgba32() [2/3]

template<typename T >
static constexpr Color4< T > gf::ColorBase< T >::fromRgba32 ( uint32_t  color)
inlinestaticconstexpr

Get a color from 32-bit value.

Parameters
colorThe 32-bit color
Returns
The corresponding color

◆ fromRgba32() [3/3]

template<typename T >
static constexpr Color4< T > gf::ColorBase< T >::fromRgba32 ( uint8_t  r,
uint8_t  g,
uint8_t  b,
uint8_t  a = 255 
)
inlinestaticconstexpr

Get a color from 4 8-bit channels.

Parameters
rThe red channel
gThe green channel
bThe blue channel
aThe alpha channel
Returns
The corresponding color

◆ Gray()

template<typename T >
static constexpr Color4< T > gf::ColorBase< T >::Gray ( value = T(0.5))
inlinestaticconstexpr

Gray predefined color.

Parameters
valueThe gray value

◆ lighter()

template<typename T >
static constexpr Color4< T > gf::ColorBase< T >::lighter ( Color4< T >  color,
percent = T(0.5) 
)
inlinestaticconstexpr

Compute a lighter color.

This function takes a color and gives a lighter color based on a percentage. If this percentage is 0, the same color is returned. If this percentage is 1, the white color is returned.

Parameters
colorThe color
percentThe percentage, must be in \( [0, 1] \)

◆ Opaque()

template<typename T >
static constexpr Color4< T > gf::ColorBase< T >::Opaque ( value = T(0.5))
inlinestaticconstexpr

Opaque predefined color.

Parameters
valueThe opacity value

◆ toRgba32()

template<typename T >
static constexpr Color4u gf::ColorBase< T >::toRgba32 ( Color4< T >  color)
inlinestaticconstexpr

Convert a color to a 32-bit color.

Parameters
colorA color
Returns
The corresponding 32-bit color

Member Data Documentation

◆ Azure

template<typename T >
constexpr Color4<T> gf::ColorBase< T >::Azure {T(0), T(0.5), T(1), T(1)}
staticconstexpr

Azure predefined color.

◆ Black

template<typename T >
constexpr Color4<T> gf::ColorBase< T >::Black {T(0), T(0), T(0), T(1)}
staticconstexpr

Black predefined color.

◆ Blue

template<typename T >
constexpr Color4<T> gf::ColorBase< T >::Blue {T(0), T(0), T(1), T(1)}
staticconstexpr

Blue predefined color.

◆ Chartreuse

template<typename T >
constexpr Color4<T> gf::ColorBase< T >::Chartreuse {T(0.5), T(1), T(0), T(1)}
staticconstexpr

Chartreuse predefined color.

◆ Cyan

template<typename T >
constexpr Color4<T> gf::ColorBase< T >::Cyan {T(0), T(1), T(1), T(1)}
staticconstexpr

Cyan predefined color.

◆ Green

template<typename T >
constexpr Color4<T> gf::ColorBase< T >::Green {T(0), T(1), T(0), T(1)}
staticconstexpr

Green predefined color.

◆ Magenta

template<typename T >
constexpr Color4<T> gf::ColorBase< T >::Magenta {T(1), T(0), T(1), T(1)}
staticconstexpr

Magenta predefined color.

◆ Orange

template<typename T >
constexpr Color4<T> gf::ColorBase< T >::Orange {T(1), T(0.5), T(0), T(1)}
staticconstexpr

Orange predefined color.

◆ Red

template<typename T >
constexpr Color4<T> gf::ColorBase< T >::Red {T(1), T(0), T(0), T(1)}
staticconstexpr

Red predefined color.

◆ Rose

template<typename T >
constexpr Color4<T> gf::ColorBase< T >::Rose {T(1), T(0), T(0.5), T(1)}
staticconstexpr

Rose predefined color.

◆ Spring

template<typename T >
constexpr Color4<T> gf::ColorBase< T >::Spring {T(0), T(1), T(0.5), T(1)}
staticconstexpr

Spring (green) predefined color.

◆ Transparent

template<typename T >
constexpr Color4<T> gf::ColorBase< T >::Transparent {T(0), T(0), T(0), T(0)}
staticconstexpr

Transparent (black) predefined color.

◆ Violet

template<typename T >
constexpr Color4<T> gf::ColorBase< T >::Violet {T(0.5), T(0), T(1), T(1)}
staticconstexpr

Violet predefined color.

◆ White

template<typename T >
constexpr Color4<T> gf::ColorBase< T >::White {T(1), T(1), T(1), T(1)}
staticconstexpr

White predefined color.

◆ Yellow

template<typename T >
constexpr Color4<T> gf::ColorBase< T >::Yellow {T(1), T(1), T(0), T(1)}
staticconstexpr

Yellow predefined color.