CPP_SRCS += \
../src/graphics/Animation.cpp \
../src/graphics/Camera.cpp \
+../src/graphics/ColorFade.cpp \
../src/graphics/ComplexAnimation.cpp \
../src/graphics/Font.cpp \
../src/graphics/Frame.cpp \
OBJS += \
./src/graphics/Animation.o \
./src/graphics/Camera.o \
+./src/graphics/ColorFade.o \
./src/graphics/ComplexAnimation.o \
./src/graphics/Font.o \
./src/graphics/Frame.o \
CPP_DEPS += \
./src/graphics/Animation.d \
./src/graphics/Camera.d \
+./src/graphics/ColorFade.d \
./src/graphics/ComplexAnimation.d \
./src/graphics/Font.d \
./src/graphics/Frame.d \
CPP_SRCS += \
../src/graphics/Animation.cpp \
../src/graphics/Camera.cpp \
+../src/graphics/ColorFade.cpp \
../src/graphics/ComplexAnimation.cpp \
../src/graphics/Font.cpp \
../src/graphics/Frame.cpp \
OBJS += \
./src/graphics/Animation.o \
./src/graphics/Camera.o \
+./src/graphics/ColorFade.o \
./src/graphics/ComplexAnimation.o \
./src/graphics/Font.o \
./src/graphics/Frame.o \
CPP_DEPS += \
./src/graphics/Animation.d \
./src/graphics/Camera.d \
+./src/graphics/ColorFade.d \
./src/graphics/ComplexAnimation.d \
./src/graphics/Font.d \
./src/graphics/Frame.d \
--- /dev/null
+/*
+ * ColorFade.cpp
+ *
+ * Created on: Oct 7, 2012
+ * Author: holy
+ */
+
+#include "ColorFade.h"
+
+#include "../app/Application.h"
+
+using app::Application;
+using app::State;
+using app::Input;
+
+namespace graphics {
+
+ColorFade::ColorFade(State *slave, Uint32 color, int duration, bool in, bool interactive)
+: ctrl(0)
+, slave(slave)
+, blinds(0)
+, color(color)
+, duration(duration)
+, in(in)
+, interactive(interactive) {
+
+}
+
+void ColorFade::EnterState(Application &c, SDL_Surface *screen) {
+ timer = GraphicsTimers().StartCountdown(duration);
+ ctrl = &c;
+}
+
+void ColorFade::ExitState(Application &, SDL_Surface *screen) {
+ if (blinds) {
+ SDL_FreeSurface(blinds);
+ blinds = 0;
+ }
+}
+
+void ColorFade::ResumeState(Application &ctrl, SDL_Surface *screen) {
+ UpdateBlinds(screen->w, screen->h);
+}
+
+void ColorFade::PauseState(Application &ctrl, SDL_Surface *screen) {
+
+}
+
+
+void ColorFade::Resize(int width, int height) {
+ slave->Resize(width, height);
+ UpdateBlinds(width, height);
+}
+
+void ColorFade::UpdateBlinds(int width, int height) {
+ if (blinds && blinds->w == width && blinds->h == height) return;
+ if (blinds) {
+ SDL_FreeSurface(blinds);
+ }
+ blinds = SDL_CreateRGBSurface(0, width, height, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000);
+ SDL_FillRect(blinds, 0, color);
+}
+
+Uint8 ColorFade::GetAlpha() const {
+ if (in) {
+ return timer.Remaining() * 255 / duration;
+ } else {
+ return timer.Elapsed() * 255 / duration;
+ }
+}
+
+
+void ColorFade::HandleEvents(const Input &input) {
+ if (interactive) {
+ slave->HandleEvents(input);
+ }
+ if (timer.Finished()) {
+ ctrl->PopState();
+ }
+}
+
+
+void ColorFade::UpdateWorld(float deltaT) {
+ if (interactive) {
+ slave->UpdateWorld(deltaT);
+ }
+}
+
+void ColorFade::Render(SDL_Surface *screen) {
+ slave->Render(screen);
+ SDL_SetAlpha(blinds, SDL_SRCALPHA, GetAlpha());
+ SDL_BlitSurface(blinds, 0, screen, 0);
+}
+
+}
--- /dev/null
+/*
+ * ColorFade.h
+ *
+ * Created on: Oct 7, 2012
+ * Author: holy
+ */
+
+#ifndef GRAPHICS_COLORFADE_H_
+#define GRAPHICS_COLORFADE_H_
+
+#include "../app/State.h"
+#include "../app/Timer.h"
+
+#include <SDL.h>
+
+namespace graphics {
+
+class ColorFade
+: public app::State {
+
+public:
+ ColorFade(app::State *slave, Uint32 color, int duration, bool in = false, bool interactive = false);
+ virtual ~ColorFade() { }
+
+public:
+ virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
+ virtual void ExitState(app::Application &ctrl, SDL_Surface *screen);
+ virtual void ResumeState(app::Application &ctrl, SDL_Surface *screen);
+ virtual void PauseState(app::Application &ctrl, SDL_Surface *screen);
+
+ virtual void Resize(int width, int height);
+
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+private:
+ void UpdateBlinds(int width, int height);
+ Uint8 GetAlpha() const;
+
+private:
+ app::Timer<Uint32> timer;
+ app::Application *ctrl;
+ app::State *slave;
+ SDL_Surface *blinds;
+ Uint32 color;
+ int duration;
+ bool in;
+ bool interactive;
+
+};
+
+}
+
+#endif /* GRAPHICS_COLORFADE_H_ */