xmario/xSDL/xSprite.h

60 lines
1.6 KiB
C
Raw Normal View History

#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:
// copy constructor
xSprite(const xSprite& other);
// color sprite
xSprite(const int rgba[]);
// image sprite
xSprite(const char *url);
// image with default clip
xSprite(const char *url, SDL_Rect clip);
2020-02-04 18:03:03 +00:00
// 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);
2020-02-04 18:03:03 +00:00
// 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
const SDL_Surface* surface();
// sets the sprite clip
void setClip(SDL_Rect clip);
void setClip(int x, int y, int w, int h);
const SDL_Rect clip();
// set projection into scene
void project(SDL_Rect dest);
void project(int x, int y, int w, int h);
const SDL_Rect projection();
// implement xDrawable
virtual void draw(SDL_Renderer* renderer) override;
private:
SDL_Surface* _surface = NULL;
2020-02-04 19:21:35 +00:00
SDL_Rect _clip { 0, 0, 0, 0 };
SDL_Rect _projection { 0, 0, 0, 0 };
mutex _mutex;
};
#endif