Gamedev Framework (gf)  0.17.0
A C++14 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< TOpaque (T value=T(0.5))
 Opaque predefined color. More...
 
static constexpr Color4< TGray (T value=T(0.5))
 Gray predefined color. More...
 
static constexpr Color4< Tlighter (Color4< T > color, T percent=T(0.5))
 Compute a lighter color. More...
 
static constexpr Color4< Tdarker (Color4< T > color, T percent=T(0.5))
 Compute a darker color. More...
 
static constexpr Color4< TfromRgb (T r, T g, T b)
 Get an opaque color from 3 RGB floats in \( [0, 1] \). More...
 
static constexpr Color4< TfromRgba32 (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< TfromRgba32 (uint32_t color)
 Get a color from 32-bit value. More...
 
static constexpr Color4< TfromRgba32 (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< TBlack {T(0), T(0), T(0), T(1)}
 Black predefined color. More...
 
static constexpr Color4< TWhite {T(1), T(1), T(1), T(1)}
 White predefined color. More...
 
static constexpr Color4< TRed {T(1), T(0), T(0), T(1)}
 Red predefined color. More...
 
static constexpr Color4< TGreen {T(0), T(1), T(0), T(1)}
 Green predefined color. More...
 
static constexpr Color4< TBlue {T(0), T(0), T(1), T(1)}
 Blue predefined color. More...
 
static constexpr Color4< TCyan {T(0), T(1), T(1), T(1)}
 Cyan predefined color. More...
 
static constexpr Color4< TMagenta {T(1), T(0), T(1), T(1)}
 Magenta predefined color. More...
 
static constexpr Color4< TYellow {T(1), T(1), T(0), T(1)}
 Yellow predefined color. More...
 
static constexpr Color4< TTransparent {T(0), T(0), T(0), T(0)}
 Transparent (black) predefined color. More...
 
static constexpr Color4< TOrange {T(1), T(0.5), T(0), T(1)}
 Orange predefined color. More...
 
static constexpr Color4< TRose {T(1), T(0), T(0.5), T(1)}
 Rose predefined color. More...
 
static constexpr Color4< TChartreuse {T(0.5), T(1), T(0), T(1)}
 Chartreuse predefined color. More...
 
static constexpr Color4< TSpring {T(0), T(1), T(0.5), T(1)}
 Spring (green) predefined color. More...
 
static constexpr Color4< TViolet {T(0.5), T(0), T(1), T(1)}
 Violet predefined color. More...
 
static constexpr Color4< TAzure {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::Color4f

Member Function Documentation

◆ darker()

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

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 ( T  r,
T  g,
T  b 
)
inlinestatic

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 ( uint8_t  r,
uint8_t  g,
uint8_t  b,
uint8_t  a = 255 
)
inlinestatic

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

◆ fromRgba32() [2/3]

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

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 ( Color4u  color)
inlinestatic

Get a color from a 32-bit color.

Parameters
colorA 32-bit color
Returns
The corresponding color

◆ Gray()

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

Gray predefined color.

Parameters
valueThe gray value

◆ lighter()

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

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 ( T  value = T(0.5))
inlinestatic

Opaque predefined color.

Parameters
valueThe opacity value

◆ toRgba32()

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

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)}
static

Azure predefined color.

◆ Black

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

Black predefined color.

◆ Blue

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

Blue predefined color.

◆ Chartreuse

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

Chartreuse predefined color.

◆ Cyan

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

Cyan predefined color.

◆ Green

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

Green predefined color.

◆ Magenta

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

Magenta predefined color.

◆ Orange

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

Orange predefined color.

◆ Red

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

Red predefined color.

◆ Rose

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

Rose predefined color.

◆ Spring

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

Spring (green) predefined color.

◆ Transparent

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

Transparent (black) predefined color.

◆ Violet

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

Violet predefined color.

◆ White

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

White predefined color.

◆ Yellow

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

Yellow predefined color.