DALi Version 1.4.38
[platform/core/uifw/dali-demo.git] / examples / tilt / tilt-example.cpp
index 08d6fd6..dec8078 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -56,22 +56,25 @@ public:
     stage.Add( mTextLabel );
 
     // Respond to a click anywhere on the stage
-    stage.GetRootLayer().TouchedSignal().Connect( this, &TiltController::OnTouch );
+    stage.GetRootLayer().TouchSignal().Connect( this, &TiltController::OnTouch );
 
     CreateSensor();
+
+    // Connect signals to allow Back and Escape to exit.
+    stage.KeyEventSignal().Connect( this, &TiltController::OnKeyEvent );
   }
 
   void CreateSensor()
   {
     mTiltSensor = TiltSensor::Get();
-    if ( mTiltSensor.Enable() )
+    if ( mTiltSensor.Start() )
     {
       // Get notifications when the device is tilted
       mTiltSensor.TiltedSignal().Connect( this, &TiltController::OnTilted );
     }
   }
 
-  bool OnTouch( Actor actor, const TouchEvent& touch )
+  bool OnTouch( Actor actor, const TouchData& touch )
   {
     // quit the application
     mApplication.Quit();
@@ -88,14 +91,27 @@ public:
     mTextLabel.RotateBy(pitchRot);;
   }
 
+  /**
+   * @brief OnKeyEvent signal handler.
+   * @param[in] event The key event information
+   */
+  void OnKeyEvent( const KeyEvent& event )
+  {
+    if( event.state == KeyEvent::Down )
+    {
+      if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
+      {
+        mApplication.Quit();
+      }
+    }
+  }
+
 private:
   Application&  mApplication;
   TiltSensor mTiltSensor;
   TextLabel mTextLabel;
 };
 
-// Entry point for Linux & Tizen applications
-//
 int DALI_EXPORT_API main( int argc, char **argv )
 {
   Application application = Application::New( &argc, &argv );