57 lines
1.6 KiB
C++
57 lines
1.6 KiB
C++
#ifndef DEF_XSPRITE_H
|
|
#define DEF_XSPRITE_H
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <mutex>
|
|
#include "SDL.h"
|
|
#include "SDL_image.h"
|
|
#include "xDrawable.h"
|
|
#include "xApplication.h"
|
|
using namespace std;
|
|
|
|
class xSprite : public xDrawable{
|
|
|
|
public:
|
|
// color sprite
|
|
xSprite(const int rgba[]);
|
|
// image sprite
|
|
xSprite(const char *url);
|
|
// image with default 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
|
|
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();
|
|
|
|
// 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;
|
|
private:
|
|
SDL_Surface* _surface = NULL;
|
|
SDL_Rect _clip { 0, 0, 0, 0 };
|
|
SDL_Rect _projection { 0, 0, 0, 0 };
|
|
|
|
mutex _mutex;
|
|
|
|
};
|
|
|
|
#endif |