TGUI  0.9.5
Loading...
Searching...
No Matches

Wrapper for colors. More...

#include <TGUI/Color.hpp>

Public Member Functions

TGUI_CONSTEXPR Color ()
 Creates the object without a color.
 
TGUI_CONSTEXPR Color (const sf::Color &color)
 Creates the object from an sf::Color.
 
TGUI_CONSTEXPR Color (std::uint8_t red, std::uint8_t green, std::uint8_t blue, std::uint8_t alpha=255)
 Creates the object from an the RGB or RGBA values.
 
 Color (const String &string)
 Creates the object from a string.
 
 Color (const char *string)
 Creates the object from a string.
 
TGUI_CONSTEXPR bool isSet () const
 Checks if a color was set.
 
 operator sf::Color () const
 Converts this object into an sf::Color object.
 
 operator Vertex::Color () const
 Converts this object into a Vertex::Color object.
 
TGUI_CONSTEXPR std::uint8_t getRed () const
 Returns the red component of the color.
 
TGUI_CONSTEXPR std::uint8_t getGreen () const
 Returns the green component of the color.
 
TGUI_CONSTEXPR std::uint8_t getBlue () const
 Returns the blue component of the color.
 
TGUI_CONSTEXPR std::uint8_t getAlpha () const
 Returns the alpha component of the color.
 
TGUI_CONSTEXPR bool operator== (const Color &rhs) const
 Compares the color with another one.
 
TGUI_CONSTEXPR bool operator!= (const Color &right) const
 Compares the color with another one.
 

Static Public Member Functions

static TGUI_CONSTEXPR Color applyOpacity (const Color &color, float alpha)
 Returns the color with its alpha channel multiplied with the alpha parameter.
 

Static Public Attributes

static const Color Black { 0, 0, 0}
 Black predefined color.
 
static const Color White {255, 255, 255}
 White predefined color.
 
static const Color Red {255, 0, 0}
 Red predefined color.
 
static const Color Green { 0, 255, 0}
 Green predefined color.
 
static const Color Blue { 0, 0, 255}
 Blue predefined color.
 
static const Color Yellow {255, 255, 0}
 Yellow predefined color.
 
static const Color Magenta {255, 0, 255}
 Magenta predefined color.
 
static const Color Cyan { 0, 255, 255}
 Cyan predefined color.
 
static const Color Transparent { 0, 0, 0, 0}
 Transparent (black) predefined color.
 
static const std::map< String, ColorcolorMap
 
static const std::array< std::pair< StringView, Color >, 9 > colorNamesMap
 

Detailed Description

Wrapper for colors.

The class is used for 2 purposes:

  • Implicit converter for parameters. A function taking a Color as parameter can be given an sf::Color, RGB values or even a serialized string as argument.
  • Storing no color at all. Some colors may be optionally set and can thus remain unspecified.

Constructor & Destructor Documentation

◆ Color() [1/5]

TGUI_CONSTEXPR tgui::Color::Color ( )
inline

Creates the object without a color.

The isSet() function will return false when the object was created using this constructor.

◆ Color() [2/5]

TGUI_CONSTEXPR tgui::Color::Color ( const sf::Color &  color)
inline

Creates the object from an sf::Color.

Parameters
colorColor to set

◆ Color() [3/5]

TGUI_CONSTEXPR tgui::Color::Color ( std::uint8_t  red,
std::uint8_t  green,
std::uint8_t  blue,
std::uint8_t  alpha = 255 
)
inline

Creates the object from an the RGB or RGBA values.

Parameters
redRed component
greenGreen component
blueBlue component
alphaAlpha component

◆ Color() [4/5]

tgui::Color::Color ( const String string)
inline

Creates the object from a string.

Parameters
stringString to be deserialized as color

The Deserializer class is used to convert the string into a color.

◆ Color() [5/5]

tgui::Color::Color ( const char *  string)
inline

Creates the object from a string.

Parameters
stringString to be deserialized as color

The Deserializer class is used to convert the string into a color.

Member Function Documentation

◆ getAlpha()

TGUI_CONSTEXPR std::uint8_t tgui::Color::getAlpha ( ) const
inline

Returns the alpha component of the color.

Returns
Alpha component of the stored color or the one from the default color is no color was set

◆ getBlue()

TGUI_CONSTEXPR std::uint8_t tgui::Color::getBlue ( ) const
inline

Returns the blue component of the color.

Returns
Blue component of the stored color or the one from the default color is no color was set

◆ getGreen()

TGUI_CONSTEXPR std::uint8_t tgui::Color::getGreen ( ) const
inline

Returns the green component of the color.

Returns
Green component of the stored color or the one from the default color is no color was set

◆ getRed()

TGUI_CONSTEXPR std::uint8_t tgui::Color::getRed ( ) const
inline

Returns the red component of the color.

Returns
Red component of the stored color or the one from the default color is no color was set

◆ isSet()

TGUI_CONSTEXPR bool tgui::Color::isSet ( ) const
inline

Checks if a color was set.

Returns
True if a color was passed to the constructor, false when the default constructor was used

◆ operator sf::Color()

tgui::Color::operator sf::Color ( ) const
inline

Converts this object into an sf::Color object.

Returns
The color stored in this object, or the default color if no color was set

◆ operator Vertex::Color()

tgui::Color::operator Vertex::Color ( ) const
inlineexplicit

Converts this object into a Vertex::Color object.

Returns
The color stored in this object, or the default color if no color was set

Member Data Documentation

◆ colorNamesMap

constexpr const std::array< std::pair< StringView, Color >, 9 > tgui::Color::colorNamesMap
inlinestaticconstexpr
Initial value:
{
{{U"black", Color::Black},
{U"white", Color::White},
{U"red", Color::Red},
{U"yellow", Color::Yellow},
{U"green", Color::Green},
{U"cyan", Color::Cyan},
{U"blue", Color::Blue},
{U"magenta", Color::Magenta},
{U"transparent", Color::Transparent}}
}
static const Color Transparent
Transparent (black) predefined color.
Definition Color.hpp:261
static const Color Black
Black predefined color.
Definition Color.hpp:253
static const Color Green
Green predefined color.
Definition Color.hpp:256
static const Color White
White predefined color.
Definition Color.hpp:254
static const Color Cyan
Cyan predefined color.
Definition Color.hpp:260
static const Color Magenta
Magenta predefined color.
Definition Color.hpp:259
static const Color Yellow
Yellow predefined color.
Definition Color.hpp:258
static const Color Red
Red predefined color.
Definition Color.hpp:255
static const Color Blue
Blue predefined color.
Definition Color.hpp:257

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