Refactoring Gestures Class
[platform/core/uifw/dali-demo.git] / examples / image-view-svg / image-view-svg-example.cpp
old mode 100644 (file)
new mode 100755 (executable)
index b62b6fe..05eae9a
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 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.
@@ -63,30 +63,27 @@ public:
   // The Init signal is received once (only) during the Application lifetime
   void Create( Application& application )
   {
-    // Get a handle to the stage
-    Stage stage = Stage::GetCurrent();
-    stage.SetBackgroundColor( Color::WHITE );
-    Vector2 stageSize = stage.GetSize();
-    mActorSize = stageSize/2.f;
+    // Get a handle to the window
+    Window window = application.GetWindow();
+    window.SetBackgroundColor( Color::WHITE );
+    Vector2 windowSize = window.GetSize();
+    mActorSize = windowSize/2.f;
 
-    // Hide the indicator bar
-    application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
-
-    stage.KeyEventSignal().Connect(this, &ImageSvgController::OnKeyEvent);
+    window.KeyEventSignal().Connect(this, &ImageSvgController::OnKeyEvent);
 
     // Background, for receiving gestures
-    mStageBackground = Actor::New();
-    mStageBackground.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER );
-    mStageBackground.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
-    mStageBackground.SetProperty( Actor::Property::SIZE, Vector2( stageSize.x, stageSize.y ) );
-    stage.Add(mStageBackground);
+    mWindowBackground = Actor::New();
+    mWindowBackground.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER );
+    mWindowBackground.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
+    mWindowBackground.SetProperty( Actor::Property::SIZE, Vector2( windowSize.x, windowSize.y ) );
+    window.Add(mWindowBackground);
 
     // Push button,  for changing the image set for displaying
     Toolkit::PushButton changeButton = Toolkit::PushButton::New();
     changeButton.SetProperty( Toolkit::Button::Property::LABEL, "Next" );
     changeButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT );
     changeButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT );
-    stage.Add( changeButton );
+    window.Add( changeButton );
     changeButton.ClickedSignal().Connect( this, &ImageSvgController::OnChangeButtonClicked );
 
     // Push button, for resetting the actor size and position
@@ -94,16 +91,16 @@ public:
     resetButton.SetProperty( Toolkit::Button::Property::LABEL, "Reset" );
     resetButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
     resetButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
-    stage.Add( resetButton );
+    window.Add( resetButton );
     resetButton.ClickedSignal().Connect( this, &ImageSvgController::OnResetButtonClicked );
 
-    // Create and put imageViews to stage
+    // Create and put imageViews to window
     for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++ )
     {
       mSvgActor[i] = Toolkit::ImageView::New(SVG_IMAGES[mIndex+i]);
       mSvgActor[i].SetProperty( Actor::Property::SIZE, mActorSize );
-      mSvgActor[i].TranslateBy( Vector3( 0.0, stageSize.height * 0.05, 0.0f ) );
-      stage.Add( mSvgActor[i] );
+      mSvgActor[i].TranslateBy( Vector3( 0.0, windowSize.height * 0.05, 0.0f ) );
+      window.Add( mSvgActor[i] );
     }
     mSvgActor[0].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
     mSvgActor[0].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT );
@@ -117,11 +114,11 @@ public:
     // Connect pan gesture for moving the actors
     mPanGestureDetector = PanGestureDetector::New();
     mPanGestureDetector.DetectedSignal().Connect( this, &ImageSvgController::OnPanGesture );
-    mPanGestureDetector.Attach( mStageBackground );
+    mPanGestureDetector.Attach( mWindowBackground );
 
     // Connect pinch gesture for resizing the actors
     mPinchGestureDetector = PinchGestureDetector::New();
-    mPinchGestureDetector.Attach( mStageBackground);
+    mPinchGestureDetector.Attach( mWindowBackground);
     mPinchGestureDetector.DetectedSignal().Connect(this, &ImageSvgController::OnPinch);
 
     changeButton.RaiseToTop();
@@ -156,11 +153,11 @@ public:
   // Callback of pan gesture, for moving the actors
   void OnPanGesture( Actor actor, const PanGesture& gesture )
   {
-    if( gesture.state == Gesture::Continuing )
+    if( gesture.GetState() == Gesture::Continuing )
     {
       for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++ )
       {
-        mSvgActor[i].TranslateBy(Vector3(gesture.displacement));
+        mSvgActor[i].TranslateBy(Vector3(gesture.GetDisplacement()));
       }
     }
   }
@@ -168,14 +165,14 @@ public:
   // Callback of pinch gesture, for resizing the actors
   void OnPinch(Actor actor, const PinchGesture& gesture)
   {
-    switch( gesture.state )
+    switch( gesture.GetState() )
     {
       // Only scale the image when we start or continue pinching
 
       case Gesture::Started:
       case Gesture::Continuing:
       {
-        float scale = std::max( gesture.scale, MIN_SCALE / mScale );
+        float scale = std::max( gesture.GetScale(), MIN_SCALE / mScale );
         scale = std::min( MAX_SCALE / mScale, scale );
 
         for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++ )
@@ -189,7 +186,7 @@ public:
       {
         // Resize the image when pinching is complete, this will rasterize the SVG to the new size
 
-        mScale = mScale * gesture.scale;
+        mScale = mScale * gesture.GetScale();
         mScale = mScale > MAX_SCALE ? MAX_SCALE : mScale;
         mScale = mScale < MIN_SCALE ? MIN_SCALE : mScale;
         for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++ )
@@ -212,7 +209,7 @@ public:
     */
    void OnKeyEvent(const KeyEvent& event)
    {
-     if(event.state == KeyEvent::Down)
+     if(event.GetState() == KeyEvent::DOWN)
      {
        if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
        {
@@ -220,7 +217,7 @@ public:
        }
        else
        {
-         const char* keyName = event.keyPressedName.c_str();
+         const char* keyName = event.GetKeyName().c_str();
          if( strcmp(keyName, "Left") == 0 )
          {
            if( mScale > MIN_SCALE )
@@ -249,7 +246,7 @@ public:
 
 private:
   Application&         mApplication;
-  Actor                mStageBackground;
+  Actor                mWindowBackground;
   PanGestureDetector   mPanGestureDetector;
   PinchGestureDetector mPinchGestureDetector;