Changes required after Visual parent-origin & anchor-point defaults change
[platform/core/uifw/dali-demo.git] / examples / mesh-visual / mesh-visual-example.cpp
1 #include <dali-toolkit/dali-toolkit.h>
2 #include <dali/public-api/object/property-map.h>
3 #include <dali-toolkit/devel-api/align-enums.h>
4 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
5
6 using namespace Dali;
7 using namespace Dali::Toolkit;
8
9 namespace
10 {
11 // Keeps information about each model for access.
12 struct Model
13 {
14   Control control; // Control housing the mesh visual of the model.
15   Vector2 rotation; // Keeps track of rotation about x and y axis for manual rotation.
16   Animation rotationAnimation; // Automatically rotates when left alone.
17 };
18
19 // Files for meshes
20 const char * const MODEL_FILE_TABLE[] =
21 {
22     DEMO_MODEL_DIR "Dino.obj",
23     DEMO_MODEL_DIR "ToyRobot-Metal.obj",
24     DEMO_MODEL_DIR "Toyrobot-Plastic.obj"
25 };
26
27 const char * const MATERIAL_FILE_TABLE[] =
28 {
29     DEMO_MODEL_DIR "Dino.mtl",
30     DEMO_MODEL_DIR "ToyRobot-Metal.mtl",
31     DEMO_MODEL_DIR "Toyrobot-Plastic.mtl"
32 };
33
34 const char * const TEXTURES_PATH( DEMO_IMAGE_DIR "" );
35
36 // Possible shading modes.
37 MeshVisual::ShadingMode::Value SHADING_MODE_TABLE[] =
38 {
39   MeshVisual::ShadingMode::TEXTURED_WITH_DETAILED_SPECULAR_LIGHTING,
40   MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING,
41   MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING
42 };
43
44 // Button labels.
45 const char * const PAUSE =  "  ||  ";
46 const char * const PLAY =   "  >  ";
47 const char * const FIXED =  "FIXED";
48 const char * const MANUAL = "MANUAL";
49 const char * const FRONT =  "FRONT";
50 const char * const BACK =   "BACK";
51
52 // Image urls for the light.
53 const char * const LIGHT_URL_FRONT = DEMO_IMAGE_DIR "light-icon-front.png";
54 const char * const LIGHT_URL_BACK =  DEMO_IMAGE_DIR "light-icon-back.png";
55
56 const float X_ROTATION_DISPLACEMENT_FACTOR = 60.0f;
57 const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.0f;
58 const float MODEL_SCALE =                    0.75f;
59 const float LIGHT_SCALE =                    0.15f;
60 const float BUTTONS_OFFSET_BOTTOM =          0.08f;
61 const float BUTTONS_OFFSET_SIDE =            0.2f;
62 const int   NUM_MESHES =                     2;
63
64 // Used to identify actors.
65 const int MODEL_TAG = 0;
66 const int LIGHT_TAG = 1;
67 const int LAYER_TAG = 2;
68
69 const Vector4 STAGE_COLOR( 211.0f / 255.0f, 211.0f / 255.0f, 211.0f / 255.0f, 1.0f ); ///< The color of the stage
70
71 } // unnamed namespace
72
73 class MeshVisualController : public ConnectionTracker
74 {
75 public:
76
77   MeshVisualController( Application& application )
78   : mApplication( application ),   //Store handle to the application.
79     mModelIndex( 1 ),              //Start with metal robot.
80     mShadingModeIndex( 0 ),        //Start with texture and detailed specular lighting.
81     mTag( -1 ),                    //Non-valid default, which will get set to a correct value when used.
82     mSelectedModelIndex( -1 ),     //Non-valid default, which will get set to a correct value when used.
83     mPaused( false ),              //Animations play by default.
84     mLightFixed( true ),           //The light is fixed by default.
85     mLightFront( true )            //The light is in front by default.
86   {
87     // Connect to the Application's Init signal
88     mApplication.InitSignal().Connect( this, &MeshVisualController::Create );
89   }
90
91   ~MeshVisualController()
92   {
93   }
94
95   // The Init signal is received once (only) during the Application lifetime
96   void Create( Application& application )
97   {
98     // Get a handle to the stage
99     Stage stage = Stage::GetCurrent();
100     stage.SetBackgroundColor( STAGE_COLOR );
101
102     //Set up root layer to receive touch gestures.
103     Layer rootLayer = stage.GetRootLayer();
104     rootLayer.RegisterProperty( "Tag", LAYER_TAG ); //Used to differentiate between different kinds of actor.
105     rootLayer.TouchSignal().Connect( this, &MeshVisualController::OnTouch );
106
107     //Place models on the scene.
108     SetupModels( rootLayer );
109
110     //Place buttons on the scene.
111     SetupButtons( rootLayer );
112
113     //Add a light to the scene.
114     SetupLight( rootLayer );
115
116     //Allow for exiting of the application via key presses.
117     stage.KeyEventSignal().Connect( this, &MeshVisualController::OnKeyEvent );
118   }
119
120   //Loads and adds the models to the scene, inside containers for hit detection.
121   void SetupModels( Layer layer )
122   {
123     //Add containers to house each renderer-holding-actor.
124     for( int i = 0; i < NUM_MESHES; i++ )
125     {
126       mContainers[i] = Actor::New();
127       mContainers[i].SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
128       mContainers[i].RegisterProperty( "Tag", MODEL_TAG ); //Used to differentiate between different kinds of actor.
129       mContainers[i].RegisterProperty( "Model", Property::Value( i ) ); //Used to index into the model.
130       mContainers[i].TouchSignal().Connect( this, &MeshVisualController::OnTouch );
131       layer.Add( mContainers[i] );
132     }
133
134     //Position each container individually on screen
135
136     //Main, central model
137     mContainers[0].SetSizeModeFactor( Vector3( MODEL_SCALE, MODEL_SCALE, 0.0f ) );
138     mContainers[0].SetParentOrigin( ParentOrigin::CENTER );
139     mContainers[0].SetAnchorPoint( AnchorPoint::CENTER );
140
141     //Top left model
142     mContainers[1].SetSizeModeFactor( Vector3( MODEL_SCALE / 3.0f, MODEL_SCALE / 3.0f, 0.0f ) );
143     mContainers[1].SetParentOrigin( Vector3( 0.05, 0.03, 0.5 ) ); //Offset from top left
144     mContainers[1].SetAnchorPoint( AnchorPoint::TOP_LEFT );
145
146     //Set up models
147     for( int i = 0; i < NUM_MESHES; i++ )
148     {
149       //Create control to display model
150       Control control = Control::New();
151       control.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
152       control.SetParentOrigin( ParentOrigin::CENTER );
153       control.SetAnchorPoint( AnchorPoint::CENTER );
154       mContainers[i].Add( control );
155
156       //Make model spin to demonstrate 3D
157       Animation rotationAnimation = Animation::New( 15.0f );
158       float spin = i % 2 == 0 ? 1.0f : -1.0f; //Make actors spin in different directions to better show independence.
159       rotationAnimation.AnimateBy( Property( control, Actor::Property::ORIENTATION ),
160                                    Quaternion( Degree( 0.0f ), Degree( spin * 360.0f ), Degree( 0.0f ) ) );
161       rotationAnimation.SetLooping( true );
162       rotationAnimation.Play();
163
164       //Store model information in corresponding structs.
165       mModels[i].control = control;
166       mModels[i].rotation.x = 0.0f;
167       mModels[i].rotation.y = 0.0f;
168       mModels[i].rotationAnimation = rotationAnimation;
169     }
170
171     //Calling this sets the model in the controls.
172     ReloadModel();
173   }
174
175   //Place the various buttons on the bottom of the screen, with title labels where necessary.
176   void SetupButtons( Layer layer )
177   {
178     //Actor for positioning model and shading mode buttons.
179     Actor positionActorModel = Actor::New();
180     positionActorModel.SetParentOrigin( Vector3( BUTTONS_OFFSET_SIDE, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) );
181     positionActorModel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
182     layer.Add( positionActorModel );
183
184     //Create button for model changing.
185     PushButton modelButton = Toolkit::PushButton::New();
186     modelButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
187     modelButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeModelClicked );
188     modelButton.SetParentOrigin( ParentOrigin::TOP_CENTER );
189     modelButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
190     modelButton.SetProperty( Toolkit::Button::Property::LABEL, "Model" );
191     positionActorModel.Add( modelButton );
192
193     //Create button for shading mode changing.
194     PushButton shadingModeButton = Toolkit::PushButton::New();
195     shadingModeButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
196     shadingModeButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeShadingModeClicked );
197     shadingModeButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
198     shadingModeButton.SetAnchorPoint( AnchorPoint::TOP_CENTER );
199     shadingModeButton.SetProperty( Toolkit::Button::Property::LABEL, "Shading Mode" );
200     positionActorModel.Add( shadingModeButton );
201
202     //Text label title for changing model or shading mode.
203     TextLabel changeTitleLabel = TextLabel::New( "Change" );
204     changeTitleLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
205     changeTitleLabel.SetProperty( TextLabel::Property::UNDERLINE, "{\"thickness\":\"2.0\"}" );
206     changeTitleLabel.SetParentOrigin( ParentOrigin::TOP_CENTER );
207     changeTitleLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
208     modelButton.Add( changeTitleLabel );
209
210     //Create button for pausing animations.
211     PushButton pauseButton = Toolkit::PushButton::New();
212     pauseButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
213     pauseButton.ClickedSignal().Connect( this, &MeshVisualController::OnPauseClicked );
214     pauseButton.SetParentOrigin( Vector3( 0.5, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) );
215     pauseButton.SetAnchorPoint( AnchorPoint::CENTER );
216     pauseButton.SetProperty( Toolkit::Button::Property::LABEL, PAUSE );
217     layer.Add( pauseButton );
218
219     //Actor for positioning light position buttons.
220     Actor positionActorLight = Actor::New();
221     positionActorLight.SetParentOrigin( Vector3( 1.0 - BUTTONS_OFFSET_SIDE, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) );
222     positionActorLight.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
223     layer.Add( positionActorLight );
224
225     //Create button for switching between manual and fixed light position.
226     PushButton lightModeButton = Toolkit::PushButton::New();
227     lightModeButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
228     lightModeButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightModeClicked );
229     lightModeButton.SetParentOrigin( ParentOrigin::TOP_CENTER );
230     lightModeButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
231     lightModeButton.SetProperty( Toolkit::Button::Property::LABEL, FIXED );
232     positionActorLight.Add( lightModeButton );
233
234     //Create button for switching between front and back light position.
235     PushButton lightSideButton = Toolkit::PushButton::New();
236     lightSideButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
237     lightSideButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightSideClicked );
238     lightSideButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
239     lightSideButton.SetAnchorPoint( AnchorPoint::TOP_CENTER );
240     lightSideButton.SetProperty( Toolkit::Button::Property::LABEL, FRONT );
241     positionActorLight.Add( lightSideButton );
242
243     //Text label title for light position mode.
244     TextLabel lightTitleLabel = TextLabel::New( "Light Position" );
245     lightTitleLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
246     lightTitleLabel.SetProperty( TextLabel::Property::UNDERLINE, "{\"thickness\":\"2.0\"}" );
247     lightTitleLabel.SetParentOrigin( ParentOrigin::TOP_CENTER );
248     lightTitleLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
249     lightModeButton.Add( lightTitleLabel );
250   }
251
252   //Add a point light source the the scene, on a layer above the first.
253   void SetupLight( Layer baseLayer )
254   {
255     //Create control to act as light source of scene.
256     mLightSource = Control::New();
257     mLightSource.RegisterProperty( "Tag", LIGHT_TAG );
258
259     //Set size of control based on screen dimensions.
260     Stage stage = Stage::GetCurrent();
261     if( stage.GetSize().width < stage.GetSize().height )
262     {
263       //Scale to width.
264       mLightSource.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
265       mLightSource.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
266       mLightSource.SetSizeModeFactor( Vector3( LIGHT_SCALE, 0.0f, 0.0f ) );
267     }
268     else
269     {
270       //Scale to height.
271       mLightSource.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT );
272       mLightSource.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::WIDTH );
273       mLightSource.SetSizeModeFactor( Vector3( 0.0f, LIGHT_SCALE, 0.0f ) );
274     }
275
276     //Set position relative to top left, as the light source property is also relative to the top left.
277     mLightSource.SetParentOrigin( ParentOrigin::TOP_LEFT );
278     mLightSource.SetAnchorPoint( AnchorPoint::CENTER );
279     mLightSource.SetPosition( Stage::GetCurrent().GetSize().x * 0.85f, Stage::GetCurrent().GetSize().y * 0.125 );
280
281     //Supply an image to represent the light.
282     SetLightImage();
283
284     //Connect to touch signal for dragging.
285     mLightSource.TouchSignal().Connect( this, &MeshVisualController::OnTouch );
286
287     //Place the light source on a layer above the base, so that it is rendered above everything else.
288     Layer upperLayer = Layer::New();
289     upperLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
290     upperLayer.SetParentOrigin( ParentOrigin::CENTER );
291     upperLayer.SetAnchorPoint( AnchorPoint::CENTER );
292
293     baseLayer.Add( upperLayer );
294     upperLayer.Add( mLightSource );
295
296     //Decide which light to use to begin with.
297     SetLightMode();
298   }
299
300   //Sets the image to use for the light source depending on whether the light is in front or behind.
301   void SetLightImage()
302   {
303     std::string imageUrl;
304
305     if( mLightFront )
306     {
307       imageUrl = LIGHT_URL_FRONT;
308     }
309     else
310     {
311       imageUrl = LIGHT_URL_BACK;
312     }
313
314     Property::Map lightMap;
315     lightMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
316     lightMap.Insert( ImageVisual::Property::URL, imageUrl );
317     mLightSource.SetProperty( Control::Property::BACKGROUND, Property::Value( lightMap ) );
318   }
319
320   //Updates the displayed models to account for parameter changes.
321   void ReloadModel()
322   {
323     //Create mesh property map
324     Property::Map map;
325     map.Insert( Visual::Property::TYPE,  Visual::MESH );
326     map.Insert( DevelVisual::Property::TRANSFORM,
327                 Property::Map().Add( DevelVisual::Transform::Property::ORIGIN, Align::CENTER )
328                                .Add( DevelVisual::Transform::Property::ANCHOR_POINT, Align::CENTER ) );
329     map.Insert( MeshVisual::Property::OBJECT_URL, MODEL_FILE_TABLE[mModelIndex] );
330     map.Insert( MeshVisual::Property::MATERIAL_URL, MATERIAL_FILE_TABLE[mModelIndex] );
331     map.Insert( MeshVisual::Property::TEXTURES_PATH, TEXTURES_PATH );
332     map.Insert( MeshVisual::Property::SHADING_MODE, SHADING_MODE_TABLE[mShadingModeIndex] );
333
334     //Set the two controls to use the mesh
335     for( int i = 0; i < NUM_MESHES; i++ )
336     {
337       mModels[i].control.SetProperty( Control::Property::BACKGROUND, Property::Value( map ) );
338     }
339   }
340
341   //Set the mode used to light the models.
342   void SetLightMode()
343   {
344     if( mLightFixed )
345     {
346       UseFixedLight();
347     }
348     else
349     {
350       UseManualLight();
351     }
352   }
353
354   //Make the models use a fixed, invisible light above the center of the stage.
355   void UseFixedLight()
356   {
357     //Hide draggable source
358     mLightSource.SetVisible( false );
359
360     //Use stage dimensions to place light at center, offset in z axis.
361     Stage stage = Stage::GetCurrent();
362     float width = stage.GetSize().width;
363     float height = stage.GetSize().height;
364     Vector3 lightPosition = Vector3( width / 2.0f, height / 2.0f,
365                                      ( mLightFront ? 1 : -1 ) * std::max( width, height ) * 5.0f );
366
367     //Set global light position
368     for( int i = 0; i < NUM_MESHES; ++i )
369     {
370       mModels[i].control.RegisterProperty( "lightPosition", lightPosition, Property::ANIMATABLE );
371     }
372   }
373
374   //Make the models use a light source that the user can drag around.
375   void UseManualLight()
376   {
377     //Show draggable source
378     mLightSource.SetVisible( true );
379
380     //Update to switch light position of models to that of the source.
381     UpdateLight();
382   }
383
384   //Updates the light position for each model to account for changes in the source on screen.
385   void UpdateLight()
386   {
387     //Set light position to the x and y of the light control, offset into/out of the screen.
388     Vector3 controlPosition = mLightSource.GetCurrentPosition();
389     Vector3 lightPosition = Vector3( controlPosition.x, controlPosition.y,
390                                      ( mLightFront ? 1 : -1 ) * Stage::GetCurrent().GetSize().x / 2.0f );
391
392     for( int i = 0; i < NUM_MESHES; ++i )
393     {
394       mModels[i].control.RegisterProperty( "lightPosition", lightPosition, Property::ANIMATABLE );
395     }
396   }
397
398   //If the light source is touched, move it by dragging it.
399   //If a model is touched, rotate it by panning around.
400   bool OnTouch( Actor actor, const TouchData& touch )
401   {
402     switch( touch.GetState( 0 ) )
403     {
404       case PointState::DOWN:
405       {
406         //Determine what was touched.
407         actor.GetProperty( actor.GetPropertyIndex( "Tag" ) ).Get( mTag );
408
409         if( mTag == MODEL_TAG )
410         {
411           //Find out which model has been selected
412           actor.GetProperty( actor.GetPropertyIndex( "Model" ) ).Get( mSelectedModelIndex );
413
414           //Pause current animation, as the touch gesture will be used to manually rotate the model
415           mModels[mSelectedModelIndex].rotationAnimation.Pause();
416
417           //Store start points.
418           mPanStart = touch.GetScreenPosition( 0 );
419           mRotationStart = mModels[mSelectedModelIndex].rotation;
420         }
421
422         break;
423       }
424       case PointState::MOTION:
425       {
426         //Switch on the kind of actor we're interacting with.
427         switch( mTag )
428         {
429           case MODEL_TAG: //Rotate model
430           {
431             //Calculate displacement and corresponding rotation.
432             Vector2 displacement = touch.GetScreenPosition( 0 ) - mPanStart;
433             mModels[mSelectedModelIndex].rotation = Vector2( mRotationStart.x - displacement.y / Y_ROTATION_DISPLACEMENT_FACTOR,   // Y displacement rotates around X axis
434                                                              mRotationStart.y + displacement.x / X_ROTATION_DISPLACEMENT_FACTOR ); // X displacement rotates around Y axis
435             Quaternion rotation = Quaternion( Radian( mModels[mSelectedModelIndex].rotation.x ), Vector3::XAXIS) *
436                                   Quaternion( Radian( mModels[mSelectedModelIndex].rotation.y ), Vector3::YAXIS);
437
438             //Apply rotation.
439             mModels[mSelectedModelIndex].control.SetOrientation( rotation );
440
441             break;
442           }
443           case LIGHT_TAG: //Drag light
444           {
445             //Set light source to new position and update the models accordingly.
446             mLightSource.SetPosition( Vector3( touch.GetScreenPosition( 0 ) ) );
447             UpdateLight();
448
449             break;
450           }
451         }
452
453         break;
454       }
455       case PointState::INTERRUPTED: //Same as finished.
456       case PointState::FINISHED:
457       {
458         if( mTag == MODEL_TAG )
459         {
460           //Return to automatic animation
461           if( !mPaused )
462           {
463             mModels[mSelectedModelIndex].rotationAnimation.Play();
464           }
465         }
466
467         break;
468       }
469       default:
470       {
471         //Other touch states do nothing.
472         break;
473       }
474     }
475
476     return true;
477   }
478
479   //Cycle through the list of models.
480   bool OnChangeModelClicked( Toolkit::Button button )
481   {
482     ++mModelIndex %= 3;
483
484     ReloadModel();
485
486     return true;
487   }
488
489   //Cycle through the list of shading modes.
490   bool OnChangeShadingModeClicked( Toolkit::Button button )
491   {
492     ++mShadingModeIndex %= 3;
493
494     ReloadModel();
495
496     return true;
497   }
498
499   //Pause all animations, and keep them paused even after user panning.
500   //This button is a toggle, so pressing again will start the animations again.
501   bool OnPauseClicked( Toolkit::Button button )
502   {
503     //Toggle pause state.
504     mPaused = !mPaused;
505
506     //If we wish to pause animations, do so and keep them paused.
507     if( mPaused )
508     {
509       for( int i = 0; i < NUM_MESHES ; ++i )
510       {
511         mModels[i].rotationAnimation.Pause();
512       }
513
514       button.SetProperty( Toolkit::Button::Property::LABEL, PLAY );
515     }
516     else //Unpause all animations again.
517     {
518       for( int i = 0; i < NUM_MESHES ; ++i )
519       {
520         mModels[i].rotationAnimation.Play();
521       }
522
523       button.SetProperty( Toolkit::Button::Property::LABEL, PAUSE );
524     }
525
526     return true;
527   }
528
529
530   //Switch between a fixed light source above/behind the screen, and a light source the user can drag around.
531   bool OnChangeLightModeClicked( Toolkit::Button button )
532   {
533     //Toggle state.
534     mLightFixed = !mLightFixed;
535
536     if( mLightFixed )
537     {
538       button.SetProperty( Toolkit::Button::Property::LABEL, FIXED );
539     }
540     else
541     {
542       button.SetProperty( Toolkit::Button::Property::LABEL, MANUAL );
543     }
544
545     SetLightMode();
546
547     return true;
548   }
549
550   //Switch between the light being in front of and behind the models.
551   bool OnChangeLightSideClicked( Toolkit::Button button )
552   {
553     //Toggle state.
554     mLightFront = !mLightFront;
555
556     if( mLightFront )
557     {
558       button.SetProperty( Toolkit::Button::Property::LABEL, FRONT );
559     }
560     else
561     {
562       button.SetProperty( Toolkit::Button::Property::LABEL, BACK );
563     }
564
565     //Change light image.
566     SetLightImage();
567
568     //Update light to account for the change.
569     SetLightMode();
570
571     return true;
572   }
573
574   //If escape or the back button is pressed, quit the application (and return to the launcher)
575   void OnKeyEvent( const KeyEvent& event )
576   {
577     if( event.state == KeyEvent::Down )
578     {
579       if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
580       {
581         mApplication.Quit();
582       }
583     }
584   }
585
586 private:
587   Application&  mApplication;
588
589   //The models displayed on screen, including information about rotation.
590   Model mModels[NUM_MESHES];
591   Actor mContainers[NUM_MESHES];
592
593   //Acts as a global light source, which can be dragged around.
594   Control mLightSource;
595
596   //Used to detect panning to rotate the selected model.
597   Vector2 mPanStart;
598   Vector2 mRotationStart;
599
600   int mModelIndex; //Index of model to load.
601   int mShadingModeIndex; //Index of shading mode to use.
602   int mTag; //Identifies what kind of actor has been selected in OnTouch.
603   int mSelectedModelIndex; //Index of model selected on screen.
604   bool mPaused; //If true, all animations are paused and should stay so.
605   bool mLightFixed; //If false, the light is in manual.
606   bool mLightFront; //Bool for light being in front or behind the models.
607 };
608
609 // Entry point for Linux & Tizen applications
610 //
611 int main( int argc, char **argv )
612 {
613   Application application = Application::New( &argc, &argv );
614   MeshVisualController test( application );
615   application.MainLoop();
616   return 0;
617 }