Added key event handling to image-view-example 34/50734/1
authorFerran Sole <ferran.sole@samsung.com>
Fri, 30 Oct 2015 11:07:37 +0000 (11:07 +0000)
committerFerran Sole <ferran.sole@samsung.com>
Fri, 30 Oct 2015 11:07:37 +0000 (11:07 +0000)
To allow quitting example with escape or back key

Change-Id: Icaa30d4991ee2f65e8c10e4fc136f52de05168cd

examples/image-view/image-view-example.cpp

index e2779c2..9f49294 100644 (file)
@@ -141,6 +141,8 @@ class ImageViewController: public ConnectionTracker
     buttonsTable.AddChild( button3, Toolkit::TableView::CellPosition( 2, 0 ) );
 
     mContentLayer.Add(buttonsTable);
+
+    Stage::GetCurrent().KeyEventSignal().Connect(this, &ImageViewController::OnKeyEvent);
   }
 
 private:
@@ -220,6 +222,20 @@ private:
     return true;
   }
 
+  /**
+   * Main key event handler
+   */
+  void OnKeyEvent(const KeyEvent& event)
+  {
+    if(event.state == KeyEvent::Down)
+    {
+      if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
+      {
+        mApplication.Quit();
+      }
+    }
+  }
+
 private:
   Application&  mApplication;