ES-DE/src/components/GuiAnimation.cpp

93 lines
1.5 KiB
C++
Raw Normal View History

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
{
float mult = deltaTime * 0.05;
if(mMoveX != 0 || mMoveY != 0)
{
int offsetx = (mMoveX > mMoveSpeed) ? mMoveSpeed : mMoveX;
int offsety = (mMoveY > mMoveSpeed) ? mMoveSpeed : mMoveY;
offsetx *= mult;
offsety *= mult;
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
}
}