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-2024 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{
39class 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
191constexpr Color& operator+=(Color& left, Color right);
192
207constexpr Color& operator-=(Color& left, Color right);
208
225constexpr Color& operator*=(Color& left, Color right);
226
227} // namespace sf
228
229#include <SFML/Graphics/Color.inl>
230
231
Utility class for manipulating RGBA colors.
Definition Color.hpp:40
static const Color Red
Red predefined color.
Definition Color.hpp:84
constexpr Color operator-(Color left, Color right)
Overload of the binary operator-
constexpr Color(std::uint32_t color)
Construct the color from 32-bit unsigned integer.
constexpr Color & operator-=(Color &left, Color right)
Overload of the binary operator-=
static const Color White
White predefined color.
Definition Color.hpp:83
constexpr Color operator*(Color left, Color right)
Overload of the binary operator*
static const Color Transparent
Transparent (black) predefined color.
Definition Color.hpp:90
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.
std::uint8_t a
Alpha (opacity) component.
Definition Color.hpp:99
static const Color Cyan
Cyan predefined color.
Definition Color.hpp:89
std::uint8_t b
Blue component.
Definition Color.hpp:98
static const Color Magenta
Magenta predefined color.
Definition Color.hpp:88
constexpr Color & operator+=(Color &left, Color right)
Overload of the binary operator+=
static const Color Black
Black predefined color.
Definition Color.hpp:82
constexpr bool operator!=(Color left, Color right)
Overload of the operator!=
constexpr Color operator+(Color left, Color right)
Overload of the binary operator+
constexpr bool operator==(Color left, Color right)
Overload of the operator==
static const Color Green
Green predefined color.
Definition Color.hpp:85
std::uint8_t g
Green component.
Definition Color.hpp:97
static const Color Blue
Blue predefined color.
Definition Color.hpp:86
constexpr Color()=default
Default constructor.
constexpr Color & operator*=(Color &left, Color right)
Overload of the binary operator*=
std::uint8_t r
Red component.
Definition Color.hpp:96
constexpr std::uint32_t toInteger() const
Retrieve the color as a 32-bit unsigned integer.
static const Color Yellow
Yellow predefined color.
Definition Color.hpp:87