Added Color support for Texture

This commit is contained in:
Vraiment 2017-07-03 22:30:39 -07:00
parent b1cc4d5711
commit daab479c0f
2 changed files with 38 additions and 0 deletions

View File

@ -157,6 +157,10 @@ Texture& Texture::SetColorMod(Uint8 r, Uint8 g, Uint8 b) {
return *this;
}
Texture& Texture::SetColorAndAlphaMod(const Color color) {
return SetColorMod(color.r, color.g, color.b).SetAlphaMod(color.a);
}
Texture::LockHandle Texture::Lock(const Optional<Rect>& rect) {
return LockHandle(this, rect);
}
@ -215,4 +219,11 @@ void Texture::GetColorMod(Uint8& r, Uint8& g, Uint8& b) const {
throw Exception("SDL_GetTextureColorMod");
}
Color Texture::GetColorAndAlphaMod() const {
Color color;
GetColorMod(color.r, color.g, color.b);
color.SetAlpha(GetAlphaMod());
return color;
}
}

View File

@ -31,6 +31,7 @@
#include <SDL2pp/Rect.hh>
#include <SDL2pp/Config.hh>
#include <SDL2pp/Export.hh>
#include <SDL2pp/Color.hh>
struct SDL_Texture;
@ -421,6 +422,20 @@ public:
////////////////////////////////////////////////////////////
Texture& SetColorMod(Uint8 r = 255, Uint8 g = 255, Uint8 b = 255);
////////////////////////////////////////////////////////////
/// \brief Set an additional color value multiplied into render copy operations
///
/// \param[in] color Color to be used when multiplied into render copy operations
///
/// \returns Reference to self
///
/// \throws SDL2pp::Exception
///
/// \see http://wiki.libsdl.org/SDL_SetTextureColorMod
///
////////////////////////////////////////////////////////////
Texture& SetColorAndAlphaMod(const Color color = Color{255, 255, 255, 255});
////////////////////////////////////////////////////////////
/// \brief Lock texture for write-only pixel access
///
@ -536,6 +551,18 @@ public:
///
////////////////////////////////////////////////////////////
void GetColorMod(Uint8& r, Uint8& g, Uint8 &b) const;
////////////////////////////////////////////////////////////
/// \brief Get the additional color value multiplied into render copy operations
///
/// \return Color object with the values used to do render copy operations
///
/// \throws SDL2pp::Exception
///
/// \see http://wiki.libsdl.org/SDL_GetTextureColorMod
///
////////////////////////////////////////////////////////////
Color GetColorAndAlphaMod() const;
};
}