1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __I_GUI_SPRITE_BANK_H_INCLUDED__
\r
6 #define __I_GUI_SPRITE_BANK_H_INCLUDED__
\r
8 #include "IReferenceCounted.h"
\r
9 #include "irrArray.h"
\r
19 } // end namespace video
\r
24 //! A single sprite frame.
\r
25 // Note for implementer: Can't fix variable names to uppercase as this is a public interface used since a while
\r
26 struct SGUISpriteFrame
\r
28 SGUISpriteFrame() : textureNumber(0), rectNumber(0)
\r
32 SGUISpriteFrame(u32 textureIndex, u32 positionIndex)
\r
33 : textureNumber(textureIndex), rectNumber(positionIndex)
\r
37 //! Texture index in IGUISpriteBank
\r
40 //! Index in IGUISpriteBank::getPositions()
\r
44 //! A sprite composed of several frames.
\r
45 // Note for implementer: Can't fix variable names to uppercase as this is a public interface used since a while
\r
48 SGUISprite() : frameTime(0) {}
\r
49 SGUISprite(const SGUISpriteFrame& firstFrame) : frameTime(0)
\r
51 Frames.push_back(firstFrame);
\r
54 core::array<SGUISpriteFrame> Frames;
\r
59 //! Sprite bank interface.
\r
60 /** See http://http://irrlicht.sourceforge.net/forum//viewtopic.php?f=9&t=25742
\r
61 * for more information how to use the spritebank.
\r
63 class IGUISpriteBank : public virtual IReferenceCounted
\r
67 //! Returns the list of rectangles held by the sprite bank
\r
68 virtual core::array< core::rect<s32> >& getPositions() = 0;
\r
70 //! Returns the array of animated sprites within the sprite bank
\r
71 virtual core::array< SGUISprite >& getSprites() = 0;
\r
73 //! Returns the number of textures held by the sprite bank
\r
74 virtual u32 getTextureCount() const = 0;
\r
76 //! Gets the texture with the specified index
\r
77 virtual video::ITexture* getTexture(u32 index) const = 0;
\r
79 //! Adds a texture to the sprite bank
\r
80 virtual void addTexture(video::ITexture* texture) = 0;
\r
82 //! Changes one of the textures in the sprite bank
\r
83 virtual void setTexture(u32 index, video::ITexture* texture) = 0;
\r
85 //! Add the texture and use it for a single non-animated sprite.
\r
86 /** The texture and the corresponding rectangle and sprite will all be added to the end of each array.
\r
87 \returns The index of the sprite or -1 on failure */
\r
88 virtual s32 addTextureAsSprite(video::ITexture* texture) = 0;
\r
90 //! Clears sprites, rectangles and textures
\r
91 virtual void clear() = 0;
\r
93 //! Draws a sprite in 2d with position and color
\r
95 \param index Index of SGUISprite to draw
\r
96 \param pos Target position - depending on center value either the left-top or the sprite center is used as pivot
\r
97 \param clip Clipping rectangle, can be 0 when clipping is not wanted.
\r
98 \param color Color with which the image is drawn.
\r
99 Note that the alpha component is used. If alpha is other than
\r
100 255, the image will be transparent.
\r
101 \param starttime Tick when the first frame was drawn (only difference currenttime-starttime matters).
\r
102 \param currenttime To calculate the frame of animated sprites
\r
103 \param loop When true animations are looped
\r
104 \param center When true pivot is set to the sprite-center. So it affects pos.
\r
106 virtual void draw2DSprite(u32 index, const core::position2di& pos,
\r
107 const core::rect<s32>* clip=0,
\r
108 const video::SColor& color= video::SColor(255,255,255,255),
\r
109 u32 starttime=0, u32 currenttime=0,
\r
110 bool loop=true, bool center=false) = 0;
\r
112 //! Draws a sprite in 2d with destination rectangle and colors
\r
114 \param index Index of SGUISprite to draw
\r
115 \param destRect The sprite will be scaled to fit this target rectangle
\r
116 \param clip Clipping rectangle, can be 0 when clipping is not wanted.
\r
117 \param colors Array of 4 colors denoting the color values of
\r
118 the corners of the destRect
\r
119 \param timeTicks Current frame for animated sprites
\r
120 (same as currenttime-starttime in other draw2DSprite function)
\r
121 \param loop When true animations are looped
\r
123 virtual void draw2DSprite(u32 index, const core::rect<s32>& destRect,
\r
124 const core::rect<s32>* clip=0,
\r
125 const video::SColor * const colors=0,
\r
127 bool loop=true) = 0;
\r
129 //! Draws a sprite batch in 2d using an array of positions and a color
\r
130 virtual void draw2DSpriteBatch(const core::array<u32>& indices, const core::array<core::position2di>& pos,
\r
131 const core::rect<s32>* clip=0,
\r
132 const video::SColor& color= video::SColor(255,255,255,255),
\r
133 u32 starttime=0, u32 currenttime=0,
\r
134 bool loop=true, bool center=false) = 0;
\r
138 } // end namespace gui
\r
139 } // end namespace irr
\r
141 #endif // __I_GUI_SPRITE_BANK_H_INCLUDED__
\r