Changes after TouchedSignal changes
[platform/core/uifw/dali-demo.git] / examples / animated-gradient-card-active / animated-gradient-card-active.cpp
index 3414361..a4da888 100644 (file)
@@ -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.
@@ -30,9 +30,9 @@ namespace
 {
 // The value for scale-change between wearable-mobile
 // Can be changed on App-Create time
-Vector2 STAGE_SIZE = Vector2( 360.0f, 360.0f );
-Vector2 SCALED_STAGE_SIZE = Vector2( 1.0f, 1.0f );
-Vector3 SCALED_STAGE_SIZE_3 = Vector3( 1.0f, 1.0f, 0.0f );
+Vector2 WINDOW_SIZE = Vector2( 360.0f, 360.0f );
+Vector2 SCALED_WINDOW_SIZE = Vector2( 1.0f, 1.0f );
+Vector3 SCALED_WINDOW_SIZE_3 = Vector3( 1.0f, 1.0f, 0.0f );
 float SCALED_WIDTH = 1.0f;
 float SCALED_HEIGHT = 1.0f;
 float FONT_SCALE = 0.25f;
@@ -122,7 +122,7 @@ public:
   }
   ~CardManager() {}
 
-  void Init(Stage& stage)
+  void Init(Window& window)
   {
     mSize = CARD_SIZE * SCALED_WIDTH;
     mOffset = CARD_OFFSET * SCALED_WIDTH;
@@ -151,12 +151,12 @@ public:
         mCard[k].SetProperty(Toolkit::ImageView::Property::IMAGE, propertyMap);
       }
 
-      mCard[k].SetParentOrigin( ParentOrigin::CENTER );
-      mCard[k].SetAnchorPoint( AnchorPoint::CENTER );
-      mCard[k].SetSize( mSize.x, mSize.y );
-      mCard[k].SetPosition( mPosition[k].x, mPosition[k].y );
+      mCard[k].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+      mCard[k].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+      mCard[k].SetProperty( Actor::Property::SIZE, Vector2( mSize.x, mSize.y ) );
+      mCard[k].SetProperty( Actor::Property::POSITION, Vector2( mPosition[k].x, mPosition[k].y ));
 
-      stage.Add( mCard[k] );
+      window.Add( mCard[k] );
     }
   }
 
@@ -280,26 +280,27 @@ public:
   // The Init signal is received once (only) during the Application lifetime
   void Create(Application& application)
   {
-    // Get a handle to the stage
-    mStage = Stage::GetCurrent();
-    mStage.KeyEventSignal().Connect( this, &CardController::OnKeyEvent );
+    // Get a handle to the window
+    mWindow = application.GetWindow();
+    mWindow.KeyEventSignal().Connect( this, &CardController::OnKeyEvent );
 
     // Get current device's width and height.
-    STAGE_SIZE = mStage.GetSize();
-    SCALED_STAGE_SIZE = STAGE_SIZE / 360.0f;
-    SCALED_STAGE_SIZE_3 = Vector3( SCALED_STAGE_SIZE.x, SCALED_STAGE_SIZE.y, 0.0f );
-    SCALED_WIDTH = SCALED_STAGE_SIZE.x < SCALED_STAGE_SIZE.y ? SCALED_STAGE_SIZE.x : SCALED_STAGE_SIZE.y;
+    const Window::WindowSize windowSize = mWindow.GetSize();
+    WINDOW_SIZE = Vector2(windowSize.GetWidth(), windowSize.GetHeight() );
+    SCALED_WINDOW_SIZE = WINDOW_SIZE / 360.0f;
+    SCALED_WINDOW_SIZE_3 = Vector3( SCALED_WINDOW_SIZE.x, SCALED_WINDOW_SIZE.y, 0.0f );
+    SCALED_WIDTH = SCALED_WINDOW_SIZE.x < SCALED_WINDOW_SIZE.y ? SCALED_WINDOW_SIZE.x : SCALED_WINDOW_SIZE.y;
     SCALED_HEIGHT = SCALED_WIDTH;
 
     // Note that this is heuristic value
-    FONT_SCALE = 0.25f * STAGE_SIZE.y / STAGE_SIZE.x;
+    FONT_SCALE = 0.25f * WINDOW_SIZE.y / WINDOW_SIZE.x;
 
     mBackground = Control::New();
-    mBackground.SetParentOrigin( ParentOrigin::CENTER );
-    mBackground.SetAnchorPoint( AnchorPoint::CENTER );
-    mBackground.SetSize( STAGE_SIZE );
+    mBackground.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+    mBackground.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+    mBackground.SetProperty( Actor::Property::SIZE, WINDOW_SIZE );
 
-    mStage.Add( mBackground );
+    mWindow.Add( mBackground );
 
     BuildParameter();
     InitMap();
@@ -307,11 +308,11 @@ public:
     SetupActors();
     SetupAnimation();
 
-    mStage.GetRootLayer().TouchSignal().Connect( this, &CardController::OnTouchLayer );
+    mWindow.GetRootLayer().TouchedSignal().Connect( this, &CardController::OnTouchLayer );
     Reset();
   }
 
-  bool OnTouchCards(Actor actor, const TouchData &data)
+  bool OnTouchCards(Actor actor, const TouchEvent &data)
   {
     if( data.GetPointCount() > 0 )
     {
@@ -346,7 +347,7 @@ public:
     return true;
   }
 
-  bool OnTouchLayer(Actor actor, const TouchData &data)
+  bool OnTouchLayer(Actor actor, const TouchEvent &data)
   {
     if( data.GetPointCount() > 0 )
     {
@@ -379,8 +380,9 @@ public:
     {
       Vector2 diff = (mLastTouchPos - mFirstTouchPos);
       float offset = PSEUDO_SCROLL_OFFSET;
+      const float windowWidth = mWindow.GetSize().GetWidth();
       // Scroll to right
-      if( diff.x > mStage.GetSize().x * offset )
+      if( diff.x > windowWidth * offset )
       {
         mCards.mCurState = 2;
         MoveRight();
@@ -389,7 +391,7 @@ public:
         mCardChanger.Start();
       }
       // Scroll to left
-      else if( diff.x < -mStage.GetSize().x * offset )
+      else if( diff.x < -windowWidth * offset )
       {
         mCards.mCurState = 2;
         MoveLeft();
@@ -423,7 +425,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 ) )
       {
@@ -578,62 +580,62 @@ private:
 
   void SetupCards()
   {
-    mCards.Init( mStage );
+    mCards.Init( mWindow );
     for( int k = 0; k < CARD_NUM; k++ )
     {
-      mCards[k].TouchSignal().Connect( this, &CardController::OnTouchCards );
+      mCards[k].TouchedSignal().Connect( this, &CardController::OnTouchCards );
     }
     mNormalStartColor = mCards.GetColorBackground( mCards.mCurIndex );
     mNormalEndColor = mCards.GetColorBackground( mCards.mCurIndex );
   }
 
-  // Create and Add to stage
+  // Create and Add to window
   void SetupActors()
   {
     mAddButton = ImageView::New();
     mAddButton.SetImage( BUTTON_ADD_IMAGE );
-    mAddButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
-    mAddButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
-    mAddButton.SetSize( BUTTON_ADD_SIZE * SCALED_WIDTH );
-    mAddButton.SetPosition( BUTTON_ADD_POSITION * SCALED_WIDTH );
+    mAddButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER );
+    mAddButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER );
+    mAddButton.SetProperty( Actor::Property::SIZE, BUTTON_ADD_SIZE * SCALED_WIDTH );
+    mAddButton.SetProperty( Actor::Property::POSITION, BUTTON_ADD_POSITION * SCALED_WIDTH );
 
     mLabel1 = TextLabel::New( LABEL_TICKET_STR );
-    mLabel1.SetParentOrigin( ParentOrigin::TOP_CENTER );
-    mLabel1.SetAnchorPoint( AnchorPoint::TOP_CENTER );
-    mLabel1.SetSize( LABEL_TICKET_SIZE * SCALED_WIDTH );
-    mLabel1.SetPosition( LABEL_TICKET_POSITION * SCALED_WIDTH );
-    mLabel1.SetVisible( true );
+    mLabel1.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
+    mLabel1.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER );
+    mLabel1.SetProperty( Actor::Property::SIZE, LABEL_TICKET_SIZE * SCALED_WIDTH );
+    mLabel1.SetProperty( Actor::Property::POSITION, LABEL_TICKET_POSITION * SCALED_WIDTH );
+    mLabel1.SetProperty( Actor::Property::VISIBLE, true );
     mLabel1.SetProperty( TextLabel::Property::TEXT_COLOR, LABEL_TICKET_FONT_COLOR );
     mLabel1.SetProperty( TextLabel::Property::POINT_SIZE, LABEL_TICKET_FONT_SIZE * FONT_SCALE );
     mLabel1.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
     mLabel1.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
 
     mLabel2 = TextLabel::New( LABEL_HOLD_STR );
-    mLabel2.SetParentOrigin( ParentOrigin::CENTER );
-    mLabel2.SetAnchorPoint( AnchorPoint::CENTER );
-    mLabel2.SetSize( LABEL_HOLD_SIZE * SCALED_WIDTH );
-    mLabel2.SetPosition( LABEL_HOLD_POSITION * SCALED_WIDTH );
-    mLabel2.SetVisible( false );
+    mLabel2.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+    mLabel2.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+    mLabel2.SetProperty( Actor::Property::SIZE, LABEL_HOLD_SIZE * SCALED_WIDTH );
+    mLabel2.SetProperty( Actor::Property::POSITION, LABEL_HOLD_POSITION * SCALED_WIDTH );
+    mLabel2.SetProperty( Actor::Property::VISIBLE, false );
     mLabel2.SetProperty( TextLabel::Property::TEXT_COLOR, LABEL_HOLD_FONT_COLOR );
     mLabel2.SetProperty( TextLabel::Property::POINT_SIZE, LABEL_HOLD_FONT_SIZE * FONT_SCALE );
     mLabel2.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
     mLabel2.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
 
     mLabel3 = TextLabel::New( LABEL_TERMINAL_STR );
-    mLabel3.SetParentOrigin( ParentOrigin::CENTER );
-    mLabel3.SetAnchorPoint( AnchorPoint::CENTER );
-    mLabel3.SetSize( LABEL_TERMINAL_SIZE * SCALED_WIDTH );
-    mLabel3.SetPosition( LABEL_TERMINAL_POSITION * SCALED_WIDTH );
-    mLabel3.SetVisible( false );
+    mLabel3.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+    mLabel3.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+    mLabel3.SetProperty( Actor::Property::SIZE, LABEL_TERMINAL_SIZE * SCALED_WIDTH );
+    mLabel3.SetProperty( Actor::Property::POSITION, LABEL_TERMINAL_POSITION * SCALED_WIDTH );
+    mLabel3.SetProperty( Actor::Property::VISIBLE, false );
     mLabel3.SetProperty( TextLabel::Property::TEXT_COLOR, LABEL_TERMINAL_FONT_COLOR );
     mLabel3.SetProperty( TextLabel::Property::POINT_SIZE, LABEL_TERMINAL_FONT_SIZE * FONT_SCALE );
     mLabel3.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
     mLabel3.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
 
-    mStage.Add( mAddButton );
-    mStage.Add( mLabel1 );
-    mStage.Add( mLabel2 );
-    mStage.Add( mLabel3 );
+    mWindow.Add( mAddButton );
+    mWindow.Add( mLabel1 );
+    mWindow.Add( mLabel2 );
+    mWindow.Add( mLabel3 );
   }
 
   void SetupAnimation()
@@ -776,7 +778,7 @@ private:
 
 private:
   Application&  mApplication;
-  Stage mStage;
+  Window mWindow;
 
   CardManager mCards;
 
@@ -824,7 +826,7 @@ private:
   bool mIsTouchedActor;
 };
 
-int main(int argc, char **argv)
+int DALI_EXPORT_API main(int argc, char **argv)
 {
   Application application = Application::New( &argc, &argv );