Nokia N97 SDK
Example Applications Guide

Particlescontainer.h

00001 /*
00002  * ==============================================================================
00003  *  Name        : Particlescontainer.h
00004  *  Part of     : OpenGLEx / Particles
00005  *
00006  *  Copyright (c) 2005-2006 Nokia Corporation.
00007  *  This material, including documentation and any related
00008  *  computer programs, is protected by copyright controlled by
00009  *  Nokia Corporation.
00010  * ==============================================================================
00011  */
00012 
00013 #ifndef PARTICLESCONTAINER_H
00014 #define PARTICLESCONTAINER_H
00015 
00016 // INCLUDES
00017 #include <coecntrl.h>
00018 #include <GLES\egl.h>
00019 #include "particles.h"
00020 #include <akndef.h>
00021 #include <aknappui.h> 
00022 
00023 // CLASS DECLARATION
00024 
00025 /**
00026  * Container control class that handles the OpenGL ES initialization and deinitializations.
00027  * Also uses the CParticles class to do the actual OpenGL ES rendering.
00028  */
00029 class CParticlesContainer : public CCoeControl, MCoeControlObserver
00030     {
00031     public: // Constructors and destructor
00032 
00033         /**
00034          * Second phase constructor that can call methods that may leave.
00035          * Initializes the OpenGL ES for rendering to the window surface.
00036          * @param aRect Screen rectangle for container.
00037          */
00038         void ConstructL(const TRect& aRect, CAknAppUi* aAppUi);
00039 
00040         /**
00041          * Destructor. Destroys the CPeriodic, CParticles and uninitializes OpenGL ES.
00042          */
00043         virtual ~CParticlesContainer();
00044 
00045     public: // New functions
00046 
00047         /**
00048          * Callback function for the CPeriodic. Calculates the current frame, keeps the background
00049          * light from turning off and orders the CParticles to do the rendering for each frame.
00050          *@param aInstance Pointer to this instance of CParticlesContainer.
00051          */
00052         static TInt DrawCallBack( TAny* aInstance );
00053 
00054         /**
00055          * Returns the current system time.
00056          * @return System time.
00057          */
00058         static TTime GetTimeTick();
00059 
00060     private: // Functions from base classes
00061 
00062         /**
00063          * Method from CoeControl that gets called when the display size changes.
00064          * If OpenGL has been initialized, notifies the renderer class that the screen
00065          * size has changed.
00066          */
00067         void SizeChanged();
00068 
00069          /**
00070           * Handles a change to the control's resources. This method
00071           * reacts to the KEikDynamicLayoutVariantSwitch event (that notifies of
00072           * screen size change) by calling the SetExtentToWholeScreen() again so that
00073           * this control fills the new screen size. This will then trigger a call to the
00074           * SizeChanged() method.
00075           * @param aType Message UID value, only KEikDynamicLayoutVariantSwitch is handled by this method.
00076           */
00077         void HandleResourceChange(TInt aType);
00078 
00079         /**
00080          * Method from CoeControl. Does nothing in this implementation.
00081          */
00082         TInt CountComponentControls() const;
00083 
00084         /**
00085          * Method from CCoeControl. Does nothing in this implementation.
00086          */
00087         CCoeControl* ComponentControl(TInt aIndex) const;
00088 
00089         /**
00090          * Method from CCoeControl. Does nothing in this implementation.
00091          * All rendering is done in the DrawCallBack() method.
00092          */
00093         void Draw(const TRect& aRect) const;
00094 
00095         /**
00096          * Method from MCoeControlObserver that handles an event from the observed control.
00097          * Does nothing in this implementation.
00098          * @param aControl   Control changing its state.
00099          * @param aEventType Type of the control event.
00100          */
00101         void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType);
00102 
00103     private: //data
00104 
00105         /** Display where the OpenGL ES window surface resides. */
00106         EGLDisplay  iEglDisplay;
00107         /** Window surface where the OpenGL ES rendering is blitted to. */
00108         EGLSurface  iEglSurface;
00109         /** OpenGL ES rendering context. */
00110         EGLContext  iEglContext;
00111         /** Active object that is the timing source for the animation. */
00112         CPeriodic*  iPeriodic;
00113         /**
00114          * Flag that indicates if OpenGL ES has been initialized or not.
00115          * Used to check if SizeChanged() can react to incoming notifications.
00116          */
00117         TBool iOpenGlInitialized;
00118 
00119         /** Time when the example started running (rendering frames). */
00120         TUint32 iStartTimeTicks;
00121         /** Time when the previous frame was rendered. */
00122         TUint32 iLastFrameTimeSecs;
00123         /** Current average seconds per frame. Used to interpolated during frames when the internal clock hasn't updated. */
00124         TReal iSecondsPerFrame;
00125         /** Counts the number of frames rendered. */
00126         TInt iFrame;
00127 
00128 /** Application UI class for querying the client rectangle size. */ 
00129         CAknAppUi* iAppUi;
00130 
00131     public:  //data
00132 
00133         /** Used in DrawCallBack() method to do the actual OpenGL ES rendering.  */
00134         CParticles* iParticles;
00135     };
00136 
00137 #endif
00138 
00139 // End of File

© Nokia 2009

Back to top