[dali_1.0.34] Merge branch 'tizen'
[platform/core/uifw/dali-demo.git] / examples / image-scaling-irregular-grid / image-scaling-irregular-grid-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 /**
19  * @file image-scaling-irregular-grid-example.cpp
20  * @brief Demonstrates how to use image scaling modes when loading images.
21  *
22  * If an image is going to be drawn on-screen at a lower resolution than it is
23  * stored at on-disk, the scaling feature of the image loader can be used to
24  * reduce the image to save memory, improve performance, and potentially display
25  * a better small version of the image than if the default size were loaded.
26  *
27  * The functions CreateImage and CreateImageActor below show how to build an
28  * image using a scaling mode to have %Dali resize it during loading.
29  *
30  * This demo defaults to the ScaleToFill mode of ImageAttributes which makes
31  * sure that every pixel in the loaded image is filled with a source colour
32  * from the image's central region while losing the minimum number of pixels
33  * from its periphery.
34  * It is the best option for producing thumbnails of input images that have
35  * diverse aspect ratios.
36  *
37  * The other four scaling modes of dali can be cycled-through for the whole
38  * grid  using the button in the top-right of the toolbar.
39  * A single image can be cycled by clicking the image directly.
40  *
41  * @see CreateImage CreateImageActor
42  */
43
44 // EXTERNAL INCLUDES
45 #include <algorithm>
46 #include <map>
47 #include <dali-toolkit/dali-toolkit.h>
48 #include <iostream>
49
50 // INTERNAL INCLUDES
51 #include "grid-flags.h"
52 #include "shared/view.h"
53
54 using namespace Dali;
55 using namespace Dali::Toolkit;
56 using namespace Dali::Demo;
57
58 namespace
59 {
60
61 /** Controls the output of application logging. */
62 //#define DEBUG_PRINT_DIAGNOSTICS;
63
64 const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-gradient.jpg" );
65 const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
66 const char* APPLICATION_TITLE( "Image Scaling Modes" );
67 const char* TOGGLE_SCALING_IMAGE( DALI_IMAGE_DIR "icon-change.png" );
68
69 /** The width of the grid in whole grid cells. */
70 const unsigned GRID_WIDTH = 9;
71 /** Limit the grid to be no higher than this in units of a cell. */
72 const unsigned GRID_MAX_HEIGHT = 600;
73
74 /** The space between the edge of a grid cell and the image embedded within it. */
75 const unsigned GRID_CELL_PADDING = 4;
76
77 /** The aspect ratio of cells in the image grid. */
78 const float CELL_ASPECT_RATIO = 1.33333333333333333333f;
79
80 const ImageAttributes::ScalingMode DEFAULT_SCALING_MODE = ImageAttributes::ScaleToFill;
81
82 /** The number of times to spin an image on touching, each spin taking a second.*/
83 const float SPIN_DURATION = 1.0f;
84
85 /** The target image sizes in grid cells. */
86 const Vector2 IMAGE_SIZES[] = {
87  Vector2( 1, 1 ),
88  Vector2( 2, 1 ),
89  Vector2( 3, 1 ),
90  Vector2( 1, 2 ),
91  Vector2( 1, 3 ),
92  Vector2( 2, 3 ),
93  Vector2( 3, 2 ),
94  // Large, tall configuration:
95  Vector2( GRID_WIDTH / 2, GRID_WIDTH + GRID_WIDTH / 2 ),
96  // Large, square-ish images to show shrink-to-fit well with wide and tall images:
97  Vector2( GRID_WIDTH / 2, GRID_WIDTH / 2.0f * CELL_ASPECT_RATIO + 0.5f ),
98  Vector2( GRID_WIDTH - 2, (GRID_WIDTH - 2) * CELL_ASPECT_RATIO + 0.5f ),
99 };
100 const unsigned NUM_IMAGE_SIZES = sizeof(IMAGE_SIZES) / sizeof(IMAGE_SIZES[0]);
101
102 /** Images to load into the grid. These are mostly large and non-square to
103  *  show the scaling. */
104 const char* IMAGE_PATHS[] = {
105
106   DALI_IMAGE_DIR "dali-logo.png",
107   DALI_IMAGE_DIR "com.samsung.dali-demo.ico",
108   DALI_IMAGE_DIR "square_primitive_shapes.bmp",
109   DALI_IMAGE_DIR "gallery-large-14.wbmp",
110
111   // Images that show aspect ratio changes clearly in primitive shapes:
112
113   DALI_IMAGE_DIR "portrait_screen_primitive_shapes.gif",
114   DALI_IMAGE_DIR "landscape_screen_primitive_shapes.gif",
115
116   // Images from other demos that are tall, wide or just large:
117
118   DALI_IMAGE_DIR "gallery-large-1.jpg",
119   DALI_IMAGE_DIR "gallery-large-2.jpg",
120   DALI_IMAGE_DIR "gallery-large-3.jpg",
121   DALI_IMAGE_DIR "gallery-large-4.jpg",
122   DALI_IMAGE_DIR "gallery-large-5.jpg",
123   DALI_IMAGE_DIR "gallery-large-6.jpg",
124   DALI_IMAGE_DIR "gallery-large-7.jpg",
125   DALI_IMAGE_DIR "gallery-large-8.jpg",
126   DALI_IMAGE_DIR "gallery-large-9.jpg",
127   DALI_IMAGE_DIR "gallery-large-10.jpg",
128   DALI_IMAGE_DIR "gallery-large-11.jpg",
129   DALI_IMAGE_DIR "gallery-large-12.jpg",
130   DALI_IMAGE_DIR "gallery-large-13.jpg",
131   DALI_IMAGE_DIR "gallery-large-14.jpg",
132   DALI_IMAGE_DIR "gallery-large-15.jpg",
133   DALI_IMAGE_DIR "gallery-large-16.jpg",
134   DALI_IMAGE_DIR "gallery-large-17.jpg",
135   DALI_IMAGE_DIR "gallery-large-18.jpg",
136   DALI_IMAGE_DIR "gallery-large-19.jpg",
137   DALI_IMAGE_DIR "gallery-large-20.jpg",
138   DALI_IMAGE_DIR "gallery-large-21.jpg",
139
140   DALI_IMAGE_DIR "background-1.jpg",
141   DALI_IMAGE_DIR "background-2.jpg",
142   DALI_IMAGE_DIR "background-3.jpg",
143   DALI_IMAGE_DIR "background-4.jpg",
144   DALI_IMAGE_DIR "background-5.jpg",
145   DALI_IMAGE_DIR "background-blocks.jpg",
146   DALI_IMAGE_DIR "background-magnifier.jpg",
147
148   DALI_IMAGE_DIR "background-1.jpg",
149   DALI_IMAGE_DIR "background-2.jpg",
150   DALI_IMAGE_DIR "background-3.jpg",
151   DALI_IMAGE_DIR "background-4.jpg",
152   DALI_IMAGE_DIR "background-5.jpg",
153   DALI_IMAGE_DIR "background-blocks.jpg",
154   DALI_IMAGE_DIR "background-magnifier.jpg",
155
156   DALI_IMAGE_DIR "book-landscape-cover-back.jpg",
157   DALI_IMAGE_DIR "book-landscape-cover.jpg",
158   DALI_IMAGE_DIR "book-landscape-p1.jpg",
159   DALI_IMAGE_DIR "book-landscape-p2.jpg",
160
161   DALI_IMAGE_DIR "book-portrait-cover.jpg",
162   DALI_IMAGE_DIR "book-portrait-p1.jpg",
163   DALI_IMAGE_DIR "book-portrait-p2.jpg",
164   NULL
165 };
166 const unsigned NUM_IMAGE_PATHS = sizeof(IMAGE_PATHS) / sizeof(IMAGE_PATHS[0]) - 1u;
167
168
169 /**
170  * Creates an Image
171  *
172  * @param[in] filename The path of the image.
173  * @param[in] width The width of the image in pixels.
174  * @param[in] height The height of the image in pixels.
175  * @param[in] scalingMode The mode to use when scaling the image to fit the desired dimensions.
176  */
177 Image CreateImage(const std::string& filename, unsigned int width, unsigned int height, ImageAttributes::ScalingMode scalingMode )
178 {
179 #ifdef DEBUG_PRINT_DIAGNOSTICS
180     fprintf( stderr, "CreateImage(%s, %u, %u, scalingMode=%u)\n", filename.c_str(), width, height, unsigned( scalingMode ) );
181 #endif
182   ImageAttributes attributes;
183
184   attributes.SetSize( width, height );
185   attributes.SetScalingMode( scalingMode );
186   attributes.SetFilterMode( ImageAttributes::BoxThenLinear );
187   Image image = ResourceImage::New( filename, attributes );
188   return image;
189 }
190
191 /**
192  * Creates an ImageActor
193  *
194  * @param[in] filename The path of the image.
195  * @param[in] width The width of the image in pixels.
196  * @param[in] height The height of the image in pixels.
197  * @param[in] scalingMode The mode to use when scaling the image to fit the desired dimensions.
198  */
199 ImageActor CreateImageActor(const std::string& filename, unsigned int width, unsigned int height, ImageAttributes::ScalingMode scalingMode )
200 {
201   Image img = CreateImage( filename, width, height, scalingMode );
202   ImageActor actor = ImageActor::New( img );
203   actor.SetName( filename );
204   actor.SetParentOrigin(ParentOrigin::CENTER);
205   actor.SetAnchorPoint(AnchorPoint::CENTER);
206
207   return actor;
208 }
209
210 /** Cycle the scaling mode options. */
211 ImageAttributes::ScalingMode NextMode( const ImageAttributes::ScalingMode oldMode )
212 {
213   ImageAttributes::ScalingMode newMode = ImageAttributes::ShrinkToFit;
214   switch ( oldMode )
215   {
216     case ImageAttributes::ShrinkToFit:
217       newMode = ImageAttributes::ScaleToFill;
218       break;
219     case ImageAttributes::ScaleToFill:
220       newMode = ImageAttributes::FitWidth;
221       break;
222     case ImageAttributes::FitWidth:
223       newMode = ImageAttributes::FitHeight;
224       break;
225     case ImageAttributes::FitHeight:
226       newMode = ImageAttributes::ShrinkToFit;
227       break;
228   }
229   return newMode;
230 }
231
232 /**
233  * Bundle an image path with the rectangle to pack it into.
234  * */
235 struct ImageConfiguration
236 {
237   ImageConfiguration( const char * const path, const Vector2 dimensions ) :
238     path( path ),
239     dimensions( dimensions )
240   {}
241   const char * path;
242   Vector2 dimensions;
243 };
244
245 /**
246  * Post-layout image data.
247  */
248 struct PositionedImage
249 {
250   PositionedImage(ImageConfiguration& configuration, unsigned cellX, unsigned cellY, Vector2 imageGridDims) :
251     configuration( configuration ),
252     cellX( cellX ),
253     cellY( cellY ),
254     imageGridDims( imageGridDims )
255   {}
256
257   ImageConfiguration configuration;
258   unsigned cellX;
259   unsigned cellY;
260   Vector2 imageGridDims;
261 };
262
263 }
264
265 /**
266  * @brief The main class of the demo.
267  */
268 class ImageScalingIrregularGridController : public ConnectionTracker
269 {
270 public:
271
272   ImageScalingIrregularGridController( Application& application )
273   : mApplication( application ),
274     mScrolling( false )
275   {
276     std::cout << "ImageScalingScaleToFillController::ImageScalingScaleToFillController" << std::endl;
277
278     // Connect to the Application's Init signal
279     mApplication.InitSignal().Connect( this, &ImageScalingIrregularGridController::Create );
280   }
281
282   ~ImageScalingIrregularGridController()
283   {
284     // Nothing to do here.
285   }
286
287   /**
288    * One-time setup in response to Application InitSignal.
289    */
290   void Create( Application& application )
291   {
292     std::cout << "ImageScalingScaleToFillController::Create" << std::endl;
293
294     // Get a handle to the stage:
295     Stage stage = Stage::GetCurrent();
296
297     // Connect to input event signals:
298     stage.KeyEventSignal().Connect(this, &ImageScalingIrregularGridController::OnKeyEvent);
299
300     // Hide the indicator bar
301     mApplication.GetWindow().ShowIndicator(Dali::Window::INVISIBLE);
302
303     // Create a default view with a default tool bar:
304     mContentLayer = DemoHelper::CreateView( mApplication,
305                                             mView,
306                                             mToolBar,
307                                             BACKGROUND_IMAGE,
308                                             TOOLBAR_IMAGE,
309                                             "" );
310
311     // Create an image scaling toggle button. (right of toolbar)
312     Image toggleScalingImage = ResourceImage::New( TOGGLE_SCALING_IMAGE );
313     Toolkit::PushButton toggleScalingButton = Toolkit::PushButton::New();
314     toggleScalingButton.SetBackgroundImage( toggleScalingImage );
315     toggleScalingButton.ClickedSignal().Connect( this, &ImageScalingIrregularGridController::OnToggleScalingTouched );
316     mToolBar.AddControl( toggleScalingButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING  );
317
318     SetTitle( APPLICATION_TITLE );
319
320     // Build the main content of the widow:
321     PopulateContentLayer( DEFAULT_SCALING_MODE );
322   }
323
324   /**
325    * Build the main part of the application's view.
326    */
327   void PopulateContentLayer( const ImageAttributes::ScalingMode scalingMode )
328   {
329     Stage stage = Stage::GetCurrent();
330     Vector2 stageSize = stage.GetSize();
331
332     float fieldHeight;
333     Actor imageField = BuildImageField( stageSize.x, GRID_WIDTH, GRID_MAX_HEIGHT, scalingMode, fieldHeight );
334
335     mScrollView = ScrollView::New();
336
337     mScrollView.ScrollStartedSignal().Connect( this, &ImageScalingIrregularGridController::OnScrollStarted );
338     mScrollView.ScrollCompletedSignal().Connect( this, &ImageScalingIrregularGridController::OnScrollCompleted );
339
340     mScrollView.EnableScrollComponent( Scrollable::VerticalScrollBar );
341     mScrollView.EnableScrollComponent( Scrollable::HorizontalScrollBar );
342
343     mScrollView.SetAnchorPoint(AnchorPoint::CENTER);
344     mScrollView.SetParentOrigin(ParentOrigin::CENTER);
345
346     mScrollView.SetSize( stageSize );//Vector2( stageSize.width, fieldHeight ) );//stageSize );
347     mScrollView.SetAxisAutoLock( true );
348     mScrollView.SetAxisAutoLockGradient( 1.0f );
349
350     // Restrict scrolling to mostly vertical only, but with some horizontal wiggle-room:
351
352     RulerPtr rulerX = new FixedRuler( stageSize.width ); //< Pull the view back to the grid's centre-line when touch is release using a snapping ruler.
353     rulerX->SetDomain( RulerDomain( stageSize.width * -0.125f, stageSize.width * 1.125f ) ); //< Scroll slightly left/right of image field.
354     mScrollView.SetRulerX ( rulerX );
355
356     RulerPtr rulerY = new DefaultRuler(); //stageSize.height ); //< Snap in multiples of a screen / stage height
357     rulerY->SetDomain( RulerDomain( - fieldHeight * 0.5f + stageSize.height * 0.5f - GRID_CELL_PADDING, fieldHeight * 0.5f + stageSize.height * 0.5f + GRID_CELL_PADDING ) );
358     mScrollView.SetRulerY ( rulerY );
359
360     mContentLayer.Add( mScrollView );
361     mScrollView.Add( imageField );
362     mGridActor = imageField;
363
364     // Scroll to top of grid so first images loaded are on-screen:
365     mScrollView.ScrollTo( Vector3( 0, -1000000, 0 ) );
366   }
367
368   /**
369    * Build a field of images scaled into a variety of shapes from very wide,
370    * through square, to very tall. The images are direct children of the Dali::Actor
371    * returned.
372    **/
373   Actor BuildImageField( const float fieldWidth,
374                            const unsigned gridWidth,
375                            const unsigned maxGridHeight,
376                            ImageAttributes::ScalingMode scalingMode,
377                            float & outFieldHeight )
378   {
379     // Generate the list of image configurations to be fitted into the field:
380
381     std::vector<ImageConfiguration> configurations;
382     configurations.reserve( NUM_IMAGE_PATHS * NUM_IMAGE_SIZES );
383     for( unsigned imageIndex = 0; imageIndex < NUM_IMAGE_PATHS; ++imageIndex )
384     {
385       for( unsigned dimensionsIndex = 0; dimensionsIndex < NUM_IMAGE_SIZES; ++ dimensionsIndex )
386       {
387         configurations.push_back( ImageConfiguration( IMAGE_PATHS[imageIndex], IMAGE_SIZES[dimensionsIndex] ) );
388       }
389     }
390     // Stir-up the list to get some nice irregularity in the generated field:
391     std::random_shuffle( configurations.begin(), configurations.end() );
392     std::random_shuffle( configurations.begin(), configurations.end() );
393
394     // Place the images in the grid:
395
396     std::vector<ImageConfiguration>::iterator config, end;
397     GridFlags grid( gridWidth, maxGridHeight );
398     std::vector<PositionedImage> placedImages;
399
400     for( config = configurations.begin(), end = configurations.end(); config != end; ++config )
401     {
402       unsigned cellX, cellY;
403       Vector2 imageGridDims;
404
405       // Allocate a region of the grid for the image:
406       bool allocated = grid.AllocateRegion( config->dimensions, cellX, cellY, imageGridDims );
407       if( !allocated )
408       {
409 #ifdef DEBUG_PRINT_DIAGNOSTICS
410           fprintf( stderr, "Failed to allocate image in grid with dims (%f, %f) and path: %s.\n", config->dimensions.x, config->dimensions.y, config->path );
411 #endif
412         continue;
413       }
414
415       placedImages.push_back( PositionedImage( *config, cellX, cellY, imageGridDims ) );
416     }
417     DALI_ASSERT_DEBUG( grid.DebugCheckGridValid() && "Cells were set more than once, indicating erroneous overlap in placing images on the grid." );
418     const unsigned actualGridHeight = grid.GetHighestUsedRow() + 1;
419
420     // Take the images images in the grid and turn their logical locations into
421     // coordinates in a frame defined by a parent actor:
422
423     Actor gridActor = Actor::New();
424     gridActor.SetSizeMode( SIZE_EQUAL_TO_PARENT );
425     gridActor.SetParentOrigin( ParentOrigin::CENTER );
426     gridActor.SetAnchorPoint( AnchorPoint::CENTER );
427
428     // Work out the constants of the grid and cell dimensions and positions:
429     const float cellWidth = fieldWidth / gridWidth;
430     const float cellHeight = cellWidth / CELL_ASPECT_RATIO;
431     const Vector2 cellSize = Vector2( cellWidth, cellHeight );
432     outFieldHeight = actualGridHeight * cellHeight;
433     const Vector2 gridOrigin = Vector2( -fieldWidth * 0.5f, -outFieldHeight * 0.5 );
434
435     // Build the image actors in their right locations in their parent's frame:
436     for( std::vector<PositionedImage>::const_iterator i = placedImages.begin(), end = placedImages.end(); i != end; ++i )
437     {
438       const PositionedImage& imageSource = *i;
439       const Vector2 imageSize = imageSource.imageGridDims * cellSize - Vector2( GRID_CELL_PADDING * 2, GRID_CELL_PADDING * 2 );
440       const Vector2 imageRegionCorner = gridOrigin + cellSize * Vector2( imageSource.cellX, imageSource.cellY );
441       const Vector2 imagePosition = imageRegionCorner + Vector2( GRID_CELL_PADDING , GRID_CELL_PADDING ) + imageSize * 0.5f;
442
443       ImageActor image = CreateImageActor( imageSource.configuration.path, imageSize.x, imageSize.y, scalingMode );
444       image.SetPosition( Vector3( imagePosition.x, imagePosition.y, 0 ) );
445       image.SetSize( imageSize );
446       image.TouchedSignal().Connect( this, &ImageScalingIrregularGridController::OnTouchImage );
447       mScalingModes[image.GetId()] = scalingMode;
448       mSizes[image.GetId()] = imageSize;
449
450       gridActor.Add( image );
451     }
452
453     return gridActor;
454   }
455
456  /**
457   * Upon Touching an image (Release), change its scaling mode and make it spin, provided we're not scrolling.
458   * @param[in] actor The actor touched
459   * @param[in] event The TouchEvent.
460   */
461   bool OnTouchImage( Actor actor, const TouchEvent& event )
462   {
463     if( (event.points.size() > 0) && (!mScrolling) )
464     {
465       TouchPoint point = event.points[0];
466       if(point.state == TouchPoint::Up)
467       {
468         // Spin the image a few times:
469         Animation animation = Animation::New(SPIN_DURATION);
470         animation.RotateBy( actor, Degree(360.0f * SPIN_DURATION), Vector3::XAXIS, AlphaFunctions::EaseOut);
471         animation.Play();
472
473         // Change the scaling mode:
474         const unsigned id = actor.GetId();
475         ImageAttributes::ScalingMode newMode = NextMode( mScalingModes[id] );
476         const Vector2 imageSize = mSizes[actor.GetId()];
477
478         ImageActor imageActor = ImageActor::DownCast( actor );
479         Image oldImage = imageActor.GetImage();
480         Image newImage = CreateImage( ResourceImage::DownCast(oldImage).GetUrl(), imageSize.width + 0.5f, imageSize.height + 0.5f, newMode );
481         imageActor.SetImage( newImage );
482         mScalingModes[id] = newMode;
483       }
484     }
485     return false;
486   }
487
488  /**
489   * Main key event handler.
490   * Quit on escape key.
491   */
492   void OnKeyEvent(const KeyEvent& event)
493   {
494     if( event.state == KeyEvent::Down )
495     {
496       if( IsKey( event, Dali::DALI_KEY_ESCAPE )
497           || IsKey( event, Dali::DALI_KEY_BACK ) )
498       {
499         mApplication.Quit();
500       }
501     }
502   }
503
504  /**
505   * Signal handler, called when the 'Scaling' button has been touched.
506   *
507   * @param[in] button The button that was pressed.
508   */
509   bool OnToggleScalingTouched( Button button )
510   {
511     const unsigned numChildren = mGridActor.GetChildCount();
512
513     for( unsigned i = 0; i < numChildren; ++i )
514     {
515       ImageActor gridImageActor = ImageActor::DownCast( mGridActor.GetChildAt( i ) );
516       if( gridImageActor )
517       {
518         // Cycle the scaling mode options:
519         const Vector2 imageSize = mSizes[gridImageActor.GetId()];
520         ImageAttributes::ScalingMode newMode = NextMode( mScalingModes[gridImageActor.GetId()] );
521         Image oldImage = gridImageActor.GetImage();
522         Image newImage = CreateImage(ResourceImage::DownCast(oldImage).GetUrl(), imageSize.width, imageSize.height, newMode );
523         gridImageActor.SetImage( newImage );
524
525         mScalingModes[gridImageActor.GetId()] = newMode;
526
527         SetTitle( std::string( newMode == ImageAttributes::ShrinkToFit ? "ShrinkToFit" : newMode == ImageAttributes::ScaleToFill ?  "ScaleToFill" : newMode == ImageAttributes::FitWidth ? "FitWidth" : "FitHeight" ) );
528       }
529     }
530     return true;
531   }
532
533   /**
534    * Sets/Updates the title of the View
535    * @param[in] title The new title for the view.
536    */
537   void SetTitle(const std::string& title)
538   {
539     if(!mTitleActor)
540     {
541       mTitleActor = TextView::New();
542       // Add title to the tool bar.
543       mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter );
544     }
545
546     Font font = Font::New();
547     mTitleActor.SetText( title );
548     mTitleActor.SetSize( font.MeasureText( title ) );
549     mTitleActor.SetStyleToCurrentText(DemoHelper::GetDefaultTextStyle());
550   }
551
552   /**
553    * When scroll starts (i.e. user starts to drag scrollview),
554    * note this state (mScrolling = true)
555    * @param[in] position Current Scroll Position
556    */
557   void OnScrollStarted( const Vector3& position )
558   {
559     mScrolling = true;
560   }
561
562   /**
563    * When scroll starts (i.e. user stops dragging scrollview, and scrollview has snapped to destination),
564    * note this state (mScrolling = false).
565    * @param[in] position Current Scroll Position
566    */
567   void OnScrollCompleted( const Vector3& position )
568   {
569     mScrolling = false;
570   }
571
572 private:
573   Application&  mApplication;
574
575   Layer mContentLayer;                ///< The content layer (contains non gui chrome actors)
576   Toolkit::View mView;                ///< The View instance.
577   Toolkit::ToolBar mToolBar;          ///< The View's Toolbar.
578   TextView mTitleActor;               ///< The Toolbar's Title.
579   Actor mGridActor;                   ///< The container for the grid of images
580   ScrollView mScrollView;             ///< ScrollView UI Component
581   bool mScrolling;                    ///< ScrollView scrolling state (true = scrolling, false = stationary)
582   std::map<unsigned, ImageAttributes::ScalingMode> mScalingModes; ///< Stores the current scaling mode of each image, keyed by image actor id.
583   std::map<unsigned, Vector2> mSizes; ///< Stores the current size of each image, keyed by image actor id.
584 };
585
586 void RunTest( Application& application )
587 {
588   ImageScalingIrregularGridController test( application );
589
590   application.MainLoop();
591 }
592
593 /** Entry point for Linux & Tizen applications */
594 int main( int argc, char **argv )
595 {
596   Application application = Application::New( &argc, &argv );
597
598   RunTest( application );
599
600   return 0;
601 }