git repos / blockattack-game

blame: source/code/sago/SagoSprite.hpp

normal view · raw

82da8a1c sago007 2015-12-19 18:00 1
/*
82da8a1c sago007 2015-12-19 18:00 2
  Copyright (c) 2015 Poul Sander
82da8a1c sago007 2015-12-19 18:00 3
82da8a1c sago007 2015-12-19 18:00 4
  Permission is hereby granted, free of charge, to any person
82da8a1c sago007 2015-12-19 18:00 5
  obtaining a copy of this software and associated documentation files
82da8a1c sago007 2015-12-19 18:00 6
  (the "Software"), to deal in the Software without restriction,
82da8a1c sago007 2015-12-19 18:00 7
  including without limitation the rights to use, copy, modify, merge,
82da8a1c sago007 2015-12-19 18:00 8
  publish, distribute, sublicense, and/or sell copies of the Software,
82da8a1c sago007 2015-12-19 18:00 9
  and to permit persons to whom the Software is furnished to do so,
82da8a1c sago007 2015-12-19 18:00 10
  subject to the following conditions:
82da8a1c sago007 2015-12-19 18:00 11
82da8a1c sago007 2015-12-19 18:00 12
  The above copyright notice and this permission notice shall be
82da8a1c sago007 2015-12-19 18:00 13
  included in all copies or substantial portions of the Software.
82da8a1c sago007 2015-12-19 18:00 14
82da8a1c sago007 2015-12-19 18:00 15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
82da8a1c sago007 2015-12-19 18:00 16
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
82da8a1c sago007 2015-12-19 18:00 17
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
82da8a1c sago007 2015-12-19 18:00 18
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
82da8a1c sago007 2015-12-19 18:00 19
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
82da8a1c sago007 2015-12-19 18:00 20
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
82da8a1c sago007 2015-12-19 18:00 21
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
82da8a1c sago007 2015-12-19 18:00 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
82da8a1c sago007 2015-12-19 18:00 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
82da8a1c sago007 2015-12-19 18:00 32
class SagoSprite {
82da8a1c sago007 2015-12-19 18:00 33
public:
c6bde3e3 sago007 2015-12-22 16:56 34
	SagoSprite();
82da8a1c sago007 2015-12-19 18:00 35
	SagoSprite(const SagoDataHolder &texHolder, const std::string &texture,const SDL_Rect& initImage,const int animationFrames, const int animationFrameLength);
82da8a1c sago007 2015-12-19 18:00 36
	/**
82da8a1c sago007 2015-12-19 18:00 37
	 * Draws the sprite to a given render window
82da8a1c sago007 2015-12-19 18:00 38
     * @param target The render window to draw on
82da8a1c sago007 2015-12-19 18:00 39
     * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
82da8a1c sago007 2015-12-19 18:00 40
     * @param x Place to draw the sprite
82da8a1c sago007 2015-12-19 18:00 41
     * @param y Place to draw the sprite
82da8a1c sago007 2015-12-19 18:00 42
     */
c6bde3e3 sago007 2015-12-22 16:56 43
	void Draw(SDL_Renderer* target, Sint32 frameTime, int x, int y) const;
82da8a1c sago007 2015-12-19 18:00 44
	/**
82da8a1c sago007 2015-12-19 18:00 45
	 * Draws part of the sprite to a given render window
82da8a1c sago007 2015-12-19 18:00 46
     * @param target The render window to draw on
82da8a1c sago007 2015-12-19 18:00 47
     * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
82da8a1c sago007 2015-12-19 18:00 48
     * @param x Place to draw the sprite
82da8a1c sago007 2015-12-19 18:00 49
     * @param y Place to draw the sprite
82da8a1c sago007 2015-12-19 18:00 50
     * @param part the part of the sprite that should be drawn. 
82da8a1c sago007 2015-12-19 18:00 51
     */
c6bde3e3 sago007 2015-12-22 16:56 52
	void Draw(SDL_Renderer* target, Sint32 frameTime, int x, int y, const SDL_Rect& part) const;
c6bde3e3 sago007 2015-12-22 16:56 53
	/**
c6bde3e3 sago007 2015-12-22 16:56 54
	 * Draws the wprite to the given renderer but makes sure to not draw outside th bounds given
c6bde3e3 sago007 2015-12-22 16:56 55
	 * @param target The render window to draw on
c6bde3e3 sago007 2015-12-22 16:56 56
	 * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
c6bde3e3 sago007 2015-12-22 16:56 57
	 * @param x Place to draw the sprite
c6bde3e3 sago007 2015-12-22 16:56 58
	 * @param y Place to draw the sprite
c6bde3e3 sago007 2015-12-22 16:56 59
	 * @param bounds A recagular area that we must not draw outside.
c6bde3e3 sago007 2015-12-22 16:56 60
	 */
c6bde3e3 sago007 2015-12-22 16:56 61
	void DrawBounded(SDL_Renderer* target, Sint32 frameTime, int x, int y, const SDL_Rect& bounds) const;
68313e95 sago007 2016-09-28 16:52 62
	void DrawScaled(SDL_Renderer* target, Sint32 frameTime, int x, int y, int w, int h) const;
82da8a1c sago007 2015-12-19 18:00 63
	/**
82da8a1c sago007 2015-12-19 18:00 64
	 * 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
82da8a1c sago007 2015-12-19 18:00 65
     * @param newOrigin the coordinates that should be the new origin. Call with {0,0} to reset to default 
82da8a1c sago007 2015-12-19 18:00 66
     */
82da8a1c sago007 2015-12-19 18:00 67
	void SetOrigin(const SDL_Rect& newOrigin);
c6bde3e3 sago007 2015-12-22 16:56 68
	SagoSprite(const SagoSprite& base);
c6bde3e3 sago007 2015-12-22 16:56 69
    SagoSprite& operator=(const SagoSprite& base);
1d2e2129 sago007 2015-12-23 15:41 70
	int GetWidth() const;
1d2e2129 sago007 2015-12-23 15:41 71
	int GetHeight() const;
82da8a1c sago007 2015-12-19 18:00 72
	virtual ~SagoSprite();
82da8a1c sago007 2015-12-19 18:00 73
private:
82da8a1c sago007 2015-12-19 18:00 74
	struct SagoSpriteData;
82da8a1c sago007 2015-12-19 18:00 75
	SagoSpriteData *data;
82da8a1c sago007 2015-12-19 18:00 76
};
82da8a1c sago007 2015-12-19 18:00 77
82da8a1c sago007 2015-12-19 18:00 78
}
82da8a1c sago007 2015-12-19 18:00 79
82da8a1c sago007 2015-12-19 18:00 80
#endif	/* SAGOSPRITE_HPP */
82da8a1c sago007 2015-12-19 18:00 81
1970-01-01 00:00 82