//
//  SpriteNode.h
//  PixelKit
//
//  Copyright (c) 2014 César Parent. All rights reserved.
//
#ifndef _SPRITENODE_H
#define _SPRITENODE_H

#include "includes.h"
#include "Node.h"

namespace PixelKit
{
	class Animation;
	
	class SpriteNode : public Node
	{
	public:
		/*!
		 * @brief SpriteNode Constructor
		 * @param image Sprite's image filename. The file must be part of the currently loaded
		 * binary resource file.
		 */
		SpriteNode(std::string image);
		
		/*!
		 * @brief SpriteNode destructor
		 */
		~SpriteNode() override;
		
		/*!
		 * @brief Draw the node's sprite on the screen. If no animation is set, the whole image
		 * will be drawn. Only a frame of it will be drawn otherwise.
		 * @param renderer Renderer to draaw with.
		 */
		virtual void draw(SDL_Renderer *renderer) override;
		
		/*!
		 * @brief Load an animation file to use when drawing the Node.
		 * @param animationName Animation file's name. The file must be part of the currently
		 * loaded binary resource file.
		 */
		virtual void animate(std::string animationName);
		
		/*!
		 * @brief Update method ran each frame before rendering to the screen.
		 * @param timeInterval Time elapsed since last frame in milliseconds.
		 */
		virtual void update(int timeInterval) override;
		
		/*!
		 * @brief Set the portion of a texture to use as sprite.
		 * @param x x position of the sprite in the atlas.
		 * @param y y position of the sprite in the atlas.
		 * @param w sprite's width.
		 * @param h sprite's height.
		 */
		virtual void setClipFrame(int x, int y, int w, int h);
		
		/*!
		 * @brief SpriteNode's opacity
		 */
		Uint8 alpha;
		
	protected:
		
		/*!
		 * @brief  SpriteNode's texture.
		 */
		SDL_Texture *_texture;
		
		/*!
		 * @brief  SpriteNode's current animation file, or nullptr if none was
		 * loaded
		 */
		Animation* _currentAnimation;
		
		
		SDL_Rect _clipFrame;
		
	private:
	};
}

#endif