//------------------------------------------------------------------------------------
// irr::gui::IGUISpriteBank wrappers
//------------------------------------------------------------------------------------
extern "C" 
{
	//------------------------------------------------------------------------------------
	// SGUISpriteFrame
	//------------------------------------------------------------------------------------

	void IrrGUI_SGUISpriteFrame_setTextureNumber(SGUISpriteFrame* sf,u32 textureNumber)
	{
		if (sf)
			sf->textureNumber=textureNumber;
	}

	u32 IrrGUI_SGUISpriteFrame_getTextureNumber(SGUISpriteFrame* sf)
	{
		if (sf)
			return sf->textureNumber;
	}

	void IrrGUI_SGUISpriteFrame_setRectNumber(SGUISpriteFrame* sf,u32 rectNumber)
	{
		if (sf)
			sf->rectNumber=rectNumber;
	}

	u32 IrrGUI_SGUISpriteFrame_getRectNumber(SGUISpriteFrame* sf)
	{
		if (sf)
			return sf->rectNumber;
	}

	//------------------------------------------------------------------------------------
	// SGUISprite
	//------------------------------------------------------------------------------------

	u32 IrrGUI_SGUISprite_getFrameCount(SGUISprite* sprite)
	{
		if (sprite)
			return sprite->Frames.size();
	}

	// do note delete
	SGUISpriteFrame* IrrGUI_SGUISprite_getFrame(SGUISprite* sprite,u32 frameNumber)
	{
		if (sprite)
			return &sprite->Frames[frameNumber];
		else return 0;
	}
	
	u32 IrrGUI_SGUISprite_getFrameTime(SGUISprite* sprite)
	{
		if (sprite)
			return sprite->frameTime;
		else return 0;
	}

	void IrrGUI_SGUISprite_setFrameTime(SGUISprite* sprite,u32 frameTime)
	{		
		if (sprite)
			sprite->frameTime=frameTime;
	}

	//------------------------------------------------------------------------------------
	// SGUISpriteBank
	//------------------------------------------------------------------------------------

	//! Sprite bank interface.
	//class IGUISpriteBank : public virtual IUnknown
	bool IrrGUI_IGUISpriteBank_drop(IGUISpriteBank* unk)
	{
		if (unk)
			return unk->drop();
		else return 0;
	}
	
	const c8* IrrGUI_IGUISpriteBank_getDebugName(IGUISpriteBank* unk)
	{
		if (unk)
			return unk->getDebugName();
		else return "";
	}
	
	void IrrGUI_IGUISpriteBank_grab(IGUISpriteBank* unk)
	{
		if (unk)
			unk->grab();
	}

	// must delete array ptr
	s32 IrrGUI_IGUISpriteBank_getPositions(IGUISpriteBank* sb,u32** positions)
	{
		if (sb) {
			Irr_ptrarray_allocate(positions,sb->getPositions().size());
			
			for (s32 i=0; i<sb->getPositions().size(); i++) {
				((u32*)*positions)[i]=(u32)&(sb->getPositions()[i]);
			}
			
			return sb->getPositions().size();
		} else return -1;
	}

	// must delete array ptr
	s32 IrrGUI_IGUISpriteBank_getSprites(IGUISpriteBank* sb,u32** sprites)
	{
		if (sb) {
			Irr_ptrarray_allocate(sprites,sb->getSprites().size());
			
			for (s32 i=0; i<sb->getSprites().size(); i++) {
				((u32*)*sprites)[i]=(u32)&(sb->getSprites()[i]);
			}
			
			return sb->getSprites().size();
		} else return -1;
	}
	
	u32 IrrGUI_IGUISpriteBank_getTextureCount(IGUISpriteBank* sb)
	{
		if (sb)
			return sb->getTextureCount();
		else return 0;
	}

	ITexture* IrrGUI_IGUISpriteBank_getTexture(IGUISpriteBank* sb,u32 index)
	{
		if (sb)
			return sb->getTexture(index);
		else return 0;
	}

	void IrrGUI_IGUISpriteBank_addTexture(IGUISpriteBank* sb,ITexture* texture)
	{
		if (sb)
			sb->addTexture(texture);
	}

	void IrrGUI_IGUISpriteBank_setTexture(IGUISpriteBank* sb,u32 index,ITexture* texture)
	{
		if (sb)
			sb->setTexture(index,texture);
	}

	void IrrGUI_IGUISpriteBank_draw2DSprite(IGUISpriteBank* sb,u32 index, const position2di& pos, const rect<s32>* clip=0,
			SColor* color= 0, u32 starttime=0, u32 currenttime=0, bool loop=true, bool center=false)
	{
		if (sb)
			sb->draw2DSprite(index,pos,clip,(color ? *color : SColor(255,255,255,255)),starttime,currenttime,loop,center);
	}

	void IrrGUI_IGUISpriteBank_draw2DSpriteBatch(IGUISpriteBank* sb,
			u32* indices_array, s32 indices_size, 
			position2di** pos_array, s32 pos_size, 
			const core::rect<s32>* clip=0,
			const video::SColor* color= 0,
			u32 starttime=0, u32 currenttime=0,
			bool loop=true, bool center=false) {

		if (sb) {
			array<u32> indices;
			for (int i=0; i<indices_size; i++) {	
				indices.push_back(indices_array[i]);
			}
			
			array<position2di> pos;
			for (int i=0; i<pos_size; i++) {	
				pos.push_back(*pos_array[i]);
			}
		
			sb->draw2DSpriteBatch(indices, pos, clip, (color ? *color : SColor(255,255,255,255)), starttime, currenttime, loop, center);
		}				
	}

	s32 IrrGUI_IGUISpriteBank_addTextureAsSprite(IGUISpriteBank* sb, ITexture* texture)
	{
		if (sb)
			return sb->addTextureAsSprite(texture);
		else return -1;
	}

	void IrrGUI_IGUISpriteBank_clear(IGUISpriteBank* sb)
	{
		if (sb)
			sb->clear();
	}
	
}