Skip to content

Commit

Permalink
Color mod functions for ttexture.
Browse files Browse the repository at this point in the history
  • Loading branch information
lipk committed Jun 11, 2014
1 parent d80b478 commit d702664
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/sdl/texture.cpp
Expand Up @@ -40,6 +40,9 @@ ttexture::ttexture(SDL_Renderer& renderer,
, smooth_scaling_(false)
, flip_(SDL_FLIP_NONE)
, clip_(create_rect(0, 0, w, h))
, mod_r_(0)
, mod_g_(0)
, mod_b_(0)
, source_surface_(NULL)
{
if(!texture_) {
Expand All @@ -58,6 +61,9 @@ ttexture::ttexture(SDL_Renderer& renderer,
, smooth_scaling_(false)
, flip_(SDL_FLIP_NONE)
, clip_()
, mod_r_(0)
, mod_g_(0)
, mod_b_(0)
, source_surface_(IMG_Load(file.c_str()))
{
if(source_surface_ == NULL) {
Expand All @@ -77,6 +83,9 @@ ttexture::ttexture()
, smooth_scaling_(false)
, flip_(SDL_FLIP_NONE)
, clip_()
, mod_r_(0)
, mod_g_(0)
, mod_b_(0)
, source_surface_(NULL)
{}

Expand Down Expand Up @@ -105,6 +114,9 @@ ttexture::ttexture(const ttexture& texture)
, smooth_scaling_(texture.smooth_scaling_)
, flip_(texture.flip_)
, clip_(texture.clip_)
, mod_r_(texture.mod_r_)
, mod_g_(texture.mod_g_)
, mod_b_(texture.mod_b_)
, source_surface_(texture.source_surface_)
{
assert(reference_count_);
Expand All @@ -125,6 +137,9 @@ ttexture::ttexture(SDL_Renderer& renderer,
, smooth_scaling_(false)
, flip_(SDL_FLIP_NONE)
, clip_()
, mod_r_(0)
, mod_g_(0)
, mod_b_(0)
, source_surface_(source_surface__)
{
if(source_surface_ == NULL) {
Expand All @@ -147,6 +162,9 @@ ttexture::ttexture(SDL_Renderer& renderer,
, smooth_scaling_(false)
, flip_(SDL_FLIP_NONE)
, clip_()
, mod_r_(0)
, mod_g_(0)
, mod_b_(0)
, source_surface_(
SDL_ConvertSurface(surface, surface->format, surface->flags))
{
Expand Down Expand Up @@ -325,6 +343,28 @@ SDL_BlendMode ttexture::blend_mode() const
return res;
}

void ttexture::set_color_mod(Uint8 r, Uint8 g, Uint8 b)
{
mod_r_ = r;
mod_g_ = g;
mod_b_ = b;
}

Uint8 ttexture::red_mod() const
{
return mod_r_;
}

Uint8 ttexture::green_mod() const
{
return mod_g_;
}

Uint8 ttexture::blue_mod() const
{
return mod_b_;
}

void ttexture::update_pixels(SDL_Surface *surf)
{
const int retcode = SDL_UpdateTexture(texture_,
Expand Down
27 changes: 27 additions & 0 deletions src/sdl/texture.hpp
Expand Up @@ -271,6 +271,30 @@ class ttexture
*/
SDL_BlendMode blend_mode() const;

/**
* Sets the color modulation of the texture.
*
* @param r Red modulation.
* @param g Green modulation.
* @param b Blue modulation.
*/
void set_color_mod(Uint8 r, Uint8 g, Uint8 b);

/**
* Returns the red modulation of the texture.
*/
Uint8 red_mod() const;

/**
* Returns the green modulation of the texture.
*/
Uint8 green_mod() const;

/**
* Returns the blue modulation of the texture.
*/
Uint8 blue_mod() const;

/***** ***** ***** Other. ***** ***** *****/

/**
Expand Down Expand Up @@ -318,6 +342,9 @@ class ttexture
/** What should actually be displayed of the texture. */
SDL_Rect clip_;

/** Color modulation. */
Uint8 mod_r_, mod_g_, mod_b_;

/**
* The SDL_Surface source of the @ref texture_.
*
Expand Down

0 comments on commit d702664

Please sign in to comment.