1 #include "DefeatState.h"
4 #include "../BattleState.h"
5 #include "../Resources.h"
6 #include "../../app/Application.h"
7 #include "../../app/Input.h"
8 #include "../../math/Vector.h"
9 #include "../../graphics/ColorFade.h"
10 #include "../../graphics/Font.h"
11 #include "../../graphics/Frame.h"
12 #include "../../sdl/Desaturate.h"
14 using app::Application;
16 using graphics::ColorFade;
18 using graphics::Frame;
24 DefeatState::DefeatState(
35 void DefeatState::OnEnterState(SDL_Surface *screen) {
36 timer = GraphicsTimers().StartCountdown(1500);
37 format = screen->format;
38 OnResize(screen->w, screen->h);
41 void DefeatState::OnExitState(SDL_Surface *screen) {
43 SDL_FreeSurface(cache);
48 void DefeatState::OnResumeState(SDL_Surface *screen) {
52 void DefeatState::OnPauseState(SDL_Surface *screen) {
57 void DefeatState::OnResize(int width, int height) {
58 const Resources &res = parent->Res();
59 const Frame &frame = *res.titleFrame;
60 const Font &font = *res.titleFont;
62 framePosition = parent->ScreenOffset();
63 frameSize = Vector<int> (
65 frame.BorderHeight() * 2 + font.CharHeight());
67 textPosition = Vector<int>(
68 (parent->Width() - strlen(res.defeatText) * font.CharWidth()) / 2,
69 frame.BorderHeight());
71 parent->Resize(width, height);
73 SDL_FreeSurface(cache);
75 cache = SDL_CreateRGBSurface(0, width, height, format->BitsPerPixel,
76 format->Rmask, format->Gmask, format->Bmask, format->Amask);
77 parent->Render(cache);
78 parent->RenderHeroes(cache);
79 RenderTitleBar(cache);
83 void DefeatState::HandleEvents(const Input &input) {
84 if (timer.Finished()) {
90 void DefeatState::UpdateWorld(Uint32 deltaT) {
94 void DefeatState::Render(SDL_Surface *screen) {
95 if (screen->format->palette
96 || cache->format->palette) {
97 // I refuse to desaturate an indexed color urface
98 SDL_BlitSurface(cache, 0, screen, 0);
102 sdl::Desaturate(cache, screen, timer.Remaining() * 255 / 1500);
105 void DefeatState::RenderTitleBar(SDL_Surface *screen) {
106 const Resources &res = parent->Res();
107 res.titleFrame->Draw(screen, framePosition, frameSize.X(), frameSize.Y());
108 res.titleFont->DrawString(res.defeatText, screen, textPosition);