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)
25 , interactive(interactive) {
29 void ColorFade::EnterState(Application &c, SDL_Surface *screen) {
30 timer = GraphicsTimers().StartCountdown(duration);
34 void ColorFade::ExitState(Application &, SDL_Surface *screen) {
36 SDL_FreeSurface(blinds);
41 void ColorFade::ResumeState(Application &ctrl, SDL_Surface *screen) {
42 UpdateBlinds(screen->w, screen->h);
45 void ColorFade::PauseState(Application &ctrl, SDL_Surface *screen) {
50 void ColorFade::Resize(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 {
66 return timer.Remaining() * 255 / duration;
68 return timer.Elapsed() * 255 / duration;
73 void ColorFade::HandleEvents(const Input &input) {
75 slave->HandleEvents(input);
77 if (timer.Finished()) {
83 void ColorFade::UpdateWorld(float deltaT) {
85 slave->UpdateWorld(deltaT);
89 void ColorFade::Render(SDL_Surface *screen) {
90 slave->Render(screen);
91 SDL_SetAlpha(blinds, SDL_SRCALPHA, GetAlpha());
92 SDL_BlitSurface(blinds, 0, screen, 0);