mirror of
https://github.com/Relintai/programming_tutorials.git
synced 2025-04-21 21:51:22 +02:00
Propagated back some of the changes to older projects.
This commit is contained in:
parent
478578f2fe
commit
47b9d65596
@ -93,6 +93,8 @@ void Renderer::draw_sprite(const Sprite &sprite) {
|
||||
return;
|
||||
}
|
||||
|
||||
t->set_color_mod(sprite.get_color_mod());
|
||||
|
||||
double angle = sprite.get_angle();
|
||||
|
||||
if (Math::is_zero_approx(angle)) {
|
||||
@ -114,12 +116,17 @@ void Renderer::draw_sprite(const Sprite &sprite) {
|
||||
}
|
||||
|
||||
void Renderer::draw_sprite(const Sprite *sprite) {
|
||||
if (!sprite)
|
||||
return;
|
||||
|
||||
Texture *t = sprite->get_texture();
|
||||
|
||||
if (!t) {
|
||||
return;
|
||||
}
|
||||
|
||||
t->set_color_mod(sprite->get_color_mod());
|
||||
|
||||
double angle = sprite->get_angle();
|
||||
|
||||
if (Math::is_zero_approx(angle)) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "sprite.h"
|
||||
|
||||
#include "renderer.h"
|
||||
|
||||
Rect2 Sprite::get_texture_clip_rect() const {
|
||||
return _texture_clip_rect;
|
||||
}
|
||||
@ -75,6 +77,13 @@ void Sprite::set_flip(const SDL_RendererFlip val) {
|
||||
_flip = val;
|
||||
}
|
||||
|
||||
Color Sprite::get_color_mod() const {
|
||||
return _color_mod;
|
||||
}
|
||||
void Sprite::set_color_mod(const Color &color) {
|
||||
_color_mod = color;
|
||||
}
|
||||
|
||||
Texture *Sprite::get_texture() {
|
||||
return _texture;
|
||||
}
|
||||
@ -85,6 +94,10 @@ void Sprite::set_texture(Texture *texture) {
|
||||
_texture = texture;
|
||||
}
|
||||
|
||||
void Sprite::draw() {
|
||||
Renderer::get_singleton()->draw_sprite(this);
|
||||
}
|
||||
|
||||
Sprite::Sprite() {
|
||||
_angle = 0;
|
||||
|
||||
@ -94,6 +107,8 @@ Sprite::Sprite() {
|
||||
_flip = SDL_FLIP_NONE;
|
||||
|
||||
_texture = nullptr;
|
||||
|
||||
_color_mod = Color(255, 255, 255, 255);
|
||||
}
|
||||
Sprite::Sprite(Texture *texture) {
|
||||
_angle = 0;
|
||||
@ -112,7 +127,31 @@ Sprite::Sprite(Texture *texture) {
|
||||
_transform.w = texture->get_width();
|
||||
_transform.h = texture->get_height();
|
||||
}
|
||||
|
||||
_color_mod = Color(255, 255, 255, 255);
|
||||
}
|
||||
|
||||
Sprite::Sprite(Texture *texture, const Color &color_mod) {
|
||||
_angle = 0;
|
||||
|
||||
_anchor_x = 0;
|
||||
_anchor_y = 0;
|
||||
|
||||
_flip = SDL_FLIP_NONE;
|
||||
|
||||
_texture = texture;
|
||||
|
||||
if (_texture != nullptr) {
|
||||
_texture_clip_rect.w = texture->get_width();
|
||||
_texture_clip_rect.h = texture->get_height();
|
||||
|
||||
_transform.w = texture->get_width();
|
||||
_transform.h = texture->get_height();
|
||||
}
|
||||
|
||||
_color_mod = color_mod;
|
||||
}
|
||||
|
||||
Sprite::Sprite(Texture *texture, const float x, const float y, const double angle) {
|
||||
_angle = angle;
|
||||
|
||||
@ -133,6 +172,8 @@ Sprite::Sprite(Texture *texture, const float x, const float y, const double angl
|
||||
_transform.w = texture->get_width();
|
||||
_transform.h = texture->get_height();
|
||||
}
|
||||
|
||||
_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) {
|
||||
_angle = angle;
|
||||
@ -153,6 +194,8 @@ Sprite::Sprite(Texture *texture, const float x, const float y, const Rect2 &text
|
||||
}
|
||||
|
||||
_texture_clip_rect = texture_clip_rect;
|
||||
|
||||
_color_mod = Color(255, 255, 255, 255);
|
||||
}
|
||||
Sprite::Sprite(Texture *texture, const Rect2 &transform, const Rect2 &texture_clip_rect, const double angle) {
|
||||
_angle = angle;
|
||||
@ -166,6 +209,8 @@ Sprite::Sprite(Texture *texture, const Rect2 &transform, const Rect2 &texture_cl
|
||||
|
||||
_transform = transform;
|
||||
_texture_clip_rect = texture_clip_rect;
|
||||
|
||||
_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) {
|
||||
_angle = angle;
|
||||
@ -186,6 +231,8 @@ Sprite::Sprite(Texture *texture, const float x, const float y, const float w, co
|
||||
_texture_clip_rect.w = texture->get_width();
|
||||
_texture_clip_rect.h = texture->get_height();
|
||||
}
|
||||
|
||||
_color_mod = Color(255, 255, 255, 255);
|
||||
}
|
||||
Sprite::~Sprite() {
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "rect2.h"
|
||||
#include "texture.h"
|
||||
#include "color.h"
|
||||
|
||||
class Sprite {
|
||||
public:
|
||||
@ -35,22 +36,28 @@ public:
|
||||
float get_anchor_y() const;
|
||||
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;
|
||||
void set_flip(const SDL_RendererFlip val);
|
||||
|
||||
Color get_color_mod() const;
|
||||
void set_color_mod(const Color &color);
|
||||
|
||||
Texture *get_texture();
|
||||
Texture *get_texture() const;
|
||||
void set_texture(Texture *texture);
|
||||
|
||||
Sprite();
|
||||
Sprite(Texture *texture);
|
||||
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, const float w, const float h, const double angle = 0);
|
||||
virtual ~Sprite();
|
||||
void draw();
|
||||
|
||||
Sprite();
|
||||
Sprite(Texture *texture);
|
||||
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 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, const float w, const float h, const double angle = 0);
|
||||
virtual ~Sprite();
|
||||
|
||||
private:
|
||||
Rect2 _texture_clip_rect;
|
||||
@ -62,6 +69,8 @@ private:
|
||||
|
||||
SDL_RendererFlip _flip;
|
||||
|
||||
Color _color_mod;
|
||||
|
||||
Texture *_texture;
|
||||
};
|
||||
|
||||
|
@ -93,6 +93,8 @@ void Renderer::draw_sprite(const Sprite &sprite) {
|
||||
return;
|
||||
}
|
||||
|
||||
t->set_color_mod(sprite.get_color_mod());
|
||||
|
||||
double angle = sprite.get_angle();
|
||||
|
||||
if (Math::is_zero_approx(angle)) {
|
||||
@ -114,12 +116,17 @@ void Renderer::draw_sprite(const Sprite &sprite) {
|
||||
}
|
||||
|
||||
void Renderer::draw_sprite(const Sprite *sprite) {
|
||||
if (!sprite)
|
||||
return;
|
||||
|
||||
Texture *t = sprite->get_texture();
|
||||
|
||||
if (!t) {
|
||||
return;
|
||||
}
|
||||
|
||||
t->set_color_mod(sprite->get_color_mod());
|
||||
|
||||
double angle = sprite->get_angle();
|
||||
|
||||
if (Math::is_zero_approx(angle)) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "sprite.h"
|
||||
|
||||
#include "renderer.h"
|
||||
|
||||
Rect2 Sprite::get_texture_clip_rect() const {
|
||||
return _texture_clip_rect;
|
||||
}
|
||||
@ -75,6 +77,13 @@ void Sprite::set_flip(const SDL_RendererFlip val) {
|
||||
_flip = val;
|
||||
}
|
||||
|
||||
Color Sprite::get_color_mod() const {
|
||||
return _color_mod;
|
||||
}
|
||||
void Sprite::set_color_mod(const Color &color) {
|
||||
_color_mod = color;
|
||||
}
|
||||
|
||||
Texture *Sprite::get_texture() {
|
||||
return _texture;
|
||||
}
|
||||
@ -85,6 +94,10 @@ void Sprite::set_texture(Texture *texture) {
|
||||
_texture = texture;
|
||||
}
|
||||
|
||||
void Sprite::draw() {
|
||||
Renderer::get_singleton()->draw_sprite(this);
|
||||
}
|
||||
|
||||
Sprite::Sprite() {
|
||||
_angle = 0;
|
||||
|
||||
@ -94,6 +107,8 @@ Sprite::Sprite() {
|
||||
_flip = SDL_FLIP_NONE;
|
||||
|
||||
_texture = nullptr;
|
||||
|
||||
_color_mod = Color(255, 255, 255, 255);
|
||||
}
|
||||
Sprite::Sprite(Texture *texture) {
|
||||
_angle = 0;
|
||||
@ -112,7 +127,31 @@ Sprite::Sprite(Texture *texture) {
|
||||
_transform.w = texture->get_width();
|
||||
_transform.h = texture->get_height();
|
||||
}
|
||||
|
||||
_color_mod = Color(255, 255, 255, 255);
|
||||
}
|
||||
|
||||
Sprite::Sprite(Texture *texture, const Color &color_mod) {
|
||||
_angle = 0;
|
||||
|
||||
_anchor_x = 0;
|
||||
_anchor_y = 0;
|
||||
|
||||
_flip = SDL_FLIP_NONE;
|
||||
|
||||
_texture = texture;
|
||||
|
||||
if (_texture != nullptr) {
|
||||
_texture_clip_rect.w = texture->get_width();
|
||||
_texture_clip_rect.h = texture->get_height();
|
||||
|
||||
_transform.w = texture->get_width();
|
||||
_transform.h = texture->get_height();
|
||||
}
|
||||
|
||||
_color_mod = color_mod;
|
||||
}
|
||||
|
||||
Sprite::Sprite(Texture *texture, const float x, const float y, const double angle) {
|
||||
_angle = angle;
|
||||
|
||||
@ -133,6 +172,8 @@ Sprite::Sprite(Texture *texture, const float x, const float y, const double angl
|
||||
_transform.w = texture->get_width();
|
||||
_transform.h = texture->get_height();
|
||||
}
|
||||
|
||||
_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) {
|
||||
_angle = angle;
|
||||
@ -153,6 +194,8 @@ Sprite::Sprite(Texture *texture, const float x, const float y, const Rect2 &text
|
||||
}
|
||||
|
||||
_texture_clip_rect = texture_clip_rect;
|
||||
|
||||
_color_mod = Color(255, 255, 255, 255);
|
||||
}
|
||||
Sprite::Sprite(Texture *texture, const Rect2 &transform, const Rect2 &texture_clip_rect, const double angle) {
|
||||
_angle = angle;
|
||||
@ -166,6 +209,8 @@ Sprite::Sprite(Texture *texture, const Rect2 &transform, const Rect2 &texture_cl
|
||||
|
||||
_transform = transform;
|
||||
_texture_clip_rect = texture_clip_rect;
|
||||
|
||||
_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) {
|
||||
_angle = angle;
|
||||
@ -186,6 +231,8 @@ Sprite::Sprite(Texture *texture, const float x, const float y, const float w, co
|
||||
_texture_clip_rect.w = texture->get_width();
|
||||
_texture_clip_rect.h = texture->get_height();
|
||||
}
|
||||
|
||||
_color_mod = Color(255, 255, 255, 255);
|
||||
}
|
||||
Sprite::~Sprite() {
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "rect2.h"
|
||||
#include "texture.h"
|
||||
#include "color.h"
|
||||
|
||||
class Sprite {
|
||||
public:
|
||||
@ -35,22 +36,28 @@ public:
|
||||
float get_anchor_y() const;
|
||||
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;
|
||||
void set_flip(const SDL_RendererFlip val);
|
||||
|
||||
Color get_color_mod() const;
|
||||
void set_color_mod(const Color &color);
|
||||
|
||||
Texture *get_texture();
|
||||
Texture *get_texture() const;
|
||||
void set_texture(Texture *texture);
|
||||
|
||||
Sprite();
|
||||
Sprite(Texture *texture);
|
||||
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, const float w, const float h, const double angle = 0);
|
||||
virtual ~Sprite();
|
||||
void draw();
|
||||
|
||||
Sprite();
|
||||
Sprite(Texture *texture);
|
||||
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 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, const float w, const float h, const double angle = 0);
|
||||
virtual ~Sprite();
|
||||
|
||||
private:
|
||||
Rect2 _texture_clip_rect;
|
||||
@ -62,6 +69,8 @@ private:
|
||||
|
||||
SDL_RendererFlip _flip;
|
||||
|
||||
Color _color_mod;
|
||||
|
||||
Texture *_texture;
|
||||
};
|
||||
|
||||
|
@ -93,6 +93,8 @@ void Renderer::draw_sprite(const Sprite &sprite) {
|
||||
return;
|
||||
}
|
||||
|
||||
t->set_color_mod(sprite.get_color_mod());
|
||||
|
||||
double angle = sprite.get_angle();
|
||||
|
||||
if (Math::is_zero_approx(angle)) {
|
||||
@ -114,12 +116,17 @@ void Renderer::draw_sprite(const Sprite &sprite) {
|
||||
}
|
||||
|
||||
void Renderer::draw_sprite(const Sprite *sprite) {
|
||||
if (!sprite)
|
||||
return;
|
||||
|
||||
Texture *t = sprite->get_texture();
|
||||
|
||||
if (!t) {
|
||||
return;
|
||||
}
|
||||
|
||||
t->set_color_mod(sprite->get_color_mod());
|
||||
|
||||
double angle = sprite->get_angle();
|
||||
|
||||
if (Math::is_zero_approx(angle)) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "sprite.h"
|
||||
|
||||
#include "renderer.h"
|
||||
|
||||
Rect2 Sprite::get_texture_clip_rect() const {
|
||||
return _texture_clip_rect;
|
||||
}
|
||||
@ -75,6 +77,13 @@ void Sprite::set_flip(const SDL_RendererFlip val) {
|
||||
_flip = val;
|
||||
}
|
||||
|
||||
Color Sprite::get_color_mod() const {
|
||||
return _color_mod;
|
||||
}
|
||||
void Sprite::set_color_mod(const Color &color) {
|
||||
_color_mod = color;
|
||||
}
|
||||
|
||||
Texture *Sprite::get_texture() {
|
||||
return _texture;
|
||||
}
|
||||
@ -85,6 +94,10 @@ void Sprite::set_texture(Texture *texture) {
|
||||
_texture = texture;
|
||||
}
|
||||
|
||||
void Sprite::draw() {
|
||||
Renderer::get_singleton()->draw_sprite(this);
|
||||
}
|
||||
|
||||
Sprite::Sprite() {
|
||||
_angle = 0;
|
||||
|
||||
@ -94,6 +107,8 @@ Sprite::Sprite() {
|
||||
_flip = SDL_FLIP_NONE;
|
||||
|
||||
_texture = nullptr;
|
||||
|
||||
_color_mod = Color(255, 255, 255, 255);
|
||||
}
|
||||
Sprite::Sprite(Texture *texture) {
|
||||
_angle = 0;
|
||||
@ -112,7 +127,31 @@ Sprite::Sprite(Texture *texture) {
|
||||
_transform.w = texture->get_width();
|
||||
_transform.h = texture->get_height();
|
||||
}
|
||||
|
||||
_color_mod = Color(255, 255, 255, 255);
|
||||
}
|
||||
|
||||
Sprite::Sprite(Texture *texture, const Color &color_mod) {
|
||||
_angle = 0;
|
||||
|
||||
_anchor_x = 0;
|
||||
_anchor_y = 0;
|
||||
|
||||
_flip = SDL_FLIP_NONE;
|
||||
|
||||
_texture = texture;
|
||||
|
||||
if (_texture != nullptr) {
|
||||
_texture_clip_rect.w = texture->get_width();
|
||||
_texture_clip_rect.h = texture->get_height();
|
||||
|
||||
_transform.w = texture->get_width();
|
||||
_transform.h = texture->get_height();
|
||||
}
|
||||
|
||||
_color_mod = color_mod;
|
||||
}
|
||||
|
||||
Sprite::Sprite(Texture *texture, const float x, const float y, const double angle) {
|
||||
_angle = angle;
|
||||
|
||||
@ -133,6 +172,8 @@ Sprite::Sprite(Texture *texture, const float x, const float y, const double angl
|
||||
_transform.w = texture->get_width();
|
||||
_transform.h = texture->get_height();
|
||||
}
|
||||
|
||||
_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) {
|
||||
_angle = angle;
|
||||
@ -153,6 +194,8 @@ Sprite::Sprite(Texture *texture, const float x, const float y, const Rect2 &text
|
||||
}
|
||||
|
||||
_texture_clip_rect = texture_clip_rect;
|
||||
|
||||
_color_mod = Color(255, 255, 255, 255);
|
||||
}
|
||||
Sprite::Sprite(Texture *texture, const Rect2 &transform, const Rect2 &texture_clip_rect, const double angle) {
|
||||
_angle = angle;
|
||||
@ -166,6 +209,8 @@ Sprite::Sprite(Texture *texture, const Rect2 &transform, const Rect2 &texture_cl
|
||||
|
||||
_transform = transform;
|
||||
_texture_clip_rect = texture_clip_rect;
|
||||
|
||||
_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) {
|
||||
_angle = angle;
|
||||
@ -186,6 +231,8 @@ Sprite::Sprite(Texture *texture, const float x, const float y, const float w, co
|
||||
_texture_clip_rect.w = texture->get_width();
|
||||
_texture_clip_rect.h = texture->get_height();
|
||||
}
|
||||
|
||||
_color_mod = Color(255, 255, 255, 255);
|
||||
}
|
||||
Sprite::~Sprite() {
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "rect2.h"
|
||||
#include "texture.h"
|
||||
#include "color.h"
|
||||
|
||||
class Sprite {
|
||||
public:
|
||||
@ -35,22 +36,28 @@ public:
|
||||
float get_anchor_y() const;
|
||||
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;
|
||||
void set_flip(const SDL_RendererFlip val);
|
||||
|
||||
Color get_color_mod() const;
|
||||
void set_color_mod(const Color &color);
|
||||
|
||||
Texture *get_texture();
|
||||
Texture *get_texture() const;
|
||||
void set_texture(Texture *texture);
|
||||
|
||||
Sprite();
|
||||
Sprite(Texture *texture);
|
||||
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, const float w, const float h, const double angle = 0);
|
||||
virtual ~Sprite();
|
||||
void draw();
|
||||
|
||||
Sprite();
|
||||
Sprite(Texture *texture);
|
||||
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 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, const float w, const float h, const double angle = 0);
|
||||
virtual ~Sprite();
|
||||
|
||||
private:
|
||||
Rect2 _texture_clip_rect;
|
||||
@ -62,6 +69,8 @@ private:
|
||||
|
||||
SDL_RendererFlip _flip;
|
||||
|
||||
Color _color_mod;
|
||||
|
||||
Texture *_texture;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user