X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2FColorFade.cpp;h=55e14fc811d87e2427a4ef0443259a3da996d1da;hb=HEAD;hp=51fe973fd76989229c581d7186edd49dac8dcfb0;hpb=f7555575e8f2f8b9dbf740628f66e34ff93d8390;p=l2e.git diff --git a/src/graphics/ColorFade.cpp b/src/graphics/ColorFade.cpp index 51fe973..55e14fc 100644 --- a/src/graphics/ColorFade.cpp +++ b/src/graphics/ColorFade.cpp @@ -1,10 +1,3 @@ -/* - * ColorFade.cpp - * - * Created on: Oct 7, 2012 - * Author: holy - */ - #include "ColorFade.h" #include "../app/Application.h" @@ -16,38 +9,46 @@ using app::Input; namespace graphics { ColorFade::ColorFade(State *slave, Uint32 color, int duration, bool in, bool interactive) -: ctrl(0) -, slave(slave) +: slave(slave) , blinds(0) , color(color) , duration(duration) +, leadIn(0) +, leadOut(0) +, leadInDone(true) +, fadeDone(false) , in(in) -, interactive(interactive) { +, interactive(interactive) +, doublePop(false) { } -void ColorFade::EnterState(Application &c, SDL_Surface *screen) { - timer = GraphicsTimers().StartCountdown(duration); - ctrl = &c; +void ColorFade::OnEnterState(SDL_Surface *screen) { + if (leadIn > 0) { + timer = GraphicsTimers().StartCountdown(leadIn); + } else { + timer = GraphicsTimers().StartCountdown(duration); + + } } -void ColorFade::ExitState(Application &, SDL_Surface *screen) { +void ColorFade::OnExitState(SDL_Surface *screen) { if (blinds) { SDL_FreeSurface(blinds); blinds = 0; } } -void ColorFade::ResumeState(Application &ctrl, SDL_Surface *screen) { +void ColorFade::OnResumeState(SDL_Surface *screen) { UpdateBlinds(screen->w, screen->h); } -void ColorFade::PauseState(Application &ctrl, SDL_Surface *screen) { +void ColorFade::OnPauseState(SDL_Surface *screen) { } -void ColorFade::Resize(int width, int height) { +void ColorFade::OnResize(int width, int height) { slave->Resize(width, height); UpdateBlinds(width, height); } @@ -62,10 +63,12 @@ void ColorFade::UpdateBlinds(int width, int height) { } Uint8 ColorFade::GetAlpha() const { - if (in) { - return timer.Remaining() * 255 / duration; + if (!leadInDone) { + return in ? 255 : 0; + } else if (!fadeDone) { + return (in ? timer.Remaining() : timer.Elapsed()) * 255 / duration; } else { - return timer.Elapsed() * 255 / duration; + return in ? 0 : 255; } } @@ -75,12 +78,30 @@ void ColorFade::HandleEvents(const Input &input) { slave->HandleEvents(input); } if (timer.Finished()) { - ctrl->PopState(); + if (!leadInDone) { + leadInDone = true; + timer = GraphicsTimers().StartCountdown(duration); + } else if (!fadeDone) { + fadeDone = true; + if (leadOut > 0) { + timer = GraphicsTimers().StartCountdown(leadOut); + } else { + Ctrl().PopState(); + if (doublePop) { + Ctrl().PopState(); + } + } + } else { + Ctrl().PopState(); + if (doublePop) { + Ctrl().PopState(); + } + } } } -void ColorFade::UpdateWorld(float deltaT) { +void ColorFade::UpdateWorld(Uint32 deltaT) { if (interactive) { slave->UpdateWorld(deltaT); }