]> git.localhorst.tv Git - l2e.git/blob - src/graphics/Sprite.h
renamed namespace geometry -> math
[l2e.git] / src / graphics / Sprite.h
1 #ifndef GRAPHICS_SPRITE_H_
2 #define GRAPHICS_SPRITE_H_
3
4 #include "../math/Vector.h"
5
6 #include <SDL.h>
7
8 namespace graphics {
9
10 class Sprite {
11
12 public:
13         static const int TYPE_ID = 409;
14
15 public:
16         Sprite() : surface(0), size(64, 64), offset() { }
17         Sprite(SDL_Surface *s, int width, int height, int xOffset = 0, int yOffset = 0)
18         : surface(s), size(width, height), offset(xOffset, yOffset) { }
19
20 public:
21         int Width() const { return size.X(); }
22         int Height() const { return size.Y(); }
23         const math::Vector<int> &Size() const { return size; }
24         void Draw(SDL_Surface *dest, const math::Vector<int> &position, int col = 0, int row = 0) const;
25         void DrawTopRight(SDL_Surface *dest, const math::Vector<int> &position, int col = 0, int row = 0) const {
26                 math::Vector<int> offset(-Width(), 0);
27                 Draw(dest, position + offset, col, row);
28         }
29         void DrawCenter(SDL_Surface *dest, const math::Vector<int> &position, int col = 0, int row = 0) const {
30                 Draw(dest, position - (Size() / 2), col, row);
31         }
32         void DrawCenterBottom(SDL_Surface *dest, const math::Vector<int> &position, int col = 0, int row = 0) const {
33                 math::Vector<int> offset(-Width() / 2, -Height());
34                 Draw(dest, position + offset, col, row);
35         }
36
37 public:
38         void SetSurface(SDL_Surface *s) { surface = s; }
39         void SetSize(const math::Vector<int> &s) { size = s; }
40         void SetOffset(const math::Vector<int> &o) { offset = o; }
41
42         static void CreateTypeDescription();
43         static void Construct(void *);
44
45 private:
46         SDL_Surface *surface;
47         math::Vector<int> size;
48         math::Vector<int> offset;
49
50 };
51
52 }
53
54 #endif /* GRAPHICS_SPRITE_H_ */