Warning
This page refers to an old version of SFML. Click here to switch to the latest version.
Warning
This page refers to an old version of SFML. Click here to switch to the latest version.
Utility class for manipulating RGBA colors. More...
#include <SFML/Graphics/Color.hpp>
Public Member Functions | |
constexpr | Color ()=default |
Default constructor. | |
constexpr | Color (std::uint8_t red, std::uint8_t green, std::uint8_t blue, std::uint8_t alpha=255) |
Construct the color from its 4 RGBA components. | |
constexpr | Color (std::uint32_t color) |
Construct the color from 32-bit unsigned integer. | |
constexpr std::uint32_t | toInteger () const |
Retrieve the color as a 32-bit unsigned integer. |
Public Attributes | |
std::uint8_t | r {} |
Red component. | |
std::uint8_t | g {} |
Green component. | |
std::uint8_t | b {} |
Blue component. | |
std::uint8_t | a {255} |
Alpha (opacity) component. |
Static Public Attributes | |
static const Color | Black |
Black predefined color. | |
static const Color | White |
White predefined color. | |
static const Color | Red |
Red predefined color. | |
static const Color | Green |
Green predefined color. | |
static const Color | Blue |
Blue predefined color. | |
static const Color | Yellow |
Yellow predefined color. | |
static const Color | Magenta |
Magenta predefined color. | |
static const Color | Cyan |
Cyan predefined color. | |
static const Color | Transparent |
Transparent (black) predefined color. |
Related Symbols | |
(Note that these are not member symbols.) | |
constexpr bool | operator== (Color left, Color right) |
Overload of the operator== | |
constexpr bool | operator!= (Color left, Color right) |
Overload of the operator!= | |
constexpr Color | operator+ (Color left, Color right) |
Overload of the binary operator+ | |
constexpr Color | operator- (Color left, Color right) |
Overload of the binary operator- | |
constexpr Color | operator* (Color left, Color right) |
Overload of the binary operator* | |
constexpr Color & | operator+= (Color &left, Color right) |
Overload of the binary operator+= | |
constexpr Color & | operator-= (Color &left, Color right) |
Overload of the binary operator-= | |
constexpr Color & | operator*= (Color &left, Color right) |
Overload of the binary operator*= |
Utility class for manipulating RGBA colors.
sf::Color is a simple color class composed of 4 components:
Each component is a public member, an unsigned integer in the range [0, 255]. Thus, colors can be constructed and manipulated very easily:
The fourth component of colors, named "alpha", represents the opacity of the color. A color with an alpha value of 255 will be fully opaque, while an alpha value of 0 will make a color fully transparent, whatever the value of the other components is.
The most common colors are already defined as static variables:
Colors can also be added and modulated (multiplied) using the overloaded operators + and *.
|
constexprdefault |
Default constructor.
Constructs an opaque black color. It is equivalent to sf::Color(0, 0, 0, 255).
|
constexpr |
Construct the color from its 4 RGBA components.
red | Red component (in the range [0, 255]) |
green | Green component (in the range [0, 255]) |
blue | Blue component (in the range [0, 255]) |
alpha | Alpha (opacity) component (in the range [0, 255]) |
|
explicitconstexpr |
Construct the color from 32-bit unsigned integer.
color | Number containing the RGBA components (in that order) |
|
nodiscardconstexpr |
Retrieve the color as a 32-bit unsigned integer.
Overload of the operator!=
This operator compares two colors and check if they are different.
left | Left operand |
right | Right operand |
Overload of the binary operator*
This operator returns the component-wise multiplication (also called "modulation") of two colors. Components are then divided by 255 so that the result is still in the range [0, 255].
left | Left operand |
right | Right operand |
Overload of the binary operator*=
This operator returns the component-wise multiplication (also called "modulation") of two colors, and assigns the result to the left operand. Components are then divided by 255 so that the result is still in the range [0, 255].
left | Left operand |
right | Right operand |
Overload of the binary operator+
This operator returns the component-wise sum of two colors. Components that exceed 255 are clamped to 255.
left | Left operand |
right | Right operand |
Overload of the binary operator+=
This operator computes the component-wise sum of two colors, and assigns the result to the left operand. Components that exceed 255 are clamped to 255.
left | Left operand |
right | Right operand |
Overload of the binary operator-
This operator returns the component-wise subtraction of two colors. Components below 0 are clamped to 0.
left | Left operand |
right | Right operand |
Overload of the binary operator-=
This operator computes the component-wise subtraction of two colors, and assigns the result to the left operand. Components below 0 are clamped to 0.
left | Left operand |
right | Right operand |
Overload of the operator==
This operator compares two colors and check if they are equal.
left | Left operand |
right | Right operand |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |