Add Back key support to examples which do not have it 19/120919/1
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 24 Mar 2017 18:51:32 +0000 (18:51 +0000)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 24 Mar 2017 18:51:32 +0000 (18:51 +0000)
Change-Id: Ib36b14b0763130b811ae1f45ce4c631c25d6776c

examples/focus-integration/focus-integration.cpp
examples/rendering-cube/rendering-cube.cpp
examples/rendering-line/rendering-line.cpp
examples/rendering-textured-cube/rendering-textured-cube.cpp
examples/rendering-triangle/rendering-triangle.cpp

index 10520b9a47b77b230e6382bf1fb0e66f0c7fc5cd..2e80a96589b22d42459b06f253bddeb6334c7966 100644 (file)
@@ -141,6 +141,9 @@ public:
     }
 
     KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &FocusIntegrationExample::OnPreFocusChange );
+
+    // Respond to key events
+    mStage.KeyEventSignal().Connect( this, &FocusIntegrationExample::OnKeyEvent );
   }
 
   // Callback for KeyboardFocusManager
index a42e83245b0fa1dce2c6ede38bf0279869a87854..9d745bd71cefc323fe44b140ca4e8f33078ee3d5 100644 (file)
@@ -100,6 +100,9 @@ public:
 
     // Respond to a click anywhere on the stage
     stage.GetRootLayer().TouchSignal().Connect( this, &DrawCubeController::OnTouch );
+
+    // Respond to key events
+    stage.KeyEventSignal().Connect( this, &DrawCubeController::OnKeyEvent );
   }
 
   bool OnTouch( Actor actor, const TouchData& touch )
@@ -109,6 +112,23 @@ public:
     return true;
   }
 
+  /**
+   * @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 cube geometry including texture coordinates.
    * Also it demonstrates using the indexed draw feature by setting an index array.
index 70d55ccac30f9ed8adaed7713814b150766cf86b..d16f8e67430e347371b4ffb00ef2563ffe1efe10 100644 (file)
@@ -93,6 +93,9 @@ public:
 
     // Respond to a click anywhere on the stage
     stage.GetRootLayer().TouchSignal().Connect( this, &DrawLineController::OnTouch );
+
+    // Respond to key events
+    stage.KeyEventSignal().Connect( this, &DrawLineController::OnKeyEvent );
   }
 
   bool OnTouch( Actor actor, const TouchData& touch )
@@ -102,6 +105,23 @@ public:
     return true;
   }
 
+  /**
+   * @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 line geometry made of two vertices in order
    * to draw a diagonal line.
index eeda48b96fe2c12b49bbe5164d0aa8aa507ece42..c2abc59208e6a0baeec09d8ed1d7ae8d6bfe82b0 100644 (file)
@@ -106,6 +106,9 @@ public:
 
     // Respond to a click anywhere on the stage
     stage.GetRootLayer().TouchSignal().Connect( this, &TexturedCubeController::OnTouch );
+
+    // Respond to key events
+    stage.KeyEventSignal().Connect( this, &TexturedCubeController::OnKeyEvent );
   }
 
   bool OnTouch( Actor actor, const TouchData& touch )
@@ -115,6 +118,23 @@ public:
     return true;
   }
 
+  /**
+   * @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();
+      }
+    }
+  }
+
   /**
    * @brief CreateCubeGeometry
    * This function creates a cube geometry including texture coordinates.
index 57233f812e86e20427a5d6280b2e4de70b8432d4..00b4ff1b6bd8f03ef84dd9b4b2dccec782bae55d 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 )
@@ -102,6 +105,23 @@ public:
     return true;
   }
 
+  /**
+   * @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.