105 lines
2.7 KiB
C++
105 lines
2.7 KiB
C++
#include <basic_widgets/core/renderer.hpp>
|
|
#include <basic_widgets/core/texture.hpp>
|
|
|
|
using namespace bwidgets;
|
|
|
|
Texture::Texture(SDL_Texture* t) : OpaqueStruct(t)
|
|
{
|
|
_attributes = attributes(t);
|
|
}
|
|
|
|
Texture::Texture(Renderer* r, SDL_PixelFormatEnum f, SDL_TextureAccess a, int w, int h)
|
|
: Texture(ptr_or_throw<SDLError>(SDL_CreateTexture((*r)(), f, a, w, h), __FILE__,
|
|
__FUNCTION__, __LINE__))
|
|
{}
|
|
|
|
Texture::Texture(Renderer* r, SDL_Surface* s)
|
|
: OpaqueStruct(ptr_or_throw<SDLError>(SDL_CreateTextureFromSurface((*r)(), s),
|
|
__FILE__, __FUNCTION__, __LINE__))
|
|
{
|
|
_attributes = attributes(_c_pod);
|
|
}
|
|
|
|
Texture::~Texture() noexcept
|
|
{
|
|
SDL_DestroyTexture(_c_pod);
|
|
_c_pod = nullptr;
|
|
}
|
|
|
|
auto Texture::alpha_mode() -> uint8_t
|
|
{
|
|
uint8_t mode = 0;
|
|
SDLError::success_or_throw(SDL_GetTextureAlphaMod(_c_pod, &mode), __FILE__,
|
|
__FUNCTION__, __LINE__);
|
|
|
|
return mode;
|
|
}
|
|
|
|
auto Texture::alpha_mode(uint8_t m) -> Texture*
|
|
{
|
|
SDLError::success_or_throw(SDL_SetTextureAlphaMod(_c_pod, m), __FILE__, __FUNCTION__,
|
|
__LINE__);
|
|
|
|
return this;
|
|
}
|
|
|
|
auto Texture::blend_mode() -> SDL_BlendMode
|
|
{
|
|
SDL_BlendMode mode {};
|
|
SDLError::success_or_throw(SDL_GetTextureBlendMode(_c_pod, &mode), __FILE__,
|
|
__FUNCTION__, __LINE__);
|
|
|
|
return mode;
|
|
}
|
|
|
|
auto Texture::blend_mode(SDL_BlendMode m) -> Texture*
|
|
{
|
|
SDLError::success_or_throw(SDL_SetTextureBlendMode(_c_pod, m), __FILE__,
|
|
__FUNCTION__, __LINE__);
|
|
|
|
return this;
|
|
}
|
|
|
|
auto Texture::color_mode() -> Color
|
|
{
|
|
Color mode;
|
|
SDLError::success_or_throw(
|
|
SDL_GetTextureColorMod(_c_pod, &mode().r, &mode().g, &mode().b), __FILE__,
|
|
__FUNCTION__, __LINE__);
|
|
|
|
return mode;
|
|
}
|
|
|
|
auto Texture::color_mode(const Color& m) -> Texture*
|
|
{
|
|
SDLError::success_or_throw(SDL_SetTextureColorMod(_c_pod, m().r, m().g, m().b),
|
|
__FILE__, __FUNCTION__, __LINE__);
|
|
|
|
return this;
|
|
}
|
|
|
|
auto Texture::scale_mode() -> SDL_ScaleMode
|
|
{
|
|
SDL_ScaleMode mode {};
|
|
SDLError::success_or_throw(SDL_GetTextureScaleMode(_c_pod, &mode), __FILE__,
|
|
__FUNCTION__, __LINE__);
|
|
|
|
return mode;
|
|
}
|
|
|
|
auto Texture::scale_mode(SDL_ScaleMode m) -> Texture*
|
|
{
|
|
SDLError::success_or_throw(SDL_SetTextureScaleMode(_c_pod, m), __FILE__,
|
|
__FUNCTION__, __LINE__);
|
|
|
|
return this;
|
|
}
|
|
|
|
auto Texture::update(SDL_Rect* r, const void* pixels, int pitch) -> Texture*
|
|
{
|
|
SDLError::success_or_throw(SDL_UpdateTexture(_c_pod, r, pixels, pitch), __FILE__,
|
|
__FUNCTION__, __LINE__);
|
|
|
|
return this;
|
|
}
|