diff --git a/include/SFML/Graphics/Color.h b/include/SFML/Graphics/Color.h index d32de25..81a0e80 100644 --- a/include/SFML/Graphics/Color.h +++ b/include/SFML/Graphics/Color.h @@ -80,6 +80,24 @@ CSFML_GRAPHICS_API sfColor sfColor_fromRGB(sfUint8 red, sfUint8 green, sfUint8 b //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfColor sfColor_fromRGBA(sfUint8 red, sfUint8 green, sfUint8 blue, sfUint8 alpha); +//////////////////////////////////////////////////////////// +/// \brief Construct the color from 32-bit unsigned integer +/// +/// \param color Number containing the RGBA components (in that order) +/// +/// \return sfColor constructed from the 32-bit unsigned integer +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfColor sfColor_fromInteger(sfUint32 color); + +//////////////////////////////////////////////////////////// +/// \brief Convert a color to a 32-bit unsigned integer +/// +/// \return Color represented as a 32-bit unsigned integer +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfUint32 sfColor_toInteger(sfColor color); + //////////////////////////////////////////////////////////// /// \brief Add two colors /// diff --git a/src/SFML/Graphics/Color.cpp b/src/SFML/Graphics/Color.cpp index e77a56b..40e60da 100644 --- a/src/SFML/Graphics/Color.cpp +++ b/src/SFML/Graphics/Color.cpp @@ -63,6 +63,25 @@ sfColor sfColor_fromRGBA(sfUint8 red, sfUint8 green, sfUint8 blue, sfUint8 alpha } +//////////////////////////////////////////////////////////// +sfColor sfColor_fromInteger(sfUint32 color) +{ + sfUint8 red = (color & 0xff000000) >> 24; + sfUint8 green = (color & 0x00ff0000) >> 16; + sfUint8 blue = (color & 0x0000ff00) >> 8; + sfUint8 alpha = (color & 0x000000ff) >> 0; + + return sfColor_fromRGBA(red, green, blue, alpha); +} + + +//////////////////////////////////////////////////////////// +sfUint32 sfColor_toInteger(sfColor color) +{ + return (color.r << 24) | (color.g << 16) | (color.b << 8) | color.a; +} + + //////////////////////////////////////////////////////////// sfColor sfColor_add(sfColor color1, sfColor color2) {