2012-10-17 17:15:58 +00:00
|
|
|
#include "GuiAnimation.h"
|
|
|
|
|
|
|
|
GuiAnimation::GuiAnimation()
|
|
|
|
{
|
|
|
|
mMoveX = 0;
|
|
|
|
mMoveY = 0;
|
|
|
|
mMoveSpeed = 0;
|
|
|
|
mFadeRate = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiAnimation::move(int x, int y, int speed)
|
|
|
|
{
|
|
|
|
mMoveX = x;
|
|
|
|
mMoveY = y;
|
|
|
|
mMoveSpeed = speed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiAnimation::fadeIn(int time)
|
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
mOpacity = 0;
|
2012-10-17 17:15:58 +00:00
|
|
|
setChildrenOpacity(0);
|
|
|
|
|
|
|
|
mFadeRate = time;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiAnimation::fadeOut(int time)
|
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
mOpacity = 255;
|
2012-10-17 17:15:58 +00:00
|
|
|
setChildrenOpacity(255);
|
|
|
|
|
|
|
|
mFadeRate = -time;
|
|
|
|
}
|
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
void GuiAnimation::update(int deltaTime)
|
2012-10-17 17:15:58 +00:00
|
|
|
{
|
2013-05-13 19:53:28 +00:00
|
|
|
float mult = deltaTime * 0.05f;
|
2012-10-17 17:15:58 +00:00
|
|
|
|
|
|
|
if(mMoveX != 0 || mMoveY != 0)
|
|
|
|
{
|
|
|
|
int offsetx = (mMoveX > mMoveSpeed) ? mMoveSpeed : mMoveX;
|
|
|
|
int offsety = (mMoveY > mMoveSpeed) ? mMoveSpeed : mMoveY;
|
|
|
|
|
2013-05-13 19:53:28 +00:00
|
|
|
offsetx = (int)(offsetx * mult);
|
|
|
|
offsety = (int)(offsety * mult);
|
2012-10-17 17:15:58 +00:00
|
|
|
|
|
|
|
moveChildren(offsetx, offsety);
|
|
|
|
|
|
|
|
mMoveX -= offsetx;
|
|
|
|
mMoveY -= offsety;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mFadeRate != 0)
|
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
int opacity = (int)mOpacity + mFadeRate;
|
2012-10-17 17:15:58 +00:00
|
|
|
if(opacity > 255)
|
|
|
|
{
|
|
|
|
mFadeRate = 0;
|
|
|
|
opacity = 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(opacity < 0)
|
|
|
|
{
|
|
|
|
mFadeRate = 0;
|
|
|
|
opacity = 0;
|
|
|
|
}
|
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
mOpacity = (unsigned char)opacity;
|
2012-10-17 17:15:58 +00:00
|
|
|
setChildrenOpacity((unsigned char)opacity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
void GuiAnimation::addChild(GuiImage* gui)
|
|
|
|
{
|
|
|
|
mChildren.push_back(gui);
|
|
|
|
}
|
|
|
|
|
2012-10-17 17:15:58 +00:00
|
|
|
void GuiAnimation::moveChildren(int offsetx, int offsety)
|
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
for(unsigned int i = 0; i < mChildren.size(); i++)
|
2012-10-17 17:15:58 +00:00
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
GuiImage* comp = mChildren.at(i);
|
2012-10-17 17:15:58 +00:00
|
|
|
comp->setOffset(comp->getOffsetX() + offsetx, comp->getOffsetY() + offsety);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiAnimation::setChildrenOpacity(unsigned char opacity)
|
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
for(unsigned int i = 0; i < mChildren.size(); i++)
|
2012-10-17 17:15:58 +00:00
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
mChildren.at(i)->setOpacity(opacity);
|
2012-10-17 17:15:58 +00:00
|
|
|
}
|
|
|
|
}
|