epoc32/include/mw/bmpansrv.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @internalComponent 
    19 */
    20 
    21 #if !defined(__BMPANSRV_H__)
    22 #define __BMPANSRV_H__
    23 
    24 #include <e32std.h>
    25 #include <w32adll.h>
    26 #include "bmpanconsts.h"
    27 #include "bmpancli.h"
    28 #include <e32math.h>
    29 
    30 
    31 
    32 enum TBitmapAnimServerPanic
    33 	{
    34 	EAnimationServerPanicIndexOutOfRange,
    35 	EAnimationServerPanicFrameIntervalNegative
    36 	};
    37 
    38 // For packaging the new animation position offset
    39 struct SBitmapAnimNewPosition
    40 	{
    41 	TPoint iPosition;
    42 	};
    43 
    44 // For packaging the new animation index
    45 struct SBitmapAnimIndexFrame
    46 	{
    47 	TInt iIndex;
    48 	};
    49 
    50 // For packaging the number of cycles
    51 struct SBitmapAnimNumberOfCycles
    52 	{
    53 	TInt iCycles;
    54 	};
    55 
    56 
    57 
    58 /**
    59  TFrameData
    60 
    61  This class is used for packaging the data of one frame.
    62 */
    63 class TFrameData
    64 	{
    65 public:
    66 	TInt iBitmapHandle;
    67 	TInt iMaskBitmapHandle;
    68 	TPoint iPosition;
    69 	TInt iIntervalInMilliSeconds;			// the time is expressed in ms
    70 	};
    71 
    72 
    73 
    74 /**
    75  TBmpAnimAttributes
    76 
    77  This class is used for packaging the attriutes of the animation.
    78 */
    79 class TBmpAnimAttributes
    80 	{
    81 public:
    82 	TBool iFlash;
    83 	TInt iFrameIntervalInMilliSeconds;
    84 	CBitmapAnimClientData::TPlayMode iPlayMode;
    85 	};
    86 
    87 
    88 
    89 
    90 /**
    91  class MBitmapAnimTimerObserver
    92 */
    93 class MBitmapAnimTimerObserver
    94 	{
    95 public:
    96 	virtual void DisplayNextFrameL()=0;
    97 	};
    98 
    99 
   100 
   101 /**
   102  class CBitmapAnimTimer
   103 
   104  This class is used to determine when to swap the current frame with the next one.
   105 */
   106 class CBitmapAnimTimer : public CTimer
   107 	{
   108 public:
   109 	~CBitmapAnimTimer();
   110 	static CBitmapAnimTimer* NewL(MBitmapAnimTimerObserver* aObserver);
   111 	void RunL();
   112 private:
   113 	CBitmapAnimTimer(MBitmapAnimTimerObserver* aObserver);
   114 	void ConstructL();
   115 private:
   116 	MBitmapAnimTimerObserver* iAnimate;
   117 	};
   118 
   119 
   120 
   121 /**
   122  class MBitmapAnimFlashTimerObserver
   123 */
   124 
   125 class MBitmapAnimFlashTimerObserver
   126 	{
   127 public:
   128 	virtual void FlashFrame(TBool aFlash)=0;
   129 	};
   130 
   131 
   132 
   133 /**
   134  class CBitmapAnimFlashTimer
   135 */
   136 
   137 class CBitmapAnimFlashTimer : public CTimer
   138 	{
   139 public:
   140 	~CBitmapAnimFlashTimer();
   141 	static CBitmapAnimFlashTimer* NewL(MBitmapAnimFlashTimerObserver* aObserver);
   142 	void DoCancel();
   143 	void RunL();
   144 private:
   145 	CBitmapAnimFlashTimer(MBitmapAnimFlashTimerObserver* aObserver);
   146 	void ConstructL();
   147 private:
   148 	MBitmapAnimFlashTimerObserver* iAnimate;
   149 	TBool iFlash;
   150 	};
   151 
   152 
   153 
   154 /**
   155  class CBitmapAnimFrameData
   156 
   157  This class encapsulates the information of one frame.
   158 */
   159 
   160 class CBitmapAnimFrameData : public CBase
   161 	{
   162 public:
   163 	static CBitmapAnimFrameData* NewL();
   164 	static CBitmapAnimFrameData* NewLC();
   165 	~CBitmapAnimFrameData();
   166 	void FillFrameDataL(const TFrameData& aFrameDataArg);
   167 	void CheckAndCreateBitmapsL();
   168 	
   169 private:
   170 	CBitmapAnimFrameData();
   171 	void InitialiseMembers();
   172 	
   173 public:
   174 	CFbsBitmap* iBitmap;
   175 	CFbsBitmap* iMaskBitmap;
   176 	TPoint iPosition;
   177 	TTimeIntervalMicroSeconds32 iInterval;
   178 	};
   179 
   180 
   181 
   182 /**
   183  class CBitmapAnim
   184 
   185  This class encapsulates the enire animation: attributes and frames.
   186 */
   187 
   188 class CBitmapAnim : public CFreeTimerWindowAnim, MBitmapAnimTimerObserver//, MBitmapAnimFlashTimerObserver
   189 	{
   190 public:
   191 	~CBitmapAnim();
   192 	static CBitmapAnim* NewL();
   193 private:
   194 	CBitmapAnim();
   195 private:
   196 	enum TAnimateFlags
   197 		{
   198 //	State
   199 		ERunning				= 0x0001,
   200 		EFlashing				= 0x0002,
   201 		EFrozen					= 0x0004,
   202 //	Play mode
   203 		EPlayModeCycle			= 0x0010,
   204 		EPlayModeBounce			= 0x0020,
   205 		EPlayForwards			= 0x0040,
   206 		EPlayBackwards			= 0x0080,
   207 //	General
   208 		EFlash									= 0x0100,
   209 		ENoBitmapWindowRestoring				= 0x0800,
   210 		EDisplayLastFrameWhenFinished			= 0x4000,
   211 		};
   212 
   213 private: //Pure Virtual function from CAnim
   214 	virtual void ConstructL(TAny *aArgs, TBool aHasFocus);
   215 	virtual void Command(TInt aOpcode, TAny* aArgs);
   216 	virtual TInt CommandReplyL(TInt aOpcode, TAny *aArgs);
   217 	virtual void Animate(TDateTime* aDateTime);
   218 	virtual void Redraw();
   219 	virtual void FocusChanged(TBool aState);
   220 private: //Pure Virtual function from MEventHandler
   221 	virtual TBool OfferRawEvent(const TRawEvent &aRawEvent);
   222 private: //Pure Virtual function from MBitmapAnimTimerObserver
   223 	virtual void DisplayNextFrameL();
   224 private: //Pure Virtual function from MBitmapAnimFlashTimerObserver
   225 	virtual void FlashFrame(TBool aFlash);
   226 private:
   227 	void AppendFrameL(const TFrameData& aFrameData);
   228 	inline TInt Count() const;
   229 	void DisplayFrame(TInt aPreviousIndex=-1);
   230 	void DrawBitmap(TInt aPreviousIndex=-1, TBool aRedraw=EFalse);
   231 	inline TBool IsFrameDisplayable() const;
   232 	inline TBool IsRunning() const;
   233 	inline TBool IsFrozen() const;
   234 	void ResetAnimation();
   235 	void ClearFrameNow(TInt aIndex);
   236 	void RenderFrameBackground(TInt aIndex);
   237 	TRect CalcFrameRect(TInt aIndex);
   238 	void SetBackgroundFrameL(TFrameData aFrameDataArg);
   239 	void SetFlash(TBmpAnimAttributes aFlash);
   240 	void SetFrameInterval(TBmpAnimAttributes aFrameInterval);
   241 	TInt SetIndexFrame(SBitmapAnimIndexFrame aIndexFrame);
   242 	void SetNumberOfCycles(SBitmapAnimNumberOfCycles aNumberOfCycles);
   243 	void SetPlayMode(TBmpAnimAttributes aPlayMode);
   244 	void SetPosition(SBitmapAnimNewPosition aNewPosition);
   245 	void StartAnimationL();
   246 	void StopAnimation();
   247 	void UpdateCurrentIndex();
   248 	inline TRect WindowRect() const;
   249 	static TBool FrameNeedsRedrawing(const TRegion* aRedrawRegion, TRect aFrameScreenRect);
   250 	void ResetFrameArray();
   251 	void ClearFrameData();
   252 	
   253 private:
   254 	RPointerArray<CBitmapAnimFrameData> iBitmapAnimFrameDataArray;
   255 	CBitmapAnimTimer* iAnimTimer;
   256 	CBitmapAnimFlashTimer* iFlashTimer;
   257 	CBitmapAnimFrameData* iBackgroundFrame;
   258 
   259 //
   260 	TInt iDummy;
   261 	TInt iFlags;
   262 	TInt iIndex;
   263 	TInt iNumberOfCycles;
   264 	TPoint iPosition;
   265 	TInt iWindowConfig;
   266 	TTimeIntervalMicroSeconds32 iFrameInterval;	
   267 	};
   268 
   269 // Returns the number of frames store in the frame array.
   270 inline TInt CBitmapAnim::Count() const
   271 	{ return iBitmapAnimFrameDataArray.Count(); }
   272 
   273 // Returns ETrue every time the index frame is valid, otherwise it returns EFalse.
   274 inline TBool CBitmapAnim::IsFrameDisplayable() const
   275 	{ return ( (iIndex >= 0) && iBitmapAnimFrameDataArray[iIndex]->iBitmap ); }
   276 
   277 // Returns ETrue if the animation is running, otherwise it returns EFalse.
   278 inline TBool CBitmapAnim::IsRunning() const
   279 	{ return iFlags&ERunning; }
   280 
   281 //Returns ETrue if the animation is frozen (app is not in the foreground)
   282 inline TBool CBitmapAnim::IsFrozen() const
   283 { return iFlags&EFrozen; }
   284 
   285 // Returns the available window rect.
   286 inline TRect CBitmapAnim::WindowRect() const
   287 	{ return TRect(TPoint(0, 0), iWindowFunctions->WindowSize()); }
   288 
   289 
   290 
   291 
   292 /**
   293  CBitmapAnimDll class
   294 */
   295 
   296 class CBitmapAnimDll : public CAnimDll
   297 	{
   298 public:
   299 	CBitmapAnimDll();
   300 	virtual CAnim* CreateInstanceL(TInt aType);
   301 	};
   302 
   303 
   304 /**
   305  global functions
   306 */
   307 GLREF_C void Panic(TBitmapAnimServerPanic aReason);
   308 
   309 
   310 #endif
   311