Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:58:13

0001 ////////////////////////////////////////////////////////////
0002 //
0003 // SFML - Simple and Fast Multimedia Library
0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
0005 //
0006 // This software is provided 'as-is', without any express or implied warranty.
0007 // In no event will the authors be held liable for any damages arising from the use of this software.
0008 //
0009 // Permission is granted to anyone to use this software for any purpose,
0010 // including commercial applications, and to alter it and redistribute it freely,
0011 // subject to the following restrictions:
0012 //
0013 // 1. The origin of this software must not be misrepresented;
0014 //    you must not claim that you wrote the original software.
0015 //    If you use this software in a product, an acknowledgment
0016 //    in the product documentation would be appreciated but is not required.
0017 //
0018 // 2. Altered source versions must be plainly marked as such,
0019 //    and must not be misrepresented as being the original software.
0020 //
0021 // 3. This notice may not be removed or altered from any source distribution.
0022 //
0023 ////////////////////////////////////////////////////////////
0024 
0025 #ifndef SFML_COLOR_HPP
0026 #define SFML_COLOR_HPP
0027 
0028 ////////////////////////////////////////////////////////////
0029 // Headers
0030 ////////////////////////////////////////////////////////////
0031 #include <SFML/Graphics/Export.hpp>
0032 
0033 
0034 namespace sf
0035 {
0036 ////////////////////////////////////////////////////////////
0037 /// \brief Utility class for manipulating RGBA colors
0038 ///
0039 ////////////////////////////////////////////////////////////
0040 class SFML_GRAPHICS_API Color
0041 {
0042 public:
0043 
0044     ////////////////////////////////////////////////////////////
0045     /// \brief Default constructor
0046     ///
0047     /// Constructs an opaque black color. It is equivalent to
0048     /// sf::Color(0, 0, 0, 255).
0049     ///
0050     ////////////////////////////////////////////////////////////
0051     Color();
0052 
0053     ////////////////////////////////////////////////////////////
0054     /// \brief Construct the color from its 4 RGBA components
0055     ///
0056     /// \param red   Red component (in the range [0, 255])
0057     /// \param green Green component (in the range [0, 255])
0058     /// \param blue  Blue component (in the range [0, 255])
0059     /// \param alpha Alpha (opacity) component (in the range [0, 255])
0060     ///
0061     ////////////////////////////////////////////////////////////
0062     Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha = 255);
0063 
0064     ////////////////////////////////////////////////////////////
0065     /// \brief Construct the color from 32-bit unsigned integer
0066     ///
0067     /// \param color Number containing the RGBA components (in that order)
0068     ///
0069     ////////////////////////////////////////////////////////////
0070     explicit Color(Uint32 color);
0071 
0072     ////////////////////////////////////////////////////////////
0073     /// \brief Retrieve the color as a 32-bit unsigned integer
0074     ///
0075     /// \return Color represented as a 32-bit unsigned integer
0076     ///
0077     ////////////////////////////////////////////////////////////
0078     Uint32 toInteger() const;
0079 
0080     ////////////////////////////////////////////////////////////
0081     // Static member data
0082     ////////////////////////////////////////////////////////////
0083     static const Color Black;       //!< Black predefined color
0084     static const Color White;       //!< White predefined color
0085     static const Color Red;         //!< Red predefined color
0086     static const Color Green;       //!< Green predefined color
0087     static const Color Blue;        //!< Blue predefined color
0088     static const Color Yellow;      //!< Yellow predefined color
0089     static const Color Magenta;     //!< Magenta predefined color
0090     static const Color Cyan;        //!< Cyan predefined color
0091     static const Color Transparent; //!< Transparent (black) predefined color
0092 
0093     ////////////////////////////////////////////////////////////
0094     // Member data
0095     ////////////////////////////////////////////////////////////
0096     Uint8 r; //!< Red component
0097     Uint8 g; //!< Green component
0098     Uint8 b; //!< Blue component
0099     Uint8 a; //!< Alpha (opacity) component
0100 };
0101 
0102 ////////////////////////////////////////////////////////////
0103 /// \relates Color
0104 /// \brief Overload of the == operator
0105 ///
0106 /// This operator compares two colors and check if they are equal.
0107 ///
0108 /// \param left  Left operand
0109 /// \param right Right operand
0110 ///
0111 /// \return True if colors are equal, false if they are different
0112 ///
0113 ////////////////////////////////////////////////////////////
0114 SFML_GRAPHICS_API bool operator ==(const Color& left, const Color& right);
0115 
0116 ////////////////////////////////////////////////////////////
0117 /// \relates Color
0118 /// \brief Overload of the != operator
0119 ///
0120 /// This operator compares two colors and check if they are different.
0121 ///
0122 /// \param left  Left operand
0123 /// \param right Right operand
0124 ///
0125 /// \return True if colors are different, false if they are equal
0126 ///
0127 ////////////////////////////////////////////////////////////
0128 SFML_GRAPHICS_API bool operator !=(const Color& left, const Color& right);
0129 
0130 ////////////////////////////////////////////////////////////
0131 /// \relates Color
0132 /// \brief Overload of the binary + operator
0133 ///
0134 /// This operator returns the component-wise sum of two colors.
0135 /// Components that exceed 255 are clamped to 255.
0136 ///
0137 /// \param left  Left operand
0138 /// \param right Right operand
0139 ///
0140 /// \return Result of \a left + \a right
0141 ///
0142 ////////////////////////////////////////////////////////////
0143 SFML_GRAPHICS_API Color operator +(const Color& left, const Color& right);
0144 
0145 ////////////////////////////////////////////////////////////
0146 /// \relates Color
0147 /// \brief Overload of the binary - operator
0148 ///
0149 /// This operator returns the component-wise subtraction of two colors.
0150 /// Components below 0 are clamped to 0.
0151 ///
0152 /// \param left  Left operand
0153 /// \param right Right operand
0154 ///
0155 /// \return Result of \a left - \a right
0156 ///
0157 ////////////////////////////////////////////////////////////
0158 SFML_GRAPHICS_API Color operator -(const Color& left, const Color& right);
0159 
0160 ////////////////////////////////////////////////////////////
0161 /// \relates Color
0162 /// \brief Overload of the binary * operator
0163 ///
0164 /// This operator returns the component-wise multiplication
0165 /// (also called "modulation") of two colors.
0166 /// Components are then divided by 255 so that the result is
0167 /// still in the range [0, 255].
0168 ///
0169 /// \param left  Left operand
0170 /// \param right Right operand
0171 ///
0172 /// \return Result of \a left * \a right
0173 ///
0174 ////////////////////////////////////////////////////////////
0175 SFML_GRAPHICS_API Color operator *(const Color& left, const Color& right);
0176 
0177 ////////////////////////////////////////////////////////////
0178 /// \relates Color
0179 /// \brief Overload of the binary += operator
0180 ///
0181 /// This operator computes the component-wise sum of two colors,
0182 /// and assigns the result to the left operand.
0183 /// Components that exceed 255 are clamped to 255.
0184 ///
0185 /// \param left  Left operand
0186 /// \param right Right operand
0187 ///
0188 /// \return Reference to \a left
0189 ///
0190 ////////////////////////////////////////////////////////////
0191 SFML_GRAPHICS_API Color& operator +=(Color& left, const Color& right);
0192 
0193 ////////////////////////////////////////////////////////////
0194 /// \relates Color
0195 /// \brief Overload of the binary -= operator
0196 ///
0197 /// This operator computes the component-wise subtraction of two colors,
0198 /// and assigns the result to the left operand.
0199 /// Components below 0 are clamped to 0.
0200 ///
0201 /// \param left  Left operand
0202 /// \param right Right operand
0203 ///
0204 /// \return Reference to \a left
0205 ///
0206 ////////////////////////////////////////////////////////////
0207 SFML_GRAPHICS_API Color& operator -=(Color& left, const Color& right);
0208 
0209 ////////////////////////////////////////////////////////////
0210 /// \relates Color
0211 /// \brief Overload of the binary *= operator
0212 ///
0213 /// This operator returns the component-wise multiplication
0214 /// (also called "modulation") of two colors, and assigns
0215 /// the result to the left operand.
0216 /// Components are then divided by 255 so that the result is
0217 /// still in the range [0, 255].
0218 ///
0219 /// \param left  Left operand
0220 /// \param right Right operand
0221 ///
0222 /// \return Reference to \a left
0223 ///
0224 ////////////////////////////////////////////////////////////
0225 SFML_GRAPHICS_API Color& operator *=(Color& left, const Color& right);
0226 
0227 } // namespace sf
0228 
0229 
0230 #endif // SFML_COLOR_HPP
0231 
0232 
0233 ////////////////////////////////////////////////////////////
0234 /// \class sf::Color
0235 /// \ingroup graphics
0236 ///
0237 /// sf::Color is a simple color class composed of 4 components:
0238 /// \li Red
0239 /// \li Green
0240 /// \li Blue
0241 /// \li Alpha (opacity)
0242 ///
0243 /// Each component is a public member, an unsigned integer in
0244 /// the range [0, 255]. Thus, colors can be constructed and
0245 /// manipulated very easily:
0246 ///
0247 /// \code
0248 /// sf::Color color(255, 0, 0); // red
0249 /// color.r = 0;                // make it black
0250 /// color.b = 128;              // make it dark blue
0251 /// \endcode
0252 ///
0253 /// The fourth component of colors, named "alpha", represents
0254 /// the opacity of the color. A color with an alpha value of
0255 /// 255 will be fully opaque, while an alpha value of 0 will
0256 /// make a color fully transparent, whatever the value of the
0257 /// other components is.
0258 ///
0259 /// The most common colors are already defined as static variables:
0260 /// \code
0261 /// sf::Color black       = sf::Color::Black;
0262 /// sf::Color white       = sf::Color::White;
0263 /// sf::Color red         = sf::Color::Red;
0264 /// sf::Color green       = sf::Color::Green;
0265 /// sf::Color blue        = sf::Color::Blue;
0266 /// sf::Color yellow      = sf::Color::Yellow;
0267 /// sf::Color magenta     = sf::Color::Magenta;
0268 /// sf::Color cyan        = sf::Color::Cyan;
0269 /// sf::Color transparent = sf::Color::Transparent;
0270 /// \endcode
0271 ///
0272 /// Colors can also be added and modulated (multiplied) using the
0273 /// overloaded operators + and *.
0274 ///
0275 ////////////////////////////////////////////////////////////