uiaccelerator_plat/alf_visual_api/inc/alf/alfimageloaderutil.h
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006 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:   Utility for creating textures from skin graphics
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef C_AlfIMAGELOADERUTIL_H
       
    21 #define C_AlfIMAGELOADERUTIL_H
       
    22 
       
    23 #include <AknsUtils.h>
       
    24 #include <AknIconUtils.h>
       
    25 #include <alf/alftexturemanager.h>
       
    26 
       
    27 class CAlfImageLoader;
       
    28 class MAlfBitmapProvider;
       
    29 class CAlfTextureManager;
       
    30 
       
    31 /**
       
    32  * CAlfImageLoaderUtil is a utility class to create image loader with the system skin 
       
    33  * applied. CAlfImageLoaderUtil holds all MAlfBitmapProvider instance created through
       
    34  * CreateImageLoaderL() so that appplication/control does not need to keep it by itself.
       
    35  * 
       
    36  * Typically, an application or a control needs to hold instance of CAlfImageLoaderUtil
       
    37  * during entire its object life time, because bitmap provision callback from texture
       
    38  * manager may be called even after instanciation of texture. For instance, image re-loading
       
    39  * happens when application coming back to foreground and resource was released.
       
    40  *  * 
       
    41  * Usage:
       
    42  * 
       
    43  * @code
       
    44  *  // Create ImageLoaderUtil
       
    45  * CAlfImageLoaderUtil* imageloader = new ( ELeave ) CAlfImageLoaderUtil();
       
    46  * 
       
    47  * //To create svgImageLoader
       
    48  * MAlfBitmapProvider* bitmapprovider = imageloader->CreateSVGImageLoaderL( svgfilename );	
       
    49  * 
       
    50  * //Create texture using bitmap provider istance
       
    51  * CAlfTexture* texture = iTextureMgr->CreateTexture( 42, *bitmapprovider, EAlfTextureFlagDefault );
       
    52  * 
       
    53  * //Use texture to create image istance
       
    54  * TAlfImage image( *texture );
       
    55  * 
       
    56  * //To create iconbased bitmap provider
       
    57  * bitmapprovider = imageloader->createImageLoader( iconUid, EAknsAppIconTypeList );
       
    58  * 
       
    59  * //Cleanup
       
    60  *  delete imageloader
       
    61  *  delete bitmapprovider;
       
    62  * @endcode
       
    63  * 
       
    64  * @see CAlfTextureManager::CreateTexture()
       
    65  * 
       
    66  * @lib alfclient.lib
       
    67  * @since S60 v3.2
       
    68  */
       
    69 NONSHARABLE_CLASS( CAlfImageLoaderUtil ): public CBase
       
    70 	{
       
    71 public:
       
    72 	/**
       
    73 	 * Constructor
       
    74 	 */
       
    75 	IMPORT_C CAlfImageLoaderUtil();
       
    76 
       
    77 	/**
       
    78 	 * Deconstructor
       
    79 	 */
       
    80 	IMPORT_C ~CAlfImageLoaderUtil();
       
    81 	
       
    82 	/**
       
    83      * Create MAlfBitmapProvider instance to load image with Avkon skin item ID with 
       
    84      * fallback. The fallback is used when the current skin does not contain the image with 
       
    85      * skin item ID. If either fails, this leaves.
       
    86      * Use CAlfTextureManager::CreateTextureL() with return value of this method as a
       
    87      * bitmap provider to create a Alf texture. You can set the size of the provided bitmap
       
    88      * in pixels using SetSize().
       
    89      *
       
    90      * @param aID  An Akvon skin item ID of the graphical item (e.g. an icon) to load.
       
    91      * @param aFileName  File name of graphics file e.g. mif file) when sepcified item is not found in the current skin.
       
    92      * @param aBitmapId  ID of the bitmap when fallback is used.
       
    93      * @param aMaskId  ID of the mask bitmap when fallback is used.
       
    94      */
       
    95 	IMPORT_C MAlfBitmapProvider* CreateImageLoaderL(const TAknsItemID &aID, const TDesC &aFileName, TInt aBitmapId, TInt aMaskId);
       
    96 
       
    97 	/**
       
    98      * Create MAlfBitmapProvider instance to load frame image with Avkon skin item ID 
       
    99      * Use CAlfTextureManager::CreateTextureL() with return value of this method as a
       
   100      * bitmap provider to create a Alf texture. 
       
   101      *
       
   102      * @param aFrameID  An Avkon skin item ID of the graphical frame item to load.
       
   103      * @param aInnerRect Inner rect of the frame
       
   104      * @param aOuterRect Outer rect of the frame
       
   105      */
       
   106 	IMPORT_C MAlfBitmapProvider* CreateImageLoaderL(const TAknsItemID &aFrameID, const TRect& aInnerRect, const TRect& aOuterRect);
       
   107 
       
   108     /**
       
   109      * Create MAlfBitmapProvider instance to load Application icon image.
       
   110      * Use CAlfTextureManager::CreateTextureL() with return value of this method as a
       
   111      * bitmap provider to create a Alf texture. You can set the size of the provided bitmap
       
   112      * in pixels using SetSize().
       
   113      *
       
   114      * @param aAppUid  Application UID of the icon to be created.
       
   115      * @param aType  Type of the application icon. Likely EAknsAppIconTypeContext is used...
       
   116      */
       
   117 	IMPORT_C MAlfBitmapProvider* CreateImageLoaderL(TUid aAppUid, TAknsAppIconType aType);
       
   118 
       
   119 
       
   120     /**
       
   121      * Create MAlfBitmapProvider instance to load an SVG Image
       
   122      * Use CAlfTextureManager::CreateTextureL() with return value of this method as a
       
   123      * bitmap provider to create a Alf texture. You can set the size of the provided bitmap
       
   124      * in pixels using SetSize(). This function works only with true SVG-T files.
       
   125      *
       
   126      * @param aFilename  Filename of the SVG file to load. If filename does not contain full path
       
   127      * then path is taken from primary env default texturemanager image path. 
       
   128      * 
       
   129      */
       
   130 	IMPORT_C MAlfBitmapProvider* CreateSVGImageLoaderL(const TDesC &aFileName);
       
   131 
       
   132     /**
       
   133      * Set size of the image to be loaded. This must be called before calling CreateImageLoaderL.
       
   134      * This call only sets information and does *NOT* cause any scalable icon rasterization. Also
       
   135      * Size setting does not affect any of image loaders already created.
       
   136      *
       
   137      * @param aSize     Size in pixel.
       
   138      * @param aMode     Scaling mode enumeration from Avkon. It takes either of following three.
       
   139      *                    EAspectRatioPreserved
       
   140      *                    EAspectRatioPreservedAndUnusedSpaceRemoved
       
   141      *                    EAspectRatioNotPreserved
       
   142      *
       
   143      */
       
   144 	IMPORT_C void SetSize(TSize aSize, TScaleMode aMode=EAspectRatioPreserved);
       
   145 
       
   146     /**
       
   147      * Set skin instance, which is acquired from AknsUtils::SkinInstance(). If skin instance
       
   148      * is not explicitly set with this method, the image loader will use skin instance from 
       
   149      * AknsUtils::SkinInstance().
       
   150      *
       
   151      * @param aSkinInstance     An Avkon skin instamce.
       
   152      */
       
   153 	IMPORT_C void SetSkinInstance(MAknsSkinInstance *aSkinInstance);
       
   154 
       
   155 protected:
       
   156 
       
   157 	/** An array to hold all loader created. */
       
   158 	RPointerArray<CAlfImageLoader> iImageLoaderList;
       
   159 
       
   160 private:
       
   161 	/** Skin instance. */
       
   162 	MAknsSkinInstance *iSkinInstance;
       
   163 	
       
   164 	/** Size of image to be created */
       
   165 	TSize iSize;
       
   166 	
       
   167 	/** Scale mode of image to be created */
       
   168 	TScaleMode iScaleMode;
       
   169 		
       
   170 	};
       
   171 
       
   172 
       
   173 /**
       
   174  * CAlfAutoSizeImageLoaderUtil is an extended image loader utility class.
       
   175  * This class can automatically keep track of the preferred sizes for
       
   176  * textures and their bitmap providers and thus always provide correct size 
       
   177  * bitmaps.
       
   178  * 
       
   179  * Example of use:
       
   180  * 
       
   181  * @code
       
   182  *
       
   183  * // Create CAlfAutoSizeImageLoaderUtil
       
   184  * iImageloader = new (ELeave) CAlfAutoSizeImageLoaderUtil;
       
   185  *
       
   186  * // Register CAlfAutoSizeImageLoaderUtil as autosize observer
       
   187  * texturemanager->AddAutoSizeObserverL(iImageloader); 
       
   188  *
       
   189  * // Create provider for a skin item
       
   190  * MAlfBitmapProvider* imageprovider = iImageloader->CreateImageLoaderL(SkinID(), 
       
   191  *      FallbackFileName(),
       
   192  *      FallbackBitmapId(),
       
   193  *      FallbackMaskId());            
       
   194  * 
       
   195  * // Create a texture using provider, set autosize flags to enable automatic texture resizing.
       
   196  * texturemanager->CreateTextureL(KAlfAutoGeneratedTextureId,
       
   197  *     imageprovider,
       
   198  *     EAlfTextureFlagAutoSize);
       
   199  * 
       
   200  * @endcode
       
   201  */
       
   202 NONSHARABLE_CLASS( CAlfAutoSizeImageLoaderUtil ): public CAlfImageLoaderUtil, public MAlfTextureAutoSizeObserver
       
   203     {
       
   204 public:
       
   205     /**
       
   206      * Constructor
       
   207      */
       
   208     IMPORT_C CAlfAutoSizeImageLoaderUtil();
       
   209     
       
   210 private:
       
   211     // From MAlfTexturePreferredSizeObserver
       
   212     IMPORT_C TBool PreferredSizeChanged(const CAlfTexture& aChangedTexture, TSize aPreferredSize);
       
   213         
       
   214     };
       
   215 
       
   216 #endif // C_AlfIMAGELOADERUTIL_H