]> git.localhorst.tv Git - l2e.git/blob - src/graphics/Sprite.h
added center positioning for Sprite
[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/operators.h"
12 #include "../geometry/Point.h"
13 #include "../geometry/Vector.h"
14
15 #include <SDL.h>
16
17 namespace graphics {
18
19 class Sprite {
20
21 public:
22         Sprite(SDL_Surface *s, int width, int height, int xOffset = 0, int yOffset = 0)
23         : surface(s), width(width), height(height), xOffset(xOffset), yOffset(yOffset) { }
24
25 public:
26         int Width() const { return width; }
27         int Height() const { return height; }
28         void Draw(SDL_Surface *dest, geometry::Point<int> position, int col = 0, int row = 0) const;
29         void DrawCenter(SDL_Surface *dest, geometry::Point<int> position, int col = 0, int row = 0) const {
30                 geometry::Vector<int> offset(-Width() / 2, -Height() / 2);
31                 Draw(dest, position + offset, col, row);
32         }
33         void DrawCenterBottom(SDL_Surface *dest, geometry::Point<int> position, int col = 0, int row = 0) const {
34                 geometry::Vector<int> offset(-Width() / 2, -Height());
35                 Draw(dest, position + offset, col, row);
36         }
37
38 private:
39         SDL_Surface *surface;
40         int width;
41         int height;
42         int xOffset;
43         int yOffset;
44
45 };
46
47 }
48
49 #endif /* GRAPHICS_SPRITE_H_ */