3 #include "../app/Application.h"
5 using app::Application;
11 ColorFade::ColorFade(State *slave, Uint32 color, int duration, bool in, bool interactive)
21 , interactive(interactive) {
25 void ColorFade::OnEnterState(SDL_Surface *screen) {
27 timer = GraphicsTimers().StartCountdown(leadIn);
29 timer = GraphicsTimers().StartCountdown(duration);
34 void ColorFade::OnExitState(SDL_Surface *screen) {
36 SDL_FreeSurface(blinds);
41 void ColorFade::OnResumeState(SDL_Surface *screen) {
42 UpdateBlinds(screen->w, screen->h);
45 void ColorFade::OnPauseState(SDL_Surface *screen) {
50 void ColorFade::OnResize(int width, int height) {
51 slave->Resize(width, height);
52 UpdateBlinds(width, height);
55 void ColorFade::UpdateBlinds(int width, int height) {
56 if (blinds && blinds->w == width && blinds->h == height) return;
58 SDL_FreeSurface(blinds);
60 blinds = SDL_CreateRGBSurface(0, width, height, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000);
61 SDL_FillRect(blinds, 0, color);
64 Uint8 ColorFade::GetAlpha() const {
67 } else if (!fadeDone) {
68 return (in ? timer.Remaining() : timer.Elapsed()) * 255 / duration;
75 void ColorFade::HandleEvents(const Input &input) {
77 slave->HandleEvents(input);
79 if (timer.Finished()) {
82 timer = GraphicsTimers().StartCountdown(duration);
83 } else if (!fadeDone) {
86 timer = GraphicsTimers().StartCountdown(leadOut);
97 void ColorFade::UpdateWorld(float deltaT) {
99 slave->UpdateWorld(deltaT);
103 void ColorFade::Render(SDL_Surface *screen) {
104 slave->Render(screen);
105 SDL_SetAlpha(blinds, SDL_SRCALPHA, GetAlpha());
106 SDL_BlitSurface(blinds, 0, screen, 0);