Make spritebank a little easier to use by adding clear and addTextureAsSprite.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3021 dfc29bdd-3216-0410-991c-e03cc46cb475
master
cutealien 2009-12-08 00:05:35 +00:00
parent 7e91fcb00f
commit ab590612a9
3 changed files with 54 additions and 0 deletions

View File

@ -39,6 +39,9 @@ struct SGUISprite
//! Sprite bank interface.
/** See http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=25742&highlight=spritebank
* for more einformation how to use the spritebank.
*/
class IGUISpriteBank : public virtual IReferenceCounted
{
public:
@ -61,6 +64,14 @@ public:
//! Changes one of the textures in the sprite bank
virtual void setTexture(u32 index, video::ITexture* texture) = 0;
//! Add the texture and use it for a single non-animated sprite.
//! The texture and the corresponding rectangle and sprite will all be added to the end of each array.
//! returns the index of the sprite or -1 on failure
virtual s32 addTextureAsSprite(video::ITexture* texture) = 0;
//! clears sprites, rectangles and textures
virtual void clear() = 0;
//! Draws a sprite in 2d with position and color
virtual void draw2DSprite(u32 index, const core::position2di& pos,
const core::rect<s32>* clip=0,

View File

@ -94,6 +94,43 @@ void CGUISpriteBank::setTexture(u32 index, video::ITexture* texture)
}
//! clear everything
void CGUISpriteBank::clear()
{
// drop textures
for (u32 i=0; i<Textures.size(); ++i)
if (Textures[i])
Textures[i]->drop();
Textures.clear();
Sprites.clear();
Rectangles.clear();
}
//! Add the texture and use it for a single non-animated sprite.
s32 CGUISpriteBank::addTextureAsSprite(video::ITexture* texture)
{
if ( !texture )
return -1;
addTexture(texture);
u32 textureIndex = getTextureCount() - 1;
u32 rectangleIndex = Rectangles.size();
Rectangles.push_back( core::rect<s32>(0,0, texture->getOriginalSize().Width, texture->getOriginalSize().Height) );
SGUISprite sprite;
sprite.frameTime = 0;
SGUISpriteFrame frame;
frame.textureNumber = textureIndex;
frame.rectNumber = rectangleIndex;
sprite.Frames.push_back( frame );
Sprites.push_back( sprite );
return Sprites.size() - 1;
}
//! draws a sprite in 2d with scale and color
void CGUISpriteBank::draw2DSprite(u32 index, const core::position2di& pos,
const core::rect<s32>* clip, const video::SColor& color,

View File

@ -40,6 +40,12 @@ public:
virtual void addTexture(video::ITexture* texture);
virtual void setTexture(u32 index, video::ITexture* texture);
//! Add the texture and use it for a single non-animated sprite.
virtual s32 addTextureAsSprite(video::ITexture* texture);
//! clears sprites, rectangles and textures
virtual void clear();
//! Draws a sprite in 2d with position and color
virtual void draw2DSprite(u32 index, const core::position2di& pos, const core::rect<s32>* clip=0,
const video::SColor& color= video::SColor(255,255,255,255),