]> git.localhorst.tv Git - l2e.git/blob - src/graphics/Sprite.h
made Sprite default constructible
[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() : surface(0), size(64, 64), offset() { }
21         Sprite(SDL_Surface *s, int width, int height, int xOffset = 0, int yOffset = 0)
22         : surface(s), size(width, height), offset(xOffset, yOffset) { }
23
24 public:
25         int Width() const { return size.X(); }
26         int Height() const { return size.Y(); }
27         const geometry::Vector<int> &Size() const { return size; }
28         void Draw(SDL_Surface *dest, const geometry::Vector<int> &position, int col = 0, int row = 0) const;
29         void DrawTopRight(SDL_Surface *dest, const geometry::Vector<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::Vector<int> &position, int col = 0, int row = 0) const {
34                 Draw(dest, position - (Size() / 2), col, row);
35         }
36         void DrawCenterBottom(SDL_Surface *dest, const geometry::Vector<int> &position, int col = 0, int row = 0) const {
37                 geometry::Vector<int> offset(-Width() / 2, -Height());
38                 Draw(dest, position + offset, col, row);
39         }
40
41 public:
42         void SetSurface(SDL_Surface *s) { surface = s; }
43         void SetSize(const geometry::Vector<int> &s) { size = s; }
44         void SetOffset(const geometry::Vector<int> &o) { offset = o; }
45
46 private:
47         SDL_Surface *surface;
48         geometry::Vector<int> size;
49         geometry::Vector<int> offset;
50
51 };
52
53 }
54
55 #endif /* GRAPHICS_SPRITE_H_ */