|
Nokia N97 SDK Example Applications Guide |
#include <Slideshow.h>
Inheritance diagram for CSlideshow:

Definition at line 32 of file Slideshow.h.
Public Types |
|
| enum | { ELoadingTextures, ERunning } |
| enum | TDirection { ENext, EPrevious } |
Public Member Functions |
|
| virtual | ~CSlideshow () |
| void | AppInitL (void) |
| void | AppExit (void) |
| void | AppCycle (TInt aFrame, TReal aTimeSecs, TReal aDeltaTimeSecs) |
| void | ShowNextPicture (void) |
| void | ShowPreviousPicture (void) |
| void | OnEnterStateL (TInt aState) |
| void | OnStartLoadingTexturesL () |
| void | OnEndLoadingTexturesL () |
| void | SetScreenSize (TUint aWidth, TUint aHeight) |
Static Public Member Functions |
|
| static CSlideshow * | NewL (TUint aWidth, TUint aHeight) |
Protected Member Functions |
|
| CSlideshow (TUint aWidth, TUint aHeight) | |
| void | ConstructL (void) |
Private Member Functions |
|
| MTransitionRenderer * | CreateTransitionRenderer (TDirection dir) |
Private Attributes |
|
| CTextureManager * | iTextureManager |
| TUint | iScreenWidth |
| TUint | iScreenHeight |
| TTexture | iPictures [5] |
| TUint | iPictureCount |
| TUint | iCurrentPicture |
| TUint | iNextPicture |
| TInt | iRequestedPictureDelta |
| TTexture | iMasks [2] |
| CStaticRenderer | iStaticRenderer |
| MTransitionRenderer * | iTransitionRenderer |
| TReal | iTransitionTime |
|
|
Application states: ELoadingTextures - indicates that the app. is loading textures. ERunning - indicates that the app. is running. Definition at line 132 of file Slideshow.h.
|
|
|
The ways one can navigate a slideshow. Definition at line 141 of file Slideshow.h.
|
|
|
Destructor. Does nothing. Definition at line 72 of file Slideshow.cpp.
|
|
||||||||||||
|
Standard constructor that must never Leave. Stores the given screen width and height.
Definition at line 46 of file Slideshow.cpp. References iScreenHeight, and iScreenWidth. Referenced by NewL(). 00047 : CFiniteStateMachine(), 00048 iCurrentPicture(0), 00049 iNextPicture(0), 00050 iRequestedPictureDelta(0), 00051 iTransitionRenderer(0), 00052 iTransitionTime(0) 00053 { 00054 iScreenWidth = aWidth; 00055 iScreenHeight = aHeight; 00056 }
|
|
||||||||||||
|
Factory method for creating a new CSlideshow object. Calls the hidden constructors. Definition at line 28 of file Slideshow.cpp. References CSlideshow(). 00029 { 00030 // Symbian 2-phase constructor. Calls both the default 00031 // C++ constructor and Symbian ConstructL methods 00032 CSlideshow* self = new (ELeave) CSlideshow( aWidth, aHeight ); 00033 CleanupStack::PushL( self ); 00034 self->ConstructL(); 00035 CleanupStack::Pop(); 00036 00037 return self; 00038 }
|
|
|
Second phase constructor that can call methods that may leave. Does nothing. Definition at line 63 of file Slideshow.cpp.
|
|
|
Initializes OpenGL ES, sets the vertex and color arrays and pointers. Also selects the shading mode and creates the CTextureManager instance and starts loading of required textures. Definition at line 81 of file Slideshow.cpp. References iMasks, iPictureCount, iPictures, iScreenHeight, iScreenWidth, iTextureManager, and SetScreenSize(). 00082 { 00083 // Construct a texture manager that uses the application's private 00084 // directory as the source location for all textures. 00085 iTextureManager = CTextureManager::NewL ( iScreenWidth, iScreenHeight, 0, 0, 0, 0, 0, 00086 this ); 00087 // Initialize viewport and projection. 00088 SetScreenSize( iScreenWidth, iScreenHeight ); 00089 00090 // Set the screen background color. 00091 glClearColor( 0.f, 0.f, 0.f, 1.f ); 00092 00093 // Enable back face culling. 00094 glDisable( GL_CULL_FACE ); 00095 glDisable( GL_DEPTH_TEST ); 00096 glEnable( GL_TEXTURE_2D ); 00097 00098 // Disable lighting 00099 glDisable( GL_LIGHTING ); 00100 00101 // Initialize viewport and projection. 00102 glViewport( 0, 0, iScreenWidth, iScreenHeight ); 00103 glMatrixMode( GL_PROJECTION ); 00104 00105 // Set best perspective correction 00106 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); 00107 00108 // Enable vertex arrays. 00109 glEnableClientState( GL_VERTEX_ARRAY ); 00110 00111 // Enable texture arrays. 00112 glEnableClientState( GL_TEXTURE_COORD_ARRAY ); 00113 00114 00115 // Push the textures into the loading queue 00116 iTextureManager->RequestToLoad( _L("los_cristianos.jpg"), &iPictures[0] ); 00117 iTextureManager->RequestToLoad( _L("sky.jpg"), &iPictures[1] ); 00118 iTextureManager->RequestToLoad( _L("sugar_loaf.jpg"), &iPictures[2] ); 00119 iTextureManager->RequestToLoad( _L("parati.jpg"), &iPictures[3] ); 00120 iTextureManager->RequestToLoad( _L("banana_trees.jpg"), &iPictures[4] ); 00121 iPictureCount = sizeof(iPictures) / sizeof(iPictures[0]); 00122 00123 // Generate some masks 00124 glGenTextures( 1, &iMasks[0].iID ); 00125 glGenTextures( 1, &iMasks[1].iID ); 00126 00127 TUint8* maskData = new TUint8[64 * 64 * 4]; 00128 TUint8* maskDataPtr = maskData; 00129 TInt x, y; 00130 00131 // The first mask has a band of colors in the middle 00132 for (y = 0; y < 64; y++) 00133 { 00134 for (x = 0; x < 64; x++) 00135 { 00136 *maskDataPtr++ = Min(Max(Abs(24 - y) * 16, 0), 255); 00137 *maskDataPtr++ = Min(Max(Abs(28 - y) * 16, 0), 255); 00138 *maskDataPtr++ = Min(Max(Abs(32 - y) * 16, 0), 255); 00139 *maskDataPtr++ = Min(Max((32 - y) * 16, 0), 255); 00140 } 00141 } 00142 00143 glBindTexture( GL_TEXTURE_2D, iMasks[0].iID ); 00144 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, maskData); 00145 00146 // The second mask has a wavy alpha threshold in the middle 00147 maskDataPtr = maskData; 00148 for (y = 0; y < 64; y++) 00149 { 00150 for (x = 0; x < 64; x++) 00151 { 00152 TReal s; 00153 Math::Sin(s, x / 4.0); 00154 TInt maskFactor = Min(Max((32 - y - s * 6) * 16, 0), 255); 00155 *maskDataPtr++ = 255; 00156 *maskDataPtr++ = 255; 00157 *maskDataPtr++ = 255; 00158 *maskDataPtr++ = maskFactor; 00159 } 00160 } 00161 glBindTexture( GL_TEXTURE_2D, iMasks[1].iID ); 00162 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, maskData); 00163 00164 delete[] maskData; 00165 00166 // Start to load the queued textures 00167 iTextureManager->DoLoadL(); 00168 }
|
|
|
Called upon application exit. Destroys the CTextureManager instance that was created in AppInitL() method. Definition at line 175 of file Slideshow.cpp. References iTextureManager, and iTransitionRenderer. Referenced by CSlideshowContainer::~CSlideshowContainer(). 00176 { 00177 delete iTextureManager; 00178 delete iTransitionRenderer; 00179 }
|
|
||||||||||||||||
|
Renders one frame.
Definition at line 190 of file Slideshow.cpp. References CreateTransitionRenderer(), iCurrentPicture, iNextPicture, iPictureCount, iPictures, iRequestedPictureDelta, iStaticRenderer, iTransitionRenderer, iTransitionTime, MTransitionRenderer::Render(), and CStaticRenderer::Render(). Referenced by CSlideshowContainer::DrawCallBack(). 00193 { 00194 // Make sure the timestep is non-zero, since otherwise the animation wouldn't progress at all. 00195 if (aDeltaTimeSecs < 0.04) 00196 aDeltaTimeSecs = 0.04; 00197 00198 // Stop the transition if it's complete 00199 if (iTransitionRenderer && iTransitionTime <= 0) 00200 { 00201 delete iTransitionRenderer; 00202 iTransitionRenderer = 0; 00203 iCurrentPicture = iNextPicture; 00204 } 00205 00206 // Advance the slideshow if we have been requested to 00207 if (iRequestedPictureDelta && !iTransitionRenderer) 00208 { 00209 iTransitionRenderer = CreateTransitionRenderer((iRequestedPictureDelta > 0) ? ENext : EPrevious); 00210 iTransitionTime = 1.0; 00211 00212 TInt direction = (iRequestedPictureDelta > 0) ? 1 : -1; 00213 iNextPicture = (iCurrentPicture + direction + iPictureCount) % iPictureCount; 00214 iRequestedPictureDelta -= direction; 00215 } 00216 00217 // Render the current picture. If there is no transition going on, enable 00218 // bilinear filtering to improve image quality. 00219 iStaticRenderer.Render(iPictures[iCurrentPicture], iTransitionRenderer == NULL); 00220 00221 // Render the transition and the next picture 00222 if (iTransitionTime > 0 && iTransitionRenderer) 00223 { 00224 iTransitionRenderer->Render(iPictures[iNextPicture], iTransitionTime); 00225 // Accelerate the transition speed if we are many pictures behind 00226 iTransitionTime -= aDeltaTimeSecs * (Abs(iRequestedPictureDelta) + 1); 00227 } 00228 }
|
|
|
Advances the slideshow to the next picture. Definition at line 230 of file Slideshow.cpp. References iRequestedPictureDelta. Referenced by CSlideshowAppUi::HandleKeyEventL(). 00231 { 00232 iRequestedPictureDelta++; 00233 }
|
|
|
Advances the slideshow to the previous picture. Definition at line 235 of file Slideshow.cpp. References iRequestedPictureDelta. Referenced by CSlideshowAppUi::HandleKeyEventL(). 00236 { 00237 iRequestedPictureDelta--; 00238 }
|
|
|
Called when the finite state machine enters a new state. Does nothing in this implementation.
Definition at line 245 of file Slideshow.cpp.
|
|
|
Called when texture manager starts loading the textures. Sets the current state to "loading textures". Definition at line 255 of file Slideshow.cpp.
|
|
|
Called when texture manager has completed texture loading. Changes the current state to "running". Definition at line 265 of file Slideshow.cpp. 00266 { 00267 if ( GetState() == ELoadingTextures ) 00268 { 00269 SetStateL( ERunning ); 00270 } 00271 }
|
|
||||||||||||
|
Notifies that the screen size has dynamically changed during execution of this program. Resets the viewport to this new size and sets this size to the CTextureManager.
Definition at line 278 of file Slideshow.cpp. References iScreenHeight, iScreenWidth, and iTextureManager. Referenced by AppInitL(), and CSlideshowContainer::SizeChanged(). 00279 { 00280 iScreenWidth = aWidth; 00281 iScreenHeight = aHeight; 00282 00283 // Notify the texture manager of screen size change 00284 iTextureManager->SetScreenSize( aWidth, aHeight ); 00285 00286 // Reinitialize viewport and projection. 00287 glViewport( 0, 0, iScreenWidth, iScreenHeight ); 00288 }
|
|
|
Creates a new random transition renderer.
Definition at line 290 of file Slideshow.cpp. References iMasks. Referenced by AppCycle(). 00291 { 00292 // Choose a transition renderer class randomly 00293 switch (Math::Random() % 3) 00294 { 00295 case 0: 00296 { 00297 // Choose a sweep style randomly 00298 const CMaskTransition::TSweepStyle s[] = 00299 { 00300 CMaskTransition::ESweepCurved, 00301 CMaskTransition::ESweepCurved2, 00302 CMaskTransition::ESweepHorizontal, 00303 CMaskTransition::ESweepVertical 00304 }; 00305 return new CMaskTransition(iMasks[Math::Random() % (sizeof(iMasks) / sizeof(iMasks[0]))], 00306 s[Math::Random() % (sizeof(s) / sizeof(s[0]))]); 00307 } 00308 case 1: 00309 if (dir == ENext) 00310 return new CWhiskTransition(CWhiskTransition::ERight); 00311 else 00312 return new CWhiskTransition(CWhiskTransition::ELeft); 00313 case 2: 00314 if (dir == ENext) 00315 return new CCurtainTransition(CCurtainTransition::ERight); 00316 else 00317 return new CCurtainTransition(CCurtainTransition::ELeft); 00318 } 00319 return 0; 00320 }
|
|
|
Texture manager that is used to load the used textures. Definition at line 157 of file Slideshow.h. Referenced by AppExit(), AppInitL(), and SetScreenSize(). |
|
|
Width of the screen Definition at line 159 of file Slideshow.h. Referenced by AppInitL(), CSlideshow(), and SetScreenSize(). |
|
|
Height of the screen Definition at line 161 of file Slideshow.h. Referenced by AppInitL(), CSlideshow(), and SetScreenSize(). |
|
|
Pictures to cycle Definition at line 164 of file Slideshow.h. Referenced by AppCycle(), and AppInitL(). |
|
|
Number of pictures to cycle Definition at line 167 of file Slideshow.h. Referenced by AppCycle(), and AppInitL(). |
|
|
Index of the currently visible picture Definition at line 170 of file Slideshow.h. Referenced by AppCycle(). |
|
|
Index of the picture we are transitioning to Definition at line 173 of file Slideshow.h. Referenced by AppCycle(). |
|
|
Number of pictures to go forward or backward Definition at line 176 of file Slideshow.h. Referenced by AppCycle(), ShowNextPicture(), and ShowPreviousPicture(). |
|
|
Transition masks Definition at line 179 of file Slideshow.h. Referenced by AppInitL(), and CreateTransitionRenderer(). |
|
|
Static picture renderer Definition at line 182 of file Slideshow.h. Referenced by AppCycle(). |
|
|
Transition renderer Definition at line 185 of file Slideshow.h. Referenced by AppCycle(), and AppExit(). |
|
|
Time to transition completion Definition at line 188 of file Slideshow.h. Referenced by AppCycle(). |
|
© Nokia 2009 |