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