2016-03-12 23:22:28 +00:00
|
|
|
/* [DESTRUCTOR] Destruction de la surface
|
|
|
|
=========================================================*/
|
|
|
|
xSprite::~xSprite(){
|
|
|
|
SDL_DestroyTexture( _texture );
|
|
|
|
_manager = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* [CONSTRUCTOR] Construction de la surface vide
|
|
|
|
=========================================================*/
|
|
|
|
xSprite::xSprite(xManager *m){
|
|
|
|
_manager = m;
|
|
|
|
_texture = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [CONSTRUCTOR] Construction de la surface avec couleur
|
|
|
|
=========================================================*/
|
|
|
|
xSprite::xSprite(xManager *m, const int rgb[]){
|
|
|
|
_manager = m;
|
|
|
|
_texture = NULL;
|
|
|
|
|
|
|
|
SDL_Surface *surf = SDL_CreateRGBSurface(0, 0, 0, 32, 0, 0, 0, rgb[3]);
|
|
|
|
|
|
|
|
// On recupere la couleur
|
|
|
|
Uint32 color = SDL_MapRGBA( surf->format, rgb[0], rgb[1], rgb[2], rgb[3]);
|
|
|
|
|
|
|
|
|
|
|
|
// On cree la texture a partir de la surface
|
|
|
|
_texture = SDL_CreateTextureFromSurface(_manager->renderer(), surf);
|
|
|
|
|
|
|
|
|
|
|
|
// On libere la surface inutile maintenant
|
|
|
|
SDL_FreeSurface( surf );
|
|
|
|
surf = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [CONSTRUCTOR] Construction de la surface avec image
|
|
|
|
=========================================================*/
|
|
|
|
xSprite::xSprite(xManager *m, const char *url){
|
|
|
|
|
|
|
|
_manager = m;
|
|
|
|
_texture = NULL;
|
|
|
|
|
|
|
|
/* (1) On cree la texture directement */
|
|
|
|
_texture = IMG_LoadTexture(_manager->renderer(), url);
|
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
// Gestion erreur
|
|
|
|
if( _texture == NULL )
|
|
|
|
return;
|
|
|
|
}
|
2016-03-12 23:22:28 +00:00
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
/* [CONSTRUCTOR] Constructions avec copie de texture
|
|
|
|
=========================================================*/
|
|
|
|
xSprite::xSprite(xManager *m, SDL_Texture *t){
|
|
|
|
_manager = m;
|
|
|
|
_texture = t;
|
2016-03-12 23:22:28 +00:00
|
|
|
|
|
|
|
// Gestion erreur
|
|
|
|
if( _texture == NULL )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* [DIMENSIONS] Definition des dimensions par defaut
|
|
|
|
=========================================================*/
|
|
|
|
void xSprite::dimensions(){
|
|
|
|
/* (1) On recupere les informations de la texture */
|
|
|
|
int w, h;
|
|
|
|
SDL_QueryTexture(_texture, NULL, NULL, &w, &h);
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) On definit les dimensions par defaut */
|
|
|
|
_dst = (SDL_Rect){0, 0, w, h};
|
|
|
|
_src = (SDL_Rect){0, 0, w, h};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* [DIMENSIONS] Definition des dimensions de la texture
|
|
|
|
=========================================================*/
|
|
|
|
void xSprite::dimensions(SDL_Rect r){
|
|
|
|
/* (1) On recupere les informations de la texture */
|
|
|
|
int w, h;
|
|
|
|
SDL_QueryTexture(_texture, NULL, NULL, &w, &h);
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) On definit les dimensions */
|
|
|
|
_dst = (SDL_Rect){r.x, r.y, r.w, r.h};
|
|
|
|
_src = (SDL_Rect){0, 0, w, h};
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [DIMENSIONS] Definition des dimensions de la texture+clip
|
|
|
|
=========================================================*/
|
2016-03-13 13:53:39 +00:00
|
|
|
void xSprite::dimensions(SDL_Rect r, SDL_Rect clip){
|
2016-03-12 23:22:28 +00:00
|
|
|
/* (1) On definit les dimensions */
|
|
|
|
_dst = (SDL_Rect){r.x, r.y, r.w, r.h};
|
|
|
|
_src = (SDL_Rect){clip.x, clip.y, clip.w, clip.h};
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [PUSH] Ajoute le xSprite au rendu
|
|
|
|
=========================================================*/
|
|
|
|
void xSprite::push(){
|
|
|
|
_manager->push(_texture, &_src, &_dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [PULL] Retire une sprite du rendu
|
|
|
|
=========================================================*/
|
|
|
|
void xSprite::pull(){
|
|
|
|
_manager->pull( _texture );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [UPDATE] Mise a jour du rendu
|
|
|
|
=========================================================*/
|
|
|
|
void xSprite::update(){
|
|
|
|
_manager->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* [TEXTURE] Retourne la texture
|
|
|
|
=========================================================*/
|
|
|
|
SDL_Texture *xSprite::texture(){ return _texture; }
|
|
|
|
|
|
|
|
/* [MANAGER] Retourne le manager
|
|
|
|
=========================================================*/
|
|
|
|
xManager *xSprite::manager(){ return _manager; }
|
2016-03-13 13:53:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [DST] Retourne le SDL_Rect de destination
|
|
|
|
=========================================================*/
|
|
|
|
SDL_Rect *xSprite::dst(){ return &_dst; }
|
|
|
|
|
|
|
|
/* [SRC] Retourne le SDL_Rect source
|
|
|
|
=========================================================*/
|
|
|
|
SDL_Rect *xSprite::src(){ return &_src; }
|