]> git.localhorst.tv Git - l2e.git/blob - src/graphics/Sprite.h
pass point as reference in graphics Draw functions
[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, const geometry::Point<int> &position, int col = 0, int row = 0) const;
29         void DrawTopRight(SDL_Surface *dest, const geometry::Point<int> &position, int col = 0, int row = 0) const {
30                 geometry::Vector<int> offset(-Width(), 0);
31                 Draw(dest, position + offset, col, row);
32         }
33         void DrawCenter(SDL_Surface *dest, const geometry::Point<int> &position, int col = 0, int row = 0) const {
34                 geometry::Vector<int> offset(-Width() / 2, -Height() / 2);
35                 Draw(dest, position + offset, col, row);
36         }
37         void DrawCenterBottom(SDL_Surface *dest, const geometry::Point<int> &position, int col = 0, int row = 0) const {
38                 geometry::Vector<int> offset(-Width() / 2, -Height());
39                 Draw(dest, position + offset, col, row);
40         }
41
42 private:
43         SDL_Surface *surface;
44         int width;
45         int height;
46         int xOffset;
47         int yOffset;
48
49 };
50
51 }
52
53 #endif /* GRAPHICS_SPRITE_H_ */