Skip to content

Commit 2ca7fbf

Browse files
committed
Merge pull request #71 from LaurentGomila/feature/color_int_ctor
Added the ctor to create a sfColor from an sfUint32
2 parents 0fe078e + 2d9ae6c commit 2ca7fbf

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

include/SFML/Graphics/Color.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ CSFML_GRAPHICS_API sfColor sfColor_fromRGB(sfUint8 red, sfUint8 green, sfUint8 b
8080
////////////////////////////////////////////////////////////
8181
CSFML_GRAPHICS_API sfColor sfColor_fromRGBA(sfUint8 red, sfUint8 green, sfUint8 blue, sfUint8 alpha);
8282

83+
////////////////////////////////////////////////////////////
84+
/// \brief Construct the color from 32-bit unsigned integer
85+
///
86+
/// \param color Number containing the RGBA components (in that order)
87+
///
88+
/// \return sfColor constructed from the 32-bit unsigned integer
89+
///
90+
////////////////////////////////////////////////////////////
91+
CSFML_GRAPHICS_API sfColor sfColor_fromInteger(sfUint32 color);
92+
93+
////////////////////////////////////////////////////////////
94+
/// \brief Convert a color to a 32-bit unsigned integer
95+
///
96+
/// \return Color represented as a 32-bit unsigned integer
97+
///
98+
////////////////////////////////////////////////////////////
99+
CSFML_GRAPHICS_API sfUint32 sfColor_toInteger(sfColor color);
100+
83101
////////////////////////////////////////////////////////////
84102
/// \brief Add two colors
85103
///

src/SFML/Graphics/Color.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,25 @@ sfColor sfColor_fromRGBA(sfUint8 red, sfUint8 green, sfUint8 blue, sfUint8 alpha
6363
}
6464

6565

66+
////////////////////////////////////////////////////////////
67+
sfColor sfColor_fromInteger(sfUint32 color)
68+
{
69+
sfUint8 red = (color & 0xff000000) >> 24;
70+
sfUint8 green = (color & 0x00ff0000) >> 16;
71+
sfUint8 blue = (color & 0x0000ff00) >> 8;
72+
sfUint8 alpha = (color & 0x000000ff) >> 0;
73+
74+
return sfColor_fromRGBA(red, green, blue, alpha);
75+
}
76+
77+
78+
////////////////////////////////////////////////////////////
79+
sfUint32 sfColor_toInteger(sfColor color)
80+
{
81+
return (color.r << 24) | (color.g << 16) | (color.b << 8) | color.a;
82+
}
83+
84+
6685
////////////////////////////////////////////////////////////
6786
sfColor sfColor_add(sfColor color1, sfColor color2)
6887
{

0 commit comments

Comments
 (0)