Use new TouchData API
[platform/core/uifw/dali-demo.git] / examples / blocks / blocks-example.cpp
index ae287f1..a308be3 100644 (file)
@@ -31,17 +31,17 @@ using namespace DemoHelper;
 
 namespace
 {
-const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-blocks.jpg" );
-const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
+const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-blocks.jpg" );
+const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
 const char* APPLICATION_TITLE( "DALi Blocks" );
-const char* BALL_IMAGE = DALI_IMAGE_DIR "blocks-ball.png";
-const char* PADDLE_IMAGE = DALI_IMAGE_DIR "blocks-paddle.png";
-const char* PADDLE_HANDLE_IMAGE = DALI_IMAGE_DIR "blocks-paddle-handle.png";
+const char* BALL_IMAGE = DEMO_IMAGE_DIR "blocks-ball.png";
+const char* PADDLE_IMAGE = DEMO_IMAGE_DIR "blocks-paddle.png";
+const char* PADDLE_HANDLE_IMAGE = DEMO_IMAGE_DIR "blocks-paddle-handle.png";
 
-const char* BRICK_IMAGE_PATH[] =    { DALI_IMAGE_DIR "blocks-brick-1.png",
-                                      DALI_IMAGE_DIR "blocks-brick-2.png",
-                                      DALI_IMAGE_DIR "blocks-brick-3.png",
-                                      DALI_IMAGE_DIR "blocks-brick-4.png" };
+const char* BRICK_IMAGE_PATH[] =    { DEMO_IMAGE_DIR "blocks-brick-1.png",
+                                      DEMO_IMAGE_DIR "blocks-brick-2.png",
+                                      DEMO_IMAGE_DIR "blocks-brick-3.png",
+                                      DEMO_IMAGE_DIR "blocks-brick-4.png" };
 
 const int TOTAL_BRICKS(4);                                                  ///< Total bricks in game.
 const Vector3 ICON_SIZE(100.0f, 100.0f, 0.0f);
@@ -56,8 +56,8 @@ const Vector3 PADDLE_COLLISION_MARGIN(0.0f, 0.0f, 0.0f);                    ///<
 const Vector3 BRICK_COLLISION_MARGIN(0.0f, 0.0f, 0.0f);                     ///< Collision margin for ball-brick detection.
 const Vector3 INITIAL_BALL_DIRECTION(1.0f, 1.0f, 0.0f);                     ///< Initial ball direction.
 
-const std::string WOBBLE_PROPERTY_NAME("wobble-property");                  ///< Wobble property name.
-const std::string COLLISION_PROPERTY_NAME("collision-property");            ///< Collision property name.
+const std::string WOBBLE_PROPERTY_NAME("wobbleProperty");                  ///< Wobble property name.
+const std::string COLLISION_PROPERTY_NAME("collisionProperty");            ///< Collision property name.
 
 const Vector2 BRICK_SIZE(0.1f, 0.05f );                                     ///< Brick size relative to width of stage.
 const Vector2 BALL_SIZE( 0.05f, 0.05f );                                    ///< Ball size relative to width of stage.
@@ -176,8 +176,8 @@ struct WobbleConstraint
    *
    * @param[in] deviation The max. deviation of wobble effect in degrees.
    */
-  WobbleConstraint(float deviation)
-  : mDeviation(Radian(Degree(deviation)))
+  WobbleConstraint( Degree deviation )
+  : mDeviation( deviation )
   {
 
   }
@@ -196,7 +196,7 @@ struct WobbleConstraint
     current = Quaternion(mDeviation * f, Vector3::ZAXIS);
   }
 
-  const float mDeviation;           ///< Deviation factor in radians.
+  Radian mDeviation;           ///< Deviation factor in radians.
 };
 
 } // unnamed namespace
@@ -283,14 +283,14 @@ private:
     mPaddleImage.SetSize( mPaddleFullSize );
 
     mWobbleProperty = mPaddle.RegisterProperty(WOBBLE_PROPERTY_NAME, 0.0f);
-    Constraint wobbleConstraint = Constraint::New<Quaternion>( mPaddle, Actor::Property::ORIENTATION, WobbleConstraint(10.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 ) );
     mContentLayer.Add(mPaddle);
-    mPaddle.TouchedSignal().Connect(this, &ExampleController::OnTouchPaddle);
-    mContentLayer.TouchedSignal().Connect(this, &ExampleController::OnTouchLayer);
+    mPaddle.TouchSignal().Connect(this, &ExampleController::OnTouchPaddle);
+    mContentLayer.TouchSignal().Connect(this, &ExampleController::OnTouchLayer);
 
     const float margin(BALL_SIZE.width * stageSize.width * 0.5f);
 
@@ -356,8 +356,8 @@ private:
     mLevelContainer = Actor::New();
     mLevelContainer.SetAnchorPoint( AnchorPoint::CENTER );
     mLevelContainer.SetParentOrigin( ParentOrigin::CENTER );
-    mLevelContainer.SetRelayoutEnabled( true );
-    mLevelContainer.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+    mLevelContainer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+
     mContentLayer.Add( mLevelContainer );
 
     mBrickCount = 0;
@@ -522,14 +522,10 @@ private:
     Vector2 stageSize(Stage::GetCurrent().GetSize());
     const Vector2 brickSize(BRICK_SIZE * Vector2(stageSize.x, stageSize.x));
 
-    ImageAttributes attr;
-    attr.SetSize( 128, 64 );
-    attr.SetScalingMode( ImageAttributes::ScaleToFill );
-    Image img = ResourceImage::New(BRICK_IMAGE_PATH[type], attr);
-    ImageActor brick = ImageActor::New(img);
+    Image img = ResourceImage::New( BRICK_IMAGE_PATH[type], Dali::ImageDimensions( 128, 64 ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR );
+    ImageView brick = ImageView::New(img);
     brick.SetParentOrigin(ParentOrigin::TOP_LEFT);
     brick.SetAnchorPoint(AnchorPoint::CENTER);
-    brick.SetRelayoutEnabled( false );
     brick.SetSize( brickSize );
     brick.SetPosition( Vector3( position ) );
 
@@ -555,13 +551,11 @@ private:
    *
    * @param[in] filename the path of the image.
    */
-  ImageActor CreateImage(const std::string& filename)
+  ImageView CreateImage(const std::string& filename)
   {
-    Image img = ResourceImage::New(filename);
-    ImageActor actor = ImageActor::New(img);
+    ImageView actor = ImageView::New(filename);
     actor.SetParentOrigin(ParentOrigin::TOP_LEFT);
     actor.SetAnchorPoint(AnchorPoint::CENTER);
-    actor.SetRelayoutEnabled( false );
     return actor;
   }
 
@@ -585,21 +579,21 @@ private:
    * @param[in] actor The actor touched
    * @param[in] event The touch event
    */
-  bool OnTouchPaddle(Actor actor, const TouchEvent& event)
+  bool OnTouchPaddle(Actor actor, const TouchData& event)
   {
     if(event.GetPointCount()>0)
     {
-      const TouchPoint& point = event.GetPoint(0);
-      if(point.state==TouchPoint::Down) // Commence dragging
+      if( event.GetState( 0 ) == PointState::DOWN ) // Commence dragging
       {
         // Get point where user touched paddle (relative to paddle's center)
-        mRelativeDragPoint = Vector3(point.screen.x, point.screen.y, 0.0f);
+        Vector2 screenPoint = event.GetScreenPosition( 0 );
+        mRelativeDragPoint = screenPoint;
         mRelativeDragPoint -= actor.GetCurrentPosition();
 
         mDragActor = actor;
         mDragAnimation = Animation::New(0.25f);
-        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.AnimateTo( Property(mDragActor, Actor::Property::SCALE), Vector3(1.1f, 1.1f, 1.0f), AlphaFunction::EASE_OUT);
+        mDragAnimation.AnimateTo( Property(mPaddleHandle, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 0.0f), AlphaFunction::EASE_OUT);
         mDragAnimation.Play();
       }
     }
@@ -611,21 +605,20 @@ private:
    * @param[in] actor The actor touched
    * @param[in] event The touch event
    */
-  bool OnTouchLayer(Actor actor, const TouchEvent& event)
+  bool OnTouchLayer(Actor actor, const TouchData& event)
   {
     if(event.GetPointCount()>0)
     {
-      const TouchPoint& point = event.GetPoint(0);
       if(mDragActor)
       {
-        Vector3 position(point.screen.x, point.screen.y, 0.0f);
+        Vector3 position( event.GetScreenPosition( 0 ) );
         mPaddle.SetPosition( position - mRelativeDragPoint );
 
-        if(point.state==TouchPoint::Up) // Stop dragging
+        if( event.GetState( 0 ) == PointState::UP ) // Stop dragging
         {
           mDragAnimation = Animation::New(0.25f);
-          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.AnimateTo( Property(mDragActor, Actor::Property::SCALE), Vector3(1.0f, 1.0f, 1.0f), AlphaFunction::EASE_IN);
+          mDragAnimation.AnimateTo( Property(mPaddleHandle, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 1.0f), AlphaFunction::EASE_OUT);
           mDragAnimation.Play();
           mDragActor.Reset();
         }
@@ -767,7 +760,7 @@ private:
 
     // fade brick (destroy)
     Animation destroyAnimation = Animation::New(0.5f);
-    destroyAnimation.AnimateTo( Property( brick, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunctions::EaseIn );
+    destroyAnimation.AnimateTo( Property( brick, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN );
     destroyAnimation.Play();
     destroyAnimation.FinishedSignal().Connect( this, &ExampleController::OnBrickDestroyed );
     mDestroyAnimationMap[destroyAnimation] = brick;
@@ -809,15 +802,15 @@ private:
 private:
 
   Application& mApplication;                            ///< Application instance
-  Toolkit::View mView;                                  ///< The View instance.
+  Toolkit::Control mView;                               ///< The View instance.
   Layer mContentLayer;                                  ///< The content layer (contains game actors)
-  ImageActor mBall;                                     ///< The Moving ball image.
+  ImageView mBall;                                      ///< The Moving ball image.
   Vector3 mBallStartPosition;                           ///< Ball Start position
   Vector3 mBallVelocity;                                ///< Ball's current direction.
   Animation mBallAnimation;                             ///< Ball's animation
   Actor mPaddle;                                        ///< The paddle including hit area.
-  ImageActor mPaddleImage;                              ///< The paddle's image.
-  ImageActor mPaddleHandle;                             ///< The paddle's handle (where the user touches)
+  ImageView mPaddleImage;                               ///< The paddle's image.
+  ImageView mPaddleHandle;                              ///< The paddle's handle (where the user touches)
   Vector2 mPaddleHitMargin;                             ///< The paddle hit margin.
   Animation mWobbleAnimation;                           ///< Paddle's animation when hit (wobbles)
   Property::Index mWobbleProperty;                      ///< The wobble property (generated from animation)
@@ -842,9 +835,9 @@ void RunTest(Application& app)
   app.MainLoop();
 }
 
-int main(int argc, char **argv)
+int DALI_EXPORT_API main(int argc, char **argv)
 {
-  Application app = Application::New(&argc, &argv);
+  Application app = Application::New(&argc, &argv, DEMO_THEME_PATH);
 
   RunTest(app);