add more xSprite SDL_Rect shorthands

This commit is contained in:
Adrien Marquès 2020-02-04 19:03:03 +01:00
parent cc276e1c2a
commit d1e6a1e9dc
2 changed files with 18 additions and 8 deletions

View File

@ -16,17 +16,28 @@ xSprite::xSprite(const int rgba[]){
xSprite::xSprite(const char *url){ xSprite::xSprite(const char *url){
this->setSurface(url); this->setSurface(url);
} }
/** image sprite with clip */ /** image sprite with clip */
xSprite::xSprite(const char *url, SDL_Rect clip){ xSprite::xSprite(const char *url, SDL_Rect clip){
this->setSurface(url); this->setSurface(url);
this->setClip(clip); this->setClip(clip);
} }
xSprite::xSprite(const char *url, int clip_x, int clip_y, int clip_w, int clip_h){
this->setSurface(url);
this->setClip(clip_x, clip_y, clip_w, clip_h);
}
/** image sprite with clip and projection */ /** image sprite with clip and projection */
xSprite::xSprite(const char *url, SDL_Rect clip, SDL_Rect projection){ xSprite::xSprite(const char *url, SDL_Rect clip, SDL_Rect projection){
this->setSurface(url); this->setSurface(url);
this->setClip(clip); this->setClip(clip);
this->project(projection); this->project(projection);
} }
xSprite::xSprite(const char *url, int clip_x, int clip_y, int clip_w, int clip_h, int project_x, int project_y, int project_w, int project_h){
this->setSurface(url);
this->setClip(clip_x, clip_y, clip_w, clip_h);
this->project(project_x, project_y, project_w, project_h);
}
/** update sprite to rhb color */ /** update sprite to rhb color */
void xSprite::setSurface(const int rgba[]){ void xSprite::setSurface(const int rgba[]){
@ -91,12 +102,10 @@ void xSprite::setClip(SDL_Rect clip){
_clip = clip; _clip = clip;
_mutex.unlock(); _mutex.unlock();
} }
/** set sprite clip */
void xSprite::setClip(int x, int y, int w, int h){ void xSprite::setClip(int x, int y, int w, int h){
_mutex.lock(); setClip( (SDL_Rect){x, y, w, h} );
_clip = (SDL_Rect){x, y, w, h};
_mutex.unlock();
} }
/** gets sprite clip */ /** gets sprite clip */
SDL_Rect xSprite::clip(){ SDL_Rect xSprite::clip(){
_mutex.lock(); _mutex.lock();
@ -111,11 +120,8 @@ void xSprite::project(SDL_Rect dest){
_projection = dest; _projection = dest;
_mutex.unlock(); _mutex.unlock();
} }
/** set sprite projection */
void xSprite::project(int x, int y, int w, int h){ void xSprite::project(int x, int y, int w, int h){
_mutex.lock(); project( (SDL_Rect){x, y, w, h} );
_projection = (SDL_Rect){x, y, w, h};
_mutex.unlock();
} }
/** gets sprite projection */ /** gets sprite projection */
SDL_Rect xSprite::projection(){ SDL_Rect xSprite::projection(){

View File

@ -19,8 +19,12 @@
xSprite(const char *url); xSprite(const char *url);
// image with default clip // image with default clip
xSprite(const char *url, SDL_Rect clip); xSprite(const char *url, SDL_Rect clip);
// image with default clip
xSprite(const char *url, int clip_x, int clip_y, int clip_w, int clip_h);
// image with default clip and projection // image with default clip and projection
xSprite(const char *url, SDL_Rect clip, SDL_Rect projection); xSprite(const char *url, SDL_Rect clip, SDL_Rect projection);
// image with default clip and projection
xSprite(const char *url, int clip_x, int clip_y, int clip_w, int clip_h, int project_x, int project_y, int project_w, int project_h);
virtual ~xSprite(); virtual ~xSprite();
// replace surface // replace surface