Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members

Presentation.h

Go to the documentation of this file.
00001 /*********************************************************************************
00002  *
00003  * Razor! Engine - A modular C++ presentation engine
00004  *
00005  * $Id$
00006  *
00007  * Copyright (c) 2000 Tilo Christ. All Rights Reserved.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022  *
00023  **********************************************************************************/
00024 
00025 
00026 #ifndef PRESENTATION_H
00027 #define PRESENTATION_H
00028 
00029 #include <PalmOS.h>
00030 #include "Customization.h"
00031 #include "ActionEngineFactory.h"
00032 
00033 #include "ActionEngine.h"
00034 #include "Canvas.h"
00035 #include "HardKeyManager.h"
00036 
00037 
00038 /**
00039  * Presentation controls the flow of a presentation. It is a facade
00040  * that delegates most of the work to other classes.
00041  *
00042  * @see ActionEngine
00043  * @see Canvas
00044  * @see HardKeyManager
00045  */
00046 class Presentation
00047 {
00048     public:
00049 
00050 ///@name Construction / Destruction
00051 //@{
00052     /**
00053      * Construct a new Presentation.
00054      */
00055     Presentation() :
00056         canvas(createCanvas()), actionEngine(createActionEngine()) 
00057     {
00058         HardKeyManager::init();
00059         SoundEngine::init();
00060         
00061         state = presReady;
00062         
00063         // Initialize the actionEngine
00064         actionEngine.restart();
00065 
00066         // Restore saved state
00067 /*      UInt16 prefsSize = 0;
00068         Int16 prefResult = PrefGetAppPreferences(appCreator, 0, NULL, &prefsSize, false);
00069         
00070         if (prefResult != noPreferenceFound)
00071         {
00072             void *stateBuffer = actionEngine.getRestoreStateBuffer();
00073             ErrNonFatalDisplayIf(stateBuffer == NULL, "Restore state buffer == NULL");
00074             prefsSize = actionEngine.getStateBufferSize();
00075             PrefGetAppPreferences(appCreator, 0, stateBuffer, &prefsSize, false);
00076             actionEngine.restoreState(stateBuffer);
00077             actionEngine.releaseRestoreStateBuffer(stateBuffer);
00078         }    */
00079     }
00080 
00081     
00082     /**
00083      * Destroy the Presentation.
00084      */
00085     ~Presentation()
00086     {
00087         // Save state
00088         void *stateBuffer = actionEngine.getSaveStateBuffer();
00089         ErrNonFatalDisplayIf(stateBuffer == NULL, "Save state buffer == NULL");
00090         UInt16 prefsSize = actionEngine.getStateBufferSize();
00091         PrefSetAppPreferences(appCreator, 0, appVersionNum, stateBuffer, prefsSize, false);
00092         actionEngine.releaseSaveStateBuffer(stateBuffer);
00093 
00094         delete &actionEngine; 
00095         delete &canvas;
00096         HardKeyManager::destroy();
00097         SoundEngine::destroy();
00098     }
00099 
00100 //@}
00101 
00102     //********************************************************************************************************
00103     
00104     
00105 /// @name Flow Control & Timing
00106 //@{
00107 
00108     /**
00109      * Begin the presentation.
00110      */
00111     void begin()
00112     {
00113         HardKeyManager::captureHardKeys();
00114 
00115         state = presResuming;
00116         pausedTime = 0;
00117         
00118         // Synchronize the periods to the timer.
00119         nextPeriodTime = TimGetTicks() + max(presPauseLengthBeforeResuming, presAdvanceTimeInterval);
00120 
00121         draw();
00122         show();
00123     }
00124 
00125 
00126     /**
00127      * Has the presentation begun?
00128      */
00129     Boolean hasBegun() const
00130     {
00131         return (state != presReady);
00132     }   
00133     
00134 
00135     /**
00136      * Step to the next period.
00137      */
00138     void nextPeriod()
00139     {
00140         state = presRunning;
00141 
00142         if (appPreventAutoOff)
00143             EvtResetAutoOffTimer();
00144     
00145         // Show display-buffer on screen
00146         show();             
00147 
00148         // Make sure SoundEngine gets invoked on a regular basis
00149         SoundEngine::timeTick();
00150 
00151         // Move objects, etc...
00152         actionEngine.nextPeriod();
00153         nextPeriodTime = TimGetTicks() + presAdvanceTimeInterval;       
00154         
00155         // Render into display-buffer
00156         draw();             
00157 
00158         // Make sure SoundEngine gets invoked on a regular basis
00159         SoundEngine::timeTick();
00160     }
00161 
00162 
00163     /**
00164      * Draw the state of the current period again.
00165      */
00166     void redraw() const
00167     {
00168         draw();
00169         show();
00170     }
00171 
00172     
00173     /**
00174      * Is the presentation currenty paused?
00175      *
00176      * @return true if paused, false if not paused
00177      */
00178     Boolean isPaused() const
00179     {
00180         return (state == presPaused);
00181     }   
00182 
00183 
00184     /**
00185      * Pause the presentation.
00186      */
00187     void pause()
00188     {
00189         state = presPaused;
00190         pausedTime = TimGetTicks();
00191 
00192         HardKeyManager::releaseHardKeys();
00193     }
00194 
00195 
00196     /**
00197      * Resume a paused presentation.
00198      */
00199     void resume()
00200     {
00201         HardKeyManager::captureHardKeys();
00202 
00203         if (state == presPaused)
00204         {
00205             nextPeriodTime += (TimGetTicks() - pausedTime);
00206 
00207             state = presResuming;
00208         }
00209         else
00210         {
00211             nextPeriodTime = TimGetTicks() + presAdvanceTimeInterval;
00212         }                   
00213     }
00214     
00215 
00216     /**
00217      * Determine the amount of time until the next period begins.
00218      * The result can be passed directly into a call to EvtGetEvent().
00219      *
00220      * @return the amount of time in ticks (1/100 secs) or evtWaitForever
00221      */
00222     Int32 getTimeUntilNextPeriod() const
00223     {
00224         if (state == presPaused)
00225         {
00226             return evtWaitForever;
00227         }
00228         else
00229         {   
00230             Int32 timeRemaining = (Int32)(nextPeriodTime - TimGetTicks());
00231             if (timeRemaining < 0)
00232                 timeRemaining = 0;
00233 
00234             return timeRemaining;   
00235         }
00236     }
00237 //@}
00238 
00239 
00240 /// @name Input management
00241 //@{
00242     /**
00243      * Receive an input event. The event will be forwarded to
00244      * the ActionEngine which has to decide whether it wants to
00245      * react to it.
00246      */
00247     void receiveEvent(const EventType* evtPtr)
00248     {
00249         actionEngine.receiveEvent(evtPtr);
00250     }
00251     
00252 //@}
00253 
00254 
00255     //********************************************************************************************************
00256     private:
00257 
00258 
00259 /// @name Multimedia output
00260 //@{
00261     /**
00262      * Draw the current state of the presentation. Drawing might occur into
00263      * an invisible buffer.
00264      */
00265     void draw() const
00266     {       
00267         canvas.beginDraw(actionEngine.getWinLockMode());
00268 
00269         RectangleType bounds;
00270         bounds.topLeft.x = 0;
00271         bounds.topLeft.y = 0;
00272         bounds.extent.x = 0;
00273         bounds.extent.y = 0;
00274         
00275         actionEngine.draw(&bounds);
00276         canvas.endDraw(&bounds);
00277     }
00278     
00279     
00280     /**
00281      * Show the result of the last invocation of draw(). 
00282      */
00283     void show() const
00284     {
00285         canvas.show();
00286     }
00287 //@}
00288 
00289 
00290 
00291     //********************************************************************************************************
00292         
00293     // The drawing canvas   
00294     Canvas& canvas;
00295 
00296     // The ActionEngine
00297     ActionEngine& actionEngine;
00298 
00299     // Current state of the presentation
00300     enum 
00301     {
00302         presReady,              ///<The presentation is ready, but has not begun yet.
00303         presResuming,           ///<Don't change the current state. Wait a little before setting presentation in motion.
00304         presRunning,            ///<Advance and draw the current state
00305         presPaused              ///<Presentation paused. Don't change the current state.
00306     } state;
00307 
00308 
00309     UInt32                  nextPeriodTime;     // Time when next period occurs
00310     UInt32                  pausedTime;         // When did the pause start?
00311 };
00312 
00313 
00314 #endif

Razor! Engine Developer's Guide. Copyright © by Tilo Christ. All Rights Reserved. Last updated: 4 Nov 2000