Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-demo.git] / examples / magnifier / magnifier-example.cpp
index 632445f..4c8ea21 100644 (file)
@@ -57,20 +57,16 @@ struct MagnifierPathConstraint
   {
   }
 
-  Vector3 operator()(const Vector3&    current,
-                     const PropertyInput& sizeProperty,
-                     const PropertyInput& animationTimeProperty)
+  void operator()( Vector3& current, const PropertyInputContainer& inputs )
   {
-    float time = animationTimeProperty.GetFloat();
-    const Vector3& size = sizeProperty.GetVector3();
+    float time = inputs[1]->GetFloat();
+    const Vector3& size = inputs[0]->GetVector3();
 
-    Vector3 range(mStageSize - size - Vector3::ONE * MAGNIFIER_INDENT * 2.0f);
-    Vector3 position(mOffset);
+    current = mOffset;
 
-    position.x += 0.5f * sinf(time * 0.471f) * range.width;
-    position.y += 0.5f * sinf(time * 0.8739f) * range.height;
-
-    return position;
+    Vector3 range( mStageSize - size - Vector3::ONE * MAGNIFIER_INDENT * 2.0f );
+    current.x += 0.5f * sinf(time * 0.471f) * range.width;
+    current.y += 0.5f * sinf(time * 0.8739f) * range.height;
   }
 
   Vector3 mStageSize;     ///< Keep track of the stage size for determining path within stage bounds
@@ -103,23 +99,19 @@ struct ConfinementConstraint
   {
   }
 
-  Vector3 operator()(const Vector3&    constPosition,
-                     const PropertyInput& sizeProperty,
-                     const PropertyInput& parentOriginProperty,
-                     const PropertyInput& anchorPointProperty,
-                     const PropertyInput& referenceSizeProperty)
+  void operator()( Vector3& current, const PropertyInputContainer& inputs )
   {
-    const Vector3& size = sizeProperty.GetVector3();
-    const Vector3 origin = parentOriginProperty.GetVector3();
-    const Vector3& anchor = anchorPointProperty.GetVector3();
-    const Vector3& referenceSize = referenceSizeProperty.GetVector3();
+    const Vector3& size = inputs[0]->GetVector3();
+    const Vector3 origin = inputs[1]->GetVector3();
+    const Vector3& anchor = inputs[2]->GetVector3();
+    const Vector3& referenceSize = inputs[3]->GetVector3();
 
     Vector3 offset(mOffsetOrigin * referenceSize);
 
-    Vector3 newPosition( constPosition + offset );
-
     // Get actual position of Actor relative to parent's Top-Left.
-    Vector3 position(constPosition + offset + origin * referenceSize);
+    Vector3 position(current + offset + origin * referenceSize);
+
+    current += offset;
 
     // if top-left corner is outside of Top-Left bounds, then push back in screen.
     Vector3 corner(position - size * anchor - mMinIndent);
@@ -127,17 +119,17 @@ struct ConfinementConstraint
     if(mFlipHorizontal && corner.x < 0.0f)
     {
       corner.x = 0.0f;
-      newPosition.x += size.width;
+      current.x += size.width;
     }
 
     if(mFlipVertical && corner.y < 0.0f)
     {
       corner.y = 0.0f;
-      newPosition.y += size.height;
+      current.y += size.height;
     }
 
-    newPosition.x -= std::min(corner.x, 0.0f);
-    newPosition.y -= std::min(corner.y, 0.0f);
+    current.x -= std::min(corner.x, 0.0f);
+    current.y -= std::min(corner.y, 0.0f);
 
     // if bottom-right corner is outside of Bottom-Right bounds, then push back in screen.
     corner += size - referenceSize + mMinIndent + mMaxIndent;
@@ -145,19 +137,17 @@ struct ConfinementConstraint
     if(mFlipHorizontal && corner.x > 0.0f)
     {
       corner.x = 0.0f;
-      newPosition.x -= size.width;
+      current.x -= size.width;
     }
 
     if(mFlipVertical && corner.y > 0.0f)
     {
       corner.y = 0.0f;
-      newPosition.y -= size.height;
+      current.y -= size.height;
     }
 
-    newPosition.x -= std::max(corner.x, 0.0f);
-    newPosition.y -= std::max(corner.y, 0.0f);
-
-    return newPosition;
+    current.x -= std::max(corner.x, 0.0f);
+    current.y -= std::max(corner.y, 0.0f);
   }
 
   Vector3 mOffsetOrigin;                                ///< Manual Parent Offset Origin.
@@ -244,14 +234,13 @@ public:
     overlay.Add( mMagnifier );
 
     // Apply constraint to animate the position of the magnifier.
-    Constraint constraint = Constraint::New<Vector3>(Actor::Property::POSITION,
-                                                     LocalSource(Actor::Property::SIZE),
-                                                     LocalSource(Actor::Property::PARENT_ORIGIN),
-                                                     LocalSource(Actor::Property::ANCHOR_POINT),
-                                                     ParentSource(Actor::Property::SIZE),
-                                                     ConfinementConstraint(ParentOrigin::CENTER, Vector2::ONE * MAGNIFIER_INDENT, Vector2::ONE * MAGNIFIER_INDENT));
+    Constraint constraint = Constraint::New<Vector3>( mMagnifier, Actor::Property::POSITION, ConfinementConstraint(ParentOrigin::CENTER, Vector2::ONE * MAGNIFIER_INDENT, Vector2::ONE * MAGNIFIER_INDENT) );
+    constraint.AddSource( LocalSource(Actor::Property::SIZE) );
+    constraint.AddSource( LocalSource(Actor::Property::PARENT_ORIGIN) );
+    constraint.AddSource( LocalSource(Actor::Property::ANCHOR_POINT) );
+    constraint.AddSource( ParentSource(Actor::Property::SIZE) );
     constraint.SetRemoveAction(Constraint::Discard);
-    mMagnifier.ApplyConstraint( constraint );
+    constraint.Apply();
 
     // Create bouncing magnifier automatically bounces around screen.
     mBouncingMagnifier = Toolkit::Magnifier::New();
@@ -265,18 +254,16 @@ public:
     ContinueAnimation();
 
     // Apply constraint to animate the position of the magnifier.
-    constraint = Constraint::New<Vector3>(Actor::Property::POSITION,
-                                          LocalSource(Actor::Property::SIZE),
-                                          LocalSource(mAnimationTimeProperty),
-                                          MagnifierPathConstraint(mStageSize, mStageSize * 0.5f));
-    mBouncingMagnifier.ApplyConstraint( constraint );
+    constraint = Constraint::New<Vector3>( mBouncingMagnifier, Actor::Property::POSITION, MagnifierPathConstraint(mStageSize, mStageSize * 0.5f) );
+    constraint.AddSource( LocalSource(Actor::Property::SIZE) );
+    constraint.AddSource( LocalSource(mAnimationTimeProperty) );
+    constraint.Apply();
 
     // Apply constraint to animate the source of the magnifier.
-    constraint = Constraint::New<Vector3>(mBouncingMagnifier.GetPropertyIndex( Toolkit::Magnifier::SOURCE_POSITION_PROPERTY_NAME ),
-                                          LocalSource(Actor::Property::SIZE),
-                                          LocalSource(mAnimationTimeProperty),
-                                          MagnifierPathConstraint(mStageSize));
-    mBouncingMagnifier.ApplyConstraint( constraint );
+    constraint = Constraint::New<Vector3>( mBouncingMagnifier, mBouncingMagnifier.GetPropertyIndex( Toolkit::Magnifier::SOURCE_POSITION_PROPERTY_NAME ), MagnifierPathConstraint(mStageSize) );
+    constraint.AddSource( LocalSource(Actor::Property::SIZE) );
+    constraint.AddSource( LocalSource(mAnimationTimeProperty) );
+    constraint.Apply();
   }
 
   /**