4 * Created on: Oct 7, 2012
10 #include "../app/Application.h"
12 using app::Application;
18 ColorFade::ColorFade(State *slave, Uint32 color, int duration, bool in, bool interactive)
29 , interactive(interactive) {
33 void ColorFade::OnEnterState(Application &c, SDL_Surface *screen) {
36 timer = GraphicsTimers().StartCountdown(leadIn);
38 timer = GraphicsTimers().StartCountdown(duration);
43 void ColorFade::OnExitState(Application &, SDL_Surface *screen) {
45 SDL_FreeSurface(blinds);
50 void ColorFade::OnResumeState(Application &ctrl, SDL_Surface *screen) {
51 UpdateBlinds(screen->w, screen->h);
54 void ColorFade::OnPauseState(Application &ctrl, SDL_Surface *screen) {
59 void ColorFade::Resize(int width, int height) {
60 slave->Resize(width, height);
61 UpdateBlinds(width, height);
64 void ColorFade::UpdateBlinds(int width, int height) {
65 if (blinds && blinds->w == width && blinds->h == height) return;
67 SDL_FreeSurface(blinds);
69 blinds = SDL_CreateRGBSurface(0, width, height, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000);
70 SDL_FillRect(blinds, 0, color);
73 Uint8 ColorFade::GetAlpha() const {
76 } else if (!fadeDone) {
77 return (in ? timer.Remaining() : timer.Elapsed()) * 255 / duration;
84 void ColorFade::HandleEvents(const Input &input) {
86 slave->HandleEvents(input);
88 if (timer.Finished()) {
91 timer = GraphicsTimers().StartCountdown(duration);
92 } else if (!fadeDone) {
95 timer = GraphicsTimers().StartCountdown(leadOut);
106 void ColorFade::UpdateWorld(float deltaT) {
108 slave->UpdateWorld(deltaT);
112 void ColorFade::Render(SDL_Surface *screen) {
113 slave->Render(screen);
114 SDL_SetAlpha(blinds, SDL_SRCALPHA, GetAlpha());
115 SDL_BlitSurface(blinds, 0, screen, 0);