2017-06-18 17:36:13 +08:00
|
|
|
#include "Texture.h"
|
2017-06-18 20:37:45 +08:00
|
|
|
#include "_caster.h"
|
2017-06-18 17:36:13 +08:00
|
|
|
#include "begin_code.h"
|
|
|
|
//private
|
|
|
|
void Texture::_set(SDL_Texture* p)
|
|
|
|
{
|
|
|
|
_text.reset(p,SDL_DestroyTexture);
|
|
|
|
updateInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
//private
|
|
|
|
void Texture::_set_no_delete(SDL_Texture* p)
|
|
|
|
{
|
|
|
|
_text.reset(p,[](SDL_Texture*) {});
|
|
|
|
updateInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
//private
|
|
|
|
void Texture::_clear()
|
|
|
|
{
|
|
|
|
_text.reset();
|
|
|
|
updateInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
//private
|
|
|
|
SDL_Texture* Texture::_get() const
|
|
|
|
{
|
|
|
|
return _text.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
Texture::Texture()
|
|
|
|
{
|
|
|
|
updateInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect Texture::getSize()
|
|
|
|
{
|
2017-06-18 20:37:45 +08:00
|
|
|
return _rect;
|
2017-06-18 17:36:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int Texture::getw() const
|
|
|
|
{
|
2017-06-18 20:37:45 +08:00
|
|
|
return _rect.w;
|
2017-06-18 17:36:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int Texture::geth() const
|
|
|
|
{
|
2017-06-18 20:37:45 +08:00
|
|
|
return _rect.h;
|
2017-06-18 17:36:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Texture::isReady() const
|
|
|
|
{
|
|
|
|
return (_get() != nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Texture::setBlendMode(BlendMode mode)
|
|
|
|
{
|
|
|
|
return SDL_SetTextureBlendMode(_get(), _internal::getSDLBlendModeFromBlendMode(mode));
|
|
|
|
}
|
|
|
|
|
|
|
|
BlendMode Texture::getBlendMode() const
|
|
|
|
{
|
|
|
|
SDL_BlendMode temp;
|
|
|
|
SDL_GetTextureBlendMode(_get(), &temp);
|
|
|
|
return _internal::getBlendModeFromSDLBlendMode(temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Alpha: 0: Transparent 255: opaque
|
|
|
|
|
|
|
|
int Texture::setAlphaMode(int alpha)
|
|
|
|
{
|
|
|
|
Uint8 temp = std::max(std::min(alpha, 255), 0);
|
|
|
|
return SDL_SetTextureAlphaMod(_get(), temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Texture::getAlphaMode() const
|
|
|
|
{
|
|
|
|
Uint8 temp;
|
|
|
|
SDL_GetTextureAlphaMod(_get(), &temp);
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorMode Texture::getColorMode() const
|
|
|
|
{
|
|
|
|
ColorMode pack;
|
|
|
|
Uint8 r, g, b;
|
|
|
|
SDL_GetTextureColorMod(_get(), &r, &g, &b);
|
|
|
|
pack.r = r;
|
|
|
|
pack.g = g;
|
|
|
|
pack.b = b;
|
|
|
|
return pack;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Texture::setColorMode(ColorMode mode)
|
|
|
|
{
|
|
|
|
return SDL_SetTextureColorMod(_get(), mode.r, mode.g, mode.b);
|
|
|
|
}
|
|
|
|
|
|
|
|
RGBA Texture::getRGBA() const
|
|
|
|
{
|
|
|
|
return RGBA(getColorMode(), getAlphaMode());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Texture::setRGBA(const RGBA& pack)
|
|
|
|
{
|
|
|
|
setColorMode(pack.toColorMode());
|
|
|
|
setAlphaMode(pack.a);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// updateInfo() must be called after Texture is changed.
|
|
|
|
//protected
|
|
|
|
void Texture::updateInfo()
|
|
|
|
{
|
|
|
|
if(_get()==nullptr)
|
|
|
|
{
|
2017-06-18 20:37:45 +08:00
|
|
|
_rect.x=_rect.y=_rect.w=_rect.h=0;
|
2017-06-18 17:36:13 +08:00
|
|
|
}
|
2017-06-18 20:37:45 +08:00
|
|
|
SDL_QueryTexture(_get(), NULL, NULL, &_rect.w, &_rect.h);
|
|
|
|
_rect.x = _rect.y = 0;
|
2017-06-18 17:36:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Texture::release()
|
|
|
|
{
|
|
|
|
_clear();
|
|
|
|
}
|
|
|
|
#include "end_code.h"
|