te::color::RGBAColor Class Reference

A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color. More...

#include <RGBAColor.h>

Public Types

enum  NameFormat { HexRgb, HexArgb }
 NameFormat enum. More...
 

Public Member Functions

Initializer Methods

Methods related to instantiation and destruction.

 RGBAColor ()
 Default constructor of a new color. More...
 
 RGBAColor (int rgba)
 It initializes a new color with the given value. More...
 
 RGBAColor (int r, int g, int b, int a)
 It initializes a new color. More...
 
 RGBAColor (const std::string &hexColor)
 It initializes a new color from a given hex RGB-encoded string. More...
 
 ~RGBAColor ()
 Destructor. More...
 
Accessor methods

Methods used to get or set properties.

te::color::RGBAColoroperator= (const RGBAColor &color)
 Assigns a copy of a color to this color, and returns a reference to it. More...
 
te::color::RGBAColoroperator= (const int &rgba)
 Assigns a copy of a color to this color. More...
 
bool operator== (const RGBAColor &color) const
 It compares the colors are iqual. More...
 
bool operator!= (const RGBAColor &color) const
 It compares the colors are different. More...
 
int getRed () const
 It returns the red component color value (a value from 0 to 255). More...
 
int getGreen () const
 It returns the green component color value (a value from 0 to 255). More...
 
int getBlue () const
 It returns the blue component color value (a value from 0 to 255). More...
 
int getAlpha () const
 It returns the alpha component color value (a value from 0 to 255). More...
 
void getRgba (int *r, int *g, int *b, int *a=0) const
 It gets the color value. More...
 
int getRgba () const
 It returns the color value (0xAARRGGBB). More...
 
void setColor (const std::string &hexColor)
 It sets the color using a two hexadecimal RGB-encoded color. More...
 
std::string getColor (const NameFormat format=HexRgb) const
 It gets the color encoded using two hexadecimal digits per primary-color component, in the order Red, Green, Blue, if HexRgb format, or Alpha, Red, Green, Blue, if HexArgb format, prefixed with a hash (#) sign. More...
 
void setColor (int r, int g, int b, int a=255)
 It sets the color. More...
 
void setColor (int rgba)
 It sets the color. More...
 

Private Attributes

int m_rgba
 It returns the internal representation as a 32-bits RGBA color. More...
 

Detailed Description

A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.

Internally the color is represented by an integer of 32-bits as the following:

  • bits 0-7: blue
  • bits 8-15: green
  • bits 16-23: red
  • bits 24-31: alpha. See the macro TE_OPAQUE and TE_TRANSPARENT for the values of totally transparent and totally opaque.

Definition at line 57 of file RGBAColor.h.

Member Enumeration Documentation

◆ NameFormat

NameFormat enum.

Possible ways for color name format.

Enumerator
HexRgb 

enum value, format #RRGGBB

HexArgb 

enum value, format #AARRGGBB

Definition at line 64 of file RGBAColor.h.

Constructor & Destructor Documentation

◆ RGBAColor() [1/4]

te::color::RGBAColor::RGBAColor ( )
inline

Default constructor of a new color.

Definition at line 255 of file RGBAColor.h.

◆ RGBAColor() [2/4]

te::color::RGBAColor::RGBAColor ( int  rgba)
inline

It initializes a new color with the given value.

Parameters
rgbaThe color encoded as an integer.

Definition at line 260 of file RGBAColor.h.

◆ RGBAColor() [3/4]

te::color::RGBAColor::RGBAColor ( int  r,
int  g,
int  b,
int  a 
)
inline

It initializes a new color.

Parameters
rRed component (range from 0 to 255).
gGreen component (range from 0 to 255).
bBlue component (range from 0 to 255).
aAlpha component. A range from 0 to 255 (see the macro TE_OPAQUE and TE_TRANSPARENT for the values of totally transparent and totally opaque).

Definition at line 265 of file RGBAColor.h.

◆ RGBAColor() [4/4]

te::color::RGBAColor::RGBAColor ( const std::string &  hexColor)
inline

It initializes a new color from a given hex RGB-encoded string.

Parameters
hexColorThe color value is RGB-encoded using two hexadecimal digits per primary-color component, in the order Red, Green, Blue, prefixed with a hash (#) sign. The hexadecimal digits between A and F may be in uppercase or lowercase.

Definition at line 274 of file RGBAColor.h.

References setColor().

◆ ~RGBAColor()

te::color::RGBAColor::~RGBAColor ( )
inline

Destructor.

Definition at line 279 of file RGBAColor.h.

Member Function Documentation

◆ getAlpha()

int te::color::RGBAColor::getAlpha ( ) const
inline

It returns the alpha component color value (a value from 0 to 255).

Returns
The alpha component color value. It is a value from 0 to 255 (see the macro TE_OPAQUE and TE_TRANSPARENT for the values of totally transparent and totally opaque).

Definition at line 322 of file RGBAColor.h.

References m_rgba.

Referenced by getColor().

◆ getBlue()

int te::color::RGBAColor::getBlue ( ) const
inline

It returns the blue component color value (a value from 0 to 255).

Returns
The blue component color value (a value from 0 to 255).

Definition at line 317 of file RGBAColor.h.

References m_rgba.

Referenced by getColor().

◆ getColor()

std::string te::color::RGBAColor::getColor ( const NameFormat  format = HexRgb) const
inline

It gets the color encoded using two hexadecimal digits per primary-color component, in the order Red, Green, Blue, if HexRgb format, or Alpha, Red, Green, Blue, if HexArgb format, prefixed with a hash (#) sign.

Parameters
formatFormar of the string return.
Returns
A string that represents the color encoded using two hexadecimal digits per primary-color component. e.g. #FF0000
Note
The hexadecimal digits between A and F will be uppercase.

Definition at line 371 of file RGBAColor.h.

References getAlpha(), getBlue(), getGreen(), getRed(), and HexRgb.

◆ getGreen()

int te::color::RGBAColor::getGreen ( ) const
inline

It returns the green component color value (a value from 0 to 255).

Returns
The green component color value (a value from 0 to 255).

Definition at line 312 of file RGBAColor.h.

References m_rgba.

Referenced by getColor().

◆ getRed()

int te::color::RGBAColor::getRed ( ) const
inline

It returns the red component color value (a value from 0 to 255).

Returns
The red component color value (a value from 0 to 255).

Definition at line 307 of file RGBAColor.h.

References m_rgba.

Referenced by getColor().

◆ getRgba() [1/2]

void te::color::RGBAColor::getRgba ( int *  r,
int *  g,
int *  b,
int *  a = 0 
) const
inline

It gets the color value.

Parameters
rRed component.
gGreen component.
bBlue component.
aAlpha component.

Definition at line 327 of file RGBAColor.h.

References m_rgba.

◆ getRgba() [2/2]

int te::color::RGBAColor::getRgba ( ) const
inline

It returns the color value (0xAARRGGBB).

Returns
It returns a number of 4 bytes. The values are on the following order: alpha, red, green and blue. The alpha is the most significant byte.

Definition at line 336 of file RGBAColor.h.

References m_rgba.

◆ operator!=()

bool te::color::RGBAColor::operator!= ( const RGBAColor color) const
inline

It compares the colors are different.

Parameters
colorThe rgba color to be compared.
Returns
Returns true if this color has not the same RGB and alpha values.

Definition at line 302 of file RGBAColor.h.

References operator==().

◆ operator=() [1/2]

te::color::RGBAColor & te::color::RGBAColor::operator= ( const RGBAColor color)
inline

Assigns a copy of a color to this color, and returns a reference to it.

Parameters
colorThe rgba color to be copied.
Returns
Returns a reference to it.

Definition at line 283 of file RGBAColor.h.

References m_rgba.

◆ operator=() [2/2]

te::color::RGBAColor & te::color::RGBAColor::operator= ( const int &  rgba)
inline

Assigns a copy of a color to this color.

Parameters
rgbathe 32-bit RGBA (Red-Green-Blue-Alpha channel) color to be copied.
Returns
Returns a reference to it.

Definition at line 289 of file RGBAColor.h.

References m_rgba.

◆ operator==()

bool te::color::RGBAColor::operator== ( const RGBAColor color) const
inline

It compares the colors are iqual.

Parameters
colorThe rgba color to be compared.
Returns
Returns true if this color has the same RGB and alpha values.

Definition at line 295 of file RGBAColor.h.

References m_rgba.

Referenced by operator!=().

◆ setColor() [1/3]

void te::color::RGBAColor::setColor ( const std::string &  hexColor)
inline

It sets the color using a two hexadecimal RGB-encoded color.

Parameters
hexColorThe color value is RGB-encoded using two hexadecimal digits per primary-color component, in the order Red, Green, Blue, prefixed with a hash (#) sign. The hexadecimal digits between A and F may be in either uppercase or lowercase.

Definition at line 341 of file RGBAColor.h.

References te::core::GetDecimalFromHexNotCS(), and TE_OPAQUE.

Referenced by RGBAColor().

◆ setColor() [2/3]

void te::color::RGBAColor::setColor ( int  r,
int  g,
int  b,
int  a = 255 
)
inline

It sets the color.

Parameters
rRed component (range from 0 to 255).
gGreen component (range from 0 to 255).
bBlue component (range from 0 to 255).
aAlpha component. A range from 0 to 255 (see the macro TE_OPAQUE and TE_TRANSPARENT for the values of totally transparent and totally opaque).

Definition at line 389 of file RGBAColor.h.

References m_rgba.

◆ setColor() [3/3]

void te::color::RGBAColor::setColor ( int  rgba)
inline

It sets the color.

Parameters
rgbaThe color represented by a number of 4 bytes, where the values ??are in the following order: alpha, red, green and blue. The alpha is the most significant byte.

Definition at line 394 of file RGBAColor.h.

References m_rgba.

Member Data Documentation

◆ m_rgba

int te::color::RGBAColor::m_rgba
private

It returns the internal representation as a 32-bits RGBA color.

Returns
The internal representation as a 32-bit RGBA color.Internal color, stored as a 32-bit.

Definition at line 252 of file RGBAColor.h.

Referenced by getAlpha(), getBlue(), getGreen(), getRed(), getRgba(), operator=(), operator==(), and setColor().


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