Changes after TouchedSignal changes
[platform/core/uifw/dali-demo.git] / examples / rendering-radial-progress / radial-progress.cpp
index 69d6e46..614123d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -124,16 +124,19 @@ public:
   // The Init signal is received once (only) during the Application lifetime
   void Create( Application& application )
   {
-    Stage stage = Stage::GetCurrent();
-    stage.SetBackgroundColor( Color::BLACK );
+    Window window = application.GetWindow();
+    window.SetBackgroundColor( Color::BLACK );
+
+    // Connect to the window's key signal to allow Back and Escape to exit.
+    window.KeyEventSignal().Connect( this, &RadialProgressController::OnKeyEvent );
 
     // 1. Create actor to show the effect
     mActor = Actor::New();
-    mActor.SetAnchorPoint( AnchorPoint::CENTER );
-    mActor.SetParentOrigin( ParentOrigin::CENTER );
-    mActor.SetSize( Vector2( TEXTURE_WIDTH, TEXTURE_HEIGHT ) );
+    mActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+    mActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+    mActor.SetProperty( Actor::Property::SIZE, Vector2( TEXTURE_WIDTH, TEXTURE_HEIGHT ) );
     mActor.RegisterProperty("uProgress", float(1.0f) );
-    stage.Add( mActor );
+    window.Add( mActor );
 
     // 1. Create stencil renderer i.e. a triangle fan in the shape of a circle
     Renderer stencilRenderer = CreatePolygon( NUMBER_OF_SIDES );
@@ -149,10 +152,10 @@ public:
     animation.Play();
 
     // 6. Exit the application when touched
-    stage.GetRootLayer().TouchSignal().Connect( this, &RadialProgressController::OnTouch );
+    window.GetRootLayer().TouchedSignal().Connect( this, &RadialProgressController::OnTouch );
   }
 
-  bool OnTouch( Actor actor, const TouchData& touch )
+  bool OnTouch( Actor actor, const TouchEvent& touch )
   {
     // quit the application
     mApplication.Quit();
@@ -185,7 +188,7 @@ public:
     vertexFormat[ "aPosition" ] = Property::VECTOR3;
 
     // describe vertex format ( only 2-dimensional positions )
-    PropertyBuffer vertexBuffer = PropertyBuffer::New( vertexFormat );
+    VertexBuffer vertexBuffer = VertexBuffer::New( vertexFormat );
     vertexBuffer.SetData( vertices.data(), vertices.size() );
 
     // create geometry
@@ -235,7 +238,7 @@ public:
 
     Property::Map vertexFormat;
     vertexFormat["aPosition"] = Property::VECTOR2;
-    PropertyBuffer vertexBuffer = PropertyBuffer::New( vertexFormat );
+    VertexBuffer vertexBuffer = VertexBuffer::New( vertexFormat );
 
     const float P( 0.5f );
     const Vector2 vertices[] = {
@@ -283,6 +286,23 @@ public:
     return renderer;
   }
 
+  /**
+   * @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.GetState() == KeyEvent::DOWN )
+    {
+      if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
+      {
+        mApplication.Quit();
+      }
+    }
+  }
+
 private:
 
   Application&  mApplication;
@@ -290,20 +310,10 @@ private:
   Actor mActor;
 };
 
-void RunTest( Application& application )
-{
-  RadialProgressController 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 );
-
+  RadialProgressController test( application );
+  application.MainLoop();
   return 0;
 }