]> git.localhorst.tv Git - l2e.git/blob - src/graphics/Sprite.h
switched some (x,y) and (w,h) pairs to vectors
[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         Sprite(SDL_Surface *s, int width, int height, int xOffset = 0, int yOffset = 0)
21         : surface(s), size(width, height), offset(xOffset, yOffset) { }
22
23 public:
24         int Width() const { return size.X(); }
25         int Height() const { return size.Y(); }
26         const geometry::Vector<int> &Size() const { return size; }
27         void Draw(SDL_Surface *dest, const geometry::Vector<int> &position, int col = 0, int row = 0) const;
28         void DrawTopRight(SDL_Surface *dest, const geometry::Vector<int> &position, int col = 0, int row = 0) const {
29                 geometry::Vector<int> offset(-Width(), 0);
30                 Draw(dest, position + offset, col, row);
31         }
32         void DrawCenter(SDL_Surface *dest, const geometry::Vector<int> &position, int col = 0, int row = 0) const {
33                 Draw(dest, position - (Size() / 2), col, row);
34         }
35         void DrawCenterBottom(SDL_Surface *dest, const geometry::Vector<int> &position, int col = 0, int row = 0) const {
36                 geometry::Vector<int> offset(-Width() / 2, -Height());
37                 Draw(dest, position + offset, col, row);
38         }
39
40 private:
41         SDL_Surface *surface;
42         geometry::Vector<int> size;
43         geometry::Vector<int> offset;
44
45 };
46
47 }
48
49 #endif /* GRAPHICS_SPRITE_H_ */