|
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 #include "bmpansrv.h" |
|
17 |
|
18 |
|
19 const TInt KAnimationGranularity = 5; |
|
20 |
|
21 // times |
|
22 const TInt KMilliToMicroSecondsFactor = 1000; |
|
23 |
|
24 |
|
25 // |
|
26 // CBitmapAnimFrameData |
|
27 // |
|
28 |
|
29 /** |
|
30 Creates a new empty frame object. |
|
31 |
|
32 @return A pointer to the new empty frame object. |
|
33 */ |
|
34 CBitmapAnimFrameData* CBitmapAnimFrameData::NewL() |
|
35 { |
|
36 CBitmapAnimFrameData* self = CBitmapAnimFrameData::NewLC(); |
|
37 CleanupStack::Pop(self); |
|
38 return self; |
|
39 } |
|
40 |
|
41 /** |
|
42 Constructs a new bitmap animation frame data object,and puts a pointer to it onto the cleanup stack. |
|
43 |
|
44 @return A pointer to the new empty frame data object or NULL if the disk is full. |
|
45 */ |
|
46 CBitmapAnimFrameData* CBitmapAnimFrameData::NewLC() |
|
47 { |
|
48 CBitmapAnimFrameData* self = new (ELeave) CBitmapAnimFrameData; |
|
49 CleanupStack::PushL(self); |
|
50 return self; |
|
51 } |
|
52 |
|
53 |
|
54 /** |
|
55 Empty default constructor. |
|
56 */ |
|
57 CBitmapAnimFrameData::CBitmapAnimFrameData() |
|
58 { |
|
59 } |
|
60 |
|
61 /** |
|
62 Frees resources owned by the object prior to deletion. |
|
63 */ |
|
64 CBitmapAnimFrameData::~CBitmapAnimFrameData() |
|
65 { |
|
66 if( iBitmap && (iBitmap != iMaskBitmap) ) |
|
67 { |
|
68 delete iBitmap; |
|
69 } |
|
70 |
|
71 if( iMaskBitmap ) |
|
72 { |
|
73 delete iMaskBitmap; |
|
74 } |
|
75 |
|
76 } |
|
77 |
|
78 |
|
79 /** |
|
80 Initialization of CBitmapAnimFrameData data members to NULL. |
|
81 */ |
|
82 void CBitmapAnimFrameData::InitialiseMembers() |
|
83 { |
|
84 if( iBitmap && (iBitmap != iMaskBitmap) ) |
|
85 { |
|
86 delete iBitmap; |
|
87 iBitmap = NULL; |
|
88 } |
|
89 |
|
90 if( iMaskBitmap ) |
|
91 { |
|
92 delete iMaskBitmap; |
|
93 iMaskBitmap = NULL; |
|
94 iBitmap = NULL; |
|
95 } |
|
96 |
|
97 |
|
98 iPosition.SetXY( 0, 0 ); |
|
99 iInterval = 0; |
|
100 } |
|
101 |
|
102 |
|
103 /** |
|
104 Creates bitmaps if they are not created earlier. |
|
105 */ |
|
106 void CBitmapAnimFrameData::CheckAndCreateBitmapsL() |
|
107 { |
|
108 if (iBitmap == NULL) |
|
109 { |
|
110 iBitmap = new(ELeave) CFbsBitmap(); |
|
111 } |
|
112 if (iMaskBitmap == NULL) |
|
113 { |
|
114 iMaskBitmap = new(ELeave) CFbsBitmap(); |
|
115 } |
|
116 } |
|
117 |
|
118 |
|
119 /** |
|
120 Un-packs the frame data arguments, aFrameDataArg, and uses this information to fill the frame |
|
121 data with two bitmaps, a position and a time interval. |
|
122 */ |
|
123 void CBitmapAnimFrameData::FillFrameDataL( const TFrameData& aFrameDataArg ) |
|
124 { |
|
125 // Create the icon by using the bitmap handles |
|
126 if ( aFrameDataArg.iBitmapHandle ) // Null member of sequence, time is only valid field in member data |
|
127 { |
|
128 iBitmap = new(ELeave) CFbsBitmap(); |
|
129 User::LeaveIfError(iBitmap->Duplicate(aFrameDataArg.iBitmapHandle)); |
|
130 if (aFrameDataArg.iMaskBitmapHandle) |
|
131 { |
|
132 iMaskBitmap = new(ELeave) CFbsBitmap(); |
|
133 User::LeaveIfError(iMaskBitmap->Duplicate(aFrameDataArg.iMaskBitmapHandle)); |
|
134 } |
|
135 |
|
136 iPosition = aFrameDataArg.iPosition; |
|
137 iInterval = (TTimeIntervalMicroSeconds32) ( aFrameDataArg.iIntervalInMilliSeconds * KMilliToMicroSecondsFactor ); |
|
138 } |
|
139 else |
|
140 { |
|
141 InitialiseMembers(); |
|
142 } |
|
143 |
|
144 } |
|
145 |
|
146 |
|
147 |
|
148 /** |
|
149 class CBitmapAnim |
|
150 */ |
|
151 |
|
152 /** |
|
153 Constructs a new bitmap animation object. |
|
154 */ |
|
155 CBitmapAnim::CBitmapAnim() : |
|
156 iBitmapAnimFrameDataArray(KAnimationGranularity), |
|
157 iFlags(ENoBitmapWindowRestoring), |
|
158 iIndex(-1), |
|
159 iNumberOfCycles(-1), |
|
160 iPosition(0,0) |
|
161 { |
|
162 } |
|
163 |
|
164 |
|
165 |
|
166 /** |
|
167 Frees resources owned by the object prior to deletion. |
|
168 */ |
|
169 CBitmapAnim::~CBitmapAnim() |
|
170 { |
|
171 StopAnimation(); |
|
172 delete iAnimTimer; |
|
173 delete iFlashTimer; |
|
174 iBitmapAnimFrameDataArray.ResetAndDestroy(); |
|
175 iBitmapAnimFrameDataArray.Close(); |
|
176 delete iBackgroundFrame; |
|
177 } |
|
178 |
|
179 |
|
180 |
|
181 /** |
|
182 Creates a new empty bitmap animation object. |
|
183 |
|
184 @return A pointer to the new empty bitmap animation object. |
|
185 */ |
|
186 CBitmapAnim* CBitmapAnim::NewL() |
|
187 { |
|
188 CBitmapAnim* self = new (ELeave) CBitmapAnim(); |
|
189 return self; |
|
190 } |
|
191 |
|
192 |
|
193 |
|
194 /** |
|
195 Pure virtual function from CAnim it creates the animation timer object. |
|
196 */ |
|
197 void CBitmapAnim::ConstructL(TAny* /*aArgs*/, TBool /*aHasFocus*/) |
|
198 { |
|
199 iAnimTimer = CBitmapAnimTimer::NewL(this); |
|
200 } |
|
201 |
|
202 void CBitmapAnim::Animate(TDateTime* /*aDateTime*/) |
|
203 { |
|
204 } |
|
205 |
|
206 |
|
207 |
|
208 /** |
|
209 Stops animation and resets animation frame data array. |
|
210 */ |
|
211 void CBitmapAnim::ResetFrameArray() |
|
212 { |
|
213 StopAnimation(); |
|
214 iBitmapAnimFrameDataArray.ResetAndDestroy(); |
|
215 } |
|
216 |
|
217 |
|
218 /** |
|
219 Appends a new frame, aFrame, to the frame array. |
|
220 */ |
|
221 void CBitmapAnim::AppendFrameL(const TFrameData& aFrameDataArg) |
|
222 { |
|
223 CBitmapAnimFrameData* dataFrame = CBitmapAnimFrameData::NewLC(); |
|
224 dataFrame->FillFrameDataL(aFrameDataArg); |
|
225 User::LeaveIfError(iBitmapAnimFrameDataArray.Append(dataFrame)); |
|
226 CleanupStack::Pop(dataFrame); |
|
227 } |
|
228 |
|
229 |
|
230 /** |
|
231 Pure virtual function from CAnim. |
|
232 */ |
|
233 void CBitmapAnim::Command(TInt aOpcode, TAny* aArgs) |
|
234 { |
|
235 switch (aOpcode) |
|
236 { |
|
237 case EBitmapAnimCommandClearDataFrames: |
|
238 ClearFrameData(); |
|
239 break; |
|
240 case EBitmapAnimCommandSetFlash: |
|
241 SetFlash(*(TBmpAnimAttributes*)aArgs); |
|
242 break; |
|
243 case EBitmapAnimCommandSetFrameIndex: |
|
244 SetIndexFrame(*(SBitmapAnimIndexFrame*)aArgs); |
|
245 break; |
|
246 case EBitmapAnimCommandSetFrameInterval: |
|
247 SetFrameInterval(*(TBmpAnimAttributes*)aArgs); |
|
248 break; |
|
249 case EBitmapAnimCommandSetNumberOfCycles: |
|
250 SetNumberOfCycles(*(SBitmapAnimNumberOfCycles*)aArgs); |
|
251 break; |
|
252 case EBitmapAnimCommandSetPlayMode: |
|
253 SetPlayMode(*(TBmpAnimAttributes*)aArgs); |
|
254 break; |
|
255 case EBitmapAnimCommandSetPosition: |
|
256 SetPosition(*(SBitmapAnimNewPosition*)aArgs); |
|
257 break; |
|
258 } |
|
259 } |
|
260 |
|
261 |
|
262 |
|
263 /** |
|
264 Pure virtual function from CAnim it handles the command received by the relative client. |
|
265 aOpcode determines the action that has to be taken while aArgs contains the information |
|
266 packed by the client. It returns KErrNone if no problem has occurred. |
|
267 */ |
|
268 TInt CBitmapAnim::CommandReplyL(TInt aOpcode, TAny* aArgs) |
|
269 { |
|
270 TInt error = KErrNone; |
|
271 switch (aOpcode) |
|
272 { |
|
273 case EBitmapAnimCommandClearDataFrames: |
|
274 ClearFrameData(); |
|
275 break; |
|
276 case EBitmapAnimCommandStartAnimation: |
|
277 StartAnimationL(); |
|
278 break; |
|
279 case EBitmapAnimCommandStopAnimation: |
|
280 StopAnimation(); |
|
281 break; |
|
282 case EBitmapAnimCommandSetBackgroundFrame: |
|
283 SetBackgroundFrameL(*(TFrameData*)aArgs); |
|
284 break; |
|
285 case EBitmapAnimCommandSetDataFrame: |
|
286 AppendFrameL(*(TFrameData*)aArgs); |
|
287 break; |
|
288 case EBitmapAnimCommandSetFlash: |
|
289 SetFlash(*(TBmpAnimAttributes*)aArgs); |
|
290 break; |
|
291 case EBitmapAnimCommandSetFrameIndex: |
|
292 error = SetIndexFrame(*(SBitmapAnimIndexFrame*)aArgs); |
|
293 break; |
|
294 case EBitmapAnimCommandSetFrameInterval: |
|
295 SetFrameInterval(*(TBmpAnimAttributes*)aArgs); |
|
296 break; |
|
297 case EBitmapAnimCommandSetNumberOfCycles: |
|
298 SetNumberOfCycles(*(SBitmapAnimNumberOfCycles*)aArgs); |
|
299 break; |
|
300 case EBitmapAnimCommandSetPlayMode: |
|
301 SetPlayMode(*(TBmpAnimAttributes*)aArgs); |
|
302 break; |
|
303 case EBitmapAnimCommandSetPosition: |
|
304 SetPosition(*(SBitmapAnimNewPosition*)aArgs); |
|
305 break; |
|
306 case EBitmapAnimCommandStartAnimationAndKeepLastFrame: |
|
307 iFlags |= EDisplayLastFrameWhenFinished; |
|
308 StartAnimationL(); |
|
309 break; |
|
310 case EBitmapAnimCommandResetFrameArray: |
|
311 ResetFrameArray(); |
|
312 break; |
|
313 default: |
|
314 error = KErrNotSupported; |
|
315 } |
|
316 return error; |
|
317 } |
|
318 |
|
319 |
|
320 |
|
321 /** |
|
322 Clears Frame data by stopping animation and resetting frame data array. |
|
323 */ |
|
324 void CBitmapAnim::ClearFrameData() |
|
325 { |
|
326 StopAnimation(); |
|
327 iBitmapAnimFrameDataArray.ResetAndDestroy(); |
|
328 iIndex = -1; |
|
329 } |
|
330 |
|
331 |
|
332 |
|
333 /** |
|
334 Pure virtual function from MAnimationTimer it is used to draw the next frame. It first updates |
|
335 the index frame, checks if the frame is displayable and if so it draws the frame otherwise it |
|
336 stops the animation. |
|
337 */ |
|
338 void CBitmapAnim::DisplayNextFrameL() |
|
339 { |
|
340 if (!IsRunning()) |
|
341 { |
|
342 return; |
|
343 } |
|
344 |
|
345 const TInt previousIndex = iIndex; |
|
346 UpdateCurrentIndex(); |
|
347 |
|
348 if (IsFrameDisplayable()) |
|
349 { |
|
350 if (!IsFrozen()) |
|
351 { |
|
352 DisplayFrame(previousIndex); |
|
353 } |
|
354 } |
|
355 else |
|
356 { |
|
357 iIndex = previousIndex; |
|
358 StopAnimation(); |
|
359 } |
|
360 } |
|
361 |
|
362 /** |
|
363 Draws the current frame in a particular position. |
|
364 */ |
|
365 void CBitmapAnim::DrawBitmap(TInt /*aPreviousIndex*/, TBool aRedraw) |
|
366 { |
|
367 __ASSERT_ALWAYS((iIndex>=0 && iIndex < Count()), Panic(EAnimationServerPanicIndexOutOfRange)); |
|
368 CBitmapAnimFrameData* frameData = iBitmapAnimFrameDataArray[iIndex]; |
|
369 |
|
370 if (frameData->iBitmap) |
|
371 { |
|
372 if (!aRedraw) |
|
373 { |
|
374 iWindowFunctions->ActivateGc(); |
|
375 } |
|
376 |
|
377 const TPoint framePosition = frameData->iPosition + iPosition; |
|
378 |
|
379 RenderFrameBackground(iIndex); |
|
380 |
|
381 if (frameData->iMaskBitmap) |
|
382 { |
|
383 iGc->BitBltMasked(framePosition, frameData->iBitmap, frameData->iBitmap->SizeInPixels(), frameData->iMaskBitmap, ETrue); |
|
384 } |
|
385 else |
|
386 { |
|
387 iGc->BitBlt(framePosition, frameData->iBitmap); |
|
388 } |
|
389 |
|
390 MAnimFreeTimerWindowFunctions* windowFunctions = WindowFunctions(); |
|
391 |
|
392 if (!aRedraw) |
|
393 { |
|
394 windowFunctions->DeactivateGc(); |
|
395 } |
|
396 |
|
397 windowFunctions->Update(); |
|
398 } |
|
399 } |
|
400 |
|
401 /** |
|
402 Sets the next call-back of the timer and draws the new frame. |
|
403 */ |
|
404 void CBitmapAnim::DisplayFrame(TInt aPreviousIndex) |
|
405 { |
|
406 TTimeIntervalMicroSeconds32 time = iBitmapAnimFrameDataArray[iIndex]->iInterval; |
|
407 if (time.Int() < 0) |
|
408 { |
|
409 time = iFrameInterval; |
|
410 } |
|
411 |
|
412 // Limits frame interval time |
|
413 const TTimeIntervalMicroSeconds32 KAnimationMinimumFrameInterval = 30 * KMilliToMicroSecondsFactor; |
|
414 |
|
415 __ASSERT_DEBUG(time >= KAnimationMinimumFrameInterval, RDebug::Print(_L("CBitmapAnim: frame interval was %d reset to %d."), time.Int(), KAnimationMinimumFrameInterval.Int())); |
|
416 time = Max(time, KAnimationMinimumFrameInterval); |
|
417 iAnimTimer->Cancel(); |
|
418 iAnimTimer->After(time); |
|
419 |
|
420 DrawBitmap(aPreviousIndex); |
|
421 } |
|
422 |
|
423 |
|
424 |
|
425 /** |
|
426 Flashes and draws the current frame. |
|
427 |
|
428 @param aFlash ETrue for the animation to flash, otherwise EFalse. |
|
429 */ |
|
430 void CBitmapAnim::FlashFrame(TBool aFlash) |
|
431 { |
|
432 const TTimeIntervalMicroSeconds32 KFlashInterval = 1000; |
|
433 |
|
434 if (aFlash) |
|
435 { |
|
436 iFlags |= EFlashing; |
|
437 } |
|
438 else |
|
439 { |
|
440 iFlags &= ~EFlashing; |
|
441 } |
|
442 |
|
443 iFlashTimer->After(KFlashInterval); |
|
444 |
|
445 DrawBitmap(); |
|
446 } |
|
447 |
|
448 |
|
449 |
|
450 /** |
|
451 Notifies change of focus. |
|
452 Overridden from virtual method CWindowAnim::FocusChanged(TBool aState). |
|
453 |
|
454 @param aState Indicates whether the focus has or has not changed. |
|
455 @see CWindowAnim::FocusChanged(TBool aState) |
|
456 */ |
|
457 void CBitmapAnim::FocusChanged(TBool aState) |
|
458 { |
|
459 if (aState) |
|
460 { |
|
461 iFlags &= ~EFrozen; |
|
462 if (IsRunning()) |
|
463 { |
|
464 TRAP_IGNORE(DisplayNextFrameL()); |
|
465 } |
|
466 } |
|
467 else |
|
468 { |
|
469 iFlags |= EFrozen; |
|
470 } |
|
471 } |
|
472 |
|
473 |
|
474 |
|
475 /** Handles raw events. |
|
476 Overridden from virtual method MEventHandler::OfferRawEvent(). |
|
477 This function does not handle the incoming events. |
|
478 |
|
479 @param aRawEvent The raw event to be processed |
|
480 @return ETrue if the raw event is handled by this function, EFalse if the function |
|
481 chooses not to process it. |
|
482 @see MEventHandler |
|
483 */ |
|
484 TBool CBitmapAnim::OfferRawEvent(const TRawEvent& /*aRawEvent*/) |
|
485 { |
|
486 return EFalse; |
|
487 } |
|
488 |
|
489 |
|
490 |
|
491 /** |
|
492 Redraws the current animation frame and the background bitmap. |
|
493 Overridden from virtual method CWindowAnim::Redraw(). |
|
494 |
|
495 @see CWindowAnim |
|
496 */ |
|
497 void CBitmapAnim::Redraw() |
|
498 { |
|
499 TWindowInfo parameter; |
|
500 WindowFunctions()->Parameters(parameter); |
|
501 const TRegion* redrawRegion; |
|
502 const TRegion* redrawShadowRegion; |
|
503 parameter.GetRedrawRegionAndRedrawShadowRegion(redrawRegion, redrawShadowRegion); |
|
504 |
|
505 // redraw the current animation frame if needed |
|
506 if (IsFrameDisplayable()) |
|
507 { |
|
508 // redraw frame unless we're absolutely sure it doesn't need doing |
|
509 TRect currentFrameScreenRect = CalcFrameRect(iIndex); |
|
510 currentFrameScreenRect.Move(parameter.iScreenPos.iTl); |
|
511 if (FrameNeedsRedrawing(redrawRegion, currentFrameScreenRect) || FrameNeedsRedrawing(redrawShadowRegion, currentFrameScreenRect)) |
|
512 { |
|
513 DrawBitmap(-1, ETrue); |
|
514 } |
|
515 } |
|
516 } |
|
517 |
|
518 |
|
519 /** |
|
520 Resets the animation to be in a valid state every time a stop request occurs. |
|
521 */ |
|
522 void CBitmapAnim::ResetAnimation() |
|
523 { |
|
524 iIndex = -1; |
|
525 iNumberOfCycles = -1; |
|
526 iFlags &= ~(ERunning|EPlayForwards|EPlayBackwards); |
|
527 iFlags |= ENoBitmapWindowRestoring; |
|
528 } |
|
529 |
|
530 |
|
531 /** |
|
532 Sets the background frame by using the information from aFrameDataArg. This will overwrite the |
|
533 existing background frame. |
|
534 */ |
|
535 void CBitmapAnim::SetBackgroundFrameL(TFrameData aFrameDataArg) |
|
536 { |
|
537 if (iBackgroundFrame) |
|
538 { |
|
539 delete iBackgroundFrame; |
|
540 iBackgroundFrame = NULL; |
|
541 } |
|
542 |
|
543 iBackgroundFrame = CBitmapAnimFrameData::NewL(); |
|
544 iBackgroundFrame->FillFrameDataL(aFrameDataArg); |
|
545 iBackgroundFrame->CheckAndCreateBitmapsL(); |
|
546 } |
|
547 |
|
548 |
|
549 |
|
550 /** |
|
551 Sets and un-sets the flash flag according to aFlash value. It can be called at any time after |
|
552 the animation has been set, and it has an immediate effect. |
|
553 */ |
|
554 void CBitmapAnim::SetFlash(TBmpAnimAttributes aFlash) |
|
555 { |
|
556 if (aFlash.iFlash) |
|
557 { |
|
558 iFlags |= EFlash; |
|
559 } |
|
560 else |
|
561 { |
|
562 iFlags &= ~EFlash; |
|
563 } |
|
564 } |
|
565 |
|
566 |
|
567 |
|
568 /** |
|
569 Sets the frame interval of the animation to aFrameInterval. It has an immediate effect. |
|
570 */ |
|
571 void CBitmapAnim::SetFrameInterval(TBmpAnimAttributes aFrameInterval) |
|
572 { |
|
573 __ASSERT_ALWAYS(aFrameInterval.iFrameIntervalInMilliSeconds >= 0, Panic(EAnimationServerPanicFrameIntervalNegative)); |
|
574 iFrameInterval = (aFrameInterval.iFrameIntervalInMilliSeconds * KMilliToMicroSecondsFactor); |
|
575 } |
|
576 |
|
577 |
|
578 |
|
579 /** |
|
580 Changes the index frame of the animation to be aIndexFrame and it has an immediate effect. |
|
581 */ |
|
582 TInt CBitmapAnim::SetIndexFrame(SBitmapAnimIndexFrame aIndexFrame) |
|
583 { |
|
584 TInt error = KErrNone; |
|
585 TInt backupFlags = iFlags; |
|
586 TInt oldNumberOfCycles = iNumberOfCycles; |
|
587 StopAnimation(); |
|
588 iIndex = aIndexFrame.iIndex; |
|
589 // Restore previous state. |
|
590 iNumberOfCycles = oldNumberOfCycles; |
|
591 iFlags = backupFlags; |
|
592 |
|
593 if (IsFrameDisplayable()) |
|
594 { |
|
595 DisplayFrame(); |
|
596 iFlags &= ~ENoBitmapWindowRestoring; |
|
597 } |
|
598 else |
|
599 { |
|
600 error = KErrOverflow; |
|
601 } |
|
602 return error; |
|
603 } |
|
604 |
|
605 |
|
606 /** |
|
607 Sets the number of times that all the frames have to be displayed. It has an immediate effect. |
|
608 */ |
|
609 void CBitmapAnim::SetNumberOfCycles(SBitmapAnimNumberOfCycles aNumberOfCycles) |
|
610 { |
|
611 TInt value = aNumberOfCycles.iCycles; |
|
612 |
|
613 if (value == 0) |
|
614 { |
|
615 value = 1; |
|
616 } |
|
617 |
|
618 iNumberOfCycles = value; |
|
619 } |
|
620 |
|
621 |
|
622 |
|
623 /** |
|
624 Sets the play mode of the animation to aPlayMode. It has an immediate effect. |
|
625 */ |
|
626 void CBitmapAnim::SetPlayMode(TBmpAnimAttributes aPlayMode) |
|
627 { |
|
628 |
|
629 TBool isRunning = IsRunning(); |
|
630 |
|
631 if( isRunning ) |
|
632 { |
|
633 StopAnimation(); |
|
634 } |
|
635 |
|
636 // EPlay = xx0x |
|
637 iFlags &= ~( EPlayModeBounce | EPlayModeCycle ); |
|
638 |
|
639 CBitmapAnimClientData::TPlayMode mode = aPlayMode.iPlayMode; |
|
640 |
|
641 switch (mode) |
|
642 { |
|
643 case CBitmapAnimClientData::EPlay: |
|
644 break; |
|
645 |
|
646 case CBitmapAnimClientData::ECycle: |
|
647 iFlags |= EPlayModeCycle; |
|
648 break; |
|
649 |
|
650 case CBitmapAnimClientData::EBounce: |
|
651 iFlags |= EPlayModeBounce; |
|
652 break; |
|
653 |
|
654 default: |
|
655 break; |
|
656 } |
|
657 |
|
658 |
|
659 if( isRunning ) |
|
660 { |
|
661 TRAP_IGNORE( StartAnimationL() ); |
|
662 } |
|
663 |
|
664 } |
|
665 |
|
666 |
|
667 |
|
668 /** |
|
669 Sets the position of the animation control to aNewPosition. |
|
670 aNewPosition is relative to the origin of the control's window |
|
671 */ |
|
672 void CBitmapAnim::SetPosition(SBitmapAnimNewPosition aNewPosition) |
|
673 { |
|
674 ClearFrameNow(iIndex); |
|
675 iPosition.iX = aNewPosition.iPosition.iX; |
|
676 iPosition.iY = aNewPosition.iPosition.iY; |
|
677 if (IsRunning()) |
|
678 { |
|
679 DrawBitmap(); |
|
680 } |
|
681 } |
|
682 |
|
683 |
|
684 |
|
685 /** |
|
686 Starts the animation routine. |
|
687 */ |
|
688 void CBitmapAnim::StartAnimationL() |
|
689 { |
|
690 if (iFunctions->WindowExtension()) |
|
691 { |
|
692 TWindowConfig windowConfig; |
|
693 iFunctions->WindowExtension()->WindowConfig(windowConfig); |
|
694 iWindowConfig = windowConfig.iFlags; |
|
695 } |
|
696 if (!IsRunning() && (Count() > 0) ) |
|
697 { |
|
698 iFlags |= EPlayForwards; |
|
699 iFlags |= ERunning; |
|
700 DisplayNextFrameL(); |
|
701 iFlags &= ~ENoBitmapWindowRestoring; |
|
702 } |
|
703 } |
|
704 |
|
705 |
|
706 |
|
707 /** |
|
708 Stops the animation by removing the last frame from the window and replacing the old contents. |
|
709 */ |
|
710 void CBitmapAnim::StopAnimation() |
|
711 { |
|
712 if (IsRunning()) |
|
713 { |
|
714 if (!(iFlags & EDisplayLastFrameWhenFinished)) |
|
715 { |
|
716 ClearFrameNow(iIndex); |
|
717 } |
|
718 |
|
719 ResetAnimation(); |
|
720 } |
|
721 if (iAnimTimer && iAnimTimer->IsActive()) |
|
722 { |
|
723 iAnimTimer->Cancel(); |
|
724 } |
|
725 } |
|
726 |
|
727 |
|
728 |
|
729 /** |
|
730 Calculates and finds frame's rectangle, relative to animation position. |
|
731 |
|
732 @param aIndex index value of the frame in frame data array. |
|
733 @return frame's rectangle. |
|
734 */ |
|
735 TRect CBitmapAnim::CalcFrameRect( TInt aIndex ) |
|
736 { |
|
737 TRect rect; |
|
738 |
|
739 CBitmapAnimFrameData* frameData = iBitmapAnimFrameDataArray[aIndex]; |
|
740 |
|
741 if ( (aIndex >= 0) && frameData && frameData->iBitmap ) |
|
742 { |
|
743 TSize frameSize = frameData->iBitmap->SizeInPixels(); |
|
744 TPoint framePosition = frameData->iPosition; |
|
745 framePosition += iPosition; |
|
746 rect.SetRect(framePosition, frameSize); |
|
747 } |
|
748 |
|
749 |
|
750 return rect; |
|
751 } |
|
752 |
|
753 /** |
|
754 Renders the background associated with the specified frame index. |
|
755 |
|
756 @param aIndex Index of frame to render background for. |
|
757 */ |
|
758 void CBitmapAnim::RenderFrameBackground(TInt aIndex) |
|
759 { |
|
760 if ((aIndex >= 0) && !(iFlags&ENoBitmapWindowRestoring) && iBackgroundFrame && iBackgroundFrame->iBitmap) |
|
761 { |
|
762 TRect frameRectOnWindow = CalcFrameRect(aIndex); |
|
763 TPoint framePosition = frameRectOnWindow.iTl; |
|
764 frameRectOnWindow.Move(-iPosition); |
|
765 iGc->BitBlt(framePosition, iBackgroundFrame->iBitmap, frameRectOnWindow); |
|
766 } |
|
767 } |
|
768 |
|
769 /** |
|
770 Clears the frame by calling ClearFrame function. |
|
771 Uses CFreeTimerWindowAnim timer functions which supports animations with their own timers. |
|
772 |
|
773 @param aIndex index value of the frame in frame data array. |
|
774 @see CFreeTimerWindowAnim |
|
775 */ |
|
776 void CBitmapAnim::ClearFrameNow(TInt /*aIndex*/) |
|
777 { |
|
778 iWindowFunctions->ActivateGc(); |
|
779 MAnimFreeTimerWindowFunctions* windowFunctions = WindowFunctions(); |
|
780 windowFunctions->DeactivateGc(); |
|
781 windowFunctions->Update(); |
|
782 } |
|
783 |
|
784 /** |
|
785 Updates the index indicating which frame should be displayed. The index value will be set |
|
786 to -1 when the animation routine is completed. |
|
787 */ |
|
788 void CBitmapAnim::UpdateCurrentIndex() |
|
789 { |
|
790 const TInt lastIndexFrame = iBitmapAnimFrameDataArray.Count() - 1; |
|
791 if (iIndex == lastIndexFrame) |
|
792 { |
|
793 if (--iNumberOfCycles == 0) |
|
794 { |
|
795 iIndex = -1; |
|
796 return; |
|
797 } |
|
798 |
|
799 |
|
800 if (iFlags&EPlayModeBounce) |
|
801 { |
|
802 iIndex--; |
|
803 |
|
804 if (iIndex < 0) |
|
805 { |
|
806 iIndex = 0; |
|
807 } |
|
808 |
|
809 iFlags &= ~EPlayForwards; |
|
810 iFlags |= EPlayBackwards; |
|
811 } |
|
812 else if (iFlags&EPlayModeCycle) |
|
813 { |
|
814 iIndex = 0; |
|
815 } |
|
816 else |
|
817 { |
|
818 iIndex = -1; |
|
819 } |
|
820 } |
|
821 else if (iIndex == 0) |
|
822 { |
|
823 if (iFlags&EPlayModeBounce) |
|
824 { |
|
825 if (--iNumberOfCycles == 0) |
|
826 { |
|
827 iIndex = -1; |
|
828 return; |
|
829 } |
|
830 |
|
831 iIndex ++; |
|
832 iFlags &= ~EPlayBackwards; |
|
833 iFlags |= EPlayForwards; |
|
834 } |
|
835 else if (iFlags&EPlayForwards) |
|
836 { |
|
837 iIndex ++; |
|
838 } |
|
839 else |
|
840 { |
|
841 iIndex = -1; |
|
842 } |
|
843 } |
|
844 else |
|
845 if (iFlags&EPlayForwards) |
|
846 { |
|
847 iIndex++; |
|
848 } |
|
849 else |
|
850 { |
|
851 iIndex--; |
|
852 } |
|
853 } |
|
854 |
|
855 /** |
|
856 returns true if there is any chance the frame needs to be redrawn, false otherwise |
|
857 */ |
|
858 TBool CBitmapAnim::FrameNeedsRedrawing(const TRegion* aRedrawRegion, TRect aFrameScreenRect) |
|
859 { |
|
860 // if the region is NULL, empty or doesn't intersect the frame rect, |
|
861 // assume we don't need to redraw the frame |
|
862 TBool ret = aRedrawRegion!=NULL; |
|
863 if (aRedrawRegion) |
|
864 { |
|
865 if (!aRedrawRegion->CheckError()) |
|
866 { |
|
867 if (aRedrawRegion->IsEmpty()) |
|
868 { |
|
869 ret = EFalse; |
|
870 } |
|
871 else |
|
872 { |
|
873 RRegionBuf<10> frameRegion; |
|
874 frameRegion.Copy(*aRedrawRegion); |
|
875 frameRegion.ClipRect(aFrameScreenRect); |
|
876 if (frameRegion.IsEmpty()) // TRegion::IsEmpty only returns true if the region contains no error |
|
877 { |
|
878 ret = EFalse; |
|
879 } |
|
880 frameRegion.Close(); |
|
881 } |
|
882 } |
|
883 } |
|
884 return ret; |
|
885 } |
|
886 |
|
887 |
|
888 |
|
889 // |
|
890 // CBitmapAnimTimer class |
|
891 // |
|
892 |
|
893 /** |
|
894 Constructs a new bitmap animation timer object,and adds the specified active object to the current active scheduler. |
|
895 |
|
896 @param aObserver a pointer to MBitmapAnimTimerObserver |
|
897 */ |
|
898 CBitmapAnimTimer::CBitmapAnimTimer(MBitmapAnimTimerObserver* aObserver) |
|
899 :CTimer(EPriorityStandard), |
|
900 iAnimate(aObserver) |
|
901 { |
|
902 CActiveScheduler::Add(this); |
|
903 } |
|
904 |
|
905 |
|
906 |
|
907 /** |
|
908 Frees resources owned by the object prior to deletion. |
|
909 */ |
|
910 CBitmapAnimTimer::~CBitmapAnimTimer() |
|
911 { |
|
912 } |
|
913 |
|
914 |
|
915 |
|
916 /** |
|
917 Creates a new bitmap animation timer object. |
|
918 |
|
919 @param aObserver A pointer to the MBitmapAnimTimerObserver |
|
920 @return A pointer to the new bitmap animation timer object. |
|
921 */ |
|
922 CBitmapAnimTimer* CBitmapAnimTimer::NewL(MBitmapAnimTimerObserver* aObserver) |
|
923 { |
|
924 CBitmapAnimTimer* timer=new(ELeave) CBitmapAnimTimer(aObserver); |
|
925 CleanupStack::PushL(timer); |
|
926 timer->ConstructL(); |
|
927 CleanupStack::Pop(); |
|
928 return timer; |
|
929 } |
|
930 |
|
931 |
|
932 |
|
933 /** |
|
934 Completes construction of the bitmap animation timer object and |
|
935 constructs a new asynchronous timer. |
|
936 */ |
|
937 void CBitmapAnimTimer::ConstructL() |
|
938 { |
|
939 CTimer::ConstructL(); |
|
940 } |
|
941 |
|
942 |
|
943 |
|
944 /** |
|
945 Handles an active object's request completion event. |
|
946 Invokes the function to draw the next frame |
|
947 */ |
|
948 void CBitmapAnimTimer::RunL() |
|
949 { |
|
950 iAnimate->DisplayNextFrameL(); |
|
951 } |
|
952 |
|
953 |
|
954 |
|
955 // |
|
956 // CBitmapAnimFlashTimer class |
|
957 // |
|
958 |
|
959 /** |
|
960 Constructs a new bitmap animation flash timer object,and adds the specified active object to the current active scheduler. |
|
961 |
|
962 @param aObserver a pointer to MBitmapAnimFlashTimerObserver |
|
963 */ |
|
964 CBitmapAnimFlashTimer::CBitmapAnimFlashTimer(MBitmapAnimFlashTimerObserver* aObserver) |
|
965 :CTimer(EPriorityStandard), |
|
966 iAnimate(aObserver), |
|
967 iFlash(EFalse) |
|
968 { |
|
969 CActiveScheduler::Add(this); |
|
970 } |
|
971 |
|
972 |
|
973 |
|
974 /** |
|
975 Frees resources owned by the object prior to deletion. |
|
976 */ |
|
977 CBitmapAnimFlashTimer::~CBitmapAnimFlashTimer() |
|
978 { |
|
979 } |
|
980 |
|
981 |
|
982 |
|
983 /** |
|
984 Creates a new bitmap animation flash timer object. |
|
985 |
|
986 @param aObserver A pointer to the MBitmapAnimFlashTimerObserver |
|
987 @return A pointer to the new bitmap animation flash timer object. |
|
988 */ |
|
989 CBitmapAnimFlashTimer* CBitmapAnimFlashTimer::NewL(MBitmapAnimFlashTimerObserver* aObserver) |
|
990 { |
|
991 CBitmapAnimFlashTimer* timer=new(ELeave) CBitmapAnimFlashTimer(aObserver); |
|
992 CleanupStack::PushL(timer); |
|
993 timer->ConstructL(); |
|
994 CleanupStack::Pop(); |
|
995 return timer; |
|
996 } |
|
997 |
|
998 |
|
999 |
|
1000 /** |
|
1001 Completes construction of the CBitmapAnimFlashTimer object and |
|
1002 constructs a new asynchronous timer. |
|
1003 */ |
|
1004 void CBitmapAnimFlashTimer::ConstructL() |
|
1005 { |
|
1006 CTimer::ConstructL(); |
|
1007 } |
|
1008 |
|
1009 |
|
1010 |
|
1011 void CBitmapAnimFlashTimer::DoCancel() |
|
1012 { |
|
1013 } |
|
1014 |
|
1015 |
|
1016 |
|
1017 /** |
|
1018 Handles an active object's request completion event. |
|
1019 Invokes the function to flash the animation frame and draw the bitmap. |
|
1020 */ |
|
1021 void CBitmapAnimFlashTimer::RunL() |
|
1022 { |
|
1023 iFlash = ~iFlash; |
|
1024 iAnimate->FlashFrame(iFlash); |
|
1025 } |
|
1026 |