git repos / blockattack-game

blame: source/code/sago/SagoSprite.hpp

normal view · raw

82da8a1c sago007 2015-12-19 18:00 1
/*
47fef8e8 sago007 2016-11-24 21:37 2
Copyright (c) 2015 Poul Sander
82da8a1c sago007 2015-12-19 18:00 3
47fef8e8 sago007 2016-11-24 21:37 4
Permission is hereby granted, free of charge, to any person
47fef8e8 sago007 2016-11-24 21:37 5
obtaining a copy of this software and associated documentation files
47fef8e8 sago007 2016-11-24 21:37 6
(the "Software"), to deal in the Software without restriction,
47fef8e8 sago007 2016-11-24 21:37 7
including without limitation the rights to use, copy, modify, merge,
47fef8e8 sago007 2016-11-24 21:37 8
publish, distribute, sublicense, and/or sell copies of the Software,
47fef8e8 sago007 2016-11-24 21:37 9
and to permit persons to whom the Software is furnished to do so,
47fef8e8 sago007 2016-11-24 21:37 10
subject to the following conditions:
82da8a1c sago007 2015-12-19 18:00 11
47fef8e8 sago007 2016-11-24 21:37 12
The above copyright notice and this permission notice shall be
47fef8e8 sago007 2016-11-24 21:37 13
included in all copies or substantial portions of the Software.
82da8a1c sago007 2015-12-19 18:00 14
47fef8e8 sago007 2016-11-24 21:37 15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
47fef8e8 sago007 2016-11-24 21:37 16
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
47fef8e8 sago007 2016-11-24 21:37 17
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
47fef8e8 sago007 2016-11-24 21:37 18
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
47fef8e8 sago007 2016-11-24 21:37 19
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
47fef8e8 sago007 2016-11-24 21:37 20
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
47fef8e8 sago007 2016-11-24 21:37 21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
47fef8e8 sago007 2016-11-24 21:37 22
SOFTWARE.
82da8a1c sago007 2015-12-19 18:00 23
*/
82da8a1c sago007 2015-12-19 18:00 24
82da8a1c sago007 2015-12-19 18:00 25
#ifndef SAGOSPRITE_HPP
e94af580 sago007 2020-12-30 17:45 26
#define SAGOSPRITE_HPP
82da8a1c sago007 2015-12-19 18:00 27
82da8a1c sago007 2015-12-19 18:00 28
#include "SagoDataHolder.hpp"
82da8a1c sago007 2015-12-19 18:00 29
82da8a1c sago007 2015-12-19 18:00 30
namespace sago {
82da8a1c sago007 2015-12-19 18:00 31
2d137b45 sago007 2018-04-02 13:59 32
class SagoSprite final {
82da8a1c sago007 2015-12-19 18:00 33
public:
c6bde3e3 sago007 2015-12-22 16:56 34
	SagoSprite();
e94af580 sago007 2020-12-30 17:45 35
	SagoSprite(const SagoDataHolder& texHolder, const std::string& texture,const SDL_Rect& initImage,const int animationFrames, const int animationFrameLength);
00ebd0ea sago007 2020-09-15 17:28 36
82da8a1c sago007 2015-12-19 18:00 37
	/**
82da8a1c sago007 2015-12-19 18:00 38
	 * Draws the sprite to a given render window
47fef8e8 sago007 2016-11-24 21:37 39
	 * @param target The render window to draw on
47fef8e8 sago007 2016-11-24 21:37 40
	 * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
47fef8e8 sago007 2016-11-24 21:37 41
	 * @param x Place to draw the sprite
47fef8e8 sago007 2016-11-24 21:37 42
	 * @param y Place to draw the sprite
47fef8e8 sago007 2016-11-24 21:37 43
	 */
c6bde3e3 sago007 2015-12-22 16:56 44
	void Draw(SDL_Renderer* target, Sint32 frameTime, int x, int y) const;
00ebd0ea sago007 2020-09-15 17:28 45
82da8a1c sago007 2015-12-19 18:00 46
	/**
84b6e374 sago007 2020-09-15 18:13 47
	 * Draws the sprite to a given render window
84b6e374 sago007 2020-09-15 18:13 48
	 * @param target The render window to draw on
84b6e374 sago007 2020-09-15 18:13 49
	 * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
84b6e374 sago007 2020-09-15 18:13 50
	 * @param x Place to draw the sprite
84b6e374 sago007 2020-09-15 18:13 51
	 * @param y Place to draw the sprite
84b6e374 sago007 2020-09-15 18:13 52
	 * @param angleRadian Angle to rotate the sprite around origin before drawing
84b6e374 sago007 2020-09-15 18:13 53
	 */
84b6e374 sago007 2020-09-15 18:13 54
	void DrawRotated(SDL_Renderer* target, Sint32 frameTime, int x, int y, const double angleRadian) const;
84b6e374 sago007 2020-09-15 18:13 55
84b6e374 sago007 2020-09-15 18:13 56
	/**
82da8a1c sago007 2015-12-19 18:00 57
	 * Draws part of the sprite to a given render window
47fef8e8 sago007 2016-11-24 21:37 58
	 * @param target The render window to draw on
47fef8e8 sago007 2016-11-24 21:37 59
	 * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
47fef8e8 sago007 2016-11-24 21:37 60
	 * @param x Place to draw the sprite
47fef8e8 sago007 2016-11-24 21:37 61
	 * @param y Place to draw the sprite
e94af580 sago007 2020-12-30 17:45 62
	 * @param part the part of the sprite that should be drawn.
47fef8e8 sago007 2016-11-24 21:37 63
	 */
c6bde3e3 sago007 2015-12-22 16:56 64
	void Draw(SDL_Renderer* target, Sint32 frameTime, int x, int y, const SDL_Rect& part) const;
00ebd0ea sago007 2020-09-15 17:28 65
c6bde3e3 sago007 2015-12-22 16:56 66
	/**
c6bde3e3 sago007 2015-12-22 16:56 67
	 * Draws the wprite to the given renderer but makes sure to not draw outside th bounds given
c6bde3e3 sago007 2015-12-22 16:56 68
	 * @param target The render window to draw on
c6bde3e3 sago007 2015-12-22 16:56 69
	 * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
c6bde3e3 sago007 2015-12-22 16:56 70
	 * @param x Place to draw the sprite
c6bde3e3 sago007 2015-12-22 16:56 71
	 * @param y Place to draw the sprite
c6bde3e3 sago007 2015-12-22 16:56 72
	 * @param bounds A recagular area that we must not draw outside.
c6bde3e3 sago007 2015-12-22 16:56 73
	 */
00ebd0ea sago007 2020-09-15 17:28 74
	void DrawBounded(SDL_Renderer* target, Sint32 frameTime, int x, int y, const SDL_Rect& bounds) const;
e94af580 sago007 2020-12-30 17:45 75
00ebd0ea sago007 2020-09-15 17:28 76
	/**
55ea55dd sago007 2018-03-24 16:07 77
	 * Draws the sprite to a given render window
55ea55dd sago007 2018-03-24 16:07 78
	 * @param target The render window to draw on
55ea55dd sago007 2018-03-24 16:07 79
	 * @param progress A float with value from 0.0f to 1.0f. Tells how far in the animation that we got
55ea55dd sago007 2018-03-24 16:07 80
	 * @param x Place to draw the sprite
55ea55dd sago007 2018-03-24 16:07 81
	 * @param y Place to draw the sprite
55ea55dd sago007 2018-03-24 16:07 82
	 */
55ea55dd sago007 2018-03-24 16:07 83
	void DrawProgressive(SDL_Renderer* target, float progress, int x, int y) const;
84b6e374 sago007 2020-09-15 18:13 84
68313e95 sago007 2016-09-28 16:52 85
	void DrawScaled(SDL_Renderer* target, Sint32 frameTime, int x, int y, int w, int h) const;
84b6e374 sago007 2020-09-15 18:13 86
	void DrawScaledAndRotated(SDL_Renderer* target, Sint32 frameTime, int x, int y, int w, int h,
e94af580 sago007 2020-12-30 17:45 87
	                          const double angleRadian, const SDL_Point* center, const SDL_RendererFlip flip) const;
84b6e374 sago007 2020-09-15 18:13 88
82da8a1c sago007 2015-12-19 18:00 89
	/**
82da8a1c sago007 2015-12-19 18:00 90
	 * 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
e94af580 sago007 2020-12-30 17:45 91
	 * @param newOrigin the coordinates that should be the new origin. Call with {0,0} to reset to default
47fef8e8 sago007 2016-11-24 21:37 92
	 */
82da8a1c sago007 2015-12-19 18:00 93
	void SetOrigin(const SDL_Rect& newOrigin);
c6bde3e3 sago007 2015-12-22 16:56 94
	SagoSprite(const SagoSprite& base);
47fef8e8 sago007 2016-11-24 21:37 95
	SagoSprite& operator=(const SagoSprite& base);
1d2e2129 sago007 2015-12-23 15:41 96
	int GetWidth() const;
1d2e2129 sago007 2015-12-23 15:41 97
	int GetHeight() const;
2d137b45 sago007 2018-04-02 13:59 98
	~SagoSprite();
82da8a1c sago007 2015-12-19 18:00 99
private:
82da8a1c sago007 2015-12-19 18:00 100
	struct SagoSpriteData;
e94af580 sago007 2020-12-30 17:45 101
	SagoSpriteData* data;
82da8a1c sago007 2015-12-19 18:00 102
};
82da8a1c sago007 2015-12-19 18:00 103
82da8a1c sago007 2015-12-19 18:00 104
}
82da8a1c sago007 2015-12-19 18:00 105
e94af580 sago007 2020-12-30 17:45 106
#endif  /* SAGOSPRITE_HPP */
82da8a1c sago007 2015-12-19 18:00 107
1970-01-01 00:00 108