139 lines
3.6 KiB
C++
139 lines
3.6 KiB
C++
/* [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);
|
|
|
|
// Gestion erreur
|
|
if( _texture == NULL )
|
|
return;
|
|
}
|
|
|
|
/* [CONSTRUCTOR] Constructions avec copie de texture
|
|
=========================================================*/
|
|
xSprite::xSprite(xManager *m, SDL_Texture *t){
|
|
_manager = m;
|
|
_texture = t;
|
|
|
|
// 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
|
|
=========================================================*/
|
|
void xSprite::dimensions(SDL_Rect r, SDL_Rect clip){
|
|
/* (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; }
|
|
|
|
|
|
/* [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; }
|