Updates following Visual Property Changes
[platform/core/uifw/dali-demo.git] / examples / primitive-shapes / primitive-shapes-example.cpp
1 #include <dali-toolkit/dali-toolkit.h>
2 #include <dali/public-api/object/property-map.h>
3 #include <dali-toolkit/public-api/controls/slider/slider.h>
4
5 using namespace Dali;
6 using namespace Dali::Toolkit;
7
8 namespace
9 {
10   //Button image urls
11   const char* BUTTON_IMAGE_URL[] =
12   {
13     DEMO_IMAGE_DIR "sphere-button.png",
14     DEMO_IMAGE_DIR "cone-button.png",
15     DEMO_IMAGE_DIR "conical-frustrum-button.png",
16     DEMO_IMAGE_DIR "cylinder-button.png",
17     DEMO_IMAGE_DIR "cube-button.png",
18     DEMO_IMAGE_DIR "bevelled-cube-button.png",
19     DEMO_IMAGE_DIR "octahedron-button.png"
20   };
21
22   //Shape property defaults
23   const int DEFAULT_SLICES = 32;
24   const int DEFAULT_STACKS = 32;
25   const float DEFAULT_SCALE_HEIGHT = 16.0f;
26   const float DEFAULT_SCALE_BOTTOM_RADIUS = 8.0f;
27   const float DEFAULT_SCALE_TOP_RADIUS = 4.0f;
28   const float DEFAULT_SCALE_RADIUS = 8.0f;
29   const float DEFAULT_BEVEL_PERCENTAGE = 0.3f;
30   const float DEFAULT_BEVEL_SMOOTHNESS = 0.0f;
31
32   //Shape property limits
33   const int SLICES_LOWER_BOUND = 3;
34   const int SLICES_UPPER_BOUND = 16;
35   const int STACKS_LOWER_BOUND = 2;
36   const int STACKS_UPPER_BOUND = 16;
37
38   //Used to the control rate of rotation when panning an object.
39   const float X_ROTATION_DISPLACEMENT_FACTOR = 60.0f;
40   const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.0f;
41
42   const int NUM_MODELS = 7; //Total number of possible base shapes.
43   const int MAX_PROPERTIES = 3; //Maximum number of properties a shape may require. (For displaying sliders.)
44
45 } //End namespace
46
47 class PrimitiveShapesController : public ConnectionTracker
48 {
49 public:
50
51   PrimitiveShapesController( Application& application )
52   : mApplication( application ),
53     mColor( Vector4( 0.3f, 0.7f, 1.0f, 1.0f ) ),
54     mRotation( Vector2::ZERO )
55   {
56     // Connect to the Application's Init signal
57     mApplication.InitSignal().Connect( this, &PrimitiveShapesController::Create );
58   }
59
60   ~PrimitiveShapesController()
61   {
62   }
63
64   // The Init signal is received once (only) during the Application lifetime
65   void Create( Application& application )
66   {
67     // Get a handle to the stage
68     Stage stage = Stage::GetCurrent();
69     stage.SetBackgroundColor( Color::WHITE );
70
71     //Set up layer to place UI on.
72     Layer layer = Layer::New();
73     layer.SetParentOrigin( ParentOrigin::CENTER );
74     layer.SetAnchorPoint( AnchorPoint::CENTER );
75     layer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
76     layer.SetBehavior( Layer::LAYER_2D ); //We use a 2D layer as this is closer to UI work than full 3D scene creation.
77     layer.SetDepthTestDisabled( false ); //Enable depth testing, as otherwise the 2D layer would not do so.
78     stage.Add( layer );
79
80     //Set up model selection buttons.
81     SetupButtons( layer );
82
83     //Set up model parameter sliders.
84     SetupSliders( layer );
85
86     //Set up 3D model.
87     SetupModel( layer );
88
89     //Allow for exiting of the application via key presses.
90     stage.KeyEventSignal().Connect( this, &PrimitiveShapesController::OnKeyEvent );
91   }
92
93   //Place buttons on the top of the screen, which allow for selection of the shape to be displayed.
94   //The buttons are laid out like so:
95   //
96   //      ^    +--------------------------------+
97   //      |    |                                |
98   //      |    | +----+ +----+ +----+ +----+    |
99   //      |    | |    | |    | |    | |    |    |
100   //  30% |    | +----+ +----+ +----+ +----+    |
101   //      |    |                                |
102   //      |    | +----+ +----+ +----+           |
103   //      |    | |    | |    | |    |           |
104   //      v    | +----+ +----+ +----+           |
105   //           |                                |
106   //           |                                |
107   //           |                                |
108   //           |                                |
109   //           |                                |
110   //           |                                |
111   //           |                                |
112   //           |                                |
113   //           |                                |
114   //           |                                |
115   //           |                                |
116   //           |                                |
117   //           |                                |
118   //           |                                |
119   //           |                                |
120   //           |                                |
121   //           |                                |
122   //           |                                |
123   //           |                                |
124   //           +--------------------------------+
125   //
126   void SetupButtons( Layer layer )
127   {
128     float containerPadding = 10.0f;
129     float buttonPadding = 5.0f;
130
131     //Create a variable-length container that can wrap buttons around as more are added.
132     FlexContainer buttonContainer = FlexContainer::New();
133     buttonContainer.SetParentOrigin( ParentOrigin::TOP_CENTER );
134     buttonContainer.SetAnchorPoint( AnchorPoint::TOP_CENTER );
135     buttonContainer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
136     buttonContainer.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT );
137     buttonContainer.SetSizeModeFactor( Vector3( 0.0, 0.3, 0.0 ) );  //30% of height.
138     buttonContainer.SetPadding( Padding( containerPadding, containerPadding, containerPadding, containerPadding ) );
139     buttonContainer.SetProperty( FlexContainer::Property::FLEX_DIRECTION, FlexContainer::ROW );
140     buttonContainer.SetProperty( FlexContainer::Property::FLEX_WRAP, FlexContainer::WRAP );
141
142     layer.Add( buttonContainer );
143
144     //Create buttons and place them in the container.
145     for( int modelNumber = 0; modelNumber < NUM_MODELS; modelNumber++ )
146     {
147       PushButton button = Toolkit::PushButton::New();
148       button.SetParentOrigin( ParentOrigin::CENTER );
149       button.SetAnchorPoint( AnchorPoint::CENTER );
150       button.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
151       button.SetPadding( Padding( buttonPadding, buttonPadding, buttonPadding, buttonPadding ) );
152       button.SetProperty( Button::Property::UNSELECTED_STATE_IMAGE, Property::Value( BUTTON_IMAGE_URL[modelNumber] ) );
153       button.SetProperty( Button::Property::SELECTED_STATE_IMAGE, Property::Value( BUTTON_IMAGE_URL[modelNumber] ) );
154       button.RegisterProperty( "modelNumber", Property::Value( modelNumber ) );
155       button.ClickedSignal().Connect( this, &PrimitiveShapesController::OnChangeShapeClicked );
156
157       buttonContainer.Add( button );
158     }
159   }
160
161   //Add sliders to the bottom of the screen, which allow for control of shape properties such as radius.
162   //Each slider is placed next to a label that states the property it affects.
163   //The sliders are laid out like so:
164   //
165   //           +--------------------------------+
166   //           |                                |
167   //           |                                |
168   //           |                                |
169   //           |                                |
170   //           |                                |
171   //           |                                |
172   //           |                                |
173   //           |                                |
174   //           |                                |
175   //           |                                |
176   //           |                                |
177   //           |                                |
178   //           |                                |
179   //           |                                |
180   //           |                                |
181   //           |                                |
182   //           |                                |
183   //           |                                |
184   //           |                                |
185   //      ^    | Label +----------O-----------+ |
186   //      |    |                                |
187   //      |    |                                |
188   //      |    | Label +--O-------------------+ |
189   //  30% |    |                                |
190   //      |    |                                |
191   //      |    | Label +----------------------O |
192   //      |    |                                |
193   //      v    +--------------------------------+
194   //
195   void SetupSliders( Layer layer )
196   {
197     //Create table to hold sliders and their corresponding labels.
198     mSliderTable = Toolkit::TableView::New( MAX_PROPERTIES, 2 );
199     mSliderTable.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
200     mSliderTable.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
201     mSliderTable.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
202     mSliderTable.SetSizeModeFactor( Vector3( 0.9, 0.3, 0.0 ) );  //90% of width, 30% of height.
203     mSliderTable.SetFitWidth( 0 );  //Label column should fit to natural size of label.
204     mSliderTable.SetRelativeWidth( 1, 1.0f );  //Slider column should fill remaining space.
205     mSliderTable.SetCellPadding( Vector2( 10.0f, 0.0f ) ); //Leave a gap between the slider and its label.
206     layer.Add( mSliderTable );
207
208     //Set up sliders, and place labels next to them.
209     for( int i = 0; i < MAX_PROPERTIES; i++ )
210     {
211       //Create slider
212       Slider slider = Slider::New();
213       slider.SetParentOrigin( ParentOrigin::CENTER );
214       slider.SetAnchorPoint( AnchorPoint::CENTER );
215       slider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
216       slider.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
217       slider.ValueChangedSignal().Connect( this, &PrimitiveShapesController::OnSliderValueChanged );
218       mSliders.push_back( slider );
219
220       //Setup slider cell properties
221       mSliderTable.AddChild( slider, TableView::CellPosition( i, 1 ) );
222       mSliderTable.SetCellAlignment( TableView::CellPosition( i, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
223
224       //Create slider label
225       TextLabel sliderLabel = TextLabel::New();
226       sliderLabel.SetParentOrigin( ParentOrigin::CENTER );
227       sliderLabel.SetAnchorPoint( AnchorPoint::CENTER );
228       sliderLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
229       mSliderLabels.push_back( sliderLabel );
230
231       //Setup slider-label cell properties
232       mSliderTable.AddChild( sliderLabel, TableView::CellPosition( i, 0 ) );
233       mSliderTable.SetCellAlignment( TableView::CellPosition( i, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
234     }
235   }
236
237   //Adds a control to the centre of the stage to display the 3D shapes.
238   //The model is placed in the center of the screen, like so:
239   //
240   //           +--------------------------------+
241   //           |                                |
242   //           |                                |
243   //           |                                |
244   //           |                                |
245   //           |                                |
246   //           |                                |
247   //           |                                |
248   //           |                                |
249   //           |                                |
250   //       ^   |           ----------           |
251   //       |   |          /          \          |
252   //       |   |         /            \         |
253   //       |   |        |              |        |
254   //   30% |   |        |              |        |
255   //       |   |        |              |        |
256   //       |   |         \            /         |
257   //       |   |          \          /          |
258   //       v   |           ----------           |
259   //           |                                |
260   //           |                                |
261   //           |                                |
262   //           |                                |
263   //           |                                |
264   //           |                                |
265   //           |                                |
266   //           |                                |
267   //           |                                |
268   //           +--------------------------------+
269   //
270   void SetupModel( Layer layer )
271   {
272     //Create a container to house the visual-holding actor, to provide a constant hitbox.
273     Actor container = Actor::New();
274     container.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
275     container.SetSizeModeFactor( Vector3( 0.9, 0.3, 0.0 ) );  //90% of width, 30% of height.
276     container.SetParentOrigin( ParentOrigin::CENTER );
277     container.SetAnchorPoint( AnchorPoint::CENTER );
278     layer.Add( container );
279
280     //Create control to display the 3D primitive.
281     mModel = Control::New();
282     mModel.SetParentOrigin( ParentOrigin::CENTER );
283     mModel.SetAnchorPoint( AnchorPoint::CENTER);
284     mModel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
285     container.Add( mModel );
286
287     //Load default shape.
288     LoadCube();
289
290     //Make model spin to demonstrate 3D.
291     mRotationAnimation = Animation::New(15.0f);
292     mRotationAnimation.AnimateBy( Property( mModel, Actor::Property::ORIENTATION ),
293                                  Quaternion( Degree( 0.0f ), Degree( 360.0f ), Degree( 0.0f ) ) );
294     mRotationAnimation.SetLooping(true);
295     mRotationAnimation.Play();
296
297     //Attach gesture detector to pan models when rotated.
298     mPanGestureDetector = PanGestureDetector::New();
299     mPanGestureDetector.Attach( container );
300     mPanGestureDetector.DetectedSignal().Connect( this, &PrimitiveShapesController::OnPan );
301   }
302
303   //Clears all sliders and resets the primitive visual property map.
304   void InitialiseSlidersAndModel()
305   {
306     //Sliders
307     for( unsigned i = 0; i < mSliders.size(); i++ )
308     {
309       mSliders.at( i ).SetProperty( Slider::Property::MARKS, Property::Value( 0 ) ); //Remove marks
310       mSliders.at( i ).SetVisible( false );
311       mSliderLabels.at( i ).SetProperty( TextLabel::Property::TEXT, Property::Value( "Default" ) );
312       mSliderLabels.at( i ).SetVisible( false );
313     }
314
315     //Visual map for model
316     mVisualMap.Clear();
317     mVisualMap[ Visual::Property::TYPE           ] = Visual::PRIMITIVE;
318     mVisualMap[ PrimitiveVisual::Property::COLOR ] = mColor;
319   }
320
321   //Sets the 3D model to a sphere and modifies the sliders appropriately.
322   void LoadSphere()
323   {
324     InitialiseSlidersAndModel();
325
326     //Set up specific visual properties.
327     mVisualMap[ PrimitiveVisual::Property::SHAPE  ] = PrimitiveVisual::Shape::SPHERE;
328     mVisualMap[ PrimitiveVisual::Property::SLICES ] = DEFAULT_SLICES;
329     mVisualMap[ PrimitiveVisual::Property::STACKS ] = DEFAULT_STACKS;
330
331     //Set up sliders.
332     SetupSlider( 0, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::SLICES, "slices" );
333     SetupMarks( mSliders.at( 0 ), SLICES_LOWER_BOUND, SLICES_UPPER_BOUND );
334     SetupSlider( 1, STACKS_LOWER_BOUND, STACKS_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::STACKS, "stacks" );
335     SetupMarks( mSliders.at( 1 ), STACKS_LOWER_BOUND, STACKS_UPPER_BOUND );
336
337     //Set model in control.
338     mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
339   }
340
341   //Sets the 3D model to a cone and modifies the sliders appropriately.
342   void LoadCone()
343   {
344     InitialiseSlidersAndModel();
345
346     //Set up specific visual properties.
347     mVisualMap[ PrimitiveVisual::Property::SHAPE               ] = PrimitiveVisual::Shape::CONE;
348     mVisualMap[ PrimitiveVisual::Property::SCALE_HEIGHT        ] = DEFAULT_SCALE_HEIGHT;
349     mVisualMap[ PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS ] = DEFAULT_SCALE_BOTTOM_RADIUS;
350     mVisualMap[ PrimitiveVisual::Property::SLICES              ] = DEFAULT_SLICES;
351
352     //Set up sliders.
353     SetupSlider( 0, 1.0f, 32.0f, DEFAULT_SCALE_HEIGHT, PrimitiveVisual::Property::SCALE_HEIGHT, "scaleHeight" );
354     SetupSlider( 1, 1.0f, 32.0f, DEFAULT_SCALE_BOTTOM_RADIUS, PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, "scaleBottomRadius" );
355     SetupSlider( 2, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::SLICES, "slices" );
356     SetupMarks( mSliders.at( 2 ), SLICES_LOWER_BOUND, SLICES_UPPER_BOUND );
357
358     //Set model in control.
359     mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
360   }
361
362   //Sets the 3D model to a conical frustrum and modifies the sliders appropriately.
363   void LoadConicalFrustrum()
364   {
365     InitialiseSlidersAndModel();
366
367     //Set up specific visual properties.
368     mVisualMap[ PrimitiveVisual::Property::SHAPE               ] = PrimitiveVisual::Shape::CONICAL_FRUSTRUM;
369     mVisualMap[ PrimitiveVisual::Property::SCALE_TOP_RADIUS    ] = DEFAULT_SCALE_TOP_RADIUS;
370     mVisualMap[ PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS ] = DEFAULT_SCALE_BOTTOM_RADIUS;
371     mVisualMap[ PrimitiveVisual::Property::SCALE_HEIGHT        ] = DEFAULT_SCALE_HEIGHT;
372     mVisualMap[ PrimitiveVisual::Property::SLICES              ] = DEFAULT_SLICES;
373
374     //Set up used sliders.
375     SetupSlider( 0, 1.0f, 32.0f, DEFAULT_SCALE_HEIGHT, PrimitiveVisual::Property::SCALE_HEIGHT, "scaleHeight" );
376     SetupSlider( 1, 0.0f, 32.0f, DEFAULT_SCALE_BOTTOM_RADIUS, PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, "scaleBottomRadius" );
377     SetupSlider( 2, 0.0f, 32.0f, DEFAULT_SCALE_TOP_RADIUS, PrimitiveVisual::Property::SCALE_TOP_RADIUS, "scaleTopRadius" );
378
379     //Set model in control.
380     mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
381   }
382
383   //Sets the 3D model to a cylinder and modifies the sliders appropriately.
384   void LoadCylinder()
385   {
386     InitialiseSlidersAndModel();
387
388     //Set up specific visual properties.
389     mVisualMap[ PrimitiveVisual::Property::SHAPE        ] = PrimitiveVisual::Shape::CYLINDER;
390     mVisualMap[ PrimitiveVisual::Property::SCALE_HEIGHT ] = DEFAULT_SCALE_HEIGHT;
391     mVisualMap[ PrimitiveVisual::Property::SCALE_RADIUS ] = DEFAULT_SCALE_RADIUS;
392     mVisualMap[ PrimitiveVisual::Property::SLICES       ] = DEFAULT_SLICES;
393
394     //Set up used sliders.
395     SetupSlider( 0, 1.0f, 32.0f, DEFAULT_SCALE_HEIGHT, PrimitiveVisual::Property::SCALE_HEIGHT, "scaleHeight" );
396     SetupSlider( 1, 1.0f, 32.0f, DEFAULT_SCALE_RADIUS, PrimitiveVisual::Property::SCALE_RADIUS, "scaleRadius" );
397     SetupSlider( 2, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::SLICES, "slices" );
398     SetupMarks( mSliders.at( 2 ), SLICES_LOWER_BOUND, SLICES_UPPER_BOUND );
399
400     //Set model in control.
401     mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
402   }
403
404   //Sets the 3D model to a cube and modifies the sliders appropriately.
405   void LoadCube()
406   {
407     InitialiseSlidersAndModel();
408
409     //Set up specific visual properties.
410     mVisualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::CUBE;
411
412     //Set model in control.
413     mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
414   }
415
416   //Sets the 3D model to a bevelled cube and modifies the sliders appropriately.
417   void LoadBevelledCube()
418   {
419     InitialiseSlidersAndModel();
420
421     //Set up specific visual properties.
422     mVisualMap[ PrimitiveVisual::Property::SHAPE            ] = PrimitiveVisual::Shape::BEVELLED_CUBE;
423     mVisualMap[ PrimitiveVisual::Property::BEVEL_PERCENTAGE ] = DEFAULT_BEVEL_PERCENTAGE;
424     mVisualMap[ PrimitiveVisual::Property::BEVEL_SMOOTHNESS ] = DEFAULT_BEVEL_SMOOTHNESS;
425
426     //Set up used sliders.
427     SetupSlider( 0, 0.0f, 1.0f, DEFAULT_BEVEL_PERCENTAGE, PrimitiveVisual::Property::BEVEL_PERCENTAGE, "bevelPercentage" );
428     SetupSlider( 1, 0.0f, 1.0f, DEFAULT_BEVEL_SMOOTHNESS, PrimitiveVisual::Property::BEVEL_SMOOTHNESS, "bevelSmoothness" );
429
430     //Set model in control.
431     mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
432   }
433
434   //Sets the 3D model to an octahedron and modifies the sliders appropriately.
435   void LoadOctahedron()
436   {
437     InitialiseSlidersAndModel();
438
439     //Set up specific visual properties.
440     mVisualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::OCTAHEDRON;
441
442     //Set model in control.
443     mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
444   }
445
446   //Sets up the slider at the given index for the supplied property, and labels it appropriately.
447   // visualProperty is the property that will be set by this slider.
448   void SetupSlider( int sliderIndex, float lowerBound, float upperBound, float startPoint,
449                     Property::Index visualProperty, std::string visualPropertyLabel )
450   {
451     //Set up the slider itself.
452     mSliders.at( sliderIndex ).RegisterProperty( "visualProperty", Property::Value( visualProperty ), Property::READ_WRITE );
453     mSliders.at( sliderIndex ).SetProperty( Slider::Property::LOWER_BOUND, Property::Value( lowerBound ) );
454     mSliders.at( sliderIndex ).SetProperty( Slider::Property::UPPER_BOUND, Property::Value( upperBound ) );
455     mSliders.at( sliderIndex ).SetProperty( Slider::Property::VALUE, Property::Value( startPoint ) );
456     mSliders.at( sliderIndex ).SetVisible( true );
457
458     //Label the slider with the property.
459     //We reset the TextLabel to force a relayout of the table.
460     mSliderTable.RemoveChildAt( TableView::CellPosition(sliderIndex, 0) );
461
462     TextLabel sliderLabel = TextLabel::New( visualPropertyLabel );
463     sliderLabel.SetParentOrigin( ParentOrigin::CENTER );
464     sliderLabel.SetAnchorPoint( AnchorPoint::CENTER );
465     sliderLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
466
467     mSliderTable.AddChild( sliderLabel, TableView::CellPosition( sliderIndex, 0 ) );
468     mSliderTable.SetCellAlignment( TableView::CellPosition( sliderIndex, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
469
470     mSliderLabels.at( sliderIndex ).SetVisible( true );
471     mSliderLabels.at( sliderIndex) = sliderLabel;
472   }
473
474   //Setup snapping to integer values between the two given values.
475   void SetupMarks( Slider& slider, int lower, int upper )
476   {
477     Property::Array marks;
478
479     for( int mark = lower; mark <= upper; mark++ )
480     {
481       marks.PushBack( Property::Value( mark ) );
482     }
483
484     slider.SetProperty( Slider::Property::MARKS, Property::Value( marks ) );
485     slider.SetProperty( Slider::Property::SNAP_TO_MARKS, Property::Value( true ) );
486   }
487
488   //When a shape button is tapped, switch to the corresponding shape.
489   bool OnChangeShapeClicked( Button button )
490   {
491     //Get the model number from the button.
492     int modelNumber;
493     button.GetProperty( button.GetPropertyIndex( "modelNumber" ) ).Get( modelNumber );
494
495     //Switch to the shape that corresponds to the model number.
496     switch( modelNumber )
497     {
498       case 0:
499       {
500         LoadSphere();
501         break;
502       }
503       case 1:
504       {
505         LoadCone();
506         break;
507       }
508       case 2:
509       {
510         LoadConicalFrustrum();
511         break;
512       }
513       case 3:
514       {
515         LoadCylinder();
516         break;
517       }
518       case 4:
519       {
520         LoadCube();
521         break;
522       }
523       case 5:
524       {
525         LoadBevelledCube();
526         break;
527       }
528       case 6:
529       {
530         LoadOctahedron();
531         break;
532       }
533     }
534
535     return true;
536   }
537
538   //When the slider is adjusted, change the corresponding shape property accordingly.
539   bool OnSliderValueChanged( Slider slider, float value )
540   {
541     //Update property map to reflect the change to the specific visual property.
542     int visualProperty;
543     slider.GetProperty( slider.GetPropertyIndex( "visualProperty" ) ).Get( visualProperty );
544     mVisualMap[ visualProperty ] = value;
545
546     //Reload the model to display the change.
547     mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
548
549     return true;
550   }
551
552   //Panning around the shape rotates it.
553   void OnPan( Actor actor, const PanGesture& gesture )
554   {
555     switch( gesture.state )
556     {
557       case Gesture::Started:
558       {
559         //Pause animation, as the gesture will be used to manually rotate the model
560         mRotationAnimation.Pause();
561
562         break;
563       }
564       case Gesture::Continuing:
565       {
566         //Rotate based off the gesture.
567         mRotation.x -= gesture.displacement.y / X_ROTATION_DISPLACEMENT_FACTOR; // Y displacement rotates around X axis
568         mRotation.y += gesture.displacement.x / Y_ROTATION_DISPLACEMENT_FACTOR; // X displacement rotates around Y axis
569         Quaternion rotation = Quaternion( Radian( mRotation.x ), Vector3::XAXIS) *
570                               Quaternion( Radian( mRotation.y ), Vector3::YAXIS);
571
572         mModel.SetOrientation( rotation );
573
574         break;
575       }
576       case Gesture::Finished:
577       {
578         //Return to automatic animation
579         mRotationAnimation.Play();
580
581         break;
582       }
583       case Gesture::Cancelled:
584       {
585         //Return to automatic animation
586         mRotationAnimation.Play();
587
588         break;
589       }
590       default:
591       {
592         break;
593       }
594     }
595   }
596
597   //If escape or the back button is pressed, quit the application (and return to the launcher)
598   void OnKeyEvent( const KeyEvent& event )
599   {
600     if( event.state == KeyEvent::Down )
601     {
602       if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
603       {
604         mApplication.Quit();
605       }
606     }
607   }
608
609 private:
610   Application& mApplication;
611
612   std::vector<Slider> mSliders; ///< Holds the sliders on screen that each shape accesses.
613   std::vector<TextLabel> mSliderLabels; ///< Holds the labels to each slider.
614   TableView mSliderTable; ///< A table to layout the sliders next to their labels.
615
616   Property::Map mVisualMap; ///< Property map to create a primitive visual.
617   Control mModel; ///< Control to house the primitive visual.
618
619   PanGestureDetector mPanGestureDetector; ///< Detects pan gestures for rotation of the model.
620   Animation mRotationAnimation; ///< Automatically rotates the model, unless it is being panned.
621
622   Vector4 mColor; ///< Color to set all shapes.
623   Vector2 mRotation; ///< Keeps track of model rotation.
624 };
625
626 void RunTest( Application& application )
627 {
628   PrimitiveShapesController test( application );
629
630   application.MainLoop();
631 }
632
633 // Entry point for Linux & Tizen applications
634 //
635 int main( int argc, char **argv )
636 {
637   Application application = Application::New( &argc, &argv );
638
639   RunTest( application );
640
641   return 0;
642 }