SFML 3.0.0

- Main Page
- Topics
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | Related Symbols | List of all members
sf::Color Class Reference
Graphics module

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*=`

## Detailed Description

Utility class for manipulating RGBA colors.

`sf::Color` is a simple color class composed of 4 components:

- Red
- Green
- Blue
- Alpha (opacity)

Each component is a public member, an unsigned integer in the range [0, 255]. Thus, colors can be constructed and manipulated very easily:

sf::Color color(255, 0, 0); // red
color.r = 0; // make it black
color.b = 128; // make it dark blue
sf::Color
Utility class for manipulating RGBA colors.
Definition Color.hpp:40

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:

sf::Color black = sf::Color::Black;
sf::Color white = sf::Color::White;
sf::Color red = sf::Color::Red;
sf::Color green = sf::Color::Green;
sf::Color blue = sf::Color::Blue;
sf::Color yellow = sf::Color::Yellow;
sf::Color magenta = sf::Color::Magenta;
sf::Color cyan = sf::Color::Cyan;
sf::Color transparent = sf::Color::Transparent;
sf::Color::Red
static const Color Red
Red predefined color.
Definition Color.hpp:84
sf::Color::White
static const Color White
White predefined color.
Definition Color.hpp:83
sf::Color::Transparent
static const Color Transparent
Transparent (black) predefined color.
Definition Color.hpp:90
sf::Color::Cyan
static const Color Cyan
Cyan predefined color.
Definition Color.hpp:89
sf::Color::Magenta
static const Color Magenta
Magenta predefined color.
Definition Color.hpp:88
sf::Color::Black
static const Color Black
Black predefined color.
Definition Color.hpp:82
sf::Color::Green
static const Color Green
Green predefined color.
Definition Color.hpp:85
sf::Color::Blue
static const Color Blue
Blue predefined color.
Definition Color.hpp:86
sf::Color::Yellow
static const Color Yellow
Yellow predefined color.
Definition Color.hpp:87

Colors can also be added and modulated (multiplied) using the overloaded operators + and *.

Definition at line 39 of file Color.hpp.

## Constructor & Destructor Documentation

## ◆ Color() [1/3]

sf::Color::Color | ( |  | ) |
| constexpr default

Default constructor.

Constructs an opaque black color. It is equivalent to `sf::Color(0, 0, 0, 255)`.

## ◆ Color() [2/3]

sf::Color::Color | ( | std::uint8_t | red,
|  | std::uint8_t | green,
|  | std::uint8_t | blue,
|  | std::uint8_t | alpha = 255 )
| constexpr

Construct the color from its 4 RGBA components.

Parameters

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

## ◆ Color() [3/3]

sf::Color::Color | ( | std::uint32_t | color | ) |
| explicit constexpr

Construct the color from 32-bit unsigned integer.

Parameters

  color | Number containing the RGBA components (in that order)

## Member Function Documentation

## ◆ toInteger()

std::uint32_t sf::Color::toInteger | ( |  | ) | const
| nodiscard constexpr

Retrieve the color as a 32-bit unsigned integer.

Returns
  Color represented as a 32-bit unsigned integer

## Friends And Related Symbol Documentation

## ◆ operator!=()

bool operator!= | ( | Color | left,
|  | Color | right )
| related

Overload of the `operator!=`

This operator compares two colors and check if they are different.

Parameters

  left | Left operand
  right | Right operand

Returns
  `true` if colors are different, `false` if they are equal

## ◆ operator*()

Color operator* | ( | Color | left,
|  | Color | right )
| related

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].

Parameters

  left | Left operand
  right | Right operand

Returns
  Result of left * right

## ◆ operator*=()

Color & operator*= | ( | Color & | left,
|  | Color | right )
| related

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].

Parameters

  left | Left operand
  right | Right operand

Returns
  Reference to left

## ◆ operator+()

Color operator+ | ( | Color | left,
|  | Color | right )
| related

Overload of the binary `operator+`

This operator returns the component-wise sum of two colors. Components that exceed 255 are clamped to 255.

Parameters

  left | Left operand
  right | Right operand

Returns
  Result of left + right

## ◆ operator+=()

Color & operator+= | ( | Color & | left,
|  | Color | right )
| related

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.

Parameters

  left | Left operand
  right | Right operand

Returns
  Reference to left

## ◆ operator-()

Color operator- | ( | Color | left,
|  | Color | right )
| related

Overload of the binary `operator-`

This operator returns the component-wise subtraction of two colors. Components below 0 are clamped to 0.

Parameters

  left | Left operand
  right | Right operand

Returns
  Result of left - right

## ◆ operator-=()

Color & operator-= | ( | Color & | left,
|  | Color | right )
| related

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.

Parameters

  left | Left operand
  right | Right operand

Returns
  Reference to left

## ◆ operator==()

bool operator== | ( | Color | left,
|  | Color | right )
| related

Overload of the `operator==`

This operator compares two colors and check if they are equal.

Parameters

  left | Left operand
  right | Right operand

Returns
  `true` if colors are equal, `false` if they are different

## Member Data Documentation

## ◆ a

std::uint8_t sf::Color::a {255}

Alpha (opacity) component.

Definition at line 99 of file Color.hpp.

## ◆ b

std::uint8_t sf::Color::b {}

Blue component.

Definition at line 98 of file Color.hpp.

## ◆ Black

const Color sf::Color::Black
| static

Black predefined color.

Definition at line 82 of file Color.hpp.

## ◆ Blue

const Color sf::Color::Blue
| static

Blue predefined color.

Definition at line 86 of file Color.hpp.

## ◆ Cyan

const Color sf::Color::Cyan
| static

Cyan predefined color.

Definition at line 89 of file Color.hpp.

## ◆ g

std::uint8_t sf::Color::g {}

Green component.

Definition at line 97 of file Color.hpp.

## ◆ Green

const Color sf::Color::Green
| static

Green predefined color.

Definition at line 85 of file Color.hpp.

## ◆ Magenta

const Color sf::Color::Magenta
| static

Magenta predefined color.

Definition at line 88 of file Color.hpp.

## ◆ r

std::uint8_t sf::Color::r {}

Red component.

Definition at line 96 of file Color.hpp.

## ◆ Red

const Color sf::Color::Red
| static

Red predefined color.

Definition at line 84 of file Color.hpp.

## ◆ Transparent

const Color sf::Color::Transparent
| static

Transparent (black) predefined color.

Definition at line 90 of file Color.hpp.

## ◆ White

const Color sf::Color::White
| static

White predefined color.

Definition at line 83 of file Color.hpp.

## ◆ Yellow

const Color sf::Color::Yellow
| static

Yellow predefined color.

Definition at line 87 of file Color.hpp.

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

- Color.hpp