Spritebanks can now draw scaled sprites.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4754 dfc29bdd-3216-0410-991c-e03cc46cb475
master
cutealien 2014-04-02 16:33:19 +00:00
parent 14fd2945cc
commit 50f43d5a3d
4 changed files with 72 additions and 18 deletions

View File

@ -1,6 +1,7 @@
--------------------------
Changes in 1.9 (not yet released)
- Spritebanks can now draw scaled sprites and are a little easier to use.
- Improved i18n key input for X11 (languages like cyrillic work now).
- Fix bug that ListBox would not allow to 'tab' to the next element (thx @ FlavourBoat for reporting)
- IGUIEnvironment::getNextElement now public (was only in CGUIEnvironment before).

View File

@ -91,12 +91,41 @@ public:
virtual void clear() = 0;
//! Draws a sprite in 2d with position and color
/**
\param index Index of SGUISprite to draw
\param pos Target position - depending on center value either the left-top or the sprite center is used as pivot
\param clip Clipping rectangle, can be 0 when clipping is not wanted.
\param color Color with which the image is drawn.
Note that the alpha component is used. If alpha is other than
255, the image will be transparent.
\param starttime Tick when the first frame was drawn (only difference currenttime-starttime matters).
\param currenttime To calculate the frame of animated sprites
\param loop When true animations are looped
\param center When true pivot is set to the sprite-center. So it affects pos.
*/
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),
u32 starttime=0, u32 currenttime=0,
bool loop=true, bool center=false) = 0;
//! Draws a sprite in 2d with destination rectangle and colors
/**
\param index Index of SGUISprite to draw
\param destRect The sprite will be scaled to fit this target rectangle
\param clip Clipping rectangle, can be 0 when clipping is not wanted.
\param colors Array of 4 colors denoting the color values of
the corners of the destRect
\param timeTicks Current frame for animated sprites
(same as currenttime-starttime in other draw2DSprite function)
\param loop When true animations are looped
*/
virtual void draw2DSprite(u32 index, const core::rect<s32>& destRect,
const core::rect<s32>* clip=0,
const video::SColor * const colors=0,
u32 timeTicks = 0,
bool loop=true) = 0;
//! Draws a sprite batch in 2d using an array of positions and a color
virtual void draw2DSpriteBatch(const core::array<u32>& indices, const core::array<core::position2di>& pos,
const core::rect<s32>* clip=0,

View File

@ -141,17 +141,7 @@ void CGUISpriteBank::draw2DSprite(u32 index, const core::position2di& pos,
if (index >= Sprites.size() || Sprites[index].Frames.empty() )
return;
// work out frame number
u32 frame = 0;
if (Sprites[index].frameTime)
{
u32 f = ((currenttime - starttime) / Sprites[index].frameTime);
if (loop)
frame = f % Sprites[index].Frames.size();
else
frame = (f >= Sprites[index].Frames.size()) ? Sprites[index].Frames.size()-1 : f;
}
u32 frame = getFrameNr(index, currenttime - starttime, loop);
const video::ITexture* tex = getTexture(Sprites[index].Frames[frame].textureNumber);
if (!tex)
return;
@ -161,19 +151,32 @@ void CGUISpriteBank::draw2DSprite(u32 index, const core::position2di& pos,
return;
const core::rect<s32>& r = Rectangles[rn];
core::position2di p(pos);
if (center)
{
core::position2di p = pos;
p -= r.getSize() / 2;
Driver->draw2DImage(tex, p, r, clip, color, true);
}
else
{
Driver->draw2DImage(tex, pos, r, clip, color, true);
}
Driver->draw2DImage(tex, p, r, clip, color, true);
}
void CGUISpriteBank::draw2DSprite(u32 index, const core::rect<s32>& destRect,
const core::rect<s32>* clip, const video::SColor * const colors,
u32 timeTicks, bool loop)
{
if (index >= Sprites.size() || Sprites[index].Frames.empty() )
return;
u32 frame = getFrameNr(index, timeTicks, loop);
const video::ITexture* tex = getTexture(Sprites[index].Frames[frame].textureNumber);
if (!tex)
return;
const u32 rn = Sprites[index].Frames[frame].rectNumber;
if (rn >= Rectangles.size())
return;
Driver->draw2DImage(tex, destRect, Rectangles[rn], clip, colors, true);
}
void CGUISpriteBank::draw2DSpriteBatch( const core::array<u32>& indices,
const core::array<core::position2di>& pos,

View File

@ -51,6 +51,13 @@ public:
const video::SColor& color= video::SColor(255,255,255,255),
u32 starttime=0, u32 currenttime=0, bool loop=true, bool center=false) _IRR_OVERRIDE_;
//! Draws a sprite in 2d with destination rectangle and colors
virtual void draw2DSprite(u32 index, const core::rect<s32>& destRect,
const core::rect<s32>* clip=0,
const video::SColor * const colors=0,
u32 timeTicks = 0,
bool loop=true) _IRR_OVERRIDE_;
//! Draws a sprite batch in 2d using an array of positions and a color
virtual void draw2DSpriteBatch(const core::array<u32>& indices, const core::array<core::position2di>& pos,
const core::rect<s32>* clip=0,
@ -60,6 +67,20 @@ public:
protected:
inline u32 getFrameNr(u32 index, u32 time, bool loop) const
{
u32 frame = 0;
if (Sprites[index].frameTime && Sprites[index].Frames.size() )
{
u32 f = (time / Sprites[index].frameTime);
if (loop)
frame = f % Sprites[index].Frames.size();
else
frame = (f >= Sprites[index].Frames.size()) ? Sprites[index].Frames.size()-1 : f;
}
return frame;
}
struct SDrawBatch
{
core::array<core::position2di> positions;