Fix the scalability issue on dali-demo
[platform/core/uifw/dali-demo.git] / examples / scroll-view / scroll-view-example.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // EXTERNAL INCLUDES
19 #include <sstream>
20
21 // INTERNAL INCLUDES
22 #include "../shared/view.h"
23 #include <dali/dali.h>
24 #include <dali-toolkit/dali-toolkit.h>
25
26 using namespace std;
27 using namespace Dali;
28 using namespace Dali::Toolkit;
29
30 namespace
31 {
32 const char * const BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-default.png" );
33 const char * const TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
34 const char * const APPLICATION_TITLE( "ScrollView" );
35 const char * const EFFECT_OUTER_CUBE_IMAGE( DALI_IMAGE_DIR "icon-scroll-view-outer-cube.png" );
36 const char * const EFFECT_DEPTH_IMAGE( DALI_IMAGE_DIR "icon-scroll-view-depth.png" );
37 const char * const EFFECT_INNER_CUBE_IMAGE( DALI_IMAGE_DIR "icon-scroll-view-inner-cube.png" );
38 const char * const EFFECT_CAROUSEL_IMAGE( DALI_IMAGE_DIR "icon-scroll-view-carousel.png" );
39 const char * const EFFECT_SPIRAL_IMAGE( DALI_IMAGE_DIR "icon-scroll-view-spiral.png" );
40
41 const Vector3 ICON_SIZE(100.0f, 100.0f, 0.0f);
42
43 const char* EFFECT_MODE_NAME[] = {
44     "OuterCube",
45     "Depth",
46     "Cube",
47     "InnerCube",
48     "Carousel",
49     "Spiral",
50 };
51
52 const char * const IMAGE_PATHS[] = {
53     DALI_IMAGE_DIR "gallery-medium-1.jpg",
54     DALI_IMAGE_DIR "gallery-medium-2.jpg",
55     DALI_IMAGE_DIR "gallery-medium-3.jpg",
56     DALI_IMAGE_DIR "gallery-medium-4.jpg",
57     DALI_IMAGE_DIR "gallery-medium-5.jpg",
58     DALI_IMAGE_DIR "gallery-medium-6.jpg",
59     DALI_IMAGE_DIR "gallery-medium-7.jpg",
60     DALI_IMAGE_DIR "gallery-medium-8.jpg",
61     DALI_IMAGE_DIR "gallery-medium-9.jpg",
62     DALI_IMAGE_DIR "gallery-medium-10.jpg",
63     DALI_IMAGE_DIR "gallery-medium-11.jpg",
64     DALI_IMAGE_DIR "gallery-medium-12.jpg",
65     DALI_IMAGE_DIR "gallery-medium-13.jpg",
66     DALI_IMAGE_DIR "gallery-medium-14.jpg",
67     DALI_IMAGE_DIR "gallery-medium-15.jpg",
68     DALI_IMAGE_DIR "gallery-medium-16.jpg",
69     DALI_IMAGE_DIR "gallery-medium-17.jpg",
70     DALI_IMAGE_DIR "gallery-medium-18.jpg",
71     DALI_IMAGE_DIR "gallery-medium-19.jpg",
72     DALI_IMAGE_DIR "gallery-medium-20.jpg",
73     DALI_IMAGE_DIR "gallery-medium-21.jpg",
74     DALI_IMAGE_DIR "gallery-medium-22.jpg",
75     DALI_IMAGE_DIR "gallery-medium-23.jpg",
76     DALI_IMAGE_DIR "gallery-medium-24.jpg",
77     DALI_IMAGE_DIR "gallery-medium-25.jpg",
78     DALI_IMAGE_DIR "gallery-medium-26.jpg",
79     DALI_IMAGE_DIR "gallery-medium-27.jpg",
80     DALI_IMAGE_DIR "gallery-medium-28.jpg",
81     DALI_IMAGE_DIR "gallery-medium-29.jpg",
82     DALI_IMAGE_DIR "gallery-medium-30.jpg",
83     DALI_IMAGE_DIR "gallery-medium-31.jpg",
84     DALI_IMAGE_DIR "gallery-medium-32.jpg",
85     DALI_IMAGE_DIR "gallery-medium-33.jpg",
86     DALI_IMAGE_DIR "gallery-medium-34.jpg",
87     DALI_IMAGE_DIR "gallery-medium-35.jpg",
88     DALI_IMAGE_DIR "gallery-medium-36.jpg",
89     DALI_IMAGE_DIR "gallery-medium-37.jpg",
90     DALI_IMAGE_DIR "gallery-medium-38.jpg",
91     DALI_IMAGE_DIR "gallery-medium-39.jpg",
92     DALI_IMAGE_DIR "gallery-medium-40.jpg",
93     DALI_IMAGE_DIR "gallery-medium-41.jpg",
94     DALI_IMAGE_DIR "gallery-medium-42.jpg",
95     DALI_IMAGE_DIR "gallery-medium-43.jpg",
96     DALI_IMAGE_DIR "gallery-medium-44.jpg",
97     DALI_IMAGE_DIR "gallery-medium-45.jpg",
98     DALI_IMAGE_DIR "gallery-medium-46.jpg",
99     DALI_IMAGE_DIR "gallery-medium-47.jpg",
100     DALI_IMAGE_DIR "gallery-medium-48.jpg",
101     DALI_IMAGE_DIR "gallery-medium-49.jpg",
102     DALI_IMAGE_DIR "gallery-medium-50.jpg",
103     DALI_IMAGE_DIR "gallery-medium-51.jpg",
104     DALI_IMAGE_DIR "gallery-medium-52.jpg",
105     DALI_IMAGE_DIR "gallery-medium-53.jpg",
106
107     NULL
108 };
109
110 const char * const GetNextImagePath()
111 {
112   static const char * const * imagePtr = &IMAGE_PATHS[0];
113
114   if ( *(++imagePtr) == NULL )
115   {
116     imagePtr = &IMAGE_PATHS[0];
117   }
118
119   return *imagePtr;
120 }
121
122 const int PAGE_COLUMNS = 10;                                                ///< Number of Pages going across (columns)
123 const int PAGE_ROWS = 1;                                                    ///< Number of Pages going down (rows)
124 const int IMAGE_ROWS = 5;                                                   ///< Number of Images going down (rows) with a Page
125
126 // 3D Effect constants
127 const Vector3 ANGLE_CUBE_PAGE_ROTATE(Math::PI * 0.2f, Math::PI * 0.2f, 0.0f); ///< Cube page rotates as if it has ten sides with the camera positioned inside
128 const Vector2 ANGLE_CUSTOM_CUBE_SWING(-Math::PI * 0.45f, -Math::PI * 0.45f);  ///< outer cube pages swing 90 degrees as they pan offscreen
129 const Vector2 ANGLE_SPIRAL_SWING_IN(Math::PI * 0.45f, Math::PI * 0.45f);
130 const Vector2 ANGLE_SPIRAL_SWING_OUT(Math::PI * 0.3f, Math::PI * 0.3f);
131
132 // Depth Effect constants
133 const Vector2 POSITION_EXTENT_DEPTH_EFFECT(0.5f, 2.5f);                     ///< Extent of X & Y position to alter function exponent.
134 const Vector2 OFFSET_EXTENT_DEPTH_EFFECT(1.0f, 1.0f);                       ///< Function exponent offset constant.
135 const float POSITION_SCALE_DEPTH_EFFECT(1.5f);                              ///< Position scaling.
136 const float SCALE_EXTENT_DEPTH_EFFECT(0.5f);                                ///< Maximum scale factor when Actors scrolled one page away (50% size)
137
138 // 3D Effect constants
139 const Vector2 ANGLE_SWING_3DEFFECT(Math::PI_2 * 0.75, Math::PI_2 * 0.75f); ///< Angle Swing in radians
140 const Vector2 POSITION_SWING_3DEFFECT(0.25f, 0.25f); ///< Position Swing relative to stage size.
141 const Vector3 ANCHOR_3DEFFECT_STYLE0(-105.0f, 30.0f, -240.0f); ///< Rotation Anchor position for 3D Effect (Style 0)
142 const Vector3 ANCHOR_3DEFFECT_STYLE1(65.0f, -70.0f, -300.0f); ///< Rotation Anchor position for 3D Effect (Style 1)
143
144
145 const unsigned int IMAGE_THUMBNAIL_WIDTH  = 256;                            ///< Width of Thumbnail Image in texels
146 const unsigned int IMAGE_THUMBNAIL_HEIGHT = 256;                            ///< Height of Thumbnail Image in texels
147
148 const float SPIN_DURATION = 5.0f;                                           ///< Times to spin an Image by upon touching, each spin taking a second.
149
150 const float EFFECT_SNAP_DURATION(0.66f);                                    ///< Scroll Snap Duration for Effects
151 const float EFFECT_FLICK_DURATION(0.5f);                                    ///< Scroll Flick Duration for Effects
152
153 } // unnamed namespace
154
155 /**
156  * This example shows how to do custom Scroll Effects
157  */
158 class ExampleController : public ConnectionTracker
159 {
160 public:
161
162   /**
163    * Constructor
164    * @param application class, stored as reference
165    */
166   ExampleController( Application& application )
167   : mApplication( application ),
168     mView(),
169     mScrolling(false),
170     mEffectMode(CubeEffect)
171   {
172     // Connect to the Application's Init and orientation changed signal
173     mApplication.InitSignal().Connect(this, &ExampleController::OnInit);
174   }
175
176   ~ExampleController()
177   {
178     // Nothing to do here; everything gets deleted automatically
179   }
180
181   /**
182    * This method gets called once the main loop of application is up and running
183    */
184   void OnInit(Application& app)
185   {
186     Stage stage = Dali::Stage::GetCurrent();
187     stage.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent);
188
189     // Hide the indicator bar
190     mApplication.GetWindow().ShowIndicator(false);
191
192     // Creates a default view with a default tool bar.
193     // The view is added to the stage.
194     mContentLayer = DemoHelper::CreateView( app,
195                                             mView,
196                                             mToolBar,
197                                             BACKGROUND_IMAGE,
198                                             TOOLBAR_IMAGE,
199                                             "" );
200
201     mEffectIcon[ OuterCubeEffect ] = Image::New( EFFECT_OUTER_CUBE_IMAGE );
202     mEffectIcon[ DepthEffect ]     = Image::New( EFFECT_DEPTH_IMAGE );
203     mEffectIcon[ CubeEffect ]      = Image::New( EFFECT_INNER_CUBE_IMAGE );
204     mEffectIcon[ InnerCubeEffect ] = Image::New( EFFECT_INNER_CUBE_IMAGE );
205     mEffectIcon[ CarouselEffect ]  = Image::New( EFFECT_CAROUSEL_IMAGE );
206     mEffectIcon[ SpiralEffect ]    = Image::New( EFFECT_SPIRAL_IMAGE );
207
208     // Create a effect change button. (right of toolbar)
209     mEffectChangeButton = Toolkit::PushButton::New();
210     mEffectChangeButton.ClickedSignal().Connect( this, &ExampleController::OnEffectTouched );
211     mToolBar.AddControl( mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING  );
212
213     // Create the content layer.
214     AddContentLayer();
215
216     // Hack to force screen refresh.
217     Animation animation = Animation::New(1.0f);
218     animation.AnimateTo(Property(mContentLayer, Actor::POSITION), Vector3::ZERO );
219     animation.Play();
220   }
221
222 private:
223
224   /**
225    * Adds content to the ContentLayer. This is everything we see
226    * excluding the toolbar at the top.
227    */
228   void AddContentLayer()
229   {
230     Stage stage = Stage::GetCurrent();
231     Vector2 stageSize = stage.GetSize();
232
233     mScrollView = ScrollView::New();
234     mScrollView.SetAnchorPoint(AnchorPoint::CENTER);
235     mScrollView.SetParentOrigin(ParentOrigin::CENTER);
236     mContentLayer.Add( mScrollView );
237     mScrollView.SetSize( stageSize );
238     mScrollView.SetAxisAutoLock( true );
239     mScrollView.SetAxisAutoLockGradient( 1.0f );
240
241     mScrollView.ScrollStartedSignal().Connect( this, &ExampleController::OnScrollStarted );
242     mScrollView.ScrollCompletedSignal().Connect( this, &ExampleController::OnScrollCompleted );
243
244     for(int row = 0;row<PAGE_ROWS;row++)
245     {
246       for(int column = 0;column<PAGE_COLUMNS;column++)
247       {
248         Actor page = CreatePage();
249
250         page.SetPosition( column * stageSize.x, row * stageSize.y );
251         mScrollView.Add( page );
252
253         mPages.push_back(page);
254       }
255     }
256
257     Update();
258   }
259
260   /**
261    * Updates the ScrollView and it's children based
262    * on the current effect.
263    */
264   void Update()
265   {
266     std::stringstream ss(APPLICATION_TITLE);
267     ss << APPLICATION_TITLE << ": " << EFFECT_MODE_NAME[mEffectMode];
268     SetTitle(ss.str());
269
270     mEffectChangeButton.SetBackgroundImage( mEffectIcon[ mEffectMode ] );
271
272     // remove old Effect if exists.
273     if(mScrollViewEffect)
274     {
275       mScrollView.RemoveEffect(mScrollViewEffect);
276     }
277
278     // apply new Effect to ScrollView
279     ApplyEffectToScrollView();
280
281     for(ActorIter pageIter = mPages.begin(); pageIter != mPages.end(); ++pageIter)
282     {
283       Actor page = *pageIter;
284       ApplyEffectToPage( page );
285
286       unsigned int numChildren = (*pageIter).GetChildCount();
287       for(unsigned int i=0; i<numChildren; ++i)
288       {
289         Actor image = (*pageIter).GetChildAt(i);
290
291         // Remove old effect's manual constraints.
292         image.RemoveConstraints();
293
294         // Apply new effect's manual constraints.
295         ApplyEffectToActor( image, page );
296       }
297     }
298   }
299
300   /**
301    * Creates a page using a source of images.
302    */
303   Actor CreatePage()
304   {
305     Actor page = Actor::New();
306     page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
307     page.SetParentOrigin( ParentOrigin::CENTER );
308     page.SetAnchorPoint( AnchorPoint::CENTER );
309
310     Stage stage = Stage::GetCurrent();
311     Vector2 stageSize = stage.GetSize();
312
313     const float margin = 10.0f;
314
315     // Calculate the number of images going across (columns) within a page, according to the screen resolution and dpi.
316     int imageColumns = round(IMAGE_ROWS * (stageSize.x / stage.GetDpi().x) / (stageSize.y / stage.GetDpi().y));
317     const Vector3 imageSize((stageSize.x / imageColumns) - margin, (stageSize.y / IMAGE_ROWS) - margin, 0.0f);
318
319     for(int row = 0;row<IMAGE_ROWS;row++)
320     {
321       for(int column = 0;column<imageColumns;column++)
322       {
323         ImageActor image = CreateImage( GetNextImagePath() );
324
325         image.SetParentOrigin( ParentOrigin::CENTER );
326         image.SetAnchorPoint( AnchorPoint::CENTER );
327
328         Vector3 position( margin * 0.5f + (imageSize.x + margin) * column - stageSize.width * 0.5f,
329                          margin * 0.5f + (imageSize.y + margin) * row - stageSize.height * 0.5f,
330                           0.0f);
331         image.SetPosition( position + imageSize * 0.5f );
332         image.SetSize( imageSize );
333         page.Add(image);
334       }
335     }
336
337     return page;
338   }
339
340   /**
341    * [ScrollView]
342    * Applies effect to scrollView
343    */
344   void ApplyEffectToScrollView()
345   {
346     bool wrap(true);
347     bool snap(true);
348
349     Stage stage = Stage::GetCurrent();
350     Vector2 stageSize = stage.GetSize();
351
352     switch(mEffectMode)
353     {
354       case OuterCubeEffect:
355       {
356         SetupOuterPageCubeEffect();
357         break;
358       }
359
360       case DepthEffect:
361       {
362         mScrollViewEffect = ScrollViewDepthEffect::New();
363         mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION);
364         mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION);
365         mScrollView.SetScrollSnapAlphaFunction(AlphaFunctions::EaseOut);
366         mScrollView.SetScrollFlickAlphaFunction(AlphaFunctions::EaseOut);
367         mScrollView.RemoveConstraintsFromChildren();
368         break;
369       }
370       case CubeEffect:
371       {
372         mScrollViewEffect = ScrollViewCubeEffect::New();
373         mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION);
374         mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION);
375         mScrollView.SetScrollSnapAlphaFunction(AlphaFunctions::EaseOutBack);
376         mScrollView.SetScrollFlickAlphaFunction(AlphaFunctions::EaseOutBack);
377         mScrollView.RemoveConstraintsFromChildren();
378         break;
379       }
380
381       case InnerCubeEffect:
382       {
383         SetupInnerPageCubeEffect();
384         break;
385       }
386
387       case CarouselEffect:
388       {
389         SetupCarouselPageEffect();
390         break;
391       }
392
393       case SpiralEffect:
394       {
395         SetupSpiralPageEffect();
396         break;
397       }
398
399       default:
400       {
401         break;
402       }
403     } // end switch
404
405     if(mScrollViewEffect)
406     {
407       mScrollView.ApplyEffect(mScrollViewEffect);
408     }
409
410     mScrollView.SetWrapMode(wrap);
411
412     RulerPtr rulerX = CreateRuler(snap ? stageSize.width : 0.0f);
413     RulerPtr rulerY = new DefaultRuler;
414     rulerX->SetDomain(RulerDomain(0.0f, stageSize.x * PAGE_COLUMNS, !wrap));
415     rulerY->Disable();
416
417     mScrollView.SetRulerX( rulerX );
418     mScrollView.SetRulerY( rulerY );
419   }
420
421   /**
422    * Creates a Ruler that snaps to a specified grid size.
423    * If that grid size is 0.0 then this ruler does not
424    * snap.
425    *
426    * @param[in] gridSize (optional) The grid size for the ruler,
427    * (Default = 0.0 i.e. no snapping)
428    * @return The ruler is returned.
429    */
430   RulerPtr CreateRuler(float gridSize = 0.0f)
431   {
432     if(gridSize <= Math::MACHINE_EPSILON_0)
433     {
434         return new DefaultRuler();
435     }
436     return new FixedRuler(gridSize);
437   }
438
439   void SetupInnerPageCubeEffect()
440   {
441     ScrollViewCustomEffect customEffect;
442     mScrollViewEffect = customEffect = ScrollViewCustomEffect::New();
443     mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION);
444     mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION);
445     mScrollView.SetScrollSnapAlphaFunction(AlphaFunctions::EaseOutBack);
446     mScrollView.SetScrollFlickAlphaFunction(AlphaFunctions::EaseOutBack);
447     mScrollView.RemoveConstraintsFromChildren();
448
449     customEffect.SetPageSpacing(Vector2(30.0f, 30.0f));
450     customEffect.SetAngledOriginPageRotation(ANGLE_CUBE_PAGE_ROTATE);
451     customEffect.SetSwingAngle(ANGLE_CUBE_PAGE_ROTATE.x, Vector3(0,-1,0));
452     customEffect.SetOpacityThreshold(0.7f);
453   }
454
455   void SetupOuterPageCubeEffect()
456   {
457     ScrollViewCustomEffect customEffect;
458     mScrollViewEffect = customEffect = ScrollViewCustomEffect::New();
459     mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION);
460     mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION);
461     mScrollView.SetScrollSnapAlphaFunction(AlphaFunctions::EaseOut);
462     mScrollView.SetScrollFlickAlphaFunction(AlphaFunctions::EaseOut);
463     mScrollView.RemoveConstraintsFromChildren();
464
465     Vector2 pageSize = Stage::GetCurrent().GetSize();
466     customEffect.SetPageTranslation(Vector3(pageSize.x, pageSize.y, 0));
467     customEffect.SetSwingAngleOut(ANGLE_CUSTOM_CUBE_SWING.x, Vector3(0.0f, -1.0f, 0.0f));
468     customEffect.SetSwingAnchor(AnchorPoint::CENTER, AnchorPoint::CENTER_LEFT);
469     customEffect.SetOpacityThreshold(0.5f);
470   }
471
472   void SetupCarouselPageEffect()
473   {
474     ScrollViewCustomEffect customEffect;
475     mScrollViewEffect = customEffect = ScrollViewCustomEffect::New();
476     mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION);
477     mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION);
478     mScrollView.SetScrollSnapAlphaFunction(AlphaFunctions::EaseOutBack);
479     mScrollView.SetScrollFlickAlphaFunction(AlphaFunctions::EaseOutBack);
480     mScrollView.RemoveConstraintsFromChildren();
481
482     customEffect.SetPageTranslation(Vector3(0,0,0), Vector3(-30, 0, 0));
483     customEffect.SetPageSpacing(Vector2(60.0f, 60.0f));
484     customEffect.SetAngledOriginPageRotation(-ANGLE_CUBE_PAGE_ROTATE);
485     customEffect.SetOpacityThreshold(0.2f, 0.6f);
486   }
487
488   void SetupSpiralPageEffect()
489   {
490     ScrollViewCustomEffect customEffect;
491     mScrollViewEffect = customEffect = ScrollViewCustomEffect::New();
492     mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION);
493     mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION);
494     mScrollView.SetScrollSnapAlphaFunction(AlphaFunctions::EaseOutBack);
495     mScrollView.SetScrollFlickAlphaFunction(AlphaFunctions::EaseOutBack);
496     mScrollView.RemoveConstraintsFromChildren();
497
498     Vector2 pageSize = Stage::GetCurrent().GetSize();
499     customEffect.SetPageTranslation(Vector3(pageSize.x, pageSize.y, 0.0f));
500     customEffect.SetSwingAngle(-ANGLE_SPIRAL_SWING_IN.x, Vector3(0.0f, -1.0f, 0.0f), ANGLE_SPIRAL_SWING_OUT.x, Vector3(0.0f, -1.0f, 0.0f));
501     customEffect.SetSwingAnchor(AnchorPoint::CENTER_RIGHT);
502     customEffect.SetPageTranslation(Vector3(pageSize.x, pageSize.y, 0), Vector3(pageSize.x, pageSize.y, 0) * 0.5f);
503     customEffect.SetOpacityThreshold(0.66f);
504   }
505
506   /**
507    * [Page]
508    * Applies effect to the pages within scroll view.
509    *
510    * @param[in] page The page Actor to apply effect to.
511    */
512   void ApplyEffectToPage(Actor page)
513   {
514     page.RemoveConstraints();
515     page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
516
517     if( ( mEffectMode == InnerCubeEffect ) ||
518         ( mEffectMode == OuterCubeEffect ) ||
519         ( mEffectMode == SpiralEffect )    ||
520         ( mEffectMode == CarouselEffect) )
521     {
522       ApplyCustomEffectToPage(page);
523     }
524   }
525
526   void ApplyCustomEffectToPage(Actor page)
527   {
528     ScrollViewCustomEffect customEffect = ScrollViewCustomEffect::DownCast(mScrollViewEffect);
529     Vector2 vStageSize(Stage::GetCurrent().GetSize());
530     customEffect.ApplyToPage(page, Vector3(vStageSize.x, vStageSize.y, 1.0f));
531   }
532
533   /**
534    * [Actor]
535    * Applies effect to child which resides in page (which in turn resides in scrollview)
536    *
537    * @note Page is typically the Parent of child, although in
538    * some scenarios Page is simply a container which has a child as
539    * a descendent.
540    *
541    * @param[in] child The child actor to apply effect to
542    * @param[in] page The page which this child is inside
543    */
544   void ApplyEffectToActor( Actor child, Actor page )
545   {
546     if( mEffectMode == DepthEffect )
547     {
548       ApplyDepthEffectToActor( child );
549     }
550     else if(mEffectMode == CubeEffect )
551     {
552       ApplyCubeEffectToActor( child );
553     }
554   }
555
556   /**
557    * Applies depth effect to the child which resides in page (which in turn resides in scrollview)
558    *
559    * @param[in] child The child actor to apply depth effect to
560    */
561   void ApplyDepthEffectToActor( Actor child )
562   {
563     ScrollViewDepthEffect depthEffect = ScrollViewDepthEffect::DownCast(mScrollViewEffect);
564     depthEffect.ApplyToActor( child,
565                               POSITION_EXTENT_DEPTH_EFFECT,
566                               OFFSET_EXTENT_DEPTH_EFFECT,
567                               POSITION_SCALE_DEPTH_EFFECT,
568                               SCALE_EXTENT_DEPTH_EFFECT );
569   }
570
571   void ApplyCubeEffectToActor( Actor child )
572   {
573     Vector3 anchor;
574     if(rand()&1)
575     {
576       anchor = ANCHOR_3DEFFECT_STYLE0;
577     }
578     else
579     {
580       anchor = ANCHOR_3DEFFECT_STYLE1;
581     }
582
583     ScrollViewCubeEffect cubeEffect = ScrollViewCubeEffect::DownCast(mScrollViewEffect);
584     cubeEffect.ApplyToActor( child,
585                              anchor,
586                              ANGLE_SWING_3DEFFECT,
587                              POSITION_SWING_3DEFFECT * Vector2(Stage::GetCurrent().GetSize()));
588   }
589
590   /**
591    * Creates an Image (Helper)
592    *
593    * @param[in] filename the path of the image.
594    * @param[in] width the width of the image in texels
595    * @param[in] height the height of the image in texels.
596    */
597   ImageActor CreateImage( const std::string& filename, unsigned int width = IMAGE_THUMBNAIL_WIDTH, unsigned int height = IMAGE_THUMBNAIL_HEIGHT )
598   {
599     ImageAttributes attributes;
600
601     attributes.SetSize(width, height);
602     attributes.SetScalingMode(ImageAttributes::ShrinkToFit);
603     Image img = Image::New(filename, attributes);
604     ImageActor actor = ImageActor::New(img);
605     actor.SetName( filename );
606     actor.SetParentOrigin(ParentOrigin::CENTER);
607     actor.SetAnchorPoint(AnchorPoint::CENTER);
608
609     actor.TouchedSignal().Connect( this, &ExampleController::OnTouchImage );
610     return actor;
611   }
612
613   /**
614    * When scroll starts (i.e. user starts to drag scrollview),
615    * note this state (mScrolling = true)
616    * @param[in] position Current Scroll Position
617    */
618   void OnScrollStarted( const Vector3& position )
619   {
620     mScrolling = true;
621   }
622
623   /**
624    * When scroll starts (i.e. user stops dragging scrollview, and scrollview has snapped to destination),
625    * note this state (mScrolling = false)
626    * @param[in] position Current Scroll Position
627    */
628   void OnScrollCompleted( const Vector3& position )
629   {
630     mScrolling = false;
631   }
632
633   /**
634    * Upon Touching an image (Release), make it spin
635    * (provided we're not scrolling).
636    * @param[in] actor The actor touched
637    * @param[in] event The TouchEvent.
638    */
639   bool OnTouchImage( Actor actor, const TouchEvent& event )
640   {
641     if( (event.points.size() > 0) && (!mScrolling) )
642     {
643       TouchPoint point = event.points[0];
644       if(point.state == TouchPoint::Up)
645       {
646         // Spin the Image a few times.
647         Animation animation = Animation::New(SPIN_DURATION);
648         animation.RotateBy( actor, Degree(360.0f * SPIN_DURATION), Vector3::XAXIS, AlphaFunctions::EaseOut);
649         animation.Play();
650       }
651     }
652     return false;
653   }
654
655   /**
656    * Signal handler, called when the 'Effect' button has been touched.
657    *
658    * @param[in] button The button that was pressed.
659    */
660   bool OnEffectTouched(Button button)
661   {
662     mEffectMode = static_cast<EffectMode>((static_cast<int>(mEffectMode) + 1) % static_cast<int>(Total));
663     Update();
664     return true;
665   }
666
667   /**
668    * Sets/Updates the title of the View
669    * @param[in] title The new title for the view.
670    */
671   void SetTitle(const std::string& title)
672   {
673     if(!mTitleActor)
674     {
675       mTitleActor = TextView::New();
676       // Add title to the tool bar.
677       mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter );
678     }
679
680     Font font = Font::New();
681     mTitleActor.SetText( title );
682     mTitleActor.SetSize( font.MeasureText( title ) );
683     mTitleActor.SetStyleToCurrentText(DemoHelper::GetDefaultTextStyle());
684   }
685
686   /**
687    * Main key event handler
688    */
689   void OnKeyEvent(const KeyEvent& event)
690   {
691     if(event.state == KeyEvent::Down)
692     {
693       if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
694       {
695         mApplication.Quit();
696       }
697     }
698   }
699
700 private:
701
702   Application& mApplication;                            ///< Application instance
703   Toolkit::View mView;                                  ///< The View instance.
704   Toolkit::ToolBar mToolBar;                            ///< The View's Toolbar.
705   TextView mTitleActor;                                 ///< The Toolbar's Title.
706   Layer mContentLayer;                                  ///< The content layer (contains game actors)
707   ScrollView mScrollView;                               ///< ScrollView UI Component
708   bool mScrolling;                                      ///< ScrollView scrolling state (true = scrolling, false = stationary)
709   ScrollViewEffect mScrollViewEffect;                   ///< ScrollView Effect instance.
710   ActorContainer mPages;                                ///< Keeps track of all the pages for applying effects.
711
712   /**
713    * Enumeration of different effects this scrollview can operate under.
714    */
715   enum EffectMode
716   {
717     OuterCubeEffect,                                    ///< Outer Cube Effect
718     DepthEffect,                                        ///< Depth Effect
719     CubeEffect,                                         ///< Cube effect
720     InnerCubeEffect,                                    ///< Page Cube Effect
721     CarouselEffect,                                     ///< Page Carousel Effect
722     SpiralEffect,                                       ///< Page Spiral Effect
723
724     Total,
725   };
726
727   EffectMode mEffectMode;                               ///< Current Effect mode
728
729   Image mEffectIcon[Total];                             ///< Icons for the effect button
730   Toolkit::PushButton mEffectChangeButton;              ///< Effect Change Button
731 };
732
733 int main(int argc, char **argv)
734 {
735   Application app = Application::New(&argc, &argv);
736   ExampleController test(app);
737   app.MainLoop();
738   return 0;
739 }