Nokia N97 SDK
Example Applications Guide

BillboardContainer.h

00001 /*
00002  * ==============================================================================
00003  *  Name        : BillboardContainer.h
00004  *  Part of     : OpenGLEx / Billboard
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 BILLBOARDCONTAINER_H
00014 #define BILLBOARDCONTAINER_H
00015 
00016 // INCLUDES
00017 #include <coecntrl.h>
00018 #include <akndef.h>
00019 #include <GLES\egl.h>
00020 #include "billboard.h"
00021 #include "Billboardinput.h"
00022 
00023 #include <aknappui.h>
00024 
00025 // CLASS DECLARATION
00026 
00027 /**
00028  * Container control class that handles the OpenGL ES initialization and deinitializations.
00029  * Also uses the CBillboard class to do the actual OpenGL ES rendering.
00030  */
00031 class CBillboardContainer : public CCoeControl, MCoeControlObserver
00032     {
00033     public: // Constructors and destructor
00034 
00035         /**
00036          * Second phase constructor that can call methods that may leave.
00037          * Initializes the OpenGL ES for rendering to the window surface.
00038          * @param aRect Screen rectangle for container.
00039          */
00040         void ConstructL(const TRect& aRect, CAknAppUi* aAppUi);
00041 
00042         /**
00043          * Destructor. Destroys the CPeriodic, CBillboard and uninitializes OpenGL ES.
00044          */
00045         virtual ~CBillboardContainer();
00046 
00047     public: // New functions
00048 
00049         /**
00050          * Callback function for the CPeriodic. Calculates the current frame, keeps the background
00051          * light from turning off and orders the CBillboard to do the rendering for each frame.
00052          *@param aInstance Pointer to this instance of CBillboardContainer.
00053          */
00054         static TInt DrawCallBack( TAny* aInstance );
00055 
00056         /**
00057          * Returns the current system time.
00058          * @return System time.
00059          */
00060         static TTime GetTimeTick();
00061 
00062     private: // Functions from base classes
00063 
00064         /**
00065          * Handles joystick movements and other key presses.
00066          * @param aKeyEvent Key event.
00067          * @param aType Key event type.
00068          * @return EKeyWasConsumed if the key event was handled or EKeyWasNotConsumed if the key event was not handled.
00069          */
00070                 TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent,TEventCode aType );
00071 
00072         /**
00073          * Method from MCoeControlObserver that handles an event from the observed control.
00074          * Does nothing in this implementation.
00075          * @param aControl   Control changing its state.
00076          * @param aEventType Type of the control event.
00077          */
00078         void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType);
00079 
00080         /**
00081          * Method from CoeControl that gets called when the display size changes.
00082          * If OpenGL has been initialized, notifies the renderer class that the screen
00083          * size has changed.
00084          */
00085         void SizeChanged();
00086 
00087          /**
00088           * Handles a change to the control's resources. This method
00089           * reacts to the KEikDynamicLayoutVariantSwitch event (that notifies of
00090           * screen size change) by calling the SetExtentToWholeScreen() again so that
00091           * this control fills the new screen size. This will then trigger a call to the
00092           * SizeChanged() method.
00093           * @param aType Message UID value, only KEikDynamicLayoutVariantSwitch is handled by this method.
00094           */
00095         void HandleResourceChange(TInt aType);
00096 
00097         /**
00098          * Method from CoeControl. Does nothing in this implementation.
00099          */
00100         TInt CountComponentControls() const;
00101 
00102         /**
00103          * Method from CCoeControl. Does nothing in this implementation.
00104          */
00105         CCoeControl* ComponentControl(TInt aIndex) const;
00106 
00107         /**
00108          * Method from CCoeControl. Does nothing in this implementation.
00109          * All rendering is done in the DrawCallBack() method.
00110          */
00111         void Draw(const TRect& aRect) const;
00112 
00113     private: //data
00114 
00115         /** Display where the OpenGL ES window surface resides. */
00116         EGLDisplay  iEglDisplay;
00117         /** Window surface where the OpenGL ES rendering is blitted to. */
00118         EGLSurface  iEglSurface;
00119         /** OpenGL ES rendering context. */
00120         EGLContext  iEglContext;
00121         /** Active object that is the timing source for the animation. */
00122         CPeriodic*  iPeriodic;
00123         /**
00124          * Flag that indicates if OpenGL ES has been initialized or not.
00125          * Used to check if SizeChanged() can react to incoming notifications.
00126          */
00127         TBool iOpenGlInitialized;
00128 
00129         /** Time (int ticks) when the example started running (rendering frames). */
00130         TUint iStartTimeTicks;
00131         /** Time (in seconds) when the previous frame was rendered. */
00132         GLfloat iLastFrameTimeSecs;
00133         /** Counts the number of frames rendered. */
00134         TUint iFrame;
00135         /** Input handler that maps keycodes to inputs and stores the current state for each key. */
00136         CBillboardInput* iInputHandler;
00137 
00138         /** Application UI class for querying the client rectangle size. */ 
00139         CAknAppUi* iAppUi;
00140 
00141     public:  //data
00142 
00143         /** Used in DrawCallBack() method to do the actual OpenGL ES rendering.  */
00144         CBillboard* iBillboard;
00145     };
00146 
00147 #endif
00148 
00149 // End of File

© Nokia 2009

Back to top