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)
28 , interactive(interactive) {
32 void ColorFade::OnEnterState(SDL_Surface *screen) {
34 timer = GraphicsTimers().StartCountdown(leadIn);
36 timer = GraphicsTimers().StartCountdown(duration);
41 void ColorFade::OnExitState(SDL_Surface *screen) {
43 SDL_FreeSurface(blinds);
48 void ColorFade::OnResumeState(SDL_Surface *screen) {
49 UpdateBlinds(screen->w, screen->h);
52 void ColorFade::OnPauseState(SDL_Surface *screen) {
57 void ColorFade::OnResize(int width, int height) {
58 slave->Resize(width, height);
59 UpdateBlinds(width, height);
62 void ColorFade::UpdateBlinds(int width, int height) {
63 if (blinds && blinds->w == width && blinds->h == height) return;
65 SDL_FreeSurface(blinds);
67 blinds = SDL_CreateRGBSurface(0, width, height, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000);
68 SDL_FillRect(blinds, 0, color);
71 Uint8 ColorFade::GetAlpha() const {
74 } else if (!fadeDone) {
75 return (in ? timer.Remaining() : timer.Elapsed()) * 255 / duration;
82 void ColorFade::HandleEvents(const Input &input) {
84 slave->HandleEvents(input);
86 if (timer.Finished()) {
89 timer = GraphicsTimers().StartCountdown(duration);
90 } else if (!fadeDone) {
93 timer = GraphicsTimers().StartCountdown(leadOut);
104 void ColorFade::UpdateWorld(float deltaT) {
106 slave->UpdateWorld(deltaT);
110 void ColorFade::Render(SDL_Surface *screen) {
111 slave->Render(screen);
112 SDL_SetAlpha(blinds, SDL_SRCALPHA, GetAlpha());
113 SDL_BlitSurface(blinds, 0, screen, 0);