[NUI] Support sub node's Animation
authorseungho <sbsh.baek@samsung.com>
Thu, 17 Nov 2022 06:29:04 +0000 (15:29 +0900)
committerbshsqa <32317749+bshsqa@users.noreply.github.com>
Mon, 19 Dec 2022 08:36:46 +0000 (17:36 +0900)
Signed-off-by: seungho <sbsh.baek@samsung.com>
src/Tizen.NUI/src/internal/Common/PropertyHelper.cs
src/Tizen.NUI/src/public/Animation/Animation.cs
src/Tizen.NUI/src/public/BaseComponents/ViewPublicMethods.cs

index e78f292..636326c 100755 (executable)
@@ -71,16 +71,21 @@ namespace Tizen.NUI
         ///<summary>
         /// Returns a Property if stringProperty is a valid index
         ///</summary>
-        internal static SearchResult Search(View view, string stringProperty)
+        internal static SearchResult Search(Animatable animatable, string stringProperty)
         {
             var propertyName = LowerFirstLetter(stringProperty);
 
-            return SearchProperty(view, propertyName) ?? SearchVisualProperty(view, propertyName);
+            if(animatable is View)
+            {
+                View view = animatable as View;
+                return SearchProperty(view, propertyName) ?? SearchVisualProperty(view, propertyName);
+            }
+            return SearchProperty(animatable, propertyName);
         }
 
-        private static SearchResult SearchProperty(View view, string lowercasePropertyString)
+        private static SearchResult SearchProperty(Animatable animatable, string lowercasePropertyString)
         {
-            Property property = new Property(view, lowercasePropertyString);
+            Property property = new Property(animatable, lowercasePropertyString);
 
             if (property.propertyIndex == Property.InvalidIndex)
             {
@@ -89,7 +94,7 @@ namespace Tizen.NUI
             }
 
             OOConverter converter = null;
-            if (view.GetPropertyType(property.propertyIndex).Equals(PropertyType.Float))
+            if (animatable.GetPropertyType(property.propertyIndex).Equals(PropertyType.Float))
             {
                 converter = ObjectIntToFloat;
             }
index ddd1646..6aecbd3 100755 (executable)
@@ -634,14 +634,15 @@ namespace Tizen.NUI
         /// <summary>
         /// Animates a property value by a relative amount.<br />
         /// </summary>
-        /// <param name="target">The target object to animate.</param>
+        /// <param name="target">The target animatable object to animate.</param>
         /// <param name="property">The target property to animate.</param>
         /// <param name="relativeValue">The property value will change by this amount.</param>
         /// <param name="alphaFunction">The alpha function to apply.</param>
         /// <exception cref="ArgumentNullException"> Thrown when target or property or relativeValue is null. </exception>
         /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given relativeValue is invalid format. </exception>
-        /// <since_tizen> 3 </since_tizen>
-        public void AnimateBy(View target, string property, object relativeValue, AlphaFunction alphaFunction = null)
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void AnimateBy(Animatable target, string property, object relativeValue, AlphaFunction alphaFunction = null)
         {
             if (target == null)
             {
@@ -682,7 +683,7 @@ namespace Tizen.NUI
         /// <summary>
         /// Animates a property value by a relative amount.<br />
         /// </summary>
-        /// <param name="target">The target object to animate.</param>
+        /// <param name="target">The target animatable object to animate.</param>
         /// <param name="property">The target property to animate.</param>
         /// <param name="relativeValue">The property value will change by this amount.</param>
         /// <param name="startTime">The start time of the animation.</param>
@@ -690,8 +691,9 @@ namespace Tizen.NUI
         /// <param name="alphaFunction">The alpha function to apply.</param>
         /// <exception cref="ArgumentNullException"> Thrown when target or property or relativeValue is null. </exception>
         /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given relativeValue is invalid format. </exception>
-        /// <since_tizen> 3 </since_tizen>
-        public void AnimateBy(View target, string property, object relativeValue, int startTime, int endTime, AlphaFunction alphaFunction = null)
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void AnimateBy(Animatable target, string property, object relativeValue, int startTime, int endTime, AlphaFunction alphaFunction = null)
         {
             if (target == null)
             {
@@ -731,16 +733,49 @@ namespace Tizen.NUI
         }
 
         /// <summary>
-        /// Animates a property to a destination value.<br />
+        /// Animates a property value by a relative amount.<br />
+        /// </summary>
+        /// <param name="target">The target object to animate.</param>
+        /// <param name="property">The target property to animate.</param>
+        /// <param name="relativeValue">The property value will change by this amount.</param>
+        /// <param name="alphaFunction">The alpha function to apply.</param>
+        /// <exception cref="ArgumentNullException"> Thrown when target or property or relativeValue is null. </exception>
+        /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given relativeValue is invalid format. </exception>
+        /// <since_tizen> 3 </since_tizen>
+        public void AnimateBy(View target, string property, object relativeValue, AlphaFunction alphaFunction = null)
+        {
+            AnimateBy(target as Animatable, property, relativeValue, alphaFunction);
+        }
+
+        /// <summary>
+        /// Animates a property value by a relative amount.<br />
         /// </summary>
         /// <param name="target">The target object to animate.</param>
         /// <param name="property">The target property to animate.</param>
+        /// <param name="relativeValue">The property value will change by this amount.</param>
+        /// <param name="startTime">The start time of the animation.</param>
+        /// <param name="endTime">The end time of the animation.</param>
+        /// <param name="alphaFunction">The alpha function to apply.</param>
+        /// <exception cref="ArgumentNullException"> Thrown when target or property or relativeValue is null. </exception>
+        /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given relativeValue is invalid format. </exception>
+        /// <since_tizen> 3 </since_tizen>
+        public void AnimateBy(View target, string property, object relativeValue, int startTime, int endTime, AlphaFunction alphaFunction = null)
+        {
+            AnimateBy(target as Animatable, property, relativeValue, startTime, endTime, alphaFunction);
+        }
+
+        /// <summary>
+        /// Animates a property to a destination value.<br />
+        /// </summary>
+        /// <param name="target">The target animatable object to animate.</param>
+        /// <param name="property">The target property to animate.</param>
         /// <param name="destinationValue">The destination value.</param>
         /// <param name="alphaFunction">The alpha function to apply.</param>
         /// <exception cref="ArgumentNullException"> Thrown when target or property or destinationValue is null. </exception>
         /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given destinationValue is invalid format. </exception>
-        /// <since_tizen> 3 </since_tizen>
-        public void AnimateTo(View target, string property, object destinationValue, AlphaFunction alphaFunction = null)
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void AnimateTo(Animatable target, string property, object destinationValue, AlphaFunction alphaFunction = null)
         {
             if (target == null)
             {
@@ -779,6 +814,95 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Animates a property to a destination value.<br />
+        /// </summary>
+        /// <param name="target">The target animatable object to animate.</param>
+        /// <param name="property">The target property to animate.</param>
+        /// <param name="destinationValue">The destination value.</param>
+        /// <param name="startTime">The start time of the animation.</param>
+        /// <param name="endTime">The end time of the animation.</param>
+        /// <param name="alphaFunction">The alpha function to apply.</param>
+        /// <exception cref="ArgumentNullException"> Thrown when target or property or destinationValue is null. </exception>
+        /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given destinationValue is invalid format. </exception>
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void AnimateTo(Animatable target, string property, object destinationValue, int startTime, int endTime, AlphaFunction alphaFunction = null)
+        {
+            if (target == null)
+            {
+                throw new ArgumentNullException(nameof(target));
+            }
+            if (property == null)
+            {
+                throw new ArgumentNullException(nameof(property));
+            }
+            if (destinationValue == null)
+            {
+                throw new ArgumentNullException(nameof(destinationValue));
+            }
+
+            using (var result = PropertyHelper.Search(target, property))
+            {
+                if (result == null)
+                {
+                    throw new ArgumentException("string property is invalid");
+                }
+
+                var current = result;
+                using (var time = new TimePeriod(startTime, endTime - startTime))
+                    while (current != null)
+                    {
+#if NUI_ANIMATION_PROPERTY_CHANGE_1
+                        var targetValueIntPtr = current.RefineValueIntPtr(destinationValue);
+                        if (targetValueIntPtr == global::System.IntPtr.Zero)
+                        {
+                            throw new ArgumentException("Invalid " + nameof(destinationValue));
+                        }
+                        AnimateToIntPtr(current.Property, targetValueIntPtr, alphaFunction, time);
+                        Interop.PropertyValue.DeletePropertyValueIntPtr(targetValueIntPtr);
+#else
+                        var targetValue = current.RefineValue(destinationValue) ?? throw new ArgumentException("Invalid " + nameof(destinationValue));
+                        AnimateTo(current.Property, targetValue, alphaFunction, time);
+                        targetValue.Dispose();
+#endif
+                        current = current.NextResult;
+                    }
+            }
+        }
+
+        /// <summary>
+        /// Animates a property to a destination value.<br />
+        /// </summary>
+        /// <param name="target">The target object to animate.</param>
+        /// <param name="property">The target property to animate.</param>
+        /// <param name="destinationValue">The destination value.</param>
+        /// <param name="alphaFunction">The alpha function to apply.</param>
+        /// <exception cref="ArgumentNullException"> Thrown when target or property or destinationValue is null. </exception>
+        /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given destinationValue is invalid format. </exception>
+        /// <since_tizen> 3 </since_tizen>
+        public void AnimateTo(View target, string property, object destinationValue, AlphaFunction alphaFunction = null)
+        {
+            AnimateTo(target as Animatable, property, destinationValue, alphaFunction);
+        }
+
+        /// <summary>
+        /// Animates a property to a destination value.<br />
+        /// </summary>
+        /// <param name="target">The target object to animate.</param>
+        /// <param name="property">The target property to animate.</param>
+        /// <param name="destinationValue">The destination value.</param>
+        /// <param name="startTime">The start time of the animation.</param>
+        /// <param name="endTime">The end time of the animation.</param>
+        /// <param name="alphaFunction">The alpha function to apply.</param>
+        /// <exception cref="ArgumentNullException"> Thrown when target or property or destinationValue is null. </exception>
+        /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given destinationValue is invalid format. </exception>
+        /// <since_tizen> 3 </since_tizen>
+        public void AnimateTo(View target, string property, object destinationValue, int startTime, int endTime, AlphaFunction alphaFunction = null)
+        {
+            AnimateTo(target as Animatable, property, destinationValue, startTime, endTime, alphaFunction);
+        }
+
+        /// <summary>
         /// Animates one or more properties to a destination value.<br />
         /// </summary>
         /// <param name="target">The target object to animate.</param>
@@ -846,68 +970,18 @@ namespace Tizen.NUI
         }
 
         /// <summary>
-        /// Animates a property to a destination value.<br />
-        /// </summary>
-        /// <param name="target">The target object to animate.</param>
-        /// <param name="property">The target property to animate.</param>
-        /// <param name="destinationValue">The destination value.</param>
-        /// <param name="startTime">The start time of the animation.</param>
-        /// <param name="endTime">The end time of the animation.</param>
-        /// <param name="alphaFunction">The alpha function to apply.</param>
-        /// <exception cref="ArgumentNullException"> Thrown when target or property or destinationValue is null. </exception>
-        /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given destinationValue is invalid format. </exception>
-        /// <since_tizen> 3 </since_tizen>
-        public void AnimateTo(View target, string property, object destinationValue, int startTime, int endTime, AlphaFunction alphaFunction = null)
-        {
-            if (target == null)
-            {
-                throw new ArgumentNullException(nameof(target));
-            }
-            if (property == null)
-            {
-                throw new ArgumentNullException(nameof(property));
-            }
-            if (destinationValue == null)
-            {
-                throw new ArgumentNullException(nameof(destinationValue));
-            }
-
-            using (var result = PropertyHelper.Search(target, property))
-            {
-                if (result == null)
-                {
-                    throw new ArgumentException("string property is invalid");
-                }
-
-                var current = result;
-                using (var time = new TimePeriod(startTime, endTime - startTime))
-                    while (current != null)
-                    {
-
-                        var targetValueIntPtr = current.RefineValueIntPtr(destinationValue);
-                        if (targetValueIntPtr == global::System.IntPtr.Zero)
-                        {
-                            throw new ArgumentException("Invalid " + nameof(destinationValue));
-                        }
-                        AnimateToIntPtr(current.Property, targetValueIntPtr, alphaFunction, time);
-                        Interop.PropertyValue.DeletePropertyValueIntPtr(targetValueIntPtr);
-                        current = current.NextResult;
-                    }
-            }
-        }
-
-        /// <summary>
         /// Animates a property between keyframes.
         /// </summary>
-        /// <param name="target">The target object to animate.</param>
+        /// <param name="target">The target animatable object to animate.</param>
         /// <param name="property">The target property to animate.</param>
         /// <param name="keyFrames">The set of time or value pairs between which to animate.</param>
         /// <param name="interpolation">The method used to interpolate between values.</param>
         /// <param name="alphaFunction">The alpha function to apply.</param>
         /// <exception cref="ArgumentNullException"> Thrown when target or property or keyFrames is null. </exception>
         /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given keyFrames has invalid value. </exception>
-        /// <since_tizen> 3 </since_tizen>
-        public void AnimateBetween(View target, string property, KeyFrames keyFrames, Interpolation interpolation = Interpolation.Linear, AlphaFunction alphaFunction = null)
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void AnimateBetween(Animatable target, string property, KeyFrames keyFrames, Interpolation interpolation = Interpolation.Linear, AlphaFunction alphaFunction = null)
         {
             if (target == null)
             {
@@ -942,7 +1016,7 @@ namespace Tizen.NUI
         /// <summary>
         /// Animates a property between keyframes.
         /// </summary>
-        /// <param name="target">The target object to animate</param>
+        /// <param name="target">The target animatable object to animate</param>
         /// <param name="property">The target property to animate</param>
         /// <param name="keyFrames">The set of time/value pairs between which to animate</param>
         /// <param name="startTime">The start time of animation in milliseconds.</param>
@@ -951,8 +1025,9 @@ namespace Tizen.NUI
         /// <param name="alphaFunction">The alpha function to apply.</param>
         /// <exception cref="ArgumentNullException"> Thrown when target or property or keyFrames is null. </exception>
         /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given keyFrames has invalid value. </exception>
-        /// <since_tizen> 3 </since_tizen>
-        public void AnimateBetween(View target, string property, KeyFrames keyFrames, int startTime, int endTime, Interpolation interpolation = Interpolation.Linear, AlphaFunction alphaFunction = null)
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void AnimateBetween(Animatable target, string property, KeyFrames keyFrames, int startTime, int endTime, Interpolation interpolation = Interpolation.Linear, AlphaFunction alphaFunction = null)
         {
             if (target == null)
             {
@@ -986,6 +1061,40 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Animates a property between keyframes.
+        /// </summary>
+        /// <param name="target">The target object to animate.</param>
+        /// <param name="property">The target property to animate.</param>
+        /// <param name="keyFrames">The set of time or value pairs between which to animate.</param>
+        /// <param name="interpolation">The method used to interpolate between values.</param>
+        /// <param name="alphaFunction">The alpha function to apply.</param>
+        /// <exception cref="ArgumentNullException"> Thrown when target or property or keyFrames is null. </exception>
+        /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given keyFrames has invalid value. </exception>
+        /// <since_tizen> 3 </since_tizen>
+        public void AnimateBetween(View target, string property, KeyFrames keyFrames, Interpolation interpolation = Interpolation.Linear, AlphaFunction alphaFunction = null)
+        {
+            AnimateBetween(target as Animatable, property, keyFrames, interpolation, alphaFunction);
+        }
+
+        /// <summary>
+        /// Animates a property between keyframes.
+        /// </summary>
+        /// <param name="target">The target object to animate</param>
+        /// <param name="property">The target property to animate</param>
+        /// <param name="keyFrames">The set of time/value pairs between which to animate</param>
+        /// <param name="startTime">The start time of animation in milliseconds.</param>
+        /// <param name="endTime">The end time of animation in milliseconds.</param>
+        /// <param name="interpolation">The method used to interpolate between values.</param>
+        /// <param name="alphaFunction">The alpha function to apply.</param>
+        /// <exception cref="ArgumentNullException"> Thrown when target or property or keyFrames is null. </exception>
+        /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given keyFrames has invalid value. </exception>
+        /// <since_tizen> 3 </since_tizen>
+        public void AnimateBetween(View target, string property, KeyFrames keyFrames, int startTime, int endTime, Interpolation interpolation = Interpolation.Linear, AlphaFunction alphaFunction = null)
+        {
+            AnimateBetween(target as Animatable, property, keyFrames, startTime, endTime, interpolation, alphaFunction);
+        }
+
+        /// <summary>
         /// Animates the view's position and orientation through a predefined path.<br />
         /// The view will rotate to orient the supplied forward vector with the path's tangent.<br />
         /// If forward is the zero vector then no rotation will happen.<br />
index 3eddeba..abd684a 100755 (executable)
@@ -217,6 +217,25 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// Retrieves a child view as Animatable by index.
+        /// </summary>
+        /// <param name="index">The index of the Animatable to find.</param>
+        /// <returns>A handle to the view as Animatable if found, or an empty handle if not.</returns>
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Animatable GetChildAnimatableAt(uint index)
+        {
+            if (index < Children.Count)
+            {
+                return Children[Convert.ToInt32(index)] as Animatable;
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        /// <summary>
         /// Retrieves the number of children held by the view.
         /// </summary>
         /// <seealso cref="Container.GetChildCount" />
@@ -447,6 +466,36 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// Search through this view's hierarchy for a view as Animatable with the given name.
+        /// The view itself is also considered in the search.
+        /// </summary>
+        /// <pre>The view has been initialized.</pre>
+        /// <param name="childName">The name of the Animatable to find.</param>
+        /// <returns>A handle to the view as Animatable if found, or an empty handle if not.</returns>
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Animatable FindChildAnimatableByName(string childName)
+        {
+            //to fix memory leak issue, match the handle count with native side.
+            IntPtr cPtr = Interop.Actor.FindChildByName(SwigCPtr, childName);
+            Animatable ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animatable;
+            if(ret == null)
+            {
+                // Register new camera into Registry.
+                ret = new Animatable(cPtr, true);
+            }
+            else
+            {
+                // We found matched NUI camera. Reduce cPtr reference count.
+                HandleRef handle = new HandleRef(this, cPtr);
+                Interop.Actor.DeleteActor(handle);
+                handle = new HandleRef(null, IntPtr.Zero);
+            }
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        /// <summary>
         /// Converts screen coordinates into the view's coordinate system using the default camera.
         /// </summary>
         /// <pre>The view has been initialized.</pre>