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