SFML - Simple and Fast Multimedia Library

SFML 3.0.2
Loading...
Searching...
No Matches
Color.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2025 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
28// Headers
30#include <cstdint>
31
32
33namespace sf
34{
39 class Color
40{
41public:
49 constexpr Color() = default;
50
60 constexpr Color(std::uint8_t red, std::uint8_t green, std::uint8_t blue, std::uint8_t alpha = 255);
61
68 constexpr explicit Color(std::uint32_t color);
69
76 [[nodiscard]] constexpr std::uint32_t toInteger() const;
77
79 // Static member data
81 // NOLINTBEGIN(readability-identifier-naming)
82 static const Color Black;
83 static const Color White;
84 static const Color Red;
85 static const Color Green;
86 static const Color Blue;
87 static const Color Yellow;
88 static const Color Magenta;
89 static const Color Cyan;
90 static const Color Transparent;
91 // NOLINTEND(readability-identifier-naming)
92
94 // Member data
96 std::uint8_t r{};
97 std::uint8_t g{};
98 std::uint8_t b{};
99 std::uint8_t a{255};
100};
101
114[[nodiscard]] constexpr bool operator==(Color left, Color right);
115
128[[nodiscard]] constexpr bool operator!=(Color left, Color right);
129
143[[nodiscard]] constexpr Color operator+(Color left, Color right);
144
158[[nodiscard]] constexpr Color operator-(Color left, Color right);
159
175[[nodiscard]] constexpr Color operator*(Color left, Color right);
176
191 constexpr Color& operator+=(Color& left, Color right);
192
207 constexpr Color& operator-=(Color& left, Color right);
208
225 constexpr Color& operator*=(Color& left, Color right);
226
227} // namespace sf
228
229#include <SFML/Graphics/Color.inl>
230
231
sf::Color::Red
static const Color Red
Red predefined color.
Definition Color.hpp:84
sf::Color::operator-
constexpr Color operator-(Color left, Color right)
Overload of the binary operator-
sf::Color::Color
constexpr Color(std::uint32_t color)
Construct the color from 32-bit unsigned integer.
sf::Color::operator-=
constexpr Color & operator-=(Color &left, Color right)
Overload of the binary operator-=
sf::Color::White
static const Color White
White predefined color.
Definition Color.hpp:83
sf::Color::operator*
constexpr Color operator*(Color left, Color right)
Overload of the binary operator*
sf::Color::Transparent
static const Color Transparent
Transparent (black) predefined color.
Definition Color.hpp:90
sf::Color::Color
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.
sf::Color::a
std::uint8_t a
Alpha (opacity) component.
Definition Color.hpp:99
sf::Color::Cyan
static const Color Cyan
Cyan predefined color.
Definition Color.hpp:89
sf::Color::b
std::uint8_t b
Blue component.
Definition Color.hpp:98
sf::Color::Magenta
static const Color Magenta
Magenta predefined color.
Definition Color.hpp:88
sf::Color::operator+=
constexpr Color & operator+=(Color &left, Color right)
Overload of the binary operator+=
sf::Color::Black
static const Color Black
Black predefined color.
Definition Color.hpp:82
sf::Color::operator!=
constexpr bool operator!=(Color left, Color right)
Overload of the operator!=
sf::Color::operator+
constexpr Color operator+(Color left, Color right)
Overload of the binary operator+
sf::Color::operator==
constexpr bool operator==(Color left, Color right)
Overload of the operator==
sf::Color::Green
static const Color Green
Green predefined color.
Definition Color.hpp:85
sf::Color::g
std::uint8_t g
Green component.
Definition Color.hpp:97
sf::Color::Blue
static const Color Blue
Blue predefined color.
Definition Color.hpp:86
sf::Color::Color
constexpr Color()=default
Default constructor.
sf::Color::operator*=
constexpr Color & operator*=(Color &left, Color right)
Overload of the binary operator*=
sf::Color::r
std::uint8_t r
Red component.
Definition Color.hpp:96
sf::Color::toInteger
constexpr std::uint32_t toInteger() const
Retrieve the color as a 32-bit unsigned integer.
sf::Color::Yellow
static const Color Yellow
Yellow predefined color.
Definition Color.hpp:87
sf
Definition AudioResource.hpp:36