Property refactor in dali-core: Demo changes for compiling
[platform/core/uifw/dali-demo.git] / examples / blocks / blocks-example.cpp
index 3ff40d6..e9a9b9a 100644 (file)
@@ -1,39 +1,39 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 #include <sstream>
 #include <iostream>
-#include <vector>
 #include <string>
+#include <map>
 #include <algorithm>
 
 #include <boost/any.hpp>
 #include <boost/function.hpp>
 #include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
-#include "../shared/view.h"
+#include "shared/view.h"
 
-using namespace std;
 using namespace Dali;
 using namespace Dali::Toolkit;
 using namespace DemoHelper;
 
 namespace
 {
-const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-default.png" );
+const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-blocks.jpg" );
 const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
 const char* APPLICATION_TITLE( "DALi Blocks" );
 const char* BALL_IMAGE = DALI_IMAGE_DIR "blocks-ball.png";
@@ -348,7 +348,7 @@ private:
     mPaddleImage.SetSize( mPaddleFullSize );
 
     mWobbleProperty = mPaddle.RegisterProperty(WOBBLE_PROPERTY_NAME, 0.0f);
-    Constraint wobbleConstraint = Constraint::New<Quaternion>( Actor::ROTATION,
+    Constraint wobbleConstraint = Constraint::New<Quaternion>( Actor::Property::Rotation,
                                                     LocalSource(mWobbleProperty),
                                                     WobbleConstraint(10.0f));
     mPaddle.ApplyConstraint(wobbleConstraint);
@@ -361,16 +361,16 @@ private:
     const float margin(BALL_SIZE.width * stageSize.width * 0.5f);
 
     // Set up notifications for ball's collisions against walls.
-    PropertyNotification leftNotification = mBall.AddPropertyNotification( Actor::POSITION_X, LessThanCondition(margin) );
+    PropertyNotification leftNotification = mBall.AddPropertyNotification( Actor::Property::PositionX, LessThanCondition(margin) );
     leftNotification.NotifySignal().Connect( this, &ExampleController::OnHitLeftWall );
 
-    PropertyNotification rightNotification = mBall.AddPropertyNotification( Actor::POSITION_X, GreaterThanCondition(stageSize.width - margin) );
+    PropertyNotification rightNotification = mBall.AddPropertyNotification( Actor::Property::PositionX, GreaterThanCondition(stageSize.width - margin) );
     rightNotification.NotifySignal().Connect( this, &ExampleController::OnHitRightWall );
 
-    PropertyNotification topNotification = mBall.AddPropertyNotification( Actor::POSITION_Y, LessThanCondition(margin) );
+    PropertyNotification topNotification = mBall.AddPropertyNotification( Actor::Property::PositionY, LessThanCondition(margin) );
     topNotification.NotifySignal().Connect( this, &ExampleController::OnHitTopWall );
 
-    PropertyNotification bottomNotification = mBall.AddPropertyNotification( Actor::POSITION_Y, GreaterThanCondition(stageSize.height + margin) );
+    PropertyNotification bottomNotification = mBall.AddPropertyNotification( Actor::Property::PositionY, GreaterThanCondition(stageSize.height + margin) );
     bottomNotification.NotifySignal().Connect( this, &ExampleController::OnHitBottomWall );
 
     // Set up notification for ball colliding against paddle.
@@ -378,10 +378,10 @@ private:
     stage.Add(delegate);
     Property::Index property = delegate.RegisterProperty(COLLISION_PROPERTY_NAME, Vector3::ZERO);
     Constraint constraint = Constraint::New<Vector3>( property,
-                                                    Source(mBall, Actor::POSITION),
-                                                    Source(mPaddle, Actor::POSITION),
-                                                    Source(mBall, Actor::SIZE),
-                                                    Source(mPaddle, Actor::SIZE),
+                                                    Source(mBall, Actor::Property::Position),
+                                                    Source(mPaddle, Actor::Property::Position),
+                                                    Source(mBall, Actor::Property::Size),
+                                                    Source(mPaddle, Actor::Property::Size),
                                                     CollisionCircleRectangleConstraint( -Vector3(0.0f, mPaddleHitMargin.height * 0.575f, 0.0f),-Vector3(mPaddleHitMargin) ));
     delegate.ApplyConstraint(constraint);
 
@@ -423,7 +423,7 @@ private:
     mLevelContainer = Actor::New();
     mLevelContainer.SetAnchorPoint( AnchorPoint::CENTER );
     mLevelContainer.SetParentOrigin( ParentOrigin::CENTER );
-    mLevelContainer.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
+    mLevelContainer.SetSizeMode( SIZE_EQUAL_TO_PARENT );
     mContentLayer.Add( mLevelContainer );
 
     mBrickCount = 0;
@@ -563,7 +563,7 @@ private:
       if(turn)
       {
         // turn 90 degrees clockwise.
-        swap(di, dj);
+        std::swap(di, dj);
         di = -di;
         if (length<=1)
         {
@@ -591,7 +591,7 @@ private:
     ImageAttributes attr;
     attr.SetSize( 128, 64 );
     attr.SetScalingMode( ImageAttributes::ScaleToFill );
-    Image img = Image::New(BRICK_IMAGE_PATH[type], attr);
+    Image img = ResourceImage::New(BRICK_IMAGE_PATH[type], attr);
     ImageActor brick = ImageActor::New(img);
     brick.SetParentOrigin(ParentOrigin::TOP_LEFT);
     brick.SetAnchorPoint(AnchorPoint::CENTER);
@@ -601,10 +601,10 @@ private:
     // 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);
     Constraint constraint = Constraint::New<Vector3>( property,
-                                                    Source(mBall, Actor::POSITION),
-                                                    Source(brick, Actor::POSITION),
-                                                    Source(mBall, Actor::SIZE),
-                                                    Source(brick, Actor::SIZE),
+                                                    Source(mBall, Actor::Property::Position),
+                                                    Source(brick, Actor::Property::Position),
+                                                    Source(mBall, Actor::Property::Size),
+                                                    Source(brick, Actor::Property::Size),
                                                     CollisionCircleRectangleConstraint(BRICK_COLLISION_MARGIN));
     brick.ApplyConstraint(constraint);
 
@@ -623,7 +623,7 @@ private:
    */
   ImageActor CreateImage(const std::string& filename)
   {
-    Image img = Image::New(filename);
+    Image img = ResourceImage::New(filename);
     ImageActor actor = ImageActor::New(img);
     actor.SetParentOrigin(ParentOrigin::TOP_LEFT);
     actor.SetAnchorPoint(AnchorPoint::CENTER);
@@ -641,7 +641,7 @@ private:
     }
 
     mBallAnimation = Animation::New(MAX_ANIMATION_DURATION);
-    mBallAnimation.AnimateBy( Property( mBall, Actor::POSITION ), mBallVelocity * MAX_ANIMATION_DURATION);
+    mBallAnimation.AnimateBy( Property( mBall, Actor::Property::Position ), mBallVelocity * MAX_ANIMATION_DURATION);
     mBallAnimation.Play();
   }
 
@@ -663,8 +663,8 @@ private:
 
         mDragActor = actor;
         mDragAnimation = Animation::New(0.25f);
-        mDragAnimation.AnimateTo( Property(mDragActor, Actor::SCALE), Vector3(1.1f, 1.1f, 1.0f), AlphaFunctions::EaseOut);
-        mDragAnimation.AnimateTo( Property(mPaddleHandle, Actor::COLOR), Vector4(1.0f, 1.0f, 1.0f, 0.0f), AlphaFunctions::EaseOut);
+        mDragAnimation.AnimateTo( Property(mDragActor, Actor::Property::Scale), Vector3(1.1f, 1.1f, 1.0f), AlphaFunctions::EaseOut);
+        mDragAnimation.AnimateTo( Property(mPaddleHandle, Actor::Property::Color), Vector4(1.0f, 1.0f, 1.0f, 0.0f), AlphaFunctions::EaseOut);
         mDragAnimation.Play();
       }
     }
@@ -689,8 +689,8 @@ private:
         if(point.state==TouchPoint::Up) // Stop dragging
         {
           mDragAnimation = Animation::New(0.25f);
-          mDragAnimation.AnimateTo( Property(mDragActor, Actor::SCALE), Vector3(1.0f, 1.0f, 1.0f), AlphaFunctions::EaseIn);
-          mDragAnimation.AnimateTo( Property(mPaddleHandle, Actor::COLOR), Vector4(1.0f, 1.0f, 1.0f, 1.0f), AlphaFunctions::EaseOut);
+          mDragAnimation.AnimateTo( Property(mDragActor, Actor::Property::Scale), Vector3(1.0f, 1.0f, 1.0f), AlphaFunctions::EaseIn);
+          mDragAnimation.AnimateTo( Property(mPaddleHandle, Actor::Property::Color), Vector4(1.0f, 1.0f, 1.0f, 1.0f), AlphaFunctions::EaseOut);
           mDragAnimation.Play();
           mDragActor.Reset();
         }
@@ -747,8 +747,8 @@ private:
       mBallVelocity = Vector3::ZERO;
 
       Animation shrink = Animation::New(0.5f);
-      shrink.AnimateTo( Property(mPaddle, Actor::SIZE_WIDTH), mPaddleFullSize.x * f + mPaddleHitMargin.x);
-      shrink.AnimateTo( Property(mPaddleImage, Actor::SIZE_WIDTH), mPaddleFullSize.x * f );
+      shrink.AnimateTo( Property(mPaddle, Actor::Property::SizeWidth), mPaddleFullSize.x * f + mPaddleHitMargin.x);
+      shrink.AnimateTo( Property(mPaddleImage, Actor::Property::SizeWidth), mPaddleFullSize.x * f );
 
       shrink.FinishedSignal().Connect( this, &ExampleController::OnPaddleShrunk );
       shrink.Play();
@@ -765,7 +765,7 @@ private:
     mBall.SetPosition( mBallStartPosition );
     mBall.SetColor( Vector4(1.0f, 1.0f, 1.0f, 0.1f) );
     Animation appear = Animation::New(0.5f);
-    appear.AnimateTo( Property(mBall, Actor::COLOR), Vector4(1.0f, 1.0f, 1.0f, 1.0f) );
+    appear.AnimateTo( Property(mBall, Actor::Property::Color), Vector4(1.0f, 1.0f, 1.0f, 1.0f) );
     appear.Play();
 
     if(!mLives)
@@ -832,7 +832,7 @@ private:
 
     // fade brick (destroy)
     Animation destroyAnimation = Animation::New(0.5f);
-    destroyAnimation.AnimateTo( Property( brick, Actor::COLOR_ALPHA ), 0.0f, AlphaFunctions::EaseIn );
+    destroyAnimation.AnimateTo( Property( brick, Actor::Property::ColorAlpha ), 0.0f, AlphaFunctions::EaseIn );
     destroyAnimation.Play();
     destroyAnimation.FinishedSignal().Connect( this, &ExampleController::OnBrickDestroyed );
     mDestroyAnimationMap[destroyAnimation] = brick;