[NUI] VectorGraphics: Add DrawableGroup Class
authorJunsuChoi <jsuya.choi@samsung.com>
Wed, 28 Apr 2021 06:36:26 +0000 (15:36 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Fri, 21 May 2021 07:37:43 +0000 (16:37 +0900)
This feature can add and control multiple Drawable objects.
Since this class inherits Drawable, user can use Drawable's Opacity and Transformation methods.

[Dependancy]
dali-adaptor: https://review.tizen.org/gerrit/#/c/platform/core/uifw/dali-adaptor/+/257538/
dali-csharp-binder: https://review.tizen.org/gerrit/#/c/platform/core/uifw/dali-csharp-binder/+/257607/

src/Tizen.NUI/src/internal/Interop/Interop.DrawableGroup.cs [new file with mode: 0755]
src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/DrawableGroup.cs [new file with mode: 0755]
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/CanvasViewSamsple.cs

diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.DrawableGroup.cs b/src/Tizen.NUI/src/internal/Interop/Interop.DrawableGroup.cs
new file mode 100755 (executable)
index 0000000..aefbe2b
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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
+{
+    internal static partial class Interop
+    {
+        internal static partial class DrawableGroup
+        {
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DrawableGroup_New")]
+            public static extern global::System.IntPtr New();
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DrawableGroup_AddDrawable")]
+            public static extern bool AddDrawable(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DrawableGroup_Clear")]
+            public static extern bool Clear(global::System.Runtime.InteropServices.HandleRef jarg1);
+        }
+    }
+}
diff --git a/src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/DrawableGroup.cs b/src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/DrawableGroup.cs
new file mode 100755 (executable)
index 0000000..aa491b7
--- /dev/null
@@ -0,0 +1,71 @@
+/* 
+* 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.
+*
+*/
+
+using System;
+using System.ComponentModel;
+
+namespace Tizen.NUI.BaseComponents.VectorGraphics
+{
+    /// <summary>
+    /// A class enabling to hold many Drawable objects. As a whole they can be transformed, their transparency can be changed.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class DrawableGroup : Drawable
+    {
+        /// <summary>
+        /// Creates an initialized DrawableGroup.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public DrawableGroup() : this(Interop.DrawableGroup.New(), true)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        internal DrawableGroup(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        {
+        }
+
+        /// <summary>
+        /// Add drawable object to the DrawableGroup. This method is similar to registration.
+        /// </summary>
+        /// <param name="drawable">Drawable object</param>
+        /// <exception cref="ArgumentNullException"> Thrown when drawable is null. </exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void AddDrawable(Drawable drawable)
+        {
+            if (drawable == null)
+            {
+                throw new ArgumentNullException(nameof(drawable));
+            }
+            Interop.DrawableGroup.AddDrawable(View.getCPtr(this), BaseHandle.getCPtr(drawable));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// Clears the drawable object added to the DrawableGroup. 
+        /// This method does not free the memory of the added drawable object.
+        /// </summary>
+        /// <returns>True when it's successful. False otherwise.</returns>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool Clear()
+        {
+            bool ret = Interop.DrawableGroup.Clear(BaseHandle.getCPtr(this));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+    }
+}
index b107ae0..b16dff7 100644 (file)
@@ -17,6 +17,8 @@ namespace Tizen.NUI.Samples
         private Shape circleShape;
         private Shape arcShape;
         private Shape starShape;
+        private DrawableGroup group1;
+        private DrawableGroup group2;
         private Timer timer;
         private int count = 0;
 
@@ -52,8 +54,6 @@ namespace Tizen.NUI.Samples
             roundedRectShape.Rotate(45.0f);
             roundedRectShape.AddRect(-50.0f, -50.0f, 100.0f, 100.0f, 0.0f, 0.0f);
 
-            canvasView.AddDrawable(roundedRectShape);
-
             circleShape = new Shape()
             {
                 Opacity = 0.5f,
@@ -65,8 +65,6 @@ namespace Tizen.NUI.Samples
             circleShape.AddCircle(0.0f, 0.0f, 150.0f, 100.0f);
             circleShape.Transform(new float[] { 0.6f, 0.0f, 350.0f, 0.0f, 0.6f, 100.0f, 0.0f, 0.0f, 1.0f });
 
-            canvasView.AddDrawable(circleShape);
-
             arcShape = new Shape()
             {
                 StrokeColor = new Color(0.0f, 0.5f, 0.0f, 0.5f),
@@ -76,8 +74,6 @@ namespace Tizen.NUI.Samples
             arcShape.AddArc(0.0f, 0.0f, 80.0f, 0.0f, 0.0f, true);
             arcShape.Translate(100.0f, 300.0f);
 
-            canvasView.AddDrawable(arcShape);
-
             Shape shape = new Shape()
             {
                 Opacity = 0.5f,
@@ -122,6 +118,16 @@ namespace Tizen.NUI.Samples
 
             canvasView.AddDrawable(starShape);
 
+
+            group1 = new DrawableGroup();
+            group1.AddDrawable(roundedRectShape);
+            group1.AddDrawable(arcShape);
+
+            group2 = new DrawableGroup();
+            group2.AddDrawable(group1);
+            group2.AddDrawable(circleShape);
+            canvasView.AddDrawable(group2);
+
             // Test Getter
             log.Debug(tag, "circleShape Color : " + circleShape.FillColor.R + " " + circleShape.FillColor.G + " " + circleShape.FillColor.B + " " + circleShape.FillColor.A + "\n");
             log.Debug(tag, "circleShape StrokeColor : " + circleShape.StrokeColor.R + " " + circleShape.StrokeColor.G + " " + circleShape.StrokeColor.B + " " + circleShape.StrokeColor.A + "\n");
@@ -197,6 +203,9 @@ namespace Tizen.NUI.Samples
             starShape.Rotate((count * 2.0f) % 360);
             starShape.Scale((float)(count % 50) * 0.01f + 0.6f);
 
+            group1.Scale((float)(count % 100) * 0.002f + 0.8f);
+            group2.Opacity = 1.0f - (float)(count % 80) * 0.01f;
+
             count++;
 
             return true;