uiacceltk/hitchcock/coretoolkit/src/huiskinanimationtexture.cpp
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Texture class to support Legacy theme animation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <uiacceltk/HuiEnv.h>
       
    20 #include <uiacceltk/huiskinanimationtexture.h>
       
    21 #include <uiacceltk/HuiStatic.h> 
       
    22 #include <uiacceltk/HuiTextureIf.h>
       
    23 #include <uiacceltk/HuiThemeManager.h>
       
    24 
       
    25 #include <AknsItemData.h>
       
    26 #include <AknsUtils.h>
       
    27 #include <AknsItemDef.h>
       
    28 
       
    29 
       
    30 NONSHARABLE_CLASS(CHuiSkinBitmapProvider) : public CBase, public MHuiBitmapProvider
       
    31 	{
       
    32 public:
       
    33 	CHuiSkinBitmapProvider()
       
    34 	    {}
       
    35 	// from MHuiBitmapProvider
       
    36 	void ProvideBitmapL(TInt, CFbsBitmap*&, CFbsBitmap*&)
       
    37 	    {
       
    38 	    User::Leave(KErrNotSupported);
       
    39 	    }
       
    40 							 
       
    41     void SetSize(TSize)
       
    42         {
       
    43         }
       
    44     
       
    45     TInt NumberOfImages()	// Number of images in anim.
       
    46         {
       
    47         return 0;    
       
    48         }
       
    49 	
       
    50 	// Load bitmap data based on Item ID
       
    51 	TBool LoadBitmapDataL(const TAknsItemID& )
       
    52 	    {
       
    53 	    return EFalse;
       
    54 	    }
       
    55 		
       
    56 	// Frame interval of current animation frame
       
    57 	TInt FrameInterval()
       
    58 	    {
       
    59 	    return -1;
       
    60 	    }
       
    61  
       
    62     /*	The animation can be played in any of the ways described below. */
       
    63 	enum EHuiPlayMode
       
    64 		{
       
    65 		/** Plays the animation once, from the first frame to the last one. */
       
    66 		EPlay		= 0,
       
    67 		/** Plays the animation from the first frame to the last one 
       
    68 					continuously. */
       
    69 		ECycle		= 1,
       
    70 		/** Plays the animation from the first frame to the last one then 
       
    71 					from the last frame to the first continuously. */
       
    72 		EBounce		= 2
       
    73 		};
       
    74 
       
    75 	TSize iSize;
       
    76 	CAknsBmpAnimItemData* iAnimData;	// Animation data retrieved from Skin
       
    77 	TAknsBmpAnimFrameInfo* iFramesInfo;	// Frame based info from iAnimData
       
    78 	TInt iFrameInterval;				// Interval at which frame should be refreshed
       
    79 	TInt iBmpCount;					// Number of images in the animation
       
    80 	TInt iCounter;					// Index of animation being shown now
       
    81     EHuiPlayMode iPlayMode;			// Play mode- cycle, play or bounce
       
    82     TInt iBounceIncreasing;
       
    83 	};
       
    84 
       
    85 
       
    86 /*------------------------------Beging of CHuiAnimationTexture---------------*/
       
    87     
       
    88 // ---------------------------------------------------------------------------
       
    89 // DEPRECATED: NewL:: Two phase constructor
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 EXPORT_C CHuiSkinAnimationTexture* CHuiSkinAnimationTexture::NewL(
       
    93 														const TDesC& aFilename, 
       
    94                                                         CHuiTextureManager& aManager,
       
    95                                                         TInt aID,
       
    96                                                         THuiTextureUploadFlags aFlags)
       
    97     {
       
    98     CHuiSkinAnimationTexture* self = 
       
    99     				new(ELeave) CHuiSkinAnimationTexture(aManager,aFlags, aID);
       
   100     CleanupStack::PushL(self);
       
   101     self->ConstructL(aFilename);
       
   102     CleanupStack::Pop(); // self
       
   103     return self;
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // Start():: Start animation by setting status flag
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 EXPORT_C void CHuiSkinAnimationTexture::Start()
       
   111     {
       
   112     iAnimationState |= ERunning;        
       
   113     iAnimationState &= ~EStopped;
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // Stop():: Stop animation by setting status flag
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 EXPORT_C void CHuiSkinAnimationTexture::Stop()
       
   121     {
       
   122     iAnimationState &= ~ERunning;
       
   123     iAnimationState |= EStopped;
       
   124     }
       
   125     
       
   126 // ---------------------------------------------------------------------------
       
   127 // Id():: Retrieve Texture Id
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 EXPORT_C TInt CHuiSkinAnimationTexture::Id() 
       
   131     {
       
   132     return iId;
       
   133     }
       
   134     
       
   135 // ---------------------------------------------------------------------------
       
   136 // AdvanceTime():: Animation callback from Framework
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 void CHuiSkinAnimationTexture::AdvanceTime(TReal32 aElapsedTime) __SOFTFP
       
   140     {
       
   141     iFrameInterval = iSkinBitmapProvider->FrameInterval();
       
   142 
       
   143     if (((iAnimationState & EInitializing) || (iFrameInterval == -1)) || (iAnimationState&EStopped))
       
   144         {
       
   145         return;
       
   146         }
       
   147 
       
   148     iElapsedTime+=aElapsedTime;
       
   149     
       
   150                                              
       
   151     TReal32 time = (TReal(iFrameInterval))/1000.0f;
       
   152     if (iElapsedTime >= time)
       
   153         {
       
   154 
       
   155       	if(iManager.IsLoaded(iId))
       
   156       	    {
       
   157       	    iManager.UnloadTexture(iId);
       
   158       	    }
       
   159 
       
   160     	iId = CHuiStatic::GenerateId();
       
   161 
       
   162         TRAP_IGNORE(iTexture = &iManager.CreateTextureL(iId,
       
   163         					(MHuiBitmapProvider*)iSkinBitmapProvider,iFlags));
       
   164 
       
   165         iElapsedTime = 0.0f;
       
   166         } 
       
   167     }
       
   168     
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // TextureLoadingCompleted():: Callback from Framework..finished loading aTexture
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 void CHuiSkinAnimationTexture::TextureLoadingCompleted(CHuiTexture& ,//aTexture,
       
   175                              TInt aTextureId,
       
   176                              TInt aErrorCode)
       
   177     {
       
   178     if (aErrorCode == KErrNone && iAnimationState & EInitializing && aTextureId == iId)
       
   179         {
       
   180         iAnimationState |= ERunning;
       
   181         iAnimationState &= ~EInitializing;
       
   182         }
       
   183     }
       
   184 
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // Constructor CHuiSkinAnimationTexture
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 CHuiSkinAnimationTexture::CHuiSkinAnimationTexture(CHuiTextureManager& aManager,
       
   191 										THuiTextureUploadFlags aFlags,TInt aId) : 
       
   192 									    CHuiAnimatedTexture(aManager),
       
   193 									    iFrameInterval(-1),
       
   194 									    iFrameCount(0),
       
   195 									    iAnimationState(EInitializing),
       
   196 									    iFlags(aFlags),
       
   197 									    iId(aId)
       
   198     {
       
   199     }
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // DEPRECATED: ConstructL : 2 phase constructor
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 void CHuiSkinAnimationTexture::ConstructL(const TDesC&)
       
   206     {
       
   207     User::Leave(KErrNotSupported);
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // Destructor 
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 EXPORT_C CHuiSkinAnimationTexture::~CHuiSkinAnimationTexture()
       
   215     {
       
   216     iManager.iLoadObservers.RemoveIfFound(*this);
       
   217     delete iSkinBitmapProvider;
       
   218     }