]> git.localhorst.tv Git - l2e.git/commitdiff
added lead in/out time option for ColorFade
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 8 Oct 2012 20:07:50 +0000 (22:07 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 8 Oct 2012 20:07:50 +0000 (22:07 +0200)
src/graphics/ColorFade.cpp
src/graphics/ColorFade.h

index 51fe973fd76989229c581d7186edd49dac8dcfb0..e83edbb1c0ccf4313c9f1820723b3b968abf2869 100644 (file)
@@ -21,14 +21,23 @@ ColorFade::ColorFade(State *slave, Uint32 color, int duration, bool in, bool int
 , blinds(0)
 , color(color)
 , duration(duration)
 , 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) {
 , in(in)
 , interactive(interactive) {
 
 }
 
 void ColorFade::EnterState(Application &c, SDL_Surface *screen) {
-       timer = GraphicsTimers().StartCountdown(duration);
        ctrl = &c;
        ctrl = &c;
+       if (leadIn > 0) {
+               timer = GraphicsTimers().StartCountdown(leadIn);
+       } else {
+               timer = GraphicsTimers().StartCountdown(duration);
+
+       }
 }
 
 void ColorFade::ExitState(Application &, SDL_Surface *screen) {
 }
 
 void ColorFade::ExitState(Application &, SDL_Surface *screen) {
@@ -62,10 +71,12 @@ void ColorFade::UpdateBlinds(int width, int height) {
 }
 
 Uint8 ColorFade::GetAlpha() const {
 }
 
 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 {
        } 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()) {
                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();
+               }
        }
 }
 
        }
 }
 
index 66d8192933e80f78c7b29e2ba6bb59f8e4358bcf..7226a00e29ca658ba57b23ba0e721cd5048619b0 100644 (file)
@@ -22,6 +22,10 @@ public:
        ColorFade(app::State *slave, Uint32 color, int duration, bool in = false, bool interactive = false);
        virtual ~ColorFade() { }
 
        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);
 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;
        SDL_Surface *blinds;
        Uint32 color;
        int duration;
+       int leadIn;
+       int leadOut;
+       bool leadInDone;
+       bool fadeDone;
        bool in;
        bool interactive;
 
        bool in;
        bool interactive;