mirror of
https://github.com/Relintai/programming_tutorials.git
synced 2025-05-11 22:52:11 +02:00
Sprite uml diagram.
This commit is contained in:
parent
ec64037fd2
commit
29d51c92e9
@ -1,307 +1,312 @@
|
|||||||
|
|
||||||
|
|---------------------------------------------------------------------------------------|
|
||||||
class Sprite
|
| class Sprite |
|
||||||
public:
|
|---------------------------------------------------------------------------------------|
|
||||||
Rect2 get_texture_clip_rect() const;
|
| + Rect2 get_texture_clip_rect() const |
|
||||||
void set_texture_clip_rect(const Rect2 &rect);
|
| + void set_texture_clip_rect(const Rect2 &rect) |
|
||||||
|
| |
|
||||||
Rect2 get_transform() const;
|
| + Rect2 get_transform() const |
|
||||||
void set_transform(const Rect2 &rect);
|
| + void set_transform(const Rect2 &rect) |
|
||||||
|
| |
|
||||||
float get_x() const;
|
| + float get_x() const |
|
||||||
void set_x(const float val);
|
| + void set_x(const float val) |
|
||||||
|
| |
|
||||||
float get_y() const;
|
| + float get_y() const |
|
||||||
void set_y(const float val);
|
| + void set_y(const float val) |
|
||||||
|
| |
|
||||||
float get_w() const;
|
| + float get_w() const |
|
||||||
void set_w(const float val);
|
| + void set_w(const float val) |
|
||||||
|
| |
|
||||||
float get_h() const;
|
| + float get_h() const |
|
||||||
void set_h(const float val);
|
| + void set_h(const float val) |
|
||||||
|
| |
|
||||||
double get_angle() const;
|
| + double get_angle() const |
|
||||||
void set_angle(const double val);
|
| + void set_angle(const double val) |
|
||||||
|
| |
|
||||||
float get_anchor_x() const;
|
| + float get_anchor_x() const |
|
||||||
void set_anchor_x(const float val);
|
| + void set_anchor_x(const float val) |
|
||||||
|
| |
|
||||||
float get_anchor_y() const;
|
| + float get_anchor_y() const |
|
||||||
void set_anchor_y(const float val);
|
| + void set_anchor_y(const float val) |
|
||||||
|
| |
|
||||||
void set_anchor(const float x, const float y);
|
| + void set_anchor(const float x, const float y) |
|
||||||
|
| |
|
||||||
SDL_RendererFlip get_flip() const;
|
| + SDL_RendererFlip get_flip() const |
|
||||||
void set_flip(const SDL_RendererFlip val);
|
| + void set_flip(const SDL_RendererFlip val) |
|
||||||
|
| |
|
||||||
Color get_color_mod() const;
|
| + Color get_color_mod() const |
|
||||||
void set_color_mod(const Color &color);
|
| + void set_color_mod(const Color &color) |
|
||||||
|
| |
|
||||||
Texture *get_texture();
|
| + Texture *get_texture() |
|
||||||
Texture *get_texture() const;
|
| + Texture *get_texture() const |
|
||||||
void set_texture(Texture *texture);
|
| + void set_texture(Texture *texture) |
|
||||||
|
| |
|
||||||
void draw();
|
| + void draw() |
|
||||||
|
| |
|
||||||
Sprite();
|
| + Sprite() |
|
||||||
Sprite(Texture *texture);
|
| + Sprite(Texture *texture) |
|
||||||
Sprite(Texture *texture, const Color &color_mod);
|
| + Sprite(Texture *texture, const Color &color_mod) |
|
||||||
Sprite(Texture *texture, const float x, const float y, const double angle = 0);
|
| + Sprite(Texture *texture, const float x, const float y, const double angle = 0) |
|
||||||
Sprite(Texture *texture, const float x, const float y, const Rect2 &texture_clip_rect, const double angle = 0);
|
| |
|
||||||
Sprite(Texture *texture, const Rect2 &transform, const Rect2 &texture_clip_rect, const double angle = 0);
|
| + Sprite(Texture *texture, const float x, const float y, |
|
||||||
Sprite(Texture *texture, const float x, const float y, const float w, const float h, const double angle = 0);
|
| const Rect2 &texture_clip_rect, const double angle = 0) |
|
||||||
virtual ~Sprite();
|
| |
|
||||||
|
| + Sprite(Texture *texture, const Rect2 &transform, |
|
||||||
private:
|
| const Rect2 &texture_clip_rect, const double angle = 0) |
|
||||||
Rect2 _texture_clip_rect;
|
| |
|
||||||
Rect2 _transform;
|
| + Sprite(Texture *texture, const float x, const float y, |
|
||||||
double _angle;
|
| const float w, const float h, const double angle = 0) |
|
||||||
|
| + virtual ~Sprite() |
|
||||||
float _anchor_x;
|
| |
|
||||||
float _anchor_y;
|
| - Rect2 _texture_clip_rect |
|
||||||
|
| - Rect2 _transform |
|
||||||
SDL_RendererFlip _flip;
|
| - double _angle |
|
||||||
|
| |
|
||||||
Color _color_mod;
|
| - float _anchor_x |
|
||||||
|
| - float _anchor_y |
|
||||||
Texture *_texture;
|
| |
|
||||||
|
| - SDL_RendererFlip _flip |
|
||||||
|
| |
|
||||||
|
| - Color _color_mod |
|
||||||
|
| |
|
||||||
|
| - Texture *_texture |
|
||||||
|
|---------------------------------------------------------------------------------------|
|
||||||
|
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
|
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
|
||||||
Rect2 Sprite::get_texture_clip_rect() const {
|
Rect2 Sprite::get_texture_clip_rect() const {
|
||||||
return _texture_clip_rect;
|
return _texture_clip_rect
|
||||||
}
|
}
|
||||||
void Sprite::set_texture_clip_rect(const Rect2 &rect) {
|
void Sprite::set_texture_clip_rect(const Rect2 &rect) {
|
||||||
_texture_clip_rect = rect;
|
_texture_clip_rect = rect
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect2 Sprite::get_transform() const {
|
Rect2 Sprite::get_transform() const {
|
||||||
return _transform;
|
return _transform
|
||||||
}
|
}
|
||||||
void Sprite::set_transform(const Rect2 &rect) {
|
void Sprite::set_transform(const Rect2 &rect) {
|
||||||
_transform = rect;
|
_transform = rect
|
||||||
}
|
}
|
||||||
|
|
||||||
float Sprite::get_x() const {
|
float Sprite::get_x() const {
|
||||||
return _transform.x;
|
return _transform.x
|
||||||
}
|
}
|
||||||
void Sprite::set_x(const float val) {
|
void Sprite::set_x(const float val) {
|
||||||
_transform.x = val;
|
_transform.x = val
|
||||||
}
|
}
|
||||||
|
|
||||||
float Sprite::get_y() const {
|
float Sprite::get_y() const {
|
||||||
return _transform.y;
|
return _transform.y
|
||||||
}
|
}
|
||||||
void Sprite::set_y(const float val) {
|
void Sprite::set_y(const float val) {
|
||||||
_transform.y = val;
|
_transform.y = val
|
||||||
}
|
}
|
||||||
|
|
||||||
float Sprite::get_w() const {
|
float Sprite::get_w() const {
|
||||||
return _transform.w;
|
return _transform.w
|
||||||
}
|
}
|
||||||
void Sprite::set_w(const float val) {
|
void Sprite::set_w(const float val) {
|
||||||
_transform.w = val;
|
_transform.w = val
|
||||||
}
|
}
|
||||||
|
|
||||||
float Sprite::get_h() const {
|
float Sprite::get_h() const {
|
||||||
return _transform.h;
|
return _transform.h
|
||||||
}
|
}
|
||||||
void Sprite::set_h(const float val) {
|
void Sprite::set_h(const float val) {
|
||||||
_transform.h = val;
|
_transform.h = val
|
||||||
}
|
}
|
||||||
|
|
||||||
double Sprite::get_angle() const {
|
double Sprite::get_angle() const {
|
||||||
return _angle;
|
return _angle
|
||||||
}
|
}
|
||||||
void Sprite::set_angle(const double val) {
|
void Sprite::set_angle(const double val) {
|
||||||
_angle = val;
|
_angle = val
|
||||||
}
|
}
|
||||||
|
|
||||||
float Sprite::get_anchor_x() const {
|
float Sprite::get_anchor_x() const {
|
||||||
return _anchor_x;
|
return _anchor_x
|
||||||
}
|
}
|
||||||
void Sprite::set_anchor_x(const float val) {
|
void Sprite::set_anchor_x(const float val) {
|
||||||
_anchor_x = val;
|
_anchor_x = val
|
||||||
}
|
}
|
||||||
|
|
||||||
float Sprite::get_anchor_y() const {
|
float Sprite::get_anchor_y() const {
|
||||||
return _anchor_y;
|
return _anchor_y
|
||||||
}
|
}
|
||||||
void Sprite::set_anchor_y(const float val) {
|
void Sprite::set_anchor_y(const float val) {
|
||||||
_anchor_y = val;
|
_anchor_y = val
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::set_anchor(const float x, const float y) {
|
void Sprite::set_anchor(const float x, const float y) {
|
||||||
_anchor_x = x;
|
_anchor_x = x
|
||||||
_anchor_y = y;
|
_anchor_y = y
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_RendererFlip Sprite::get_flip() const {
|
SDL_RendererFlip Sprite::get_flip() const {
|
||||||
return _flip;
|
return _flip
|
||||||
}
|
}
|
||||||
void Sprite::set_flip(const SDL_RendererFlip val) {
|
void Sprite::set_flip(const SDL_RendererFlip val) {
|
||||||
_flip = val;
|
_flip = val
|
||||||
}
|
}
|
||||||
|
|
||||||
Color Sprite::get_color_mod() const {
|
Color Sprite::get_color_mod() const {
|
||||||
return _color_mod;
|
return _color_mod
|
||||||
}
|
}
|
||||||
void Sprite::set_color_mod(const Color &color) {
|
void Sprite::set_color_mod(const Color &color) {
|
||||||
_color_mod = color;
|
_color_mod = color
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture *Sprite::get_texture() {
|
Texture *Sprite::get_texture() {
|
||||||
return _texture;
|
return _texture
|
||||||
}
|
}
|
||||||
Texture *Sprite::get_texture() const {
|
Texture *Sprite::get_texture() const {
|
||||||
return _texture;
|
return _texture
|
||||||
}
|
}
|
||||||
void Sprite::set_texture(Texture *texture) {
|
void Sprite::set_texture(Texture *texture) {
|
||||||
_texture = texture;
|
_texture = texture
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::draw() {
|
void Sprite::draw() {
|
||||||
Renderer::get_singleton()->draw_sprite(this);
|
Renderer::get_singleton()->draw_sprite(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite::Sprite() {
|
Sprite::Sprite() {
|
||||||
_angle = 0;
|
_angle = 0
|
||||||
|
|
||||||
_anchor_x = 0;
|
_anchor_x = 0
|
||||||
_anchor_y = 0;
|
_anchor_y = 0
|
||||||
|
|
||||||
_flip = SDL_FLIP_NONE;
|
_flip = SDL_FLIP_NONE
|
||||||
|
|
||||||
_texture = nullptr;
|
_texture = nullptr
|
||||||
|
|
||||||
_color_mod = Color(255, 255, 255, 255);
|
_color_mod = Color(255, 255, 255, 255)
|
||||||
}
|
}
|
||||||
Sprite::Sprite(Texture *texture) {
|
Sprite::Sprite(Texture *texture) {
|
||||||
_angle = 0;
|
_angle = 0
|
||||||
|
|
||||||
_anchor_x = 0;
|
_anchor_x = 0
|
||||||
_anchor_y = 0;
|
_anchor_y = 0
|
||||||
|
|
||||||
_flip = SDL_FLIP_NONE;
|
_flip = SDL_FLIP_NONE
|
||||||
|
|
||||||
_texture = texture;
|
_texture = texture
|
||||||
|
|
||||||
if (_texture != nullptr) {
|
if (_texture != nullptr) {
|
||||||
_texture_clip_rect.w = texture->get_width();
|
_texture_clip_rect.w = texture->get_width()
|
||||||
_texture_clip_rect.h = texture->get_height();
|
_texture_clip_rect.h = texture->get_height()
|
||||||
|
|
||||||
_transform.w = texture->get_width();
|
_transform.w = texture->get_width()
|
||||||
_transform.h = texture->get_height();
|
_transform.h = texture->get_height()
|
||||||
}
|
}
|
||||||
|
|
||||||
_color_mod = Color(255, 255, 255, 255);
|
_color_mod = Color(255, 255, 255, 255)
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite::Sprite(Texture *texture, const Color &color_mod) {
|
Sprite::Sprite(Texture *texture, const Color &color_mod) {
|
||||||
_angle = 0;
|
_angle = 0
|
||||||
|
|
||||||
_anchor_x = 0;
|
_anchor_x = 0
|
||||||
_anchor_y = 0;
|
_anchor_y = 0
|
||||||
|
|
||||||
_flip = SDL_FLIP_NONE;
|
_flip = SDL_FLIP_NONE
|
||||||
|
|
||||||
_texture = texture;
|
_texture = texture
|
||||||
|
|
||||||
if (_texture != nullptr) {
|
if (_texture != nullptr) {
|
||||||
_texture_clip_rect.w = texture->get_width();
|
_texture_clip_rect.w = texture->get_width()
|
||||||
_texture_clip_rect.h = texture->get_height();
|
_texture_clip_rect.h = texture->get_height()
|
||||||
|
|
||||||
_transform.w = texture->get_width();
|
_transform.w = texture->get_width()
|
||||||
_transform.h = texture->get_height();
|
_transform.h = texture->get_height()
|
||||||
}
|
}
|
||||||
|
|
||||||
_color_mod = color_mod;
|
_color_mod = color_mod
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite::Sprite(Texture *texture, const float x, const float y, const double angle) {
|
Sprite::Sprite(Texture *texture, const float x, const float y, const double angle) {
|
||||||
_angle = angle;
|
_angle = angle
|
||||||
|
|
||||||
_anchor_x = 0;
|
_anchor_x = 0
|
||||||
_anchor_y = 0;
|
_anchor_y = 0
|
||||||
|
|
||||||
_flip = SDL_FLIP_NONE;
|
_flip = SDL_FLIP_NONE
|
||||||
|
|
||||||
_texture = texture;
|
_texture = texture
|
||||||
|
|
||||||
_transform.x = x;
|
_transform.x = x
|
||||||
_transform.y = y;
|
_transform.y = y
|
||||||
|
|
||||||
if (_texture != nullptr) {
|
if (_texture != nullptr) {
|
||||||
_texture_clip_rect.w = texture->get_width();
|
_texture_clip_rect.w = texture->get_width()
|
||||||
_texture_clip_rect.h = texture->get_height();
|
_texture_clip_rect.h = texture->get_height()
|
||||||
|
|
||||||
_transform.w = texture->get_width();
|
_transform.w = texture->get_width()
|
||||||
_transform.h = texture->get_height();
|
_transform.h = texture->get_height()
|
||||||
}
|
}
|
||||||
|
|
||||||
_color_mod = Color(255, 255, 255, 255);
|
_color_mod = Color(255, 255, 255, 255)
|
||||||
}
|
}
|
||||||
Sprite::Sprite(Texture *texture, const float x, const float y, const Rect2 &texture_clip_rect, const double angle) {
|
Sprite::Sprite(Texture *texture, const float x, const float y, const Rect2 &texture_clip_rect, const double angle) {
|
||||||
_angle = angle;
|
_angle = angle
|
||||||
|
|
||||||
_anchor_x = 0;
|
_anchor_x = 0
|
||||||
_anchor_y = 0;
|
_anchor_y = 0
|
||||||
|
|
||||||
_flip = SDL_FLIP_NONE;
|
_flip = SDL_FLIP_NONE
|
||||||
|
|
||||||
_texture = texture;
|
_texture = texture
|
||||||
|
|
||||||
_transform.x = x;
|
_transform.x = x
|
||||||
_transform.y = y;
|
_transform.y = y
|
||||||
|
|
||||||
if (_texture != nullptr) {
|
if (_texture != nullptr) {
|
||||||
_transform.w = texture->get_width();
|
_transform.w = texture->get_width()
|
||||||
_transform.h = texture->get_height();
|
_transform.h = texture->get_height()
|
||||||
}
|
}
|
||||||
|
|
||||||
_texture_clip_rect = texture_clip_rect;
|
_texture_clip_rect = texture_clip_rect
|
||||||
|
|
||||||
_color_mod = Color(255, 255, 255, 255);
|
_color_mod = Color(255, 255, 255, 255)
|
||||||
}
|
}
|
||||||
Sprite::Sprite(Texture *texture, const Rect2 &transform, const Rect2 &texture_clip_rect, const double angle) {
|
Sprite::Sprite(Texture *texture, const Rect2 &transform, const Rect2 &texture_clip_rect, const double angle) {
|
||||||
_angle = angle;
|
_angle = angle
|
||||||
|
|
||||||
_anchor_x = 0;
|
_anchor_x = 0
|
||||||
_anchor_y = 0;
|
_anchor_y = 0
|
||||||
|
|
||||||
_flip = SDL_FLIP_NONE;
|
_flip = SDL_FLIP_NONE
|
||||||
|
|
||||||
_texture = texture;
|
_texture = texture
|
||||||
|
|
||||||
_transform = transform;
|
_transform = transform
|
||||||
_texture_clip_rect = texture_clip_rect;
|
_texture_clip_rect = texture_clip_rect
|
||||||
|
|
||||||
_color_mod = Color(255, 255, 255, 255);
|
_color_mod = Color(255, 255, 255, 255)
|
||||||
}
|
}
|
||||||
Sprite::Sprite(Texture *texture, const float x, const float y, const float w, const float h, const double angle) {
|
Sprite::Sprite(Texture *texture, const float x, const float y, const float w, const float h, const double angle) {
|
||||||
_angle = angle;
|
_angle = angle
|
||||||
|
|
||||||
_anchor_x = 0;
|
_anchor_x = 0
|
||||||
_anchor_y = 0;
|
_anchor_y = 0
|
||||||
|
|
||||||
_flip = SDL_FLIP_NONE;
|
_flip = SDL_FLIP_NONE
|
||||||
|
|
||||||
_texture = texture;
|
_texture = texture
|
||||||
|
|
||||||
_transform.x = x;
|
_transform.x = x
|
||||||
_transform.y = y;
|
_transform.y = y
|
||||||
_transform.w = w;
|
_transform.w = w
|
||||||
_transform.h = h;
|
_transform.h = h
|
||||||
|
|
||||||
if (_texture != nullptr) {
|
if (_texture != nullptr) {
|
||||||
_texture_clip_rect.w = texture->get_width();
|
_texture_clip_rect.w = texture->get_width()
|
||||||
_texture_clip_rect.h = texture->get_height();
|
_texture_clip_rect.h = texture->get_height()
|
||||||
}
|
}
|
||||||
|
|
||||||
_color_mod = Color(255, 255, 255, 255);
|
_color_mod = Color(255, 255, 255, 255)
|
||||||
}
|
}
|
||||||
Sprite::~Sprite() {
|
Sprite::~Sprite() {
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user