etk::Color< MY_TYPE, MY_TYPE_SIZE > Class Template Reference

#include <Color.hpp>

Public Member Functions

 Color ()
 
 Color (MY_TYPE _r, MY_TYPE _g, MY_TYPE _b, MY_TYPE _a)
 
 Color (MY_TYPE _r, MY_TYPE _g, MY_TYPE _b)
 
 Color (MY_TYPE _r, MY_TYPE _g)
 
 Color (MY_TYPE _r)
 
template<typename MY_TYPE_2 , int MY_TYPE_SIZE_2>
 Color (const etk::Color< MY_TYPE_2, MY_TYPE_SIZE_2 > &_obj)
 
 Color (const std::string &_input)
 
Color< MY_TYPE, MY_TYPE_SIZE > & operator= (const etk::Color< MY_TYPE, MY_TYPE_SIZE > &_input)
 
bool operator!= (const etk::Color< MY_TYPE, MY_TYPE_SIZE > &_obj) const
 
bool operator== (const etk::Color< MY_TYPE, MY_TYPE_SIZE > &_obj) const
 
uint32_t get () const
 
void set (MY_TYPE _r, MY_TYPE _g, MY_TYPE _b, MY_TYPE _a)
 
void set (MY_TYPE _r, MY_TYPE _g, MY_TYPE _b)
 
void set (MY_TYPE _r, MY_TYPE _g)
 
void set (MY_TYPE _r)
 
std::string getHexString () const
 
std::string getString () const
 
MY_TYPE r () const
 
MY_TYPE g () const
 
MY_TYPE b () const
 
MY_TYPE a () const
 
void setR (MY_TYPE _r)
 
void setG (MY_TYPE _g)
 
void setB (MY_TYPE _b)
 
void setA (MY_TYPE _a)
 
const etk::Color< MY_TYPE, MY_TYPE_SIZE > & operator+= (const etk::Color< MY_TYPE, MY_TYPE_SIZE > &_obj)
 
etk::Color< MY_TYPE, MY_TYPE_SIZE > operator+ (const etk::Color< MY_TYPE, MY_TYPE_SIZE > &_obj) const
 
etk::Color< MY_TYPE, MY_TYPE_SIZE > & operator*= (const etk::Color< MY_TYPE, MY_TYPE_SIZE > &_obj)
 
etk::Color< MY_TYPE, MY_TYPE_SIZE > & operator*= (const MY_TYPE _val)
 
etk::Color< MY_TYPE, MY_TYPE_SIZE > operator* (const etk::Color< MY_TYPE, MY_TYPE_SIZE > &_obj) const
 
etk::Color< MY_TYPE, MY_TYPE_SIZE > operator* (const MY_TYPE _val) const
 
template<>
uint32_t get () const
 

Static Public Attributes

static const Color< MY_TYPE, MY_TYPE_SIZE > emptyColor
 
static const MY_TYPE defaultAlpha
 

Detailed Description

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
class etk::Color< MY_TYPE, MY_TYPE_SIZE >

The color class is a template to abstract the color implementation choice.

It is important to note that the color choice denpznd on the level of developent. For example :

  • Graphic application use:
    • Image in 3/4 bytes for rgb(a)
    • Color description in char : '#F6780FFF' or the equivalent number:0xF6780FFF
  • middleware will mainely use a the 4 separate value with 1 byte for each.
  • graphic interface (openGL) store image in 1/2/3/4 bytes color and interpolate it in 'n' float. And note that the user color is sored in float.

Then with this class we abstract the transformation format and set an easy same way to use the color independing of the developpement level.

Some of the basic color is defined in the namespace: etk::color.

Parameters
[in]MY_TYPEType of the internal template value. The generic value is uint8_t and float
[in]MY_TYPE_SIZENumber of value in the color

Constructor & Destructor Documentation

§ Color() [1/7]

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
etk::Color< MY_TYPE, MY_TYPE_SIZE >::Color ( )
inline

Constructor. It does not initialise element of class.

§ Color() [2/7]

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
etk::Color< MY_TYPE, MY_TYPE_SIZE >::Color ( MY_TYPE  _r,
MY_TYPE  _g,
MY_TYPE  _b,
MY_TYPE  _a 
)
inline

Contructor with request initialisation.

Parameters
[in]_rRed color.
[in]_gGreen color.
[in]_bBlue color.
[in]_aAlpha blending.

§ Color() [3/7]

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
etk::Color< MY_TYPE, MY_TYPE_SIZE >::Color ( MY_TYPE  _r,
MY_TYPE  _g,
MY_TYPE  _b 
)
inline

Contructor with request initialisation.

Parameters
[in]_rRed color.
[in]_gGreen color.
[in]_bBlue color.

§ Color() [4/7]

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
etk::Color< MY_TYPE, MY_TYPE_SIZE >::Color ( MY_TYPE  _r,
MY_TYPE  _g 
)
inline

Contructor with request initialisation.

Parameters
[in]_rRed color.
[in]_gGreen color.

§ Color() [5/7]

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
etk::Color< MY_TYPE, MY_TYPE_SIZE >::Color ( MY_TYPE  _r)
inline

Contructor with request initialisation.

Parameters
[in]_rRed color.

§ Color() [6/7]

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
template<typename MY_TYPE_2 , int MY_TYPE_SIZE_2>
etk::Color< MY_TYPE, MY_TYPE_SIZE >::Color ( const etk::Color< MY_TYPE_2, MY_TYPE_SIZE_2 > &  _obj)

Copy contructor or convert contructor.

Parameters
[in]_objElement to copy in this new color class.

§ Color() [7/7]

template<typename MY_TYPE , int MY_TYPE_SIZE>
etk::Color< MY_TYPE, MY_TYPE_SIZE >::Color ( const std::string &  _input)

String extractor constructor.

Parameters
[in]_inputColor string to parse. it can be : "#rrggbb", "rgb", "rrggbbaa", "rgba", "blueviolet" ...

Member Function Documentation

§ a()

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
MY_TYPE etk::Color< MY_TYPE, MY_TYPE_SIZE >::a ( ) const
inline

Get alpha blending.

Returns
The alpha blending.

§ b()

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
MY_TYPE etk::Color< MY_TYPE, MY_TYPE_SIZE >::b ( ) const
inline

Get blue color.

Returns
The blue color.

§ g()

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
MY_TYPE etk::Color< MY_TYPE, MY_TYPE_SIZE >::g ( ) const
inline

Get green color.

Returns
The green color.

§ get() [1/2]

template<typename MY_TYPE , int MY_TYPE_SIZE>
uint32_t etk::Color< MY_TYPE, MY_TYPE_SIZE >::get ( ) const

Get the Generic uint32_t value of the color.

Returns
Color in unsigned integer

§ get() [2/2]

template<>
uint32_t etk::Color< uint8_t, 4 >::get ( ) const

Specify that the Get intance is specialized for uint8_t/4 template.

Returns
unsignad iterger containing the color value in RGBA

§ getHexString()

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
std::string etk::Color< MY_TYPE, MY_TYPE_SIZE >::getHexString ( ) const
inline

Convert the color in an hexedecimal string ("0xFEDCBA98")

Returns
The formated string

§ getString()

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
std::string etk::Color< MY_TYPE, MY_TYPE_SIZE >::getString ( ) const
inline

Convert the color in an generic string value ("#FEDCBA98")

Returns
The formated string

§ operator!=()

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
bool etk::Color< MY_TYPE, MY_TYPE_SIZE >::operator!= ( const etk::Color< MY_TYPE, MY_TYPE_SIZE > &  _obj) const
inline

Different comparaison operator.

Parameters
[in]_objColor object to compare.
Returns
true This is not the same color
false This is the same color.

§ operator*() [1/2]

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
etk::Color<MY_TYPE,MY_TYPE_SIZE> etk::Color< MY_TYPE, MY_TYPE_SIZE >::operator* ( const etk::Color< MY_TYPE, MY_TYPE_SIZE > &  _obj) const
inline

Operator*= Multiply 2 color together.

Parameters
[in]_objReference on the external object
Returns
New vector containing the value

§ operator*() [2/2]

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
etk::Color<MY_TYPE,MY_TYPE_SIZE> etk::Color< MY_TYPE, MY_TYPE_SIZE >::operator* ( const MY_TYPE  _val) const
inline

Operator*= Multiply the color With a specific value.

Parameters
[in]_valValue to multiply the color
Returns
New vector containing the value

§ operator*=() [1/2]

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
etk::Color<MY_TYPE,MY_TYPE_SIZE>& etk::Color< MY_TYPE, MY_TYPE_SIZE >::operator*= ( const etk::Color< MY_TYPE, MY_TYPE_SIZE > &  _obj)
inline

Operator*= Multiply 2 color together.

Parameters
[in]_objReference on the external object
Returns
Local reference of the vector

§ operator*=() [2/2]

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
etk::Color<MY_TYPE,MY_TYPE_SIZE>& etk::Color< MY_TYPE, MY_TYPE_SIZE >::operator*= ( const MY_TYPE  _val)
inline

Operator*= Multiply the color With a specific value.

Parameters
[in]_valValue to multiply the color
Returns
Local reference of the vector

§ operator+()

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
etk::Color<MY_TYPE,MY_TYPE_SIZE> etk::Color< MY_TYPE, MY_TYPE_SIZE >::operator+ ( const etk::Color< MY_TYPE, MY_TYPE_SIZE > &  _obj) const
inline

Operator+ Addition an other etk::color with this one.

Parameters
[in]_objReference on the external object
Returns
New vector containing the value

§ operator+=()

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
const etk::Color<MY_TYPE,MY_TYPE_SIZE>& etk::Color< MY_TYPE, MY_TYPE_SIZE >::operator+= ( const etk::Color< MY_TYPE, MY_TYPE_SIZE > &  _obj)
inline

Operator+= Addition an other etk::color with this one.

Parameters
[in]_objReference on the external object
Returns
Local reference of the vector additionned

§ operator=()

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
Color<MY_TYPE,MY_TYPE_SIZE>& etk::Color< MY_TYPE, MY_TYPE_SIZE >::operator= ( const etk::Color< MY_TYPE, MY_TYPE_SIZE > &  _input)
inline

Asignemement operator.

Parameters
[in]_inputColor object to set in this class.
Returns
reference on this element.

§ operator==()

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
bool etk::Color< MY_TYPE, MY_TYPE_SIZE >::operator== ( const etk::Color< MY_TYPE, MY_TYPE_SIZE > &  _obj) const
inline

Equality comparaison operator.

Parameters
[in]_objColor object to compare.
Returns
true This is the same color.
false The color are different.

§ r()

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
MY_TYPE etk::Color< MY_TYPE, MY_TYPE_SIZE >::r ( ) const
inline

Get red color.

Returns
The red color.

§ set() [1/4]

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
void etk::Color< MY_TYPE, MY_TYPE_SIZE >::set ( MY_TYPE  _r,
MY_TYPE  _g,
MY_TYPE  _b,
MY_TYPE  _a 
)
inline

Set the specified color elements.

Parameters
[in]_rRed color.
[in]_gGreen color.
[in]_bBlue color.
[in]_aAlpha blending.

§ set() [2/4]

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
void etk::Color< MY_TYPE, MY_TYPE_SIZE >::set ( MY_TYPE  _r,
MY_TYPE  _g,
MY_TYPE  _b 
)
inline

Set the specified color elements.

Parameters
[in]_rRed color.
[in]_gGreen color.
[in]_bBlue color.

§ set() [3/4]

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
void etk::Color< MY_TYPE, MY_TYPE_SIZE >::set ( MY_TYPE  _r,
MY_TYPE  _g 
)
inline

Set the specified color elements.

Parameters
[in]_rRed color.
[in]_gGreen color.

§ set() [4/4]

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
void etk::Color< MY_TYPE, MY_TYPE_SIZE >::set ( MY_TYPE  _r)
inline

Set the specified color elements.

Parameters
[in]_rRed color.

§ setA()

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
void etk::Color< MY_TYPE, MY_TYPE_SIZE >::setA ( MY_TYPE  _a)
inline

Set alpha blending.

Parameters
[in]_aThe alpha blending to set.

§ setB()

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
void etk::Color< MY_TYPE, MY_TYPE_SIZE >::setB ( MY_TYPE  _b)
inline

Set blue color.

Parameters
[in]_bThe blue color to set.

§ setG()

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
void etk::Color< MY_TYPE, MY_TYPE_SIZE >::setG ( MY_TYPE  _g)
inline

Set green color.

Parameters
[in]_gThe green color to set.

§ setR()

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
void etk::Color< MY_TYPE, MY_TYPE_SIZE >::setR ( MY_TYPE  _r)
inline

Set red color.

Parameters
[in]_rThe red color to set.

Member Data Documentation

§ defaultAlpha

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
const MY_TYPE etk::Color< MY_TYPE, MY_TYPE_SIZE >::defaultAlpha
static

Default alpha value.

§ emptyColor

template<typename MY_TYPE = uint8_t, int MY_TYPE_SIZE = 4>
const Color<MY_TYPE, MY_TYPE_SIZE> etk::Color< MY_TYPE, MY_TYPE_SIZE >::emptyColor
static

To auto fill with no data in all case.


The documentation for this class was generated from the following file: