|
|
|
@ -3,43 +3,86 @@
|
|
|
|
|
namespace MWGui
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ScreenFader::ScreenFader()
|
|
|
|
|
: WindowBase("openmw_screen_fader.layout")
|
|
|
|
|
, mMode(FadingMode_In)
|
|
|
|
|
, mRemainingTime(0.f)
|
|
|
|
|
, mTargetTime(0.f)
|
|
|
|
|
, mTargetAlpha(0.f)
|
|
|
|
|
, mCurrentAlpha(0.f)
|
|
|
|
|
, mStartAlpha(0.f)
|
|
|
|
|
, mFactor(1.f)
|
|
|
|
|
FadeOp::FadeOp(ScreenFader * fader, float time, float targetAlpha)
|
|
|
|
|
: mFader(fader),
|
|
|
|
|
mRemainingTime(time),
|
|
|
|
|
mTargetTime(time),
|
|
|
|
|
mTargetAlpha(targetAlpha),
|
|
|
|
|
mStartAlpha(0.f),
|
|
|
|
|
mRunning(false)
|
|
|
|
|
{
|
|
|
|
|
mMainWidget->setSize(MyGUI::RenderManager::getInstance().getViewSize());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setVisible(false);
|
|
|
|
|
bool FadeOp::isRunning()
|
|
|
|
|
{
|
|
|
|
|
return mRunning;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenFader::update(float dt)
|
|
|
|
|
void FadeOp::start()
|
|
|
|
|
{
|
|
|
|
|
if (mRunning)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
mRemainingTime = mTargetTime;
|
|
|
|
|
mStartAlpha = mFader->getCurrentAlpha();
|
|
|
|
|
mRunning = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FadeOp::update(float dt)
|
|
|
|
|
{
|
|
|
|
|
if (mRemainingTime > 0)
|
|
|
|
|
if (!mRunning)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (mRemainingTime <= 0 || mStartAlpha == mTargetAlpha)
|
|
|
|
|
{
|
|
|
|
|
if (mMode == FadingMode_In)
|
|
|
|
|
finish();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float currentAlpha = mFader->getCurrentAlpha();
|
|
|
|
|
if (mStartAlpha > mTargetAlpha)
|
|
|
|
|
{
|
|
|
|
|
mCurrentAlpha -= dt/mTargetTime * (mStartAlpha-mTargetAlpha);
|
|
|
|
|
if (mCurrentAlpha < mTargetAlpha) mCurrentAlpha = mTargetAlpha;
|
|
|
|
|
currentAlpha -= dt/mTargetTime * (mStartAlpha-mTargetAlpha);
|
|
|
|
|
if (currentAlpha < mTargetAlpha)
|
|
|
|
|
currentAlpha = mTargetAlpha;
|
|
|
|
|
}
|
|
|
|
|
else if (mMode == FadingMode_Out)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mCurrentAlpha += dt/mTargetTime * (mTargetAlpha-mStartAlpha);
|
|
|
|
|
if (mCurrentAlpha > mTargetAlpha) mCurrentAlpha = mTargetAlpha;
|
|
|
|
|
currentAlpha += dt/mTargetTime * (mTargetAlpha-mStartAlpha);
|
|
|
|
|
if (currentAlpha > mTargetAlpha)
|
|
|
|
|
currentAlpha = mTargetAlpha;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mFader->notifyAlphaChanged(currentAlpha);
|
|
|
|
|
|
|
|
|
|
mRemainingTime -= dt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (1.f-((1.f-mCurrentAlpha) * mFactor) == 0.f)
|
|
|
|
|
mMainWidget->setVisible(false);
|
|
|
|
|
else
|
|
|
|
|
applyAlpha();
|
|
|
|
|
void FadeOp::finish()
|
|
|
|
|
{
|
|
|
|
|
mRunning = false;
|
|
|
|
|
mFader->notifyOperationFinished();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScreenFader::ScreenFader(const std::string & texturePath)
|
|
|
|
|
: WindowBase("openmw_screen_fader.layout")
|
|
|
|
|
, mCurrentAlpha(0.f)
|
|
|
|
|
, mFactor(1.f)
|
|
|
|
|
, mRepeat(false)
|
|
|
|
|
{
|
|
|
|
|
mMainWidget->setSize(MyGUI::RenderManager::getInstance().getViewSize());
|
|
|
|
|
mMainWidget->setProperty("ImageTexture", texturePath);
|
|
|
|
|
setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenFader::update(float dt)
|
|
|
|
|
{
|
|
|
|
|
if (!mQueue.empty())
|
|
|
|
|
{
|
|
|
|
|
if (!mQueue.front()->isRunning())
|
|
|
|
|
mQueue.front()->start();
|
|
|
|
|
mQueue.front()->update(dt);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenFader::applyAlpha()
|
|
|
|
@ -50,62 +93,73 @@ namespace MWGui
|
|
|
|
|
|
|
|
|
|
void ScreenFader::fadeIn(float time)
|
|
|
|
|
{
|
|
|
|
|
if (time<0.f) return;
|
|
|
|
|
if (time==0.f)
|
|
|
|
|
{
|
|
|
|
|
mCurrentAlpha = 0.f;
|
|
|
|
|
applyAlpha();
|
|
|
|
|
return;
|
|
|
|
|
queue(time, 0.f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mStartAlpha = mCurrentAlpha;
|
|
|
|
|
mTargetAlpha = 0.f;
|
|
|
|
|
mMode = FadingMode_In;
|
|
|
|
|
mTargetTime = time;
|
|
|
|
|
mRemainingTime = time;
|
|
|
|
|
void ScreenFader::fadeOut(const float time)
|
|
|
|
|
{
|
|
|
|
|
queue(time, 1.f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenFader::fadeOut(const float time)
|
|
|
|
|
void ScreenFader::fadeTo(const int percent, const float time)
|
|
|
|
|
{
|
|
|
|
|
if (time<0.f) return;
|
|
|
|
|
if (time==0.f)
|
|
|
|
|
queue(time, percent/100.f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenFader::setFactor(float factor)
|
|
|
|
|
{
|
|
|
|
|
mCurrentAlpha = 1.f;
|
|
|
|
|
applyAlpha();
|
|
|
|
|
return;
|
|
|
|
|
mFactor = factor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mStartAlpha = mCurrentAlpha;
|
|
|
|
|
mTargetAlpha = 1.f;
|
|
|
|
|
mMode = FadingMode_Out;
|
|
|
|
|
mTargetTime = time;
|
|
|
|
|
mRemainingTime = time;
|
|
|
|
|
void ScreenFader::setRepeat(bool repeat)
|
|
|
|
|
{
|
|
|
|
|
mRepeat = repeat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenFader::fadeTo(const int percent, const float time)
|
|
|
|
|
void ScreenFader::queue(float time, float targetAlpha)
|
|
|
|
|
{
|
|
|
|
|
if (time<0.f) return;
|
|
|
|
|
if (time==0.f)
|
|
|
|
|
if (time < 0.f)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (time == 0.f)
|
|
|
|
|
{
|
|
|
|
|
mCurrentAlpha = percent/100.f;
|
|
|
|
|
mCurrentAlpha = targetAlpha;
|
|
|
|
|
applyAlpha();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mStartAlpha = mCurrentAlpha;
|
|
|
|
|
mTargetAlpha = percent/100.f;
|
|
|
|
|
mQueue.push_back(FadeOp::Ptr(new FadeOp(this, time, targetAlpha)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenFader::clearQueue()
|
|
|
|
|
{
|
|
|
|
|
mQueue.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenFader::notifyAlphaChanged(float alpha)
|
|
|
|
|
{
|
|
|
|
|
if (mCurrentAlpha == alpha)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (mTargetAlpha == mStartAlpha) return;
|
|
|
|
|
else if (mTargetAlpha > mStartAlpha) mMode = FadingMode_Out;
|
|
|
|
|
else mMode = FadingMode_In;
|
|
|
|
|
mCurrentAlpha = alpha;
|
|
|
|
|
|
|
|
|
|
mTargetTime = time;
|
|
|
|
|
mRemainingTime = time;
|
|
|
|
|
if (1.f-((1.f-mCurrentAlpha) * mFactor) == 0.f)
|
|
|
|
|
mMainWidget->setVisible(false);
|
|
|
|
|
else
|
|
|
|
|
applyAlpha();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenFader::setFactor(float factor)
|
|
|
|
|
void ScreenFader::notifyOperationFinished()
|
|
|
|
|
{
|
|
|
|
|
mFactor = factor;
|
|
|
|
|
FadeOp::Ptr op = mQueue.front();
|
|
|
|
|
mQueue.pop_front();
|
|
|
|
|
|
|
|
|
|
if (mRepeat)
|
|
|
|
|
mQueue.push_back(op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float ScreenFader::getCurrentAlpha()
|
|
|
|
|
{
|
|
|
|
|
return mCurrentAlpha;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|