Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

DemoMode.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  */
00009 #include "DemoMode.h"
00010 
00011 #include "Picture.h"
00012 #include "StateManager.h"
00013 #include "DemoInput.h"
00014 
00015 #include "ScriptState.h"
00016 #include "SubTitleAgent.h"
00017 #include "OptionAgent.h"
00018 #include "VideoAgent.h"
00019 #include "SurfaceTool.h"
00020 
00021 #include "demo-script.h"
00022 
00023 //-----------------------------------------------------------------
00024 DemoMode::DemoMode(const Path &demoscript)
00025     : m_demoscript(demoscript)
00026 {
00027     m_oldLimitY = 0;
00028     m_display = NULL;
00029     m_surfaceBuffer = NULL;
00030     m_script->registerFunc("demo_display", script_demo_display);
00031     takeHandler(new DemoInput(this));
00032     registerDrawable(this);
00033     registerDrawable(SubTitleAgent::agent());
00034 }
00035 //-----------------------------------------------------------------
00036 DemoMode::~DemoMode()
00037 {
00038     own_cleanState();
00039 }
00040 //-----------------------------------------------------------------
00041 /**
00042  * Run demo.
00043  */
00044     void
00045 DemoMode::own_initState()
00046 {
00047     m_oldLimitY = SubTitleAgent::agent()->getLimitY();
00048     m_script->doFile(m_demoscript);
00049 }
00050 //-----------------------------------------------------------------
00051 /**
00052  * Execute next demo command.
00053  */
00054 void
00055 DemoMode::own_updateState()
00056 {
00057     if (satisfyPlan()) {
00058         quitState();
00059     }
00060 }
00061 //-----------------------------------------------------------------
00062 void
00063 DemoMode::own_cleanState()
00064 {
00065     //NOTE: loaded dialogs are released by ~Planner()
00066     if (m_surfaceBuffer) {
00067         SDL_FreeSurface(m_surfaceBuffer);
00068         m_surfaceBuffer = NULL;
00069     }
00070     if (m_display) {
00071         delete m_display;
00072         m_display = NULL;
00073     }
00074 
00075     SubTitleAgent::agent()->setLimitY(m_oldLimitY);
00076     killPlan();
00077 }
00078 
00079 //-----------------------------------------------------------------
00080 /**
00081  * Store picture to draw it.
00082  * NOTE: limitY for long subtitles are prepared when display is set
00083  * before planning start
00084  */
00085     bool
00086 DemoMode::action_display(Picture *picture)
00087 {
00088     if (m_display) {
00089         delete m_display;
00090     }
00091     m_display = picture;
00092 
00093     if (NULL == m_surfaceBuffer) {
00094         OptionAgent *options = OptionAgent::agent();
00095         options->setParam("screen_width", m_display->getW());
00096         options->setParam("screen_height", m_display->getH());
00097         VideoAgent::agent()->initVideoMode();
00098 
00099         SubTitleAgent::agent()->setLimitY(2 * m_display->getH());
00100     }
00101     return true;
00102 }
00103 //-----------------------------------------------------------------
00104 void
00105 DemoMode::drawOn(SDL_Surface *screen)
00106 {
00107     if (NULL == m_surfaceBuffer) {
00108         m_surfaceBuffer = SurfaceTool::createEmpty(screen);
00109     }
00110 
00111     if (m_display) {
00112         m_display->drawOn(m_surfaceBuffer);
00113     }
00114     SDL_BlitSurface(m_surfaceBuffer, NULL, screen, NULL);
00115 }
00116 
00117 
00118 

Generated on Wed Jun 1 09:54:30 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2