From 123ca72f7a92d2529c6f9b6bdff3f13d6f0223c9 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 8 Oct 2012 22:07:50 +0200 Subject: [PATCH] added lead in/out time option for ColorFade --- src/graphics/ColorFade.cpp | 33 ++++++++++++++++++++++++++++----- src/graphics/ColorFade.h | 8 ++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/graphics/ColorFade.cpp b/src/graphics/ColorFade.cpp index 51fe973..e83edbb 100644 --- a/src/graphics/ColorFade.cpp +++ b/src/graphics/ColorFade.cpp @@ -21,14 +21,23 @@ ColorFade::ColorFade(State *slave, Uint32 color, int duration, bool in, bool int , blinds(0) , color(color) , duration(duration) +, leadIn(0) +, leadOut(0) +, leadInDone(true) +, fadeDone(false) , in(in) , interactive(interactive) { } void ColorFade::EnterState(Application &c, SDL_Surface *screen) { - timer = GraphicsTimers().StartCountdown(duration); ctrl = &c; + if (leadIn > 0) { + timer = GraphicsTimers().StartCountdown(leadIn); + } else { + timer = GraphicsTimers().StartCountdown(duration); + + } } void ColorFade::ExitState(Application &, SDL_Surface *screen) { @@ -62,10 +71,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,7 +86,19 @@ 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(); + } + } else { + ctrl->PopState(); + } } } diff --git a/src/graphics/ColorFade.h b/src/graphics/ColorFade.h index 66d8192..7226a00 100644 --- a/src/graphics/ColorFade.h +++ b/src/graphics/ColorFade.h @@ -22,6 +22,10 @@ public: ColorFade(app::State *slave, Uint32 color, int duration, bool in = false, bool interactive = false); virtual ~ColorFade() { } +public: + void SetLeadInTime(int ms) { leadIn = ms; if (ms > 0) leadInDone = false; } + void SetLeadOutTime(int ms) { leadOut = ms; } + public: virtual void EnterState(app::Application &ctrl, SDL_Surface *screen); virtual void ExitState(app::Application &ctrl, SDL_Surface *screen); @@ -45,6 +49,10 @@ private: SDL_Surface *blinds; Uint32 color; int duration; + int leadIn; + int leadOut; + bool leadInDone; + bool fadeDone; bool in; bool interactive; -- 2.39.2