Further Setter/Getter public API removal from Dali::Actor
[platform/core/uifw/dali-demo.git] / examples / blocks / blocks-example.cpp
index 03a99e6..8fc8424 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -23,6 +23,7 @@
 
 #include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 #include "shared/view.h"
 
 using namespace Dali;
@@ -214,7 +215,29 @@ public:
    */
   ExampleController( Application& application )
   : mApplication( application ),
-    mView()
+    mView(),
+    mContentLayer(),
+    mBall(),
+    mBallStartPosition(),
+    mBallVelocity(),
+    mBallAnimation(),
+    mPaddle(),
+    mPaddleImage(),
+    mPaddleHandle(),
+    mPaddleHitMargin(),
+    mWobbleAnimation(),
+    mWobbleProperty( Property::INVALID_INDEX ),
+    mLevelContainer(),
+    mBrickImageMap(),
+    mDragAnimation(),
+    mDragActor(),
+    mRelativeDragPoint(),
+    mDestroyAnimationMap(),
+    mPaddleFullSize(),
+    mLevel( 0 ),
+    mLives( TOTAL_LIVES ),
+    mBrickCount( 0 )
+
   {
     // Connect to the Application's Init and orientation changed signal
     mApplication.InitSignal().Connect(this, &ExampleController::Create);
@@ -261,8 +284,8 @@ private:
     // Ball setup
     mBallStartPosition = stageSize * Vector3( BALL_START_POSITION );
     mBall = CreateImage(BALL_IMAGE);
-    mBall.SetPosition( mBallStartPosition );
-    mBall.SetSize( BALL_SIZE * stageSize.width );
+    mBall.SetProperty( Actor::Property::POSITION, mBallStartPosition );
+    mBall.SetProperty( Actor::Property::SIZE, BALL_SIZE * stageSize.width );
     mContentLayer.Add(mBall);
     mBallVelocity = Vector3::ZERO;
 
@@ -273,24 +296,24 @@ private:
     mPaddleImage = CreateImage(PADDLE_IMAGE);
     mPaddle.Add( mPaddleHandle );
     mPaddle.Add( mPaddleImage );
-    mPaddleHandle.SetParentOrigin( ParentOrigin::TOP_CENTER );
-    mPaddleHandle.SetAnchorPoint( AnchorPoint::TOP_CENTER );
-    mPaddleHandle.SetPosition( 0.0f, stageSize.width * 0.0125f );
-    mPaddleImage.SetParentOrigin( ParentOrigin::TOP_CENTER );
-    mPaddleImage.SetAnchorPoint( AnchorPoint::TOP_CENTER );
-    mPaddle.SetParentOrigin( ParentOrigin::TOP_LEFT );
-    mPaddle.SetAnchorPoint( AnchorPoint::CENTER );
+    mPaddleHandle.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
+    mPaddleHandle.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER );
+    mPaddleHandle.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, stageSize.width * 0.0125f ));
+    mPaddleImage.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
+    mPaddleImage.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER );
+    mPaddle.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+    mPaddle.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
     mPaddleFullSize = PADDLE_SIZE * stageSize.width;
-    mPaddle.SetSize( mPaddleFullSize + mPaddleHitMargin );
-    mPaddleHandle.SetSize( PADDLE_HANDLE_SIZE * stageSize.width );
-    mPaddleImage.SetSize( mPaddleFullSize );
+    mPaddle.SetProperty( Actor::Property::SIZE, mPaddleFullSize + mPaddleHitMargin );
+    mPaddleHandle.SetProperty( Actor::Property::SIZE, PADDLE_HANDLE_SIZE * stageSize.width );
+    mPaddleImage.SetProperty( Actor::Property::SIZE, mPaddleFullSize );
 
     mWobbleProperty = mPaddle.RegisterProperty(WOBBLE_PROPERTY_NAME, 0.0f);
     Constraint wobbleConstraint = Constraint::New<Quaternion>( mPaddle, Actor::Property::ORIENTATION, WobbleConstraint(Degree( 10.0f )));
     wobbleConstraint.AddSource( LocalSource(mWobbleProperty) );
     wobbleConstraint.Apply();
 
-    mPaddle.SetPosition( stageSize * Vector3( PADDLE_START_POSITION ) );
+    mPaddle.SetProperty( Actor::Property::POSITION, stageSize * Vector3( PADDLE_START_POSITION ) );
     mContentLayer.Add(mPaddle);
     mPaddle.TouchSignal().Connect(this, &ExampleController::OnTouchPaddle);
     mContentLayer.TouchSignal().Connect(this, &ExampleController::OnTouchLayer);
@@ -335,10 +358,10 @@ private:
   {
     mLives = TOTAL_LIVES;
     mLevel = 0;
-    mBall.SetPosition( mBallStartPosition );
+    mBall.SetProperty( Actor::Property::POSITION, mBallStartPosition );
     mBallVelocity = Vector3::ZERO;
-    mPaddle.SetSize( mPaddleFullSize + mPaddleHitMargin );
-    mPaddleImage.SetSize( mPaddleFullSize );
+    mPaddle.SetProperty( Actor::Property::SIZE, mPaddleFullSize + mPaddleHitMargin );
+    mPaddleImage.SetProperty( Actor::Property::SIZE, mPaddleFullSize );
 
     LoadLevel(mLevel);
   }
@@ -357,8 +380,8 @@ private:
     }
 
     mLevelContainer = Actor::New();
-    mLevelContainer.SetAnchorPoint( AnchorPoint::CENTER );
-    mLevelContainer.SetParentOrigin( ParentOrigin::CENTER );
+    mLevelContainer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+    mLevelContainer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
     mLevelContainer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
 
     mContentLayer.Add( mLevelContainer );
@@ -536,9 +559,9 @@ private:
     mBrickImageMap["url"] = BRICK_IMAGE_PATH[type];
     ImageView brick = ImageView::New();
     brick.SetProperty( ImageView::Property::IMAGE, mBrickImageMap );
-    brick.SetParentOrigin(ParentOrigin::TOP_LEFT);
-    brick.SetAnchorPoint(AnchorPoint::CENTER);
-    brick.SetPosition( Vector3( position ) );
+    brick.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
+    brick.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
+    brick.SetProperty( Actor::Property::POSITION, position );
 
     // Add a constraint on the brick between it and the ball generating a collision-property
     Property::Index property = brick.RegisterProperty(COLLISION_PROPERTY_NAME, Vector3::ZERO);
@@ -564,9 +587,14 @@ private:
    */
   ImageView CreateImage(const std::string& filename)
   {
-    ImageView actor = ImageView::New(filename);
-    actor.SetParentOrigin(ParentOrigin::TOP_LEFT);
-    actor.SetAnchorPoint(AnchorPoint::CENTER);
+    Property::Map propertyMap;
+    propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
+    propertyMap.Insert(ImageVisual::Property::URL, filename);
+    propertyMap.Insert(DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FILL);
+    ImageView actor = ImageView::New();
+    actor.SetProperty(Toolkit::ImageView::Property::IMAGE, propertyMap);
+    actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
+    actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
     return actor;
   }
 
@@ -599,7 +627,7 @@ private:
         // Get point where user touched paddle (relative to paddle's center)
         Vector2 screenPoint = event.GetScreenPosition( 0 );
         mRelativeDragPoint = screenPoint;
-        mRelativeDragPoint -= actor.GetCurrentPosition();
+        mRelativeDragPoint -= actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION );
 
         mDragActor = actor;
         mDragAnimation = Animation::New(0.25f);
@@ -623,7 +651,7 @@ private:
       if(mDragActor)
       {
         Vector3 position( event.GetScreenPosition( 0 ) );
-        mPaddle.SetPosition( position - mRelativeDragPoint );
+        mPaddle.SetProperty( Actor::Property::POSITION, position - mRelativeDragPoint );
 
         if( event.GetState( 0 ) == PointState::UP ) // Stop dragging
         {
@@ -701,8 +729,8 @@ private:
   void OnPaddleShrunk( Animation &source )
   {
     // Reposition Ball in start position, and make ball appear.
-    mBall.SetPosition( mBallStartPosition );
-    mBall.SetColor( Vector4(1.0f, 1.0f, 1.0f, 0.1f) );
+    mBall.SetProperty( Actor::Property::POSITION, mBallStartPosition );
+    mBall.SetProperty( Actor::Property::COLOR, Vector4(1.0f, 1.0f, 1.0f, 0.1f) );
     Animation appear = Animation::New(0.5f);
     appear.AnimateTo( Property(mBall, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 1.0f) );
     appear.Play();
@@ -720,8 +748,8 @@ private:
   void OnHitPaddle(PropertyNotification& source)
   {
     Actor delegate = Actor::DownCast(source.GetTarget());
-    Vector3 collisionVector = delegate.GetProperty<Vector3>(source.GetTargetProperty());
-    Vector3 ballRelativePosition(mBall.GetCurrentPosition() - mPaddle.GetCurrentPosition());
+    Vector3 collisionVector = delegate.GetCurrentProperty< Vector3 >( source.GetTargetProperty() );
+    Vector3 ballRelativePosition(mBall.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ) - mPaddle.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ));
     ballRelativePosition.Normalize();
 
     collisionVector.x += ballRelativePosition.x * 0.5f;
@@ -755,7 +783,7 @@ private:
   void OnHitBrick(PropertyNotification& source)
   {
     Actor brick = Actor::DownCast(source.GetTarget());
-    Vector3 collisionVector = brick.GetProperty<Vector3>(source.GetTargetProperty());
+    Vector3 collisionVector = brick.GetCurrentProperty< Vector3 >( source.GetTargetProperty() );
 
     const float normalVelocity = fabsf(mBallVelocity.Dot(collisionVector));
     mBallVelocity += collisionVector * normalVelocity * 2.0f;
@@ -840,18 +868,10 @@ private:
   int mBrickCount;                                      ///< Total bricks on screen.
 };
 
-void RunTest(Application& app)
-{
-  ExampleController test(app);
-
-  app.MainLoop();
-}
-
 int DALI_EXPORT_API main(int argc, char **argv)
 {
   Application app = Application::New(&argc, &argv, DEMO_THEME_PATH);
-
-  RunTest(app);
-
+  ExampleController test(app);
+  app.MainLoop();
   return 0;
 }