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