Added Color support for Surface

This commit is contained in:
Vraiment 2017-07-03 21:50:49 -07:00
parent ddaee362a1
commit b1cc4d5711
2 changed files with 38 additions and 0 deletions

View File

@ -145,6 +145,13 @@ SDL_BlendMode Surface::GetBlendMode() const {
return blendMode;
}
Color Surface::GetColorAndAlphaMod() const {
Color color;
GetColorMod(color.r, color.g, color.b);
color.SetAlpha(GetAlphaMod());
return color;
}
void Surface::GetColorMod(Uint8& r, Uint8& g, Uint8& b) const {
if (SDL_GetSurfaceColorMod(surface_, &r, &g, &b) != 0)
throw Exception("SDL_GetSurfaceColorMod");
@ -180,6 +187,10 @@ Surface& Surface::SetColorMod(Uint8 r, Uint8 g, Uint8 b) {
return *this;
}
Surface& Surface::SetColorAndAlphaMod(const Color color) {
return SetColorMod(color.r, color.g, color.b).SetAlphaMod(color.a);
}
Surface& Surface::SetRLE(bool flag) {
if (SDL_SetSurfaceRLE(surface_, flag ? 1 : 0) != 0)
throw Exception("SDL_SetSurfaceRLE");

View File

@ -30,6 +30,7 @@
#include <SDL2pp/Rect.hh>
#include <SDL2pp/Point.hh>
#include <SDL2pp/Export.hh>
#include <SDL2pp/Color.hh>
struct SDL_Surface;
struct SDL_PixelFormat;
@ -390,6 +391,18 @@ public:
////////////////////////////////////////////////////////////
SDL_BlendMode GetBlendMode() const;
////////////////////////////////////////////////////////////
/// \brief Get the additional color value multiplied into blit operations
///
/// \return Color object with the values used to do blit operations
///
/// \throws SDL2pp::Exception
///
/// \see http://wiki.libsdl.org/SDL_GetSurfaceColorMod
///
////////////////////////////////////////////////////////////
Color GetColorAndAlphaMod() const;
////////////////////////////////////////////////////////////
/// \brief Get the additional color value multiplied into blit operations
///
@ -477,6 +490,20 @@ public:
////////////////////////////////////////////////////////////
Surface& SetColorMod(Uint8 r = 255, Uint8 g = 255, Uint8 b = 255);
////////////////////////////////////////////////////////////
/// \brief Set an additional color value multiplied into blit operations
///
/// \param[in] color Color to be multiplied into blit operations
///
/// \returns Reference to self
///
/// \throws SDL2pp::Exception
///
/// \see http://wiki.libsdl.org/SDL_SetSurfaceColorMod
///
////////////////////////////////////////////////////////////
Surface& SetColorAndAlphaMod(const Color color);
////////////////////////////////////////////////////////////
/// \brief Set the RLE acceleration hint for a surface
///