, 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) {
}
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;
}
}
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();
+ }
}
}
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);
SDL_Surface *blinds;
Uint32 color;
int duration;
+ int leadIn;
+ int leadOut;
+ bool leadInDone;
+ bool fadeDone;
bool in;
bool interactive;