|
1 /* |
|
2 * Copyright (c) 2008 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: CAlfPerfAppCoverTestCase implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "alfperfappcovertestcase.h" |
|
20 #include "alfperfapp.hrh" |
|
21 |
|
22 #include <aknutils.h> |
|
23 #include <gdi.h> |
|
24 #include <alf/alfenv.h> |
|
25 #include <alf/alfdisplay.h> |
|
26 #include <alf/alfgc.h> |
|
27 #include <alf/alfdisplay.h> |
|
28 #include <alf/alfcontrol.h> |
|
29 #include <alf/alfcontrolgroup.h> |
|
30 #include <alf/alfroster.h> |
|
31 #include <alf/alfcommand.h> |
|
32 #include <alf/alfevent.h> |
|
33 #include <alf/alftexturemanager.h> |
|
34 #include <alf/alfimagevisual.h> |
|
35 #include <alf/alftextvisual.h> |
|
36 #include <alf/alfimageloaderutil.h> |
|
37 #include <alf/alfutil.h> |
|
38 #include <alf/alflayout.h> |
|
39 #include <alf/alfviewportlayout.h> |
|
40 #include <alf/alfgridlayout.h> |
|
41 #include <alf/alfflowlayout.h> |
|
42 #include <alf/alfdecklayout.h> |
|
43 #include <alf/alftransformation.h> |
|
44 #include <alf/alfgradientbrush.h> |
|
45 #include <alf/alfborderbrush.h> |
|
46 #include <alf/alfbrusharray.h> |
|
47 |
|
48 #include <alfperfapp_imagetest.mbg> |
|
49 |
|
50 #include <alfperfappappui.h> |
|
51 |
|
52 |
|
53 /** |
|
54 * Control group for Cover test cases. |
|
55 */ |
|
56 const TInt KAlfPerfAppCoverControlGroup = 2; |
|
57 |
|
58 /** |
|
59 * Complete now command. |
|
60 */ |
|
61 const TInt KAlfPerfAppCoverCmdCompleteNow = 0x6000; |
|
62 |
|
63 |
|
64 /** |
|
65 * Cover flow test case control. |
|
66 */ |
|
67 class CAlfPerfAppCoverTestCaseControl : public CAlfControl |
|
68 { |
|
69 public: |
|
70 |
|
71 // Common constants |
|
72 static const TInt KTransitionTime; |
|
73 static const TInt KTransitionWaitTime; |
|
74 static const TInt KRotationAngle; |
|
75 |
|
76 static CAlfPerfAppCoverTestCaseControl* NewL( |
|
77 CAlfEnv& aEnv, TInt aCaseId, const TRect& aVisibleArea ); |
|
78 |
|
79 protected: |
|
80 /** |
|
81 * Constructor. |
|
82 */ |
|
83 CAlfPerfAppCoverTestCaseControl(); |
|
84 |
|
85 /** |
|
86 * Base class constructor. Derived classes may |
|
87 * override this, but base class needs to be called. |
|
88 */ |
|
89 virtual void ConstructL( |
|
90 CAlfEnv& aEnv, TInt aCaseId, const TRect& aVisibleArea ); |
|
91 |
|
92 public: |
|
93 /** |
|
94 * Destructor. |
|
95 */ |
|
96 ~CAlfPerfAppCoverTestCaseControl(); |
|
97 |
|
98 /** |
|
99 * Starts execution of the test case. By default, |
|
100 * request status is stored to local variable. |
|
101 */ |
|
102 void StartExecuteL( TRequestStatus& aStatus ); |
|
103 |
|
104 /** |
|
105 * Cancels execution. This control and environment will be |
|
106 * deleted soon after calling this method. |
|
107 */ |
|
108 void CancelExecution(); |
|
109 |
|
110 /** |
|
111 * Starts execution. |
|
112 * If this method leaves, then request must not be completed. |
|
113 * By default, this method completes immediately. |
|
114 */ |
|
115 virtual void DoStartExecuteL(); |
|
116 |
|
117 /** |
|
118 * Sets visible area. |
|
119 * @param aVisibleArea visible area. |
|
120 */ |
|
121 virtual void SetVisibleArea( const TRect& aVisibleArea ); |
|
122 |
|
123 // From base class CAlfControl: |
|
124 |
|
125 /** |
|
126 * Handles events. |
|
127 * Derived classes should forward to base class. |
|
128 * @param aEvent event to be handled. |
|
129 * @return ETrue if consumed, EFalse otherwise. |
|
130 */ |
|
131 virtual TBool OfferEventL( const TAlfEvent& aEvent ); |
|
132 |
|
133 protected: |
|
134 /** |
|
135 * Next cycle. |
|
136 */ |
|
137 void NextCycleL(); |
|
138 |
|
139 /** |
|
140 * Changes the view port left or right according to the given amount. |
|
141 * The amount can be negative or positive. |
|
142 */ |
|
143 void MoveImages( |
|
144 TReal32 aAmount, |
|
145 TReal32 aTransitionTime = KTransitionTime ); |
|
146 |
|
147 /** |
|
148 * Changes the scaling. The current image is scaled to normal size. |
|
149 * The previous image is scaled down. |
|
150 * This should be called when images are moved. |
|
151 * @see MoveImages |
|
152 */ |
|
153 void UpdateScaling( TReal32 aTransitionTime = KTransitionTime ); |
|
154 |
|
155 /** |
|
156 * Rotates Image from 0to 360 and 0 to -360 in alternate cycles. |
|
157 */ |
|
158 void RotateImage( ); |
|
159 |
|
160 /** |
|
161 * Clips the display layout, zooms into the image by scaling it to |
|
162 * multiples of cycle count and also moves the image with X and Y offset of 5. |
|
163 * It gives the Clip, zoom and panning effect to image. |
|
164 */ |
|
165 void ClipandZoom( ); |
|
166 |
|
167 /** |
|
168 * A way to round floating point number to integer. |
|
169 */ |
|
170 TInt RoundFloatToInt( TReal32 aVal ); |
|
171 |
|
172 /** |
|
173 * Completes automatically after specified duration. |
|
174 * @param aDuration duration in ms |
|
175 */ |
|
176 void CompleteAfterL( TInt aDuration ); |
|
177 |
|
178 /** |
|
179 * Completes current request. |
|
180 */ |
|
181 void CompleteNow( TInt aErrorCode ); |
|
182 |
|
183 /** |
|
184 * Returns test case id. |
|
185 */ |
|
186 inline TInt CaseId() const; |
|
187 |
|
188 /** |
|
189 * Returns ETrue if test case execution is still ongoing. |
|
190 */ |
|
191 inline TBool IsExecutionOngoing() const; |
|
192 |
|
193 /** |
|
194 * Test case id. |
|
195 */ |
|
196 TInt iCaseId; |
|
197 |
|
198 private: |
|
199 TInt iCycleCount; |
|
200 |
|
201 /** |
|
202 * Pointer to request status. |
|
203 * Not owned. |
|
204 */ |
|
205 TRequestStatus* iStatus; |
|
206 |
|
207 CAlfLayout* iLayout; |
|
208 TReal32 iViewportPosition; |
|
209 TReal32 iPreviousViewportPosition; |
|
210 CAlfViewportLayout* iViewport; |
|
211 }; |
|
212 |
|
213 |
|
214 // ============================ MEMBER FUNCTIONS =============================== |
|
215 // |
|
216 // ----------------------------------------------------------------------------- |
|
217 // Checks if specified case is supported by this class. |
|
218 // ----------------------------------------------------------------------------- |
|
219 // |
|
220 TBool CAlfPerfAppCoverTestCase::IsSupported( TInt aCaseId ) |
|
221 { |
|
222 return aCaseId == EAlfPerfAppCover |
|
223 || aCaseId == EAlfPerfAppCoverLandscape |
|
224 || aCaseId == EAlfPerfAppCoverRotate |
|
225 || aCaseId == EAlfPerfAppCoverClipZoomLargeImage |
|
226 || aCaseId == EAlfPerfAppCoverClipZoomBigImage |
|
227 || aCaseId == EAlfPerfAppCoverClipZoomVga |
|
228 || aCaseId == EAlfPerfAppCoverClipZoomAutoSize; |
|
229 } |
|
230 |
|
231 CAlfPerfAppCoverTestCase* CAlfPerfAppCoverTestCase::NewL( TInt aCaseId, TInt aSequenceIndex ) |
|
232 { |
|
233 if ( !IsSupported( aCaseId ) ) |
|
234 { |
|
235 User::Leave( KErrNotSupported ); |
|
236 } |
|
237 |
|
238 CAlfPerfAppCoverTestCase* self = |
|
239 new (ELeave) CAlfPerfAppCoverTestCase( aCaseId, aSequenceIndex); |
|
240 CleanupStack::PushL( self ); |
|
241 self->ConstructL(); |
|
242 CleanupStack::Pop( self ); |
|
243 return self; |
|
244 } |
|
245 |
|
246 CAlfPerfAppCoverTestCase::~CAlfPerfAppCoverTestCase() |
|
247 { |
|
248 if ( iEnv && iControl ) |
|
249 { |
|
250 iEnv->TextureManager().RemoveLoadObserver( this ); |
|
251 iControl->CancelExecution(); |
|
252 iEnv->DeleteControlGroup( KAlfPerfAppCoverControlGroup ); |
|
253 } |
|
254 } |
|
255 |
|
256 // ----------------------------------------------------------------------------- |
|
257 // Starts setup phase. |
|
258 // ----------------------------------------------------------------------------- |
|
259 // |
|
260 void CAlfPerfAppCoverTestCase::SetupL( |
|
261 CAlfEnv& aEnv, const TRect& /*aVisibleArea*/, TRequestStatus& aStatus ) |
|
262 { |
|
263 iEnv = &aEnv; |
|
264 // the status pointer is taken for completing it |
|
265 // when all the images are loaded. |
|
266 iStatus = &aStatus; |
|
267 |
|
268 CAlfPerfAppAppUi* appUi = (CAlfPerfAppAppUi*) EikonEnv()->AppUi(); |
|
269 iOrientation = appUi->Orientation(); |
|
270 |
|
271 switch ( iCaseId ) |
|
272 { |
|
273 case EAlfPerfAppCover: |
|
274 { |
|
275 appUi->SetOrientationL( CAknAppUiBase::EAppUiOrientationPortrait ); |
|
276 break; |
|
277 } |
|
278 |
|
279 case EAlfPerfAppCoverLandscape: |
|
280 { |
|
281 appUi->SetOrientationL( CAknAppUiBase::EAppUiOrientationLandscape ); |
|
282 break; |
|
283 } |
|
284 case EAlfPerfAppCoverRotate: |
|
285 case EAlfPerfAppCoverClipZoomLargeImage: |
|
286 case EAlfPerfAppCoverClipZoomBigImage: |
|
287 case EAlfPerfAppCoverClipZoomVga: |
|
288 case EAlfPerfAppCoverClipZoomAutoSize: |
|
289 { |
|
290 break; |
|
291 } |
|
292 default: |
|
293 User::Leave( KErrNotSupported ); |
|
294 break; |
|
295 } |
|
296 |
|
297 |
|
298 TRect rect; |
|
299 AknLayoutUtils::LayoutMetricsRect( |
|
300 AknLayoutUtils::EApplicationWindow, |
|
301 rect ); |
|
302 |
|
303 iEnv->SetFullScreenDrawing( ETrue ); |
|
304 CAlfDisplay& display = |
|
305 iEnv->NewDisplayL( rect, CAlfEnv::ENewDisplayFullScreen ); |
|
306 |
|
307 #if 1 |
|
308 // black seems to be the default color |
|
309 display.SetClearBackgroundL( CAlfDisplay::EClearWithColor ); |
|
310 #else |
|
311 // for development/debugging purposes it is easier to see different |
|
312 // components when there is a background. |
|
313 display.SetClearBackgroundL( CAlfDisplay::EClearWithSkinBackground ); |
|
314 #endif |
|
315 |
|
316 CAlfControlGroup& group = |
|
317 iEnv->NewControlGroupL( KAlfPerfAppCoverControlGroup ); |
|
318 |
|
319 iLoadedImages = 0; |
|
320 // the setup phase is completed only after the all images are |
|
321 // loaded by the texture manager. see the construction of the |
|
322 // control class. |
|
323 aEnv.TextureManager().AddLoadObserverL( this ); |
|
324 |
|
325 iControl = CAlfPerfAppCoverTestCaseControl::NewL( |
|
326 *iEnv, |
|
327 iCaseId, |
|
328 rect ); |
|
329 |
|
330 TRAPD(error,group.AppendL( iControl );) // ownership passed to control group. |
|
331 if(error != KErrNone) |
|
332 { |
|
333 delete iControl; |
|
334 iControl = 0; |
|
335 } |
|
336 |
|
337 |
|
338 display.Roster().ShowL( group ); |
|
339 } |
|
340 |
|
341 // ----------------------------------------------------------------------------- |
|
342 // Starts execution phase. |
|
343 // ----------------------------------------------------------------------------- |
|
344 // |
|
345 void CAlfPerfAppCoverTestCase::ExecuteL( TRequestStatus& aStatus ) |
|
346 { |
|
347 // SetupL must have been called first. |
|
348 __ASSERT_ALWAYS( iEnv, User::Invariant() ); |
|
349 __ASSERT_ALWAYS( iControl, User::Invariant() ); |
|
350 |
|
351 iControl->StartExecuteL( aStatus ); |
|
352 } |
|
353 |
|
354 // ----------------------------------------------------------------------------- |
|
355 // Tears down. |
|
356 // ----------------------------------------------------------------------------- |
|
357 // |
|
358 void CAlfPerfAppCoverTestCase::TearDown() |
|
359 { |
|
360 CAlfPerfAppAppUi* appUi = (CAlfPerfAppAppUi*) EikonEnv()->AppUi(); |
|
361 TRAP_IGNORE( appUi->SetOrientationL( iOrientation ) ); |
|
362 |
|
363 // Execution side will delete CAlfEnv, so it will delete everything |
|
364 // related to this. |
|
365 iEnv = NULL; |
|
366 iControl = NULL; |
|
367 } |
|
368 |
|
369 void CAlfPerfAppCoverTestCase::HandleVisibleAreaChange( const TRect& aRect ) |
|
370 { |
|
371 if ( iEnv && iControl ) |
|
372 { |
|
373 if ( iEnv->DisplayCount() > 0 ) |
|
374 { |
|
375 iEnv->PrimaryDisplay().SetVisibleArea( aRect ); |
|
376 } |
|
377 |
|
378 iControl->SetVisibleArea( aRect ); |
|
379 } |
|
380 } |
|
381 |
|
382 TInt CAlfPerfAppCoverTestCase::CaseID() |
|
383 { |
|
384 return iCaseId; |
|
385 } |
|
386 |
|
387 CAlfPerfAppCoverTestCase::CAlfPerfAppCoverTestCase( TInt aCaseId, TInt aSequenceIndex ) |
|
388 : CAlfPerfAppTestCase(aSequenceIndex), iCaseId ( aCaseId ) |
|
389 { |
|
390 } |
|
391 |
|
392 void CAlfPerfAppCoverTestCase::ConstructL() |
|
393 { |
|
394 } |
|
395 |
|
396 const TInt KNumberOfImages = 4; |
|
397 |
|
398 void CAlfPerfAppCoverTestCase::TextureLoadingCompleted( |
|
399 CAlfTexture& /*aTexture*/, TInt /*aTextureId*/, TInt aErrorCode) |
|
400 { |
|
401 if( aErrorCode != KErrNone && iStatus ) |
|
402 { |
|
403 User::RequestComplete( iStatus, aErrorCode ); |
|
404 iStatus = NULL; |
|
405 } |
|
406 iLoadedImages++; |
|
407 TInt noOfImagesToLoad = 1; |
|
408 if( CaseID() == EAlfPerfAppCover || |
|
409 CaseID() == EAlfPerfAppCoverLandscape ) |
|
410 { |
|
411 noOfImagesToLoad = KNumberOfImages; |
|
412 } |
|
413 if ( iStatus && ( iLoadedImages == noOfImagesToLoad ) ) |
|
414 { |
|
415 User::RequestComplete( iStatus, KErrNone ); |
|
416 iStatus = NULL; |
|
417 } |
|
418 } |
|
419 |
|
420 // Implementation of CAlfPerfAppCoverTestCaseControl: |
|
421 const TInt CAlfPerfAppCoverTestCaseControl::KTransitionTime = 1000; |
|
422 const TInt CAlfPerfAppCoverTestCaseControl::KTransitionWaitTime = 1000; |
|
423 const TInt CAlfPerfAppCoverTestCaseControl::KRotationAngle = 360; |
|
424 |
|
425 CAlfPerfAppCoverTestCaseControl* CAlfPerfAppCoverTestCaseControl::NewL( |
|
426 CAlfEnv& aEnv, TInt aCaseId, const TRect& aVisibleArea ) |
|
427 { |
|
428 CAlfPerfAppCoverTestCaseControl* |
|
429 result = new (ELeave) CAlfPerfAppCoverTestCaseControl; |
|
430 CleanupStack::PushL( result ); |
|
431 result->ConstructL( aEnv, aCaseId, aVisibleArea ); |
|
432 CleanupStack::Pop(); |
|
433 return result; |
|
434 } |
|
435 |
|
436 CAlfPerfAppCoverTestCaseControl::CAlfPerfAppCoverTestCaseControl() |
|
437 { |
|
438 } |
|
439 |
|
440 CAlfPerfAppCoverTestCaseControl::~CAlfPerfAppCoverTestCaseControl() |
|
441 { |
|
442 CompleteNow( KErrCancel ); |
|
443 } |
|
444 |
|
445 const TInt KShadowWidth = 20; // in pixels |
|
446 |
|
447 |
|
448 static void AddBorderBrushL( |
|
449 CAlfEnv& aEnv, |
|
450 CAlfVisual& aVisual, |
|
451 const TRgb& aColor, |
|
452 TInt aThickness, |
|
453 TInt aOffset ) |
|
454 { |
|
455 aVisual.EnableBrushesL(); |
|
456 CAlfBorderBrush* brush = CAlfBorderBrush::NewLC( |
|
457 aEnv, |
|
458 aThickness, |
|
459 aThickness, |
|
460 aOffset, |
|
461 aOffset ); |
|
462 brush->SetColor( aColor ); |
|
463 aVisual.Brushes()->AppendL( brush, EAlfHasOwnership ); |
|
464 CleanupStack::Pop( brush ); |
|
465 } |
|
466 |
|
467 static void AddFrameL( CAlfEnv& aEnv, CAlfVisual& aVisual ) |
|
468 { |
|
469 const TInt KNarrowBorderThickness = 2; |
|
470 const TInt KBorderThickness = 4; |
|
471 AddBorderBrushL( |
|
472 aEnv, |
|
473 aVisual, |
|
474 TRgb( 75, 75, 75 ), |
|
475 KNarrowBorderThickness, |
|
476 KNarrowBorderThickness ); |
|
477 AddBorderBrushL( |
|
478 aEnv, |
|
479 aVisual, |
|
480 TRgb( 55, 55, 55 ), |
|
481 KBorderThickness, |
|
482 KNarrowBorderThickness + KBorderThickness ); |
|
483 AddBorderBrushL( |
|
484 aEnv, |
|
485 aVisual, |
|
486 TRgb( 25, 25, 25 ), |
|
487 KNarrowBorderThickness, 2*KNarrowBorderThickness + KBorderThickness ); |
|
488 } |
|
489 |
|
490 const TReal32 KFocusedImageScale = 1.0f; |
|
491 const TReal32 KSmallImageScale = .65f; |
|
492 |
|
493 static void DownScaleImageL( CAlfVisual& aVisual, TInt aTransitionTime ) |
|
494 { |
|
495 TAlfTimedValue presser; |
|
496 presser.SetValueNow( KFocusedImageScale ); |
|
497 presser.SetTarget( KSmallImageScale, aTransitionTime ); |
|
498 CAlfTransformation& lessening = aVisual.Transformation(); |
|
499 lessening.LoadIdentity(); |
|
500 lessening.Scale( presser, presser ); |
|
501 } |
|
502 |
|
503 static CAlfGridLayout* AddItemL( |
|
504 CAlfEnv& aEnv, |
|
505 CAlfControl& aControl, |
|
506 CAlfLayout& aLayout, |
|
507 CAlfTexture& aTexture ) |
|
508 { |
|
509 // grid size: two lines, one item on the line |
|
510 CAlfGridLayout* item = CAlfGridLayout::AddNewL( aControl, 1, 1, &aLayout ); |
|
511 |
|
512 // solid background for the item |
|
513 item->EnableBrushesL(); |
|
514 CAlfGradientBrush* brush = CAlfGradientBrush::NewLC( aEnv ); |
|
515 brush->SetColor( TRgb( 60, 60, 60 ) ); // some gray |
|
516 item->Brushes()->AppendL( brush, EAlfHasOwnership ); |
|
517 CleanupStack::Pop( brush ); |
|
518 |
|
519 RArray<TInt> weights; |
|
520 CleanupClosePushL( weights ); |
|
521 // this makes the image space much larger than the text box below it. |
|
522 User::LeaveIfError( weights.Append( 100 ) ); |
|
523 User::LeaveIfError( weights.Append( 15 ) ); |
|
524 item->SetRowsL( weights ); |
|
525 CleanupStack::PopAndDestroy(); |
|
526 |
|
527 CAlfImageVisual* visual = CAlfImageVisual::AddNewL( aControl, item ); |
|
528 visual->SetImage( TAlfImage( aTexture ) ); |
|
529 visual->EnableTransformationL(); |
|
530 |
|
531 return item; |
|
532 } |
|
533 |
|
534 static CAlfGridLayout* AddItemTextL( |
|
535 CAlfControl& aControl, |
|
536 CAlfLayout& aParent, |
|
537 const TDesC& aArtist, |
|
538 const TDesC& aTitle ) |
|
539 { |
|
540 // creates a grid for holding text lines. |
|
541 // grid size: two lines, one item on the line |
|
542 CAlfGridLayout* texts = CAlfGridLayout::AddNewL( aControl, 1, 2, &aParent ); |
|
543 texts->EnableTransformationL(); |
|
544 |
|
545 CAlfTextVisual* upper = CAlfTextVisual::AddNewL( aControl, texts ); |
|
546 upper->SetStyle( EAlfTextStyleNormal, EAlfBackgroundTypeDark ); |
|
547 upper->SetWrapping( CAlfTextVisual::ELineWrapTruncate ); |
|
548 upper->SetTextL( aArtist ); |
|
549 CAlfTextVisual* lower = CAlfTextVisual::AddNewL( aControl, texts ); |
|
550 lower->SetStyle( EAlfTextStyleSmall ); |
|
551 lower->SetWrapping( CAlfTextVisual::ELineWrapTruncate ); |
|
552 lower->SetTextL( aTitle ); |
|
553 |
|
554 return texts; |
|
555 } |
|
556 |
|
557 static void GetImageTestCasePrivatePath( TFileName& aPath ) |
|
558 { |
|
559 CEikonEnv::Static()->FsSession().PrivatePath( aPath ); |
|
560 ::CompleteWithAppPath( aPath ); |
|
561 } |
|
562 |
|
563 const TReal32 KViewportOffset = -.25f; |
|
564 const TReal32 KViewportOffsetY = -.25f; |
|
565 |
|
566 void CAlfPerfAppCoverTestCaseControl::ConstructL( |
|
567 CAlfEnv& aEnv, TInt aCaseId, const TRect& aVisibleArea ) |
|
568 { |
|
569 iCaseId = aCaseId; |
|
570 CAlfControl::ConstructL( aEnv ); |
|
571 |
|
572 TFileName privatePath; |
|
573 GetImageTestCasePrivatePath( privatePath ); |
|
574 aEnv.TextureManager().SetImagePathL( privatePath ); |
|
575 |
|
576 // this is the top most visual |
|
577 CAlfDeckLayout* top = CAlfDeckLayout::AddNewL( *this ); |
|
578 |
|
579 // view port for scrolling |
|
580 // this viewport needs to be added first for the deck |
|
581 // to be under the shadows. |
|
582 iViewport = CAlfViewportLayout::AddNewL( *this, top ); |
|
583 iViewport->SetClipping( EFalse ); |
|
584 |
|
585 iViewport->SetViewportSize( TAlfRealSize( 1.5, 1.5 ), 0 ); |
|
586 iViewport->SetViewportPos( |
|
587 TAlfRealPoint( |
|
588 iViewportPosition + KViewportOffset, |
|
589 KViewportOffsetY ), |
|
590 0 ); |
|
591 // building the grid for holding images and stuff scrolled |
|
592 iLayout = CAlfGridLayout::AddNewL( |
|
593 *this, |
|
594 1, |
|
595 1, // just one line of images |
|
596 iViewport ); |
|
597 TBuf<50> KImage = _L("alfphotos_small1.jpg"); |
|
598 TInt textureFlag = EAlfTextureFlagRetainResolution; |
|
599 switch(CaseId()) |
|
600 { |
|
601 case EAlfPerfAppCover: |
|
602 case EAlfPerfAppCoverLandscape: |
|
603 { |
|
604 // one liner grid with left shadow, empty space, and right shadow |
|
605 CAlfGridLayout* shadows = CAlfGridLayout::AddNewL( *this, 3, 1, top ); |
|
606 |
|
607 RArray<TInt> weights; |
|
608 CleanupClosePushL( weights ); |
|
609 // the shadows are only small portition of |
|
610 // the size of the empty space between them |
|
611 User::LeaveIfError( weights.Append( 5 ) ); |
|
612 User::LeaveIfError( weights.Append( 200 ) ); |
|
613 User::LeaveIfError( weights.Append( 5 ) ); |
|
614 shadows->SetColumnsL( weights ); |
|
615 CleanupStack::PopAndDestroy(); |
|
616 |
|
617 // building of the left side shadow |
|
618 CAlfImageVisual* leftShadow = CAlfImageVisual::AddNewL( *this, shadows ); |
|
619 leftShadow->SetFlag( EAlfVisualFlagManualSize ); |
|
620 leftShadow->SetSize( |
|
621 TAlfRealPoint( KShadowWidth, aVisibleArea.Height() ) ); |
|
622 leftShadow->EnableBrushesL(); |
|
623 CAlfGradientBrush* leftBrush = CAlfGradientBrush::NewLC( aEnv ); |
|
624 leftBrush->SetLayer( EAlfBrushLayerForeground ); |
|
625 leftBrush->SetColor( KRgbBlack, 1.f ); |
|
626 leftBrush->AppendColorL( 0.f, KRgbBlack, 1.f ); |
|
627 leftBrush->AppendColorL( 1.0f, KRgbBlack, 0.f ); |
|
628 leftShadow->Brushes()->AppendL( leftBrush, EAlfHasOwnership ); |
|
629 CleanupStack::Pop( leftBrush ); |
|
630 |
|
631 // this is just an empty visual to get the layout correct, |
|
632 // shadows take small portitions on left and right. |
|
633 // middle part of the screen is left empty for the viewport. |
|
634 CAlfImageVisual* emptySpace = CAlfImageVisual::AddNewL( *this, shadows ); |
|
635 |
|
636 // building of the right side shadow |
|
637 CAlfImageVisual* rightShadow = CAlfImageVisual::AddNewL( *this, shadows ); |
|
638 rightShadow->SetFlag( EAlfVisualFlagManualSize ); |
|
639 rightShadow->SetSize( |
|
640 TAlfRealPoint( KShadowWidth, aVisibleArea.Height() ) ); |
|
641 rightShadow->EnableBrushesL(); |
|
642 CAlfGradientBrush* rightBrush = CAlfGradientBrush::NewLC( aEnv ); |
|
643 rightBrush->SetLayer( EAlfBrushLayerForeground ); |
|
644 rightBrush->SetColor( KRgbBlack, 0.f ); |
|
645 rightBrush->AppendColorL( .0f, KRgbBlack, 0.f ); |
|
646 rightBrush->AppendColorL( 1.0f, KRgbBlack, 1.f ); |
|
647 rightShadow->Brushes()->AppendL( rightBrush, EAlfHasOwnership ); |
|
648 CleanupStack::Pop( rightBrush ); |
|
649 |
|
650 // NOTE: Now using small images for OpenVG, because of memory issues. |
|
651 // These files may be replaced for BitGDI if needed. |
|
652 _LIT( KImage2, "alfphotos_small2.jpg"); |
|
653 _LIT( KImage3, "alfphotos_small3.jpg"); |
|
654 _LIT( KImage4, "alfphotos_small4.jpg"); |
|
655 KImage = _L("alfphotos_small1.jpg"); |
|
656 |
|
657 static_cast<CAlfGridLayout* >( iLayout )->SetColumns( KNumberOfImages ); |
|
658 iViewport->SetVirtualSize( TAlfRealSize( KNumberOfImages, 1.0 ), 0 ); |
|
659 |
|
660 CAlfTexture& texture2 = aEnv.TextureManager().LoadTextureL( |
|
661 KImage2, |
|
662 TAlfTextureFlags( textureFlag ), |
|
663 KAlfAutoGeneratedTextureId ); |
|
664 |
|
665 CAlfTexture& texture3 = aEnv.TextureManager().LoadTextureL( |
|
666 KImage3, |
|
667 TAlfTextureFlags( textureFlag ), |
|
668 KAlfAutoGeneratedTextureId ); |
|
669 |
|
670 CAlfTexture& texture4 = aEnv.TextureManager().LoadTextureL( |
|
671 KImage4, |
|
672 TAlfTextureFlags( textureFlag ), |
|
673 KAlfAutoGeneratedTextureId ); |
|
674 |
|
675 CAlfGridLayout* visual2 = AddItemL( aEnv, *this, *iLayout, texture2 ); |
|
676 visual2->EnableTransformationL(); |
|
677 AddFrameL( aEnv, *visual2 ); |
|
678 |
|
679 CAlfGridLayout* visual3 = AddItemL( aEnv, *this, *iLayout, texture3 ); |
|
680 visual3->EnableTransformationL(); |
|
681 AddFrameL( aEnv, *visual3 ); |
|
682 |
|
683 CAlfGridLayout* visual4 = AddItemL( aEnv, *this, *iLayout, texture4 ); |
|
684 visual4->EnableTransformationL(); |
|
685 AddFrameL( aEnv, *visual4 ); |
|
686 |
|
687 CAlfGridLayout* text2 = AddItemTextL( |
|
688 *this, *visual2, _L( "Gwen Stefani" ), _L("Hollaback Girl") ); |
|
689 |
|
690 CAlfGridLayout* text3 = AddItemTextL( |
|
691 *this, *visual3, _L( "No Doubt" ), _L("Don't Speak") ); |
|
692 |
|
693 CAlfGridLayout* text4 = AddItemTextL( |
|
694 *this, *visual4, _L( "Jenni Vartiainen" ), _L("Ihmisten edessä") ); |
|
695 |
|
696 DownScaleImageL( *visual2, 0 ); |
|
697 DownScaleImageL( *visual3, 0 ); |
|
698 DownScaleImageL( *visual4, 0 ); |
|
699 break; |
|
700 } |
|
701 case EAlfPerfAppCoverRotate: |
|
702 { |
|
703 KImage = _L("alfphotos_small1.jpg"); |
|
704 break; |
|
705 } |
|
706 case EAlfPerfAppCoverClipZoomLargeImage: |
|
707 { |
|
708 KImage = _L("alfphotos_5mpx.jpg"); |
|
709 iLayout->SetClipping( ETrue ); |
|
710 iViewport->SetClipping( ETrue ); |
|
711 top->SetClipping( ETrue ); |
|
712 break; |
|
713 } |
|
714 case EAlfPerfAppCoverClipZoomBigImage: |
|
715 { |
|
716 KImage = _L("alfphotos_2mpx.jpg"); |
|
717 iLayout->SetClipping( ETrue ); |
|
718 iViewport->SetClipping( ETrue ); |
|
719 top->SetClipping( ETrue ); |
|
720 break; |
|
721 } |
|
722 case EAlfPerfAppCoverClipZoomVga: |
|
723 { |
|
724 KImage = _L("alfphotos_vga.jpg"); |
|
725 iLayout->SetClipping( ETrue ); |
|
726 iViewport->SetClipping( ETrue ); |
|
727 top->SetClipping( ETrue ); |
|
728 break; |
|
729 } |
|
730 case EAlfPerfAppCoverClipZoomAutoSize: |
|
731 { |
|
732 KImage = _L("alfphotos_small9.jpg"); |
|
733 iLayout->SetClipping( ETrue ); |
|
734 iViewport->SetClipping( ETrue ); |
|
735 top->SetClipping( ETrue ); |
|
736 textureFlag |= EAlfTextureFlagAutoSize; |
|
737 break; |
|
738 } |
|
739 } |
|
740 CAlfTexture& texture1 = aEnv.TextureManager().LoadTextureL( |
|
741 KImage, |
|
742 TAlfTextureFlags( textureFlag ), |
|
743 KAlfAutoGeneratedTextureId ); |
|
744 CAlfGridLayout* visual1 = AddItemL( aEnv, *this, *iLayout, texture1 ); |
|
745 CAlfGridLayout* text1 = AddItemTextL( |
|
746 *this, *visual1, _L( "TikTak" ), _L("Sinkut 99 - 07 Disc 1") ); |
|
747 visual1->EnableTransformationL(); |
|
748 visual1->Visual( 0 ).SetClipping( EFalse ); |
|
749 if ( CaseId() == EAlfPerfAppCover || |
|
750 CaseId() == EAlfPerfAppCoverLandscape ) |
|
751 { |
|
752 AddFrameL( aEnv, *visual1 ); |
|
753 DownScaleImageL( *visual1, 0 ); |
|
754 } |
|
755 } |
|
756 |
|
757 void CAlfPerfAppCoverTestCaseControl::StartExecuteL( TRequestStatus& aStatus ) |
|
758 { |
|
759 iCycleCount = 0; |
|
760 iViewportPosition = 0; |
|
761 iPreviousViewportPosition = -1; // no previous position |
|
762 |
|
763 iStatus = &aStatus; |
|
764 *iStatus = KRequestPending; |
|
765 |
|
766 TRAPD( err, DoStartExecuteL() ); |
|
767 if ( err != KErrNone ) |
|
768 { |
|
769 iStatus = NULL; |
|
770 User::Leave( err ); |
|
771 } |
|
772 } |
|
773 |
|
774 void CAlfPerfAppCoverTestCaseControl::CancelExecution() |
|
775 { |
|
776 CompleteNow( KErrCancel ); |
|
777 } |
|
778 |
|
779 void CAlfPerfAppCoverTestCaseControl::DoStartExecuteL() |
|
780 { |
|
781 NextCycleL(); |
|
782 CompleteAfterL( KTransitionWaitTime ); |
|
783 } |
|
784 |
|
785 void CAlfPerfAppCoverTestCaseControl::SetVisibleArea( |
|
786 const TRect& /*aVisibleArea*/ ) |
|
787 { |
|
788 } |
|
789 |
|
790 TBool CAlfPerfAppCoverTestCaseControl::OfferEventL( const TAlfEvent& aEvent ) |
|
791 { |
|
792 if ( aEvent.IsCustomEvent() && |
|
793 aEvent.CustomParameter() == KAlfPerfAppCoverCmdCompleteNow ) |
|
794 { |
|
795 const TInt KNumberOfExecutedMovements = 15; |
|
796 if ( iCycleCount < KNumberOfExecutedMovements ) |
|
797 { |
|
798 NextCycleL(); |
|
799 CompleteAfterL( KTransitionWaitTime ); |
|
800 } |
|
801 else |
|
802 { |
|
803 CompleteNow( KErrNone ); |
|
804 } |
|
805 |
|
806 return ETrue; |
|
807 } |
|
808 |
|
809 return CAlfControl::OfferEventL( aEvent ); |
|
810 } |
|
811 |
|
812 void CAlfPerfAppCoverTestCaseControl::NextCycleL() |
|
813 { |
|
814 static const TReal32 movements[] = { -1, -1, -1, 1, 1, 1 }; |
|
815 const TInt size = 6; //sizeof movements; |
|
816 const TInt index = iCycleCount % size; |
|
817 |
|
818 |
|
819 switch(CaseId()) |
|
820 { |
|
821 case EAlfPerfAppCoverRotate: |
|
822 RotateImage( ); |
|
823 break; |
|
824 case EAlfPerfAppCover: |
|
825 case EAlfPerfAppCoverLandscape: |
|
826 MoveImages( movements[ index ] ); |
|
827 UpdateScaling(); |
|
828 break; |
|
829 case EAlfPerfAppCoverClipZoomLargeImage: |
|
830 case EAlfPerfAppCoverClipZoomBigImage: |
|
831 case EAlfPerfAppCoverClipZoomVga: |
|
832 case EAlfPerfAppCoverClipZoomAutoSize: |
|
833 ClipandZoom(); |
|
834 break; |
|
835 } |
|
836 ++iCycleCount; |
|
837 } |
|
838 |
|
839 void CAlfPerfAppCoverTestCaseControl::MoveImages( |
|
840 TReal32 aAmount, |
|
841 TReal32 aTransitionTime ) |
|
842 { |
|
843 iPreviousViewportPosition = iViewportPosition; |
|
844 iViewportPosition -= aAmount; |
|
845 |
|
846 if ( iViewportPosition < 0 ) |
|
847 { |
|
848 iViewportPosition = 0; |
|
849 } |
|
850 else if ( iViewportPosition > ( KNumberOfImages - 1.0 ) ) |
|
851 { |
|
852 iViewportPosition = KNumberOfImages - 1.0; |
|
853 } |
|
854 |
|
855 iViewport->SetViewportPos( |
|
856 TAlfRealPoint( iViewportPosition + KViewportOffset, KViewportOffsetY ), |
|
857 aTransitionTime ); |
|
858 } |
|
859 |
|
860 void CAlfPerfAppCoverTestCaseControl::UpdateScaling( |
|
861 TReal32 aTransitionTime ) |
|
862 { |
|
863 const TInt current = RoundFloatToInt( iViewportPosition ); |
|
864 const TInt previous = RoundFloatToInt( iPreviousViewportPosition ); |
|
865 |
|
866 if ( previous >= 0 ) |
|
867 { |
|
868 CAlfVisual& currentVisual = iLayout->Visual( current ); |
|
869 CAlfVisual& previousVisual = iLayout->Visual( previous ); |
|
870 |
|
871 TAlfTimedValue puller; |
|
872 puller.SetValueNow( KSmallImageScale ); |
|
873 puller.SetTarget( KFocusedImageScale, aTransitionTime ); |
|
874 CAlfTransformation& enlarging = currentVisual.Transformation(); |
|
875 enlarging.LoadIdentity(); |
|
876 enlarging.Scale( puller, puller ); |
|
877 |
|
878 TRAP_IGNORE(DownScaleImageL( previousVisual, aTransitionTime )); |
|
879 } |
|
880 } |
|
881 |
|
882 void CAlfPerfAppCoverTestCaseControl::RotateImage( ) |
|
883 { |
|
884 TInt angle = KRotationAngle; |
|
885 if ( iCycleCount%2 ) |
|
886 { |
|
887 angle = -KRotationAngle; |
|
888 } |
|
889 |
|
890 CAlfVisual& currentVisual = iLayout->Visual( 0 ); |
|
891 TAlfTimedValue rotator; |
|
892 rotator.SetValueNow( 0 ); |
|
893 rotator.SetTarget( angle, KTransitionTime ); |
|
894 CAlfTransformation& rotation = currentVisual.Transformation(); |
|
895 rotation.LoadIdentity(); |
|
896 rotation.Rotate( rotator ); |
|
897 } |
|
898 |
|
899 void CAlfPerfAppCoverTestCaseControl::ClipandZoom( ) |
|
900 { |
|
901 CAlfLayout& layout = static_cast< CAlfLayout& >( iLayout->Visual( 0 ) ); |
|
902 CAlfVisual& imgVisual = layout.Visual( 0 ); |
|
903 imgVisual.Move( TAlfRealPoint( -5, -5 ), KTransitionTime); |
|
904 |
|
905 TAlfTimedValue scaler; |
|
906 scaler.SetValueNow( KFocusedImageScale * ( iCycleCount + 1 ) ); |
|
907 scaler.SetTarget( KFocusedImageScale * ( iCycleCount + 2 ) , KTransitionTime ); |
|
908 CAlfTransformation& enlarging = layout.Transformation(); |
|
909 enlarging.LoadIdentity(); |
|
910 enlarging.Scale( scaler, scaler ); |
|
911 } |
|
912 |
|
913 TInt CAlfPerfAppCoverTestCaseControl::RoundFloatToInt( TReal32 aVal ) |
|
914 { |
|
915 return aVal < 0 ? (TInt)( aVal - 0.5f ) : (TInt)( aVal + 0.5f ); |
|
916 } |
|
917 |
|
918 void CAlfPerfAppCoverTestCaseControl::CompleteAfterL( TInt aDuration ) |
|
919 { |
|
920 // In order to use this service, base class StartExecuteL must |
|
921 // have been called. |
|
922 __ASSERT_ALWAYS( iStatus, User::Invariant() ); |
|
923 |
|
924 TAlfCustomEventCommand command( KAlfPerfAppCoverCmdCompleteNow, this ); |
|
925 User::LeaveIfError( Env().Send( command, aDuration ) ); |
|
926 } |
|
927 |
|
928 void CAlfPerfAppCoverTestCaseControl::CompleteNow( TInt aErrorCode ) |
|
929 { |
|
930 if ( iStatus ) |
|
931 { |
|
932 User::RequestComplete( iStatus, aErrorCode ); |
|
933 iStatus = NULL; |
|
934 } |
|
935 } |
|
936 |
|
937 inline TInt CAlfPerfAppCoverTestCaseControl::CaseId() const |
|
938 { |
|
939 return iCaseId; |
|
940 } |
|
941 |
|
942 inline TBool CAlfPerfAppCoverTestCaseControl::IsExecutionOngoing() const |
|
943 { |
|
944 return ( iStatus != NULL ); |
|
945 } |
|
946 |
|
947 |
|
948 |