Nokia N97 SDK
Example Applications Guide

SimpleCubeContainer.h

00001 /*
00002  * ==============================================================================
00003  *  Name        : SimpleCubeContainer.h
00004  *  Part of     : OpenGLEx / SimpleCube
00005  *
00006  *  Copyright (c) 2004-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 SIMPLECUBECONTAINER_H
00014 #define SIMPLECUBECONTAINER_H
00015 
00016 // INCLUDES
00017 #include <coecntrl.h>
00018 #include <GLES/egl.h>
00019 #include "SimpleCube.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 CSimpleCube class to do the actual OpenGL ES rendering.
00028  */
00029 class CSimpleCubeContainer : public CCoeControl, MCoeControlObserver
00030     {
00031     public: // Constructors and destructor
00032 
00033         /**
00034          * EPOC default constructor. Initializes the OpenGL ES for rendering to the window surface.
00035          * @param aRect Screen rectangle for container.
00036          */
00037         void ConstructL(const TRect& aRect, CAknAppUi* aAppUi);
00038 
00039         /**
00040          * Destructor. Destroys the CPeriodic, CSimpleCube and uninitializes OpenGL ES.
00041          */
00042         virtual ~CSimpleCubeContainer();
00043 
00044     public: // New functions
00045 
00046         /**
00047          * Callback function for the CPeriodic. Calculates the current frame, keeps the background
00048          * light from turning off and orders the CSimpleCube to do the rendering for each frame.
00049          *@param aInstance Pointer to this instance of CSimpleCubeContainer.
00050          */
00051         static TInt DrawCallBack( TAny* aInstance );
00052 
00053     private: // Functions from base classes
00054 
00055         /**
00056          * Method from CoeControl that gets called when the display size changes.
00057          * If OpenGL has been initialized, notifies the renderer class that the screen
00058          * size has changed.
00059          */
00060         void SizeChanged();
00061 
00062         /**
00063          * Handles a change to the control's resources. This method
00064          * reacts to the KEikDynamicLayoutVariantSwitch event (that notifies of
00065          * screen size change) by calling the SetExtentToWholeScreen() again so that
00066          * this control fills the new screen size. This will then trigger a call to the
00067          * SizeChanged() method.
00068          * @param aType Message UID value, only KEikDynamicLayoutVariantSwitch is handled by this method.
00069          */
00070         void HandleResourceChange(TInt aType);
00071 
00072         /**
00073          * Method from CoeControl. Does nothing in this implementation.
00074          */
00075         TInt CountComponentControls() const;
00076 
00077         /**
00078          * Method from CCoeControl. Does nothing in this implementation.
00079          */
00080         CCoeControl* ComponentControl(TInt aIndex) const;
00081 
00082         /**
00083          * Method from CCoeControl. Does nothing in this implementation.
00084          * All rendering is done in the DrawCallBack() method.
00085          */
00086         void Draw(const TRect& aRect) const;
00087 
00088         /**
00089          * Method from MCoeControlObserver that handles an event from the observed control.
00090          * Does nothing in this implementation.
00091                  * @param aControl   Control changing its state.
00092                  * @param aEventType Type of the control event.
00093          */
00094         void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType);
00095 
00096     private: //data
00097 
00098         /** Display where the OpenGL ES window surface resides. */
00099         EGLDisplay  iEglDisplay;
00100 
00101         /** Window surface where the OpenGL ES rendering is blitted to. */
00102         EGLSurface  iEglSurface;
00103 
00104         /** OpenGL ES rendering context. */
00105         EGLContext  iEglContext;
00106 
00107         /** Active object that is the timing source for the animation. */
00108         CPeriodic*  iPeriodic;
00109 
00110         /**
00111          * Flag that indicates if OpenGL ES has been initialized or not.
00112          * Used to check if SizeChanged() can react to incoming notifications.
00113          */
00114         TBool iOpenGlInitialized;
00115 
00116         /** Frame counter variable, used in the animation. */
00117         TInt iFrame;
00118 
00119 /** Application UI class for querying the client rectangle size. */ 
00120         CAknAppUi* iAppUi;
00121 
00122     public:  //data
00123 
00124         /** Used in DrawCallBack() method to do the actual OpenGL ES rendering.  */
00125         CSimpleCube* iSimpleCube;
00126     };
00127 
00128 #endif
00129 
00130 // End of File

© Nokia 2009

Back to top