| 1 |
/* |
| 2 |
* Copyright (C) 2004 Ivo Danihelka ([email protected]) |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; either version 2 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
*/ |
| 9 |
#include "DemoMode.h" |
| 10 |
|
| 11 |
#include "Picture.h" |
| 12 |
#include "StateManager.h" |
| 13 |
#include "DemoInput.h" |
| 14 |
|
| 15 |
#include "ScriptState.h" |
| 16 |
#include "SubTitleAgent.h" |
| 17 |
#include "OptionAgent.h" |
| 18 |
#include "VideoAgent.h" |
| 19 |
#include "SurfaceTool.h" |
| 20 |
|
| 21 |
#include "demo-script.h" |
| 22 |
|
| 23 |
//----------------------------------------------------------------- |
| 24 |
DemoMode::DemoMode(const Path &demoscript) |
| 25 |
: m_demoscript(demoscript) |
| 26 |
{ |
| 27 |
m_oldLimitY = 0; |
| 28 |
m_display = NULL; |
| 29 |
m_surfaceBuffer = NULL; |
| 30 |
m_script->registerFunc("demo_display", script_demo_display); |
| 31 |
takeHandler(new DemoInput(this)); |
| 32 |
registerDrawable(this); |
| 33 |
registerDrawable(SubTitleAgent::agent()); |
| 34 |
} |
| 35 |
//----------------------------------------------------------------- |
| 36 |
DemoMode::~DemoMode() |
| 37 |
{ |
| 38 |
own_cleanState(); |
| 39 |
} |
| 40 |
//----------------------------------------------------------------- |
| 41 |
/** |
| 42 |
* Run demo. |
| 43 |
*/ |
| 44 |
void |
| 45 |
DemoMode::own_initState() |
| 46 |
{ |
| 47 |
m_oldLimitY = SubTitleAgent::agent()->getLimitY(); |
| 48 |
m_script->doFile(m_demoscript); |
| 49 |
} |
| 50 |
//----------------------------------------------------------------- |
| 51 |
/** |
| 52 |
* Execute next demo command. |
| 53 |
*/ |
| 54 |
void |
| 55 |
DemoMode::own_updateState() |
| 56 |
{ |
| 57 |
if (satisfyPlan()) { |
| 58 |
quitState(); |
| 59 |
} |
| 60 |
} |
| 61 |
//----------------------------------------------------------------- |
| 62 |
void |
| 63 |
DemoMode::own_cleanState() |
| 64 |
{ |
| 65 |
//NOTE: loaded dialogs are released by ~Planner() |
| 66 |
if (m_surfaceBuffer) { |
| 67 |
SDL_FreeSurface(m_surfaceBuffer); |
| 68 |
m_surfaceBuffer = NULL; |
| 69 |
} |
| 70 |
if (m_display) { |
| 71 |
delete m_display; |
| 72 |
m_display = NULL; |
| 73 |
} |
| 74 |
|
| 75 |
SubTitleAgent::agent()->setLimitY(m_oldLimitY); |
| 76 |
killPlan(); |
| 77 |
} |
| 78 |
|
| 79 |
//----------------------------------------------------------------- |
| 80 |
/** |
| 81 |
* Store picture to draw it. |
| 82 |
* NOTE: limitY for long subtitles are prepared when display is set |
| 83 |
* before planning start |
| 84 |
*/ |
| 85 |
bool |
| 86 |
DemoMode::action_display(Picture *picture) |
| 87 |
{ |
| 88 |
if (m_display) { |
| 89 |
delete m_display; |
| 90 |
} |
| 91 |
m_display = picture; |
| 92 |
|
| 93 |
if (NULL == m_surfaceBuffer) { |
| 94 |
OptionAgent *options = OptionAgent::agent(); |
| 95 |
options->setParam("screen_width", m_display->getW()); |
| 96 |
options->setParam("screen_height", m_display->getH()); |
| 97 |
VideoAgent::agent()->initVideoMode(); |
| 98 |
|
| 99 |
SubTitleAgent::agent()->setLimitY(2 * m_display->getH()); |
| 100 |
} |
| 101 |
return true; |
| 102 |
} |
| 103 |
//----------------------------------------------------------------- |
| 104 |
void |
| 105 |
DemoMode::drawOn(SDL_Surface *screen) |
| 106 |
{ |
| 107 |
if (NULL == m_surfaceBuffer) { |
| 108 |
m_surfaceBuffer = SurfaceTool::createEmpty(screen); |
| 109 |
} |
| 110 |
|
| 111 |
if (m_display) { |
| 112 |
m_display->drawOn(m_surfaceBuffer); |
| 113 |
} |
| 114 |
SDL_BlitSurface(m_surfaceBuffer, NULL, screen, NULL); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|