mirror of
https://github.com/Relintai/programming_tutorials.git
synced 2025-04-29 22:08:00 +02:00
235 lines
7.2 KiB
Plaintext
235 lines
7.2 KiB
Plaintext
|
|
|
|
|---------------------------------------------------------------------------------------|
|
|
| class Texture |
|
|
|---------------------------------------------------------------------------------------|
|
|
| + Color get_color_mod() const |
|
|
| + void set_color_mod(const Color &color) |
|
|
| |
|
|
| + SDL_BlendMode get_blend_mode() const |
|
|
| + void set_blend_mode(const SDL_BlendMode blend_mode) |
|
|
| |
|
|
| + SDL_ScaleMode get_texture_scale_mode() const |
|
|
| + void set_texture_scale_mode(const SDL_ScaleMode scale_mode) |
|
|
| |
|
|
| + Image *get_image() |
|
|
| + void set_image(Image *image) |
|
|
| |
|
|
| + int get_width() const |
|
|
| + int get_height() const |
|
|
| + Uint32 get_format() const |
|
|
| + int get_access() const |
|
|
| |
|
|
| + void create(const int access, const int w, const int h) |
|
|
| + void refresh() |
|
|
| + void free() |
|
|
| |
|
|
| + SDL_Texture *get_texture() |
|
|
| + SDL_Texture *get_texture() const |
|
|
| |
|
|
| + bool is_render_target() |
|
|
| |
|
|
| + Texture() |
|
|
| + Texture(Image *image) |
|
|
| + virtual ~Texture() |
|
|
| |
|
|
| - Image *_image |
|
|
| - SDL_Texture *_texture |
|
|
|---------------------------------------------------------------------------------------|
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
get_color_mod:
|
|
Uint8 r
|
|
Uint8 g
|
|
Uint8 b
|
|
Uint8 a
|
|
|
|
SDL_GetTextureColorMod(_texture, &r, &g, &b)
|
|
SDL_GetTextureAlphaMod(_texture, &a)
|
|
|
|
return Color(r, g, b, a)
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
set_color_mod:
|
|
SDL_SetTextureColorMod(_texture, color.r, color.g, color.b)
|
|
SDL_SetTextureAlphaMod(_texture, color.a)
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
get_blend_mode:
|
|
SDL_BlendMode blendMode
|
|
|
|
SDL_GetTextureBlendMode(_texture, &blendMode)
|
|
|
|
return blendMode
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
set_blend_mode:
|
|
SDL_SetTextureBlendMode(_texture, blend_mode)
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
get_texture_scale_mode:
|
|
SDL_ScaleMode scale_mode
|
|
|
|
SDL_GetTextureScaleMode(_texture, &scale_mode)
|
|
|
|
return scale_mode
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
set_texture_scale_mode:
|
|
SDL_SetTextureScaleMode(_texture, scale_mode)
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
get_image:
|
|
return _image
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
set_image:
|
|
if (_texture)
|
|
free()
|
|
|
|
|
|
_image = image
|
|
|
|
refresh()
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
get_width:
|
|
Uint32 format
|
|
int access
|
|
int w
|
|
int h
|
|
|
|
if (SDL_QueryTexture(_texture, &format, &access, &w, &h))
|
|
return 0
|
|
|
|
|
|
return w
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
get_height:
|
|
Uint32 format
|
|
int access
|
|
int w
|
|
int h
|
|
|
|
if (SDL_QueryTexture(_texture, &format, &access, &w, &h))
|
|
return 0
|
|
|
|
|
|
return h
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
get_format:
|
|
Uint32 format
|
|
int access
|
|
int w
|
|
int h
|
|
|
|
if (SDL_QueryTexture(_texture, &format, &access, &w, &h))
|
|
return 0
|
|
|
|
|
|
return format
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
get_access:
|
|
Uint32 format
|
|
int access
|
|
int w
|
|
int h
|
|
|
|
if (SDL_QueryTexture(_texture, &format, &access, &w, &h))
|
|
return 0
|
|
|
|
|
|
return access
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
create:
|
|
if (_texture)
|
|
free()
|
|
|
|
|
|
_image = nullptr
|
|
|
|
_texture = SDL_CreateTexture(Renderer::get_singleton()->get_renderer(), SDL_PIXELFORMAT_RGBA8888, access, w, h)
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
refresh:
|
|
if (_image == nullptr)
|
|
return
|
|
|
|
|
|
if (_image->get_surface() == nullptr)
|
|
return
|
|
|
|
|
|
if (_texture)
|
|
free()
|
|
|
|
|
|
_texture = SDL_CreateTextureFromSurface(Renderer::get_singleton()->get_renderer(), _image->get_surface())
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
free:
|
|
if (_texture)
|
|
SDL_DestroyTexture(_texture)
|
|
|
|
_texture = nullptr
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
get_texture():
|
|
return _texture
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
get_texture() const:
|
|
return _texture
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
is_render_target:
|
|
if (_texture == Renderer::get_singleton()->get_render_target())
|
|
return true
|
|
|
|
|
|
return false
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
Texture():
|
|
_image = nullptr
|
|
_texture = nullptr
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
Texture(Image *image):
|
|
_image = nullptr
|
|
_texture = nullptr
|
|
|
|
set_image(image)
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
~Texture:
|
|
if (_texture)
|
|
free()
|
|
|
|
------------------------------------------------------------------------------------------
|