uiacceltk/hitchcock/coretoolkit/inc/huitextureanimationstate.h
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2008 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:   Defines CHuiTextureAnimationState, which is used by
       
    15 *                CHuiTextureManager when loading animated textures.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef C_HUITEXTUREANIMATIONSTATE_H
       
    21 #define C_HUITEXTUREANIMATIONSTATE_H
       
    22 
       
    23 #include <e32base.h>
       
    24 #include <gdi.h>
       
    25 #include <imageconversion.h>
       
    26 
       
    27 class CFbsBitmap;
       
    28 
       
    29 /**
       
    30  * This holds animation state. One instance is required per animation.
       
    31  * To produce next frame, you have to have animation state containing
       
    32  * previous frame information. Thus, if animation state is needed, 
       
    33  * you should load frames in sequence (0, 1, ..., N).
       
    34  */
       
    35 NONSHARABLE_CLASS( CHuiTextureAnimationState ) : public CBase
       
    36     {
       
    37 public:
       
    38     /**
       
    39      * Two-phased constructor.
       
    40      * @param aTextureGroupId texture group id.
       
    41      * @param aImageFile image file.
       
    42      * @param aFrameCount amount of frames in file.
       
    43      */
       
    44     static CHuiTextureAnimationState* NewL( 
       
    45         TInt aTextureGroupId, const TDesC& aImageFile, TInt aFrameCount );
       
    46         
       
    47     /**
       
    48      * Destructor.
       
    49      */
       
    50     ~CHuiTextureAnimationState();
       
    51    
       
    52     /**
       
    53      * Returns owner texture group id.
       
    54      * @return texture group id.
       
    55      */
       
    56     TInt OwnerTextureGroupId() const;
       
    57     
       
    58     /** 
       
    59      * Checks if frame defined by aImageFile and aFrameNumber can be
       
    60      * composed with this state instance.
       
    61      * @param aImageFile image file name.
       
    62      * @param aFrameNumber frame number.
       
    63      * @param aFrameCount amount of frames in the file.
       
    64      */
       
    65     TBool CheckIfCanProduce( 
       
    66         const TDesC& aImageFile, 
       
    67         TInt aFrameNumber, 
       
    68         TInt aFrameCount ) const;
       
    69 
       
    70     /**
       
    71      * Gets next frame number.
       
    72      * @return next frame number.
       
    73      */
       
    74     TInt GetNextFrameNumber() const;
       
    75     
       
    76     /**
       
    77      * Offers next frame information. This method will store
       
    78      * information in order to be able to produce next frame
       
    79      * in @c ProduceNextFrameL.
       
    80      * @param aFrameInfo frame info.
       
    81      */
       
    82     void OfferNextFrameInfo( const TFrameInfo& aFrameInfo );
       
    83     
       
    84     /**
       
    85      * Returns overall size.
       
    86      */
       
    87     TSize OverallSize() const;
       
    88 
       
    89     /**
       
    90      * Produces next frame.
       
    91      * @param aNewFrame new frame.
       
    92      * @param aNewFrameMask new frame mask.
       
    93      * @param aSubFrame sub frame.
       
    94      * @param aSubFrameMask sub frame mask.
       
    95      */
       
    96     void ProduceNextFrameL(
       
    97         CFbsBitmap*& aNewFrame,
       
    98         CFbsBitmap*& aNewFrameMask,
       
    99         CFbsBitmap* aSubFrame,
       
   100         CFbsBitmap* aSubFrameMask );
       
   101         
       
   102     /** 
       
   103      * Proceed without generating next frame.
       
   104      * @param aSubFrame sub frame.
       
   105      * @param aSubFrameMask sub frame mask.
       
   106      */
       
   107     void ProceedWithoutNextFrameL(
       
   108         CFbsBitmap* aSubFrame,
       
   109         CFbsBitmap* aSubFrameMask );
       
   110         
       
   111 private:
       
   112     CHuiTextureAnimationState();
       
   113     void ConstructL( 
       
   114         TInt aTextureGroupId, const TDesC& aImageFile, 
       
   115         TInt aFrameCount );
       
   116    
       
   117     /**
       
   118      * Produces first frame and generates previous.
       
   119      */
       
   120     void ProduceFirstFrameAndGeneratePreviousL(
       
   121         CFbsBitmap*& aNewFrame,
       
   122         CFbsBitmap*& aNewFrameMask,
       
   123         CFbsBitmap* aSubFrame,
       
   124         CFbsBitmap* aSubFrameMask );
       
   125 
       
   126     /**
       
   127      * Produces next frame and updates previous.
       
   128      */
       
   129     void ProduceNextFrameAndUpdatePreviousL(
       
   130         CFbsBitmap*& aNewFrame,
       
   131         CFbsBitmap*& aNewFrameMask,
       
   132         CFbsBitmap* aSubFrame,
       
   133         CFbsBitmap* aSubFrameMask );
       
   134 
       
   135     /**
       
   136      * Produces first frame and generates previous. Quick
       
   137      * version assumes that mask contains only values 0 and 255.
       
   138      */
       
   139     void QuickProduceFirstFrameAndGeneratePreviousL(
       
   140         CFbsBitmap*& aNewFrame,
       
   141         CFbsBitmap*& aNewFrameMask,
       
   142         CFbsBitmap* aSubFrame,
       
   143         CFbsBitmap* aSubFrameMask );
       
   144 
       
   145     /**
       
   146      * Produces next frame and updates previous. Quick
       
   147      * version assumes that mask contains only values 0 and 255.
       
   148      */
       
   149     void QuickProduceNextFrameAndUpdatePreviousL(
       
   150         CFbsBitmap*& aNewFrame,
       
   151         CFbsBitmap*& aNewFrameMask,
       
   152         CFbsBitmap* aSubFrame,
       
   153         CFbsBitmap* aSubFrameMask );
       
   154 
       
   155     inline static TRgb BitmapClearColor();
       
   156     inline static TRgb MaskClearColor();
       
   157     inline static TRgb MaskOpaqueColor();
       
   158     
       
   159     /**
       
   160      * Checks sub frame and its mask for validity.
       
   161      * Leaves if invalid.
       
   162      */
       
   163     static void CheckSubFrameL( 
       
   164         CFbsBitmap* aSubFrame, 
       
   165         CFbsBitmap* aSubFrameMask );
       
   166     
       
   167 private:
       
   168     //
       
   169     // Information about current animation
       
   170     //
       
   171     
       
   172     /**
       
   173      * Group id.
       
   174      */
       
   175     TInt iTextureGroupId;
       
   176     
       
   177     /**
       
   178      * File name.
       
   179      * Own.
       
   180      */
       
   181     HBufC* iFile;
       
   182     
       
   183     /**
       
   184      * Frame number. -1 if no frame yet produced.
       
   185      */
       
   186     TInt iFrame;
       
   187 
       
   188     /**
       
   189      * Frame count. Should be greater than one.
       
   190      */
       
   191     TInt iFrameCount;
       
   192         
       
   193     /**
       
   194      * Size of frames.
       
   195      */
       
   196     TSize iSize;
       
   197 
       
   198     //
       
   199     // Information about next frame
       
   200     //
       
   201     
       
   202     /**
       
   203      * Sub frame rectangle.
       
   204      * Updated in OfferNextFrameInfo.
       
   205      */
       
   206     TRect iNextSubFrameRect;
       
   207     
       
   208     /**
       
   209      * Background color.
       
   210      * Updated in OfferNextFrameInfo.
       
   211      */
       
   212     TRgb iNextSubFrameBgColor;
       
   213 
       
   214     /**
       
   215      * Boolean value indicating if complex blending is needed,
       
   216      * i.e. subframe has alpha channel (instead of just on/off transparency).
       
   217      * Updated in OfferNextFrameInfo.
       
   218      */
       
   219     TBool iNextSubFrameHasAlpha;
       
   220 
       
   221     /**
       
   222      * Enumeration for disposal actions
       
   223      */
       
   224     enum TDisposalAction
       
   225         {
       
   226         EUnspecified,
       
   227         ERestoreToPrevious,
       
   228         ERestoreToBackgroundColour,
       
   229         ELeaveInPlace
       
   230         };
       
   231         
       
   232     /**
       
   233      * Disposal action for next frame.
       
   234      * Updated in OfferNextFrameInfo.
       
   235      */
       
   236     TDisposalAction iNextSubFrameDisposalAction;
       
   237                 
       
   238     //
       
   239     // Previous frame information
       
   240     //
       
   241     
       
   242     /**
       
   243      * Previous frame.
       
   244      * Own.
       
   245      */
       
   246     CFbsBitmap* iPrevFrame;
       
   247     
       
   248     /**
       
   249      * Previous frame mask.
       
   250      * Own.
       
   251      */
       
   252     CFbsBitmap* iPrevFrameMask;    
       
   253     };
       
   254 
       
   255 #endif // C_HUITEXTUREANIMATIONSTATE_H
       
   256