File: SagoSprite.hpp

package info (click to toggle)
blockattack 2.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,292 kB
  • sloc: cpp: 93,645; sh: 143; pascal: 111; xml: 82; makefile: 14
file content (124 lines) | stat: -rw-r--r-- 4,953 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
Copyright (c) 2015 Poul Sander

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#ifndef SAGOSPRITE_HPP
#define SAGOSPRITE_HPP

#include "SagoDataHolder.hpp"
#include "SagoLogicalResize.hpp"

namespace sago {

class SagoSprite final {
public:
	SagoSprite();
	SagoSprite(const SagoDataHolder& texHolder, const std::string& texture,const SDL_Rect& initImage,const int animationFrames, const int animationFrameLength);

	/**
	 * Draws the sprite to a given render window
	 * @param target The render window to draw on
	 * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
	 * @param x Place to draw the sprite
	 * @param y Place to draw the sprite
	 */
	void Draw(SDL_Renderer* target, Sint32 frameTime, int x, int y, SagoLogicalResize* resize = nullptr) const;

	/**
	 * Draws the sprite to a given render window
	 * @param target The render window to draw on
	 * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
	 * @param x Place to draw the sprite
	 * @param y Place to draw the sprite
	 * @param angleRadian Angle to rotate the sprite around origin before drawing
	 */
	void DrawRotated(SDL_Renderer* target, Sint32 frameTime, int x, int y, const double angleRadian, SagoLogicalResize* resize = nullptr) const;

	/**
	 * Draws part of the sprite to a given render window
	 * @param target The render window to draw on
	 * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
	 * @param x Place to draw the sprite
	 * @param y Place to draw the sprite
	 * @param part the part of the sprite that should be drawn.
	 */
	void Draw(SDL_Renderer* target, Sint32 frameTime, int x, int y, const SDL_Rect& part, SagoLogicalResize* resize = nullptr) const;

	/**
	 * Draws the wprite to the given renderer but makes sure to not draw outside th bounds given
	 * @param target The render window to draw on
	 * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
	 * @param x Place to draw the sprite
	 * @param y Place to draw the sprite
	 * @param bounds A recagular area that we must not draw outside.
	 */
	void DrawBounded(SDL_Renderer* target, Sint32 frameTime, int x, int y, const SDL_Rect& bounds, SagoLogicalResize* resize = nullptr) const;

	/**
	 * Draws the sprite to a given render window
	 * @param target The render window to draw on
	 * @param progress A float with value from 0.0f to 1.0f. Tells how far in the animation that we got
	 * @param x Place to draw the sprite
	 * @param y Place to draw the sprite
	 */
	void DrawProgressive(SDL_Renderer* target, float progress, int x, int y, SagoLogicalResize* resize = nullptr) const;

	void DrawScaled(SDL_Renderer* target, Sint32 frameTime, int x, int y, int w, int h, SagoLogicalResize* resize = nullptr) const;
	void DrawScaledAndRotated(SDL_Renderer* target, Sint32 frameTime, int x, int y, int w, int h,
	                          const double angleRadian, const SDL_Point* center, const SDL_RendererFlip flip, SagoLogicalResize* resize = nullptr) const;

	/**
	 * Set a different origin. Normally it is the top left cornor. But in some cases you might want to center the origin or tranform it for other reasons
	 * @param newOrigin the coordinates that should be the new origin. Call with {0,0} to reset to default
	 */
	void SetOrigin(const SDL_Rect& newOrigin);
	SagoSprite(const SagoSprite& base) = default;
	SagoSprite& operator=(const SagoSprite& base) = default;
	int GetWidth() const;
	int GetHeight() const;
	~SagoSprite() = default;

	const TextureHandler& GetTextureHandler() const {
		return this->tex;
	}

	const SDL_Rect& GetImageCord() const {
		return this->imgCord;
	}

	const SDL_Rect& GetOrigin() const {
		return this->origin;
	}

private:
	TextureHandler tex;
	SDL_Rect imgCord = {};
	SDL_Rect origin = {};
	int aniFrames = 0;
	int aniFrameTime = 0;
};

}

#endif  /* SAGOSPRITE_HPP */