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)
26 void ColorFade::OnEnterState(SDL_Surface *screen) {
28 timer = GraphicsTimers().StartCountdown(leadIn);
30 timer = GraphicsTimers().StartCountdown(duration);
35 void ColorFade::OnExitState(SDL_Surface *screen) {
37 SDL_FreeSurface(blinds);
42 void ColorFade::OnResumeState(SDL_Surface *screen) {
43 UpdateBlinds(screen->w, screen->h);
46 void ColorFade::OnPauseState(SDL_Surface *screen) {
51 void ColorFade::OnResize(int width, int height) {
52 slave->Resize(width, height);
53 UpdateBlinds(width, height);
56 void ColorFade::UpdateBlinds(int width, int height) {
57 if (blinds && blinds->w == width && blinds->h == height) return;
59 SDL_FreeSurface(blinds);
61 blinds = SDL_CreateRGBSurface(0, width, height, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000);
62 SDL_FillRect(blinds, 0, color);
65 Uint8 ColorFade::GetAlpha() const {
68 } else if (!fadeDone) {
69 return (in ? timer.Remaining() : timer.Elapsed()) * 255 / duration;
76 void ColorFade::HandleEvents(const Input &input) {
78 slave->HandleEvents(input);
80 if (timer.Finished()) {
83 timer = GraphicsTimers().StartCountdown(duration);
84 } else if (!fadeDone) {
87 timer = GraphicsTimers().StartCountdown(leadOut);
104 void ColorFade::UpdateWorld(Uint32 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);