[NUI] Add Scale transition
authorSeungho Baek <sbsh.baek@samsung.com>
Fri, 20 Aug 2021 07:09:50 +0000 (16:09 +0900)
committerSeoyeon2Kim <34738918+Seoyeon2Kim@users.noreply.github.com>
Mon, 13 Sep 2021 07:33:23 +0000 (16:33 +0900)
Signed-off-by: Seungho Baek <sbsh.baek@samsung.com>
src/Tizen.NUI/src/internal/Interop/Interop.ScaleTransitionItem.cs [new file with mode: 0755]
src/Tizen.NUI/src/internal/Transition/ScaleTransitionItem.cs [new file with mode: 0755]
src/Tizen.NUI/src/public/Transition/ScaleTransition.cs [new file with mode: 0644]
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/PageTransitionSample.cs

diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.ScaleTransitionItem.cs b/src/Tizen.NUI/src/internal/Interop/Interop.ScaleTransitionItem.cs
new file mode 100755 (executable)
index 0000000..cc83f71
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright(c) 2021 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.
+ *
+ */
+
+namespace Tizen.NUI
+{
+    using global::System;
+    using global::System.Runtime.InteropServices;
+
+    internal static partial class Interop
+    {
+        internal static partial class ScaleTransitionItem
+        {
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_ScaleTransition")]
+            public static extern IntPtr NewEmpty();
+
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_ScaleTransition_New_1")]
+            public static extern IntPtr New(HandleRef view, float scale, HandleRef timePeriod);
+
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_ScaleTransition_New_2")]
+            public static extern IntPtr New(HandleRef view, HandleRef scale, HandleRef timePeriod);
+
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_ScaleTransition")]
+            public static extern void Delete(HandleRef scaleTransition);
+
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_ScaleTransition_Set")]
+            public static extern IntPtr NewScaleTransitionItem(HandleRef scaleTransition);
+
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_ScaleTransition_Assign")]
+            public static extern IntPtr Assign(HandleRef destination, HandleRef source);
+        }
+    }
+}
diff --git a/src/Tizen.NUI/src/internal/Transition/ScaleTransitionItem.cs b/src/Tizen.NUI/src/internal/Transition/ScaleTransitionItem.cs
new file mode 100755 (executable)
index 0000000..3d0a7af
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright(c) 2021 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.
+ *
+ */
+
+namespace Tizen.NUI
+{
+    using System;
+    using System.ComponentModel;
+
+    using Tizen.NUI.BaseComponents;
+
+    /// <summary>
+    /// ScaleTransitionItem is an object to set scale transition of a View that will appear or disappear.
+    /// ScaleTransitionItem object is required to be added to the TransitionSet to play.
+    /// </summary>
+    internal class ScaleTransitionItem : TransitionItemBase
+    {
+        /// <summary>
+        /// Creates an initialized ScaleTransition.<br />
+        /// </summary>
+        /// <remarks>Delay and duration of timePeriod must be greater than zero.</remarks>
+        public ScaleTransitionItem(View view, float scale, bool isAppearing, TimePeriod timePeriod, AlphaFunction alphaFunction) : this(Interop.ScaleTransitionItem.New(view.SwigCPtr, scale, timePeriod.SwigCPtr), true)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            AppearingTransition = isAppearing;
+            AlphaFunction = alphaFunction;
+        }
+
+        /// <summary>
+        /// Creates an initialized ScaleTransition.<br />
+        /// </summary>
+        /// <remarks>Delay and duration of timePeriod must be greater than zero.</remarks>
+        public ScaleTransitionItem(View view, Vector2 scale, bool isAppearing, TimePeriod timePeriod, AlphaFunction alphaFunction) : this(Interop.ScaleTransitionItem.New(view.SwigCPtr, scale.SwigCPtr, timePeriod.SwigCPtr), true)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            AppearingTransition = isAppearing;
+            AlphaFunction = alphaFunction;
+        }
+
+        internal ScaleTransitionItem(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        {
+        }
+
+        internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ScaleTransitionItem obj)
+        {
+            return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
+        }
+
+        internal ScaleTransitionItem(ScaleTransitionItem handle) : this(Interop.ScaleTransitionItem.NewScaleTransitionItem(ScaleTransitionItem.getCPtr(handle)), true)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        internal ScaleTransitionItem Assign(ScaleTransitionItem rhs)
+        {
+            ScaleTransitionItem ret = new ScaleTransitionItem(Interop.ScaleTransitionItem.Assign(SwigCPtr, ScaleTransitionItem.getCPtr(rhs)), false);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        /// <summary>
+        /// To make ScaleTransition instance be disposed.
+        /// </summary>
+        protected override void Dispose(DisposeTypes type)
+        {
+            if (disposed)
+            {
+                return;
+            }
+            base.Dispose(type);
+        }
+
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
+        {
+            if (swigCPtr.Handle == IntPtr.Zero || this.HasBody() == false)
+            {
+                Tizen.Log.Fatal("NUI", $"[ERROR] ScaleTransitionItem ReleaseSwigCPtr()! IntPtr=0x{swigCPtr.Handle:X} HasBody={this.HasBody()}");
+                return;
+            }
+            Interop.ScaleTransitionItem.Delete(swigCPtr);
+        }
+    }
+}
diff --git a/src/Tizen.NUI/src/public/Transition/ScaleTransition.cs b/src/Tizen.NUI/src/public/Transition/ScaleTransition.cs
new file mode 100644 (file)
index 0000000..c0f7d40
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright(c) 2021 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.
+ *
+ */
+
+namespace Tizen.NUI
+{
+    using System;
+    using System.ComponentModel;
+    using Tizen.NUI.BaseComponents;
+
+    /// <summary>
+    /// ScaleTransition provides smoothly appearing/disappearing scale effects for target View.
+    /// If this transition is for appearing, the View comes out with the scale factor applied
+    /// and will be animated at its original scale.
+    /// If this transition is for disappearing, the View starts at its original size
+    /// but will become the scale of scale factor and vanished.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class ScaleTransition : TransitionBase
+    {
+        /// <summary>
+        /// Create a ScaleTransition.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public ScaleTransition()
+        {
+        }
+
+        /// <summary>
+        /// Set/get Scale factor for this scale transition.
+        /// if AppearingTransition, transition starts from scaled by the ScaleFactor and is animated to the original size.
+        /// And if DisappearingTransition, transition is finished to the scaled state by the ScaleFactor.
+        ///
+        /// Default ScaleFactor is Vector2(0.5f, 0.5f).
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Vector2 ScaleFactor { get; set; } = new Vector2(0.5f, 0.5f);
+
+        internal override TransitionItemBase CreateTransition(View view, bool isAppearing)
+        {
+            ScaleTransitionItem scale = new ScaleTransitionItem(view, ScaleFactor, isAppearing, GetTimePeriod(), GetAlphaFunction());
+            return scale;
+        }
+    }
+}
index 0e6dd0b..d14da22 100755 (executable)
@@ -86,11 +86,11 @@ namespace Tizen.NUI.Samples
             {
                 BackgroundColor = Color.Transparent,
                 Content = mainRoot,
-                DisappearingTransition = new SlideTransition()
+                DisappearingTransition = new ScaleTransition()
                 {
                     TimePeriod = new TimePeriod(500),
                     AlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Default),
-                    Direction = SlideTransitionDirection.Top
+                    ScaleFactor = new Vector2(0.5f, 1.5f)
                 },
                 AppearingTransition = new SlideTransition()
                 {
@@ -337,10 +337,11 @@ namespace Tizen.NUI.Samples
                     TimePeriod = new TimePeriod(500),
                     AlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Default),
                 },
-                DisappearingTransition = new FadeTransition()
+                DisappearingTransition = new SlideTransition()
                 {
                     TimePeriod = new TimePeriod(500),
                     AlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Default),
+                    Direction = SlideTransitionDirection.Left
                 },
             };
             return page;