From daab479c0f54093c57144531b87e921c8c8d653b Mon Sep 17 00:00:00 2001 From: Vraiment Date: Mon, 3 Jul 2017 22:30:39 -0700 Subject: [PATCH] Added Color support for Texture --- SDL2pp/Texture.cc | 11 +++++++++++ SDL2pp/Texture.hh | 27 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/SDL2pp/Texture.cc b/SDL2pp/Texture.cc index 2398efb..282d935 100644 --- a/SDL2pp/Texture.cc +++ b/SDL2pp/Texture.cc @@ -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) { 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; +} + } diff --git a/SDL2pp/Texture.hh b/SDL2pp/Texture.hh index 1e923f2..35818aa 100644 --- a/SDL2pp/Texture.hh +++ b/SDL2pp/Texture.hh @@ -31,6 +31,7 @@ #include #include #include +#include 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; }; }