add xSprite constructors and SDL_Rect primitive shorthands
This commit is contained in:
parent
7a6022e694
commit
49deb9e868
|
@ -21,6 +21,12 @@ xSprite::xSprite(const char *url, SDL_Rect clip){
|
|||
this->setSurface(url);
|
||||
this->setClip(clip);
|
||||
}
|
||||
/** image sprite with clip and projection */
|
||||
xSprite::xSprite(const char *url, SDL_Rect clip, SDL_Rect projection){
|
||||
this->setSurface(url);
|
||||
this->setClip(clip);
|
||||
this->project(projection);
|
||||
}
|
||||
|
||||
/** update sprite to rhb color */
|
||||
void xSprite::setSurface(const int rgba[]){
|
||||
|
@ -72,6 +78,12 @@ void xSprite::setSurface(SDL_Surface *s){
|
|||
|
||||
_mutex.unlock();
|
||||
}
|
||||
SDL_Surface* xSprite::surface(){
|
||||
_mutex.lock();
|
||||
SDL_Surface* surface = _surface;
|
||||
_mutex.unlock();
|
||||
return surface;
|
||||
}
|
||||
|
||||
/** set sprite clip */
|
||||
void xSprite::setClip(SDL_Rect clip){
|
||||
|
@ -79,6 +91,19 @@ void xSprite::setClip(SDL_Rect clip){
|
|||
_clip = clip;
|
||||
_mutex.unlock();
|
||||
}
|
||||
/** set sprite clip */
|
||||
void xSprite::setClip(int x, int y, int w, int h){
|
||||
_mutex.lock();
|
||||
_clip = (SDL_Rect){x, y, w, h};
|
||||
_mutex.unlock();
|
||||
}
|
||||
/** gets sprite clip */
|
||||
SDL_Rect xSprite::clip(){
|
||||
_mutex.lock();
|
||||
const SDL_Rect clip = _clip;
|
||||
_mutex.unlock();
|
||||
return clip;
|
||||
}
|
||||
|
||||
/** set sprite projection */
|
||||
void xSprite::project(SDL_Rect dest){
|
||||
|
@ -86,6 +111,19 @@ void xSprite::project(SDL_Rect dest){
|
|||
_projection = dest;
|
||||
_mutex.unlock();
|
||||
}
|
||||
/** set sprite projection */
|
||||
void xSprite::project(int x, int y, int w, int h){
|
||||
_mutex.lock();
|
||||
_projection = (SDL_Rect){x, y, w, h};
|
||||
_mutex.unlock();
|
||||
}
|
||||
/** gets sprite projection */
|
||||
SDL_Rect xSprite::projection(){
|
||||
_mutex.lock();
|
||||
const SDL_Rect projection = _projection;
|
||||
_mutex.unlock();
|
||||
return projection;
|
||||
}
|
||||
|
||||
/** draws to renderer */
|
||||
void xSprite::draw(SDL_Renderer* renderer){
|
||||
|
|
|
@ -19,18 +19,25 @@
|
|||
xSprite(const char *url);
|
||||
// image with default clip
|
||||
xSprite(const char *url, SDL_Rect clip);
|
||||
// image with default clip and projection
|
||||
xSprite(const char *url, SDL_Rect clip, SDL_Rect projection);
|
||||
virtual ~xSprite();
|
||||
|
||||
// replace surface
|
||||
void setSurface(const int rgba[]); // color sprite
|
||||
void setSurface(const char *url); // image sprite
|
||||
void setSurface(SDL_Surface *t); // copy surface
|
||||
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();
|
||||
|
||||
// set projection into scene
|
||||
void project(SDL_Rect dest);
|
||||
void project(int x, int y, int w, int h);
|
||||
SDL_Rect projection();
|
||||
|
||||
// implement xDrawable
|
||||
virtual void draw(SDL_Renderer* renderer) override;
|
||||
|
|
Loading…
Reference in New Issue