[Tizen] Add codes for Dali Windows Backend
[platform/core/uifw/dali-demo.git] / examples / rendering-triangle / rendering-triangle.cpp
index 57233f8..76fae81 100644 (file)
@@ -93,6 +93,9 @@ public:
 
     // Respond to a click anywhere on the stage
     stage.GetRootLayer().TouchSignal().Connect( this, &DrawTriangleController::OnTouch );
+
+    // Respond to key events
+    stage.KeyEventSignal().Connect( this, &DrawTriangleController::OnKeyEvent );
   }
 
   bool OnTouch( Actor actor, const TouchData& touch )
@@ -103,6 +106,23 @@ public:
   }
 
   /**
+   * @brief Called when any key event is received
+   *
+   * Will use this to quit the application if Back or the Escape key is received
+   * @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();
+      }
+    }
+  }
+
+  /**
    * This function creates a triangle geometry made of three vertices in order
    * to draw a coloured triangle.
    */
@@ -167,20 +187,10 @@ private:
   Actor mActor;
 };
 
-void RunTest( Application& application )
-{
-  DrawTriangleController test( application );
-
-  application.MainLoop();
-}
-
-// Entry point for Linux & Tizen applications
-//
 int DALI_EXPORT_API main( int argc, char **argv )
 {
   Application application = Application::New( &argc, &argv );
-
-  RunTest( application );
-
+  DrawTriangleController test( application );
+  application.MainLoop();
   return 0;
 }