|
1 // Copyright (c) 2004-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 #include "BasicAnimation.h" |
|
17 |
|
18 #include <w32std.h> |
|
19 #include <coecntrl.h> |
|
20 |
|
21 #include "AnimationDataProvider.h" |
|
22 #include "Animator.h" |
|
23 #include "AnimationConfig.h" |
|
24 #include "AnimationTls.h" |
|
25 #include "AnimationEvents.h" |
|
26 #include "AnimationTicker.h" |
|
27 #include "coeaui.h" |
|
28 #include "basicanimationext.h" |
|
29 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
30 #include <vwsdefpartner.h> |
|
31 #endif |
|
32 |
|
33 |
|
34 /** |
|
35 Two stage constructor. |
|
36 |
|
37 This creates and returns a new basic animation. |
|
38 |
|
39 @param aDataProvider The data provider from which the animation contents will |
|
40 be obtained. The animation takes ownership of this object |
|
41 @param aPoint The starting position of the animation in the window (top left corner) |
|
42 @param aWs A session with the window server |
|
43 @param aWindow The window in which the animation will be drawn |
|
44 @param aObserver An optional receiver of animation events (such as errors) |
|
45 @return The new object |
|
46 */ |
|
47 EXPORT_C CBasicAnimation* CBasicAnimation::NewL(CAnimationDataProvider* aDataProvider, const TPoint& aPoint, RWsSession& aWs, RWindow& aWindow, MAnimationObserver* aObserver) |
|
48 { |
|
49 return CBasicAnimation::NewL(aDataProvider, aPoint, aWs, aWindow, aDataProvider->DataType(), aObserver); |
|
50 } |
|
51 |
|
52 /** |
|
53 Two stage constructor. |
|
54 |
|
55 This is identical to the other NewL except that it allows an alternative data |
|
56 type to be specified. Unless you are trying to use a custom animator class |
|
57 the other form of constructor should be used. |
|
58 |
|
59 @param aDataProvider The data provider from which the animation contents will |
|
60 be obtained. The animation takes ownership of this object |
|
61 @param aPoint The starting position of the animation in the window (top left corner) |
|
62 @param aWs A session with the window server |
|
63 @param aWindow The window in which the animation will be drawn |
|
64 @param aDataType Overrides the data type specified by the data provider |
|
65 @param aObserver An optional receiver of animation events (such as errors) |
|
66 @return The new object |
|
67 */ |
|
68 EXPORT_C CBasicAnimation* CBasicAnimation::NewL(CAnimationDataProvider* aDataProvider, const TPoint& aPoint, RWsSession& aWs, RWindow& aWindow, const TDesC8& aDataType, MAnimationObserver* aObserver) |
|
69 { |
|
70 __ASSERT_ALWAYS(aDataProvider, User::Leave(KErrArgument)); |
|
71 CleanupStack::PushL(aDataProvider); |
|
72 CBasicAnimation* self = new (ELeave) CBasicAnimation(aDataProvider, aPoint, &aWs, &aWindow, aObserver); |
|
73 CleanupStack::Pop(aDataProvider); |
|
74 CleanupStack::PushL(self); |
|
75 self->ConstructL(aDataType); |
|
76 CleanupStack::Pop(self); |
|
77 |
|
78 return self; |
|
79 } |
|
80 |
|
81 /** |
|
82 Two stage constructor. |
|
83 This creates and returns a new basic animation. |
|
84 |
|
85 @param aDataProvider The data provider from which the animation contents will |
|
86 be obtained. The animation takes ownership of this object |
|
87 @param aPoint The starting position of the animation in the window (top left corner) |
|
88 @param aObserver An optional receiver of animation events (such as errors) |
|
89 @param aHost The CCoeControl responsible for drawing this animation |
|
90 @return The new object |
|
91 */ |
|
92 EXPORT_C CBasicAnimation* CBasicAnimation::NewL(CAnimationDataProvider* aDataProvider, const TPoint& aPoint, MAnimationObserver* aObserver, const CCoeControl* aHost) |
|
93 { |
|
94 return CBasicAnimation::NewL(aDataProvider, aPoint, aDataProvider->DataType(), aObserver, aHost); |
|
95 } |
|
96 |
|
97 /** |
|
98 Two stage constructor. |
|
99 |
|
100 This is identical to the other NewL except that it allows an alternative data |
|
101 type to be specified. Unless you are trying to use a custom animator class |
|
102 the other form of constructor should be used. |
|
103 |
|
104 @param aDataProvider The data provider from which the animation contents will |
|
105 be obtained. The animation takes ownership of this object |
|
106 @param aPoint The starting position of the animation in the window (top left corner) |
|
107 @param aDataType Overrides the data type specified by the data provider |
|
108 @param aObserver An optional receiver of animation events (such as errors) |
|
109 @param aHost The CCoeControl responsible for drawing this animation |
|
110 @return The new object |
|
111 */ |
|
112 EXPORT_C CBasicAnimation* CBasicAnimation::NewL(CAnimationDataProvider* aDataProvider, const TPoint& aPoint, const TDesC8& aDataType, MAnimationObserver* aObserver, const CCoeControl* aHost) |
|
113 { |
|
114 __ASSERT_ALWAYS(aDataProvider, User::Leave(KErrArgument)); |
|
115 CleanupStack::PushL(aDataProvider); |
|
116 CBasicAnimation* self = new (ELeave) CBasicAnimation(aDataProvider, aPoint, aObserver); |
|
117 CleanupStack::Pop(aDataProvider); |
|
118 CleanupStack::PushL(self); |
|
119 self->ConstructL(aDataType,aHost); |
|
120 CleanupStack::Pop(self); |
|
121 return self; |
|
122 } |
|
123 |
|
124 /** Destructor. */ |
|
125 EXPORT_C CBasicAnimation::~CBasicAnimation() |
|
126 { |
|
127 while (iFreezeCount > 0) |
|
128 CBasicAnimation::Unfreeze(); |
|
129 delete iAnimator; |
|
130 delete iRenderGc; |
|
131 delete iMaskDevice; |
|
132 delete iBitmapDevice; |
|
133 delete iMask; |
|
134 delete iBitmap; |
|
135 delete iDataProvider; |
|
136 delete iDataType; |
|
137 delete iBasicAnimationExt; |
|
138 iObserver = NULL; |
|
139 if(iTls) |
|
140 { |
|
141 iTls->Close(); |
|
142 iTls = NULL; |
|
143 } |
|
144 iWs = NULL; |
|
145 iWindow = NULL; |
|
146 } |
|
147 |
|
148 /** Implements CAnimation::Start. |
|
149 |
|
150 @param aConfig Flags and possibly data regarding the way in which the animation should be run */ |
|
151 void CBasicAnimation::Start(const TAnimationConfig& aConfig) |
|
152 { |
|
153 iAnimator->Start(aConfig); |
|
154 } |
|
155 |
|
156 /** Implements CAnimation::Stop.*/ |
|
157 void CBasicAnimation::Stop() |
|
158 { |
|
159 iAnimator->Stop(); |
|
160 } |
|
161 |
|
162 /** Implements CAnimation::Pause.*/ |
|
163 void CBasicAnimation::Pause() |
|
164 { |
|
165 iAnimator->Pause(); |
|
166 } |
|
167 |
|
168 /** Implements CAnimation::Resume.*/ |
|
169 void CBasicAnimation::Resume() |
|
170 { |
|
171 iAnimator->Resume(); |
|
172 } |
|
173 |
|
174 /** Implements CAnimation::Hold.*/ |
|
175 void CBasicAnimation::Hold() |
|
176 { |
|
177 iAnimator->Hold(); |
|
178 } |
|
179 |
|
180 /** Implements CAnimation::Unhold.*/ |
|
181 void CBasicAnimation::Unhold() |
|
182 { |
|
183 iAnimator->Unhold(); |
|
184 } |
|
185 |
|
186 /** Implements CAnimation::SetPosition. |
|
187 |
|
188 @param aPoint The new location of the top left corner of the animation, relative to the window in which it is to be drawn */ |
|
189 void CBasicAnimation::SetPosition(const TPoint& aPoint) |
|
190 { |
|
191 if (iBasicAnimationExt && (iPoint != aPoint)) |
|
192 { |
|
193 iPoint = aPoint; |
|
194 } |
|
195 else if (iWindow) |
|
196 { |
|
197 iWindow->Invalidate(TRect(iPoint, iPoint + iSize)); |
|
198 iPoint = aPoint; |
|
199 iWindow->Invalidate(TRect(iPoint, iPoint + iSize)); |
|
200 } |
|
201 } |
|
202 |
|
203 /** Implements CAnimation::Freeze.*/ |
|
204 void CBasicAnimation::Freeze() |
|
205 { |
|
206 ++iFreezeCount; |
|
207 iTls->Ticker()->Freeze(); |
|
208 } |
|
209 |
|
210 /** Implements CAnimation::Unfreeze.*/ |
|
211 void CBasicAnimation::Unfreeze() |
|
212 { |
|
213 --iFreezeCount; |
|
214 iTls->Ticker()->Unfreeze(); |
|
215 } |
|
216 |
|
217 /** |
|
218 This function should be called with a valid graphics context whenever |
|
219 a redraw event is received for the window this animation resides in. |
|
220 |
|
221 The graphics context attributes will not be modified, which means effects such |
|
222 as opacity can be applied to it before the call to Draw. |
|
223 |
|
224 @param aGc A graphics context which will be used for blitting the animation |
|
225 frame onto the window |
|
226 */ |
|
227 EXPORT_C void CBasicAnimation::Draw(CWindowGc& aGc) const |
|
228 { |
|
229 if (iFlags & EAnimationInitialised) |
|
230 { |
|
231 aGc.BitBltMasked(iPoint,iBitmap, TRect(iSize),iMask, EFalse); |
|
232 } |
|
233 } |
|
234 |
|
235 /** |
|
236 This function lets you set the host at a later stage if you haven't got access to it during |
|
237 construction, or if you for some reason need to change it in run time. |
|
238 |
|
239 @param aHost |
|
240 */ |
|
241 EXPORT_C void CBasicAnimation::SetHostL(const CCoeControl* aHost) |
|
242 { |
|
243 if (iBasicAnimationExt) |
|
244 { |
|
245 iBasicAnimationExt->iHost = aHost; |
|
246 } |
|
247 else |
|
248 { |
|
249 // If iBasicAnimationExt is 0 it means the NewL that takes an RWindow was used, |
|
250 // host is not supported in this case |
|
251 User::Leave(KErrNotSupported); |
|
252 } |
|
253 } |
|
254 |
|
255 void CBasicAnimation::AnimatorDraw() |
|
256 { |
|
257 if (iFlags & EAnimationInitialised) |
|
258 { |
|
259 iRenderGc->Activate(iBitmapDevice); |
|
260 iAnimator->Draw(*iRenderGc); |
|
261 iRenderGc->Activate(iMaskDevice); |
|
262 iAnimator->DrawMask(*iRenderGc); |
|
263 if (iBasicAnimationExt && iBasicAnimationExt->iHost) |
|
264 { |
|
265 iBasicAnimationExt->iHost->DrawNow(); |
|
266 } |
|
267 else if (iWindow) |
|
268 { |
|
269 iWindow->Invalidate((TRect(iPoint, iPoint + iSize))); |
|
270 iWs->Flush(); |
|
271 } |
|
272 } |
|
273 } |
|
274 |
|
275 void CBasicAnimation::DataProviderEventL(TInt aEvent, TAny* aData, TInt aDataSize) |
|
276 { |
|
277 if (!(aEvent & ~EAnimationReservedEvents)) |
|
278 { |
|
279 switch(aEvent) |
|
280 { |
|
281 case EAnimationDataChanged: |
|
282 iDataProvider->StartL(); |
|
283 break; |
|
284 case EAnimationDataProviderError: |
|
285 if (iObserver) |
|
286 { |
|
287 iObserver->AnimationEvent(*this, MAnimationObserver::EDataProviderError, aData); |
|
288 } |
|
289 break; |
|
290 default: |
|
291 User::Leave(KErrArgument); |
|
292 } |
|
293 } |
|
294 iAnimator->DataEventL(aEvent, aData, aDataSize); |
|
295 } |
|
296 |
|
297 CBasicAnimation::CBasicAnimation(CAnimationDataProvider* aDataProvider, const TPoint& aPoint, RWsSession* aWs, RWindow* aWindow, MAnimationObserver* aObserver) : |
|
298 iObserver (aObserver), |
|
299 iDataProvider(aDataProvider), |
|
300 iPoint(aPoint), |
|
301 iWs(aWs), |
|
302 iWindow(aWindow) |
|
303 { |
|
304 } |
|
305 |
|
306 CBasicAnimation::CBasicAnimation(CAnimationDataProvider* aDataProvider, const TPoint& aPoint, MAnimationObserver* aObserver) :iObserver(aObserver),iDataProvider(aDataProvider), iPoint(aPoint) |
|
307 { |
|
308 } |
|
309 |
|
310 // This ConstructL is called when no RWindow is provided but maybe a host |
|
311 void CBasicAnimation::ConstructL(const TDesC8& aDataType,const CCoeControl* aHost) |
|
312 { |
|
313 iDataType = HBufC8::NewL(aDataType.Length()); |
|
314 (*iDataType) = aDataType; |
|
315 |
|
316 iTls = CAnimationTls::NewL(); |
|
317 iAnimator = CAnimator::NewL(this); |
|
318 iRenderGc = CFbsBitGc::NewL(); |
|
319 |
|
320 iBasicAnimationExt = CBasicAnimationExt::NewL(aHost); |
|
321 if (iBasicAnimationExt->iHost) |
|
322 { |
|
323 iBitmap = new (ELeave) CWsBitmap(iBasicAnimationExt->iHost->ControlEnv()->WsSession()); |
|
324 User::LeaveIfError(iBitmap->Create(TSize(0,0), iBasicAnimationExt->iHost->ControlEnv()->ScreenDevice()->DisplayMode())); |
|
325 iMask = new (ELeave) CWsBitmap(iBasicAnimationExt->iHost->ControlEnv()->WsSession()); |
|
326 } |
|
327 else |
|
328 { |
|
329 iBitmap = new (ELeave) CFbsBitmap(); |
|
330 User::LeaveIfError(iBitmap->Create(TSize(0,0), CCoeEnv::Static()->ScreenDevice()->DisplayMode())); |
|
331 iMask = new (ELeave) CFbsBitmap(); |
|
332 } |
|
333 |
|
334 User::LeaveIfError(iMask->Create(TSize(0,0), EGray256)); |
|
335 |
|
336 iDataProvider->SetObserver(this); |
|
337 iDataProvider->StartL(); |
|
338 } |
|
339 |
|
340 // This ConstructL is called when an RWindow is provided |
|
341 void CBasicAnimation::ConstructL(const TDesC8& aDataType) |
|
342 { |
|
343 iDataType = HBufC8::NewL(aDataType.Length()); |
|
344 (*iDataType) = aDataType; |
|
345 |
|
346 iTls = CAnimationTls::NewL(); |
|
347 iAnimator = CAnimator::NewL(this); |
|
348 iRenderGc = CFbsBitGc::NewL(); |
|
349 iBitmap = new (ELeave) CWsBitmap(*iWs); |
|
350 User::LeaveIfError(iBitmap->Create(TSize(0,0), iWindow->DisplayMode())); |
|
351 iMask = new (ELeave) CWsBitmap(*iWs); |
|
352 User::LeaveIfError(iMask->Create(TSize(0,0), EGray256)); |
|
353 |
|
354 iDataProvider->SetObserver(this); |
|
355 iDataProvider->StartL(); |
|
356 } |
|
357 |
|
358 void CBasicAnimation::AnimatorInitialisedL(const TSize& aSize) |
|
359 { |
|
360 iSize = aSize; |
|
361 User::LeaveIfError(iBitmap->Resize(iSize)); |
|
362 User::LeaveIfError(iMask->Resize(iSize)); |
|
363 |
|
364 delete iBitmapDevice; |
|
365 iBitmapDevice = NULL; |
|
366 delete iMaskDevice; |
|
367 iMaskDevice = NULL; |
|
368 |
|
369 iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap); |
|
370 iMaskDevice = CFbsBitmapDevice::NewL(iMask); |
|
371 |
|
372 iRenderGc->Activate(iMaskDevice); |
|
373 iRenderGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
374 iRenderGc->SetBrushColor(KRgbBlack); |
|
375 iRenderGc->Clear(); |
|
376 |
|
377 iFlags |= EAnimationInitialised; |
|
378 |
|
379 if(iObserver) |
|
380 { |
|
381 iObserver->AnimationEvent(*this, MAnimationObserver::EAnimationInitialized, NULL); |
|
382 } |
|
383 } |
|
384 |
|
385 |
|
386 void CBasicAnimation::AnimatorResetL() |
|
387 { |
|
388 iFlags &= ~EAnimationInitialised; |
|
389 |
|
390 if (iBasicAnimationExt && iBasicAnimationExt->iHost) |
|
391 { |
|
392 iBasicAnimationExt->iHost->DrawNow(); |
|
393 } |
|
394 else if (iWindow) |
|
395 { |
|
396 iWindow->Invalidate(TRect(iPoint, iPoint + iSize)); |
|
397 } |
|
398 iSize.iWidth = 0; |
|
399 iSize.iHeight = 0; |
|
400 delete iBitmapDevice; |
|
401 iBitmapDevice = NULL; |
|
402 delete iMaskDevice; |
|
403 iMaskDevice = NULL; |
|
404 iFlags = 0; |
|
405 } |
|
406 |
|
407 const TPtrC8 CBasicAnimation::AnimatorDataType() const |
|
408 { |
|
409 return *iDataType; |
|
410 } |
|
411 |
|
412 CAnimationTicker& CBasicAnimation::AnimatorTicker() |
|
413 { |
|
414 return *iTls->Ticker(); |
|
415 } |
|
416 |
|
417 /** Reserved for future use */ |
|
418 EXPORT_C void CBasicAnimation::CBasicAnimation_Reserved1() {} |
|
419 |
|
420 /** Reserved for future use */ |
|
421 EXPORT_C void CBasicAnimation::CBasicAnimation_Reserved2() {} |
|
422 |
|
423 |