TGUI  1.6.1
Loading...
Searching...
No Matches

Wrapper for colors. More...

#include <TGUI/Color.hpp>

Public Member Functions

constexpr Color ()
 Creates the object without a color.
 
constexpr Color (const sf::Color &color)
 Creates the object from an sf::Color.
 
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.
 
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.
 
constexpr std::uint8_t getRed () const
 Returns the red component of the color.
 
constexpr std::uint8_t getGreen () const
 Returns the green component of the color.
 
constexpr std::uint8_t getBlue () const
 Returns the blue component of the color.
 
constexpr std::uint8_t getAlpha () const
 Returns the alpha component of the color.
 
constexpr bool operator== (const Color &rhs) const
 Compares the color with another one.
 
constexpr bool operator!= (const Color &right) const
 Compares the color with another one.
 

Static Public Member Functions

static 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::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::Color::Color ( )
inlineconstexpr

Creates the object without a color.

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

◆ Color() [2/5]

tgui::Color::Color ( const sf::Color & color)
inlineconstexpr

Creates the object from an sf::Color.

Parameters
colorColor to set

◆ Color() [3/5]

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

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()

std::uint8_t tgui::Color::getAlpha ( ) const
inlinenodiscardconstexpr

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()

std::uint8_t tgui::Color::getBlue ( ) const
inlinenodiscardconstexpr

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()

std::uint8_t tgui::Color::getGreen ( ) const
inlinenodiscardconstexpr

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()

std::uint8_t tgui::Color::getRed ( ) const
inlinenodiscardconstexpr

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()

bool tgui::Color::isSet ( ) const
inlinenodiscardconstexpr

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

const std::array< std::pair< StringView, Color >, 9 > tgui::Color::colorNamesMap
inlinestaticconstexpr
Initial value:
{
{{U"black"sv, Color::Black},
{U"white"sv, Color::White},
{U"red"sv, Color::Red},
{U"yellow"sv, Color::Yellow},
{U"green"sv, Color::Green},
{U"cyan"sv, Color::Cyan},
{U"blue"sv, Color::Blue},
{U"magenta"sv, Color::Magenta},
{U"transparent"sv, Color::Transparent}}
}
static const Color Transparent
Transparent (black) predefined color.
Definition Color.hpp:267
static const Color Black
Black predefined color.
Definition Color.hpp:259
static const Color Green
Green predefined color.
Definition Color.hpp:262
static const Color White
White predefined color.
Definition Color.hpp:260
static const Color Cyan
Cyan predefined color.
Definition Color.hpp:266
static const Color Magenta
Magenta predefined color.
Definition Color.hpp:265
static const Color Yellow
Yellow predefined color.
Definition Color.hpp:264
static const Color Red
Red predefined color.
Definition Color.hpp:261
static const Color Blue
Blue predefined color.
Definition Color.hpp:263

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