diff --git a/xSDL/xSprite.cpp b/xSDL/xSprite.cpp index f420e11..fbf3173 100644 --- a/xSDL/xSprite.cpp +++ b/xSDL/xSprite.cpp @@ -7,6 +7,16 @@ xSprite::~xSprite(){ _mutex.unlock(); } +/** copy constructor */ +xSprite::xSprite(const xSprite& other){ + // copy surface + if( other._surface != NULL ){ + this->setSurface( SDL_ConvertSurface(other._surface, other._surface->format, SDL_SWSURFACE) ); + } + this->setClip(other._clip); + this->project(other._projection); +} + /** color sprite */ xSprite::xSprite(const int rgba[]){ this->setSurface(rgba); @@ -89,7 +99,7 @@ void xSprite::setSurface(SDL_Surface *s){ _mutex.unlock(); } -SDL_Surface* xSprite::surface(){ +const SDL_Surface* xSprite::surface(){ _mutex.lock(); SDL_Surface* surface = _surface; _mutex.unlock(); @@ -107,7 +117,7 @@ void xSprite::setClip(int x, int y, int w, int h){ } /** gets sprite clip */ -SDL_Rect xSprite::clip(){ +const SDL_Rect xSprite::clip(){ _mutex.lock(); const SDL_Rect clip = _clip; _mutex.unlock(); @@ -124,7 +134,7 @@ void xSprite::project(int x, int y, int w, int h){ project( (SDL_Rect){x, y, w, h} ); } /** gets sprite projection */ -SDL_Rect xSprite::projection(){ +const SDL_Rect xSprite::projection(){ _mutex.lock(); const SDL_Rect projection = _projection; _mutex.unlock(); diff --git a/xSDL/xSprite.h b/xSDL/xSprite.h index c0961b1..617ef0d 100644 --- a/xSDL/xSprite.h +++ b/xSDL/xSprite.h @@ -13,6 +13,9 @@ class xSprite : public xDrawable{ public: + // copy constructor + xSprite(const xSprite& other); + // color sprite xSprite(const int rgba[]); // image sprite @@ -31,17 +34,17 @@ void setSurface(const int rgba[]); // color sprite void setSurface(const char *url); // image sprite void setSurface(SDL_Surface *t); // copy surface - SDL_Surface* surface(); + const SDL_Surface* surface(); // sets the sprite clip void setClip(SDL_Rect clip); void setClip(int x, int y, int w, int h); - SDL_Rect clip(); + const SDL_Rect clip(); // set projection into scene void project(SDL_Rect dest); void project(int x, int y, int w, int h); - SDL_Rect projection(); + const SDL_Rect projection(); // implement xDrawable virtual void draw(SDL_Renderer* renderer) override;