[NUI] VectorGraphics: Add Gradient feature
authorJunsuChoi <jsuya.choi@samsung.com>
Thu, 5 Aug 2021 08:58:47 +0000 (17:58 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 18 Aug 2021 03:10:44 +0000 (12:10 +0900)
Add Gradient, LinearGradient, and RadialGradient classes that
implement Linear and Radial Gradient features.
Each Gradient can be applied to Fill and Stroke of Shape after
setting Bounds and ColorStop suitable for style.

src/Tizen.NUI/src/internal/Interop/Interop.Gradient.cs [new file with mode: 0755]
src/Tizen.NUI/src/internal/Interop/Interop.LinearGradient.cs [new file with mode: 0755]
src/Tizen.NUI/src/internal/Interop/Interop.RadialGradient.cs [new file with mode: 0755]
src/Tizen.NUI/src/internal/Interop/Interop.Shape.cs
src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/ColorStop.cs [new file with mode: 0755]
src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/Gradient.cs [new file with mode: 0755]
src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/LinearGradient.cs [new file with mode: 0755]
src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/RadialGradient .cs [new file with mode: 0755]
src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/Shape.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/CanvasViewSamsple.cs

diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.Gradient.cs b/src/Tizen.NUI/src/internal/Interop/Interop.Gradient.cs
new file mode 100755 (executable)
index 0000000..f2e7948
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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 Gradient
+        {
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Gradient_SetColorStops")]
+            public static extern void SetColorStops(global::System.Runtime.InteropServices.HandleRef gradient, [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)] float[] stops, int stopsLength);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Gradient_GetColorStopsCount")]
+            public static extern int GetColorStopsCount(global::System.Runtime.InteropServices.HandleRef gradient);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Gradient_GetColorStopsOffsetIndexOf")]
+            public static extern float GetColorStopsOffsetIndexOf(global::System.Runtime.InteropServices.HandleRef gradient, int index);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Gradient_GetColorStopsColorIndexOf")]
+            public static extern global::System.IntPtr GetColorStopsColorIndexOf(global::System.Runtime.InteropServices.HandleRef gradient, int index);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Gradient_SetSpread")]
+            public static extern void SetSpread(global::System.Runtime.InteropServices.HandleRef gradient, int index);
+            
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Gradient_GetSpread")]
+            public static extern int GetSpread(global::System.Runtime.InteropServices.HandleRef gradient);
+        }
+    }
+}
diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.LinearGradient.cs b/src/Tizen.NUI/src/internal/Interop/Interop.LinearGradient.cs
new file mode 100755 (executable)
index 0000000..111250f
--- /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 LinearGradient
+        {
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_LinearGradient_New")]
+            public static extern global::System.IntPtr New();
+            
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_LinearGradient_SetBounds")]
+            public static extern void SetBounds(global::System.Runtime.InteropServices.HandleRef linearGradient, global::System.Runtime.InteropServices.HandleRef firstPoint, global::System.Runtime.InteropServices.HandleRef secondPoint);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_LinearGradient_GetBounds")]
+            public static extern void GetBounds(global::System.Runtime.InteropServices.HandleRef linearGradient, global::System.Runtime.InteropServices.HandleRef firstPoint, global::System.Runtime.InteropServices.HandleRef secondPoint);
+        }
+    }
+}
diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.RadialGradient.cs b/src/Tizen.NUI/src/internal/Interop/Interop.RadialGradient.cs
new file mode 100755 (executable)
index 0000000..fe9400d
--- /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 RadialGradient
+        {
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_RadialGradient_New")]
+            public static extern global::System.IntPtr New();
+            
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_RadialGradient_SetBounds")]
+            public static extern void SetBounds(global::System.Runtime.InteropServices.HandleRef linearGradient, global::System.Runtime.InteropServices.HandleRef centerPoint, float radius);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_RadialGradient_GetBounds")]
+            public unsafe static extern void GetBounds(global::System.Runtime.InteropServices.HandleRef linearGradient, global::System.Runtime.InteropServices.HandleRef centerPoint, void* radius);
+        }
+    }
+}
index a6477f8..2327363 100755 (executable)
@@ -100,6 +100,20 @@ namespace Tizen.NUI
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Shape_GetStrokeJoin")]
             public static extern int GetStrokeJoin(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Shapep_SetFillGradient")]
+            [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
+            public static extern bool SetFillGradient(global::System.Runtime.InteropServices.HandleRef pShape, global::System.Runtime.InteropServices.HandleRef pGradient);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Shapep_GetFillGradient")]
+            public static extern global::System.IntPtr GetFillGradient(global::System.Runtime.InteropServices.HandleRef pShape);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Shapep_SetStrokeGradient")]
+            [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
+            public static extern bool SetStrokeGradient(global::System.Runtime.InteropServices.HandleRef pShape, global::System.Runtime.InteropServices.HandleRef pGradient);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Shapep_GetStrokeGradient")]
+            public static extern global::System.IntPtr GetStrokeGradient(global::System.Runtime.InteropServices.HandleRef pShape);
         }
     }
 }
diff --git a/src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/ColorStop.cs b/src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/ColorStop.cs
new file mode 100755 (executable)
index 0000000..8fa4f25
--- /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 data storing the information about the color and its relative position inside the gradient bounds.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class ColorStop
+    {
+        private float offset; //The relative position of the color. 
+        private Color color; //The color value.
+
+        /// <summary>
+        /// Initialize ColorStop.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public ColorStop(float offset, Color color)
+        {
+            this.offset = offset;
+            this.color = color;
+        }
+
+        /// <summary>
+        /// The relative position of the color. 
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public float Offset
+        {
+            set
+            {
+                this.offset = value;
+            }
+            get
+            {
+                return this.offset;
+            }
+        }
+
+        /// <summary>
+        /// The color value.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Color Color
+        {
+            set {
+                this.color = value;
+            }
+            get {
+                return this.color;
+            }
+        }
+    };
+}
diff --git a/src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/Gradient.cs b/src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/Gradient.cs
new file mode 100755 (executable)
index 0000000..ab97aef
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+* 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;
+using System.Collections.ObjectModel;
+using System.Collections.Generic;
+
+namespace Tizen.NUI.BaseComponents.VectorGraphics
+{
+    /// <summary>
+    /// An abstract class representing the gradient fill of the Shape.
+    /// It contains the information about the gradient colors and their arrangement
+    /// inside the gradient bounds. The gradients bounds are defined in the LinearGradient
+    /// or RadialGradient class, depending on the type of the gradient to be used.
+    /// It specifies the gradient behavior in case the area defined by the gradient bounds
+    /// is smaller than the area to be filled.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class Gradient : BaseHandle
+    {
+        /// <summary>
+        /// Creates an initialized gradient.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        private Gradient() { }
+
+        internal Gradient(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        {
+        }
+
+        /// <summary>
+        /// Enumeration specifying how to fill the area outside the gradient bounds.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public enum SpreadType
+        {
+            /// <summary>
+            /// The remaining area is filled with the closest stop color.
+            /// </summary>
+            Pad = 0,
+            /// <summary>
+            /// The gradient pattern is reflected outside the gradient area until the expected region is filled.
+            /// </summary>
+            Reflect,
+            /// <summary>
+            /// The gradient pattern is repeated continuously beyond the gradient area until the expected region is filled.
+            /// </summary>
+            Repeat
+        };
+
+        /// <summary>
+        /// Specifying how to fill the area outside the gradient bounds.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public SpreadType Spread
+        {
+            get
+            {
+                return (SpreadType)Interop.Gradient.GetSpread(BaseHandle.getCPtr(this));
+            }
+            set
+            {
+                Interop.Gradient.SetSpread(BaseHandle.getCPtr(this), (int)value);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            }
+        }
+
+        /// <summary>
+        /// The parameters list of the colors of the gradient and their position.
+        /// </summary>
+        /// <exception cref="ArgumentNullException"> Thrown when value is null. </exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public ReadOnlyCollection<ColorStop> ColorStops
+        {
+            get
+            {
+                List<ColorStop> retList = new List<ColorStop>();
+                int colorStopsCount = Interop.Gradient.GetColorStopsCount(BaseHandle.getCPtr(this));
+                for (int i = 0; i < colorStopsCount; i++)
+                {
+                    retList.Add(new ColorStop(Interop.Gradient.GetColorStopsOffsetIndexOf(BaseHandle.getCPtr(this), i),
+                                              Vector4.GetVector4FromPtr(Interop.Gradient.GetColorStopsColorIndexOf(BaseHandle.getCPtr(this), i))));
+                }
+
+                return retList.AsReadOnly();
+            }
+            set
+            {
+                if (value == null)
+                {
+                    throw new ArgumentNullException(nameof(value));
+                }
+
+                float[] rawColorStops = new float[value.Count * 5];
+                for (int i = 0; i < value.Count; i++)
+                {
+                    rawColorStops[i * 5] = value[i].Offset;
+                    rawColorStops[i * 5 + 1] = value[i].Color.R;
+                    rawColorStops[i * 5 + 2] = value[i].Color.G;
+                    rawColorStops[i * 5 + 3] = value[i].Color.B;
+                    rawColorStops[i * 5 + 4] = value[i].Color.A;
+                }
+
+                Interop.Gradient.SetColorStops(BaseHandle.getCPtr(this), rawColorStops, value.Count);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            }
+        }
+    }
+}
diff --git a/src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/LinearGradient.cs b/src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/LinearGradient.cs
new file mode 100755 (executable)
index 0000000..10c640b
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+* 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 representing the linear gradient fill of the Shape object.
+    /// Besides the class inherited from the Gradient class, it enables setting and getting the linear gradient bounds.
+    /// The behavior outside the gradient bounds depends on the value specified in the spread API.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class LinearGradient : Gradient
+    {
+        /// <summary>
+        /// Creates an initialized linear gradient.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public LinearGradient() : this(Interop.LinearGradient.New(), true)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        internal LinearGradient(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        {
+        }
+
+        /// <summary>
+        /// Sets the linear gradient bounds.
+        /// 
+        /// The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing
+        /// the given points firstPoint and secondPoint, respectively. Both lines are perpendicular to the line linking
+        /// firstPoint and secondPoint.
+        /// </summary>
+        /// <param name="firstPoint">The first point used to determine the gradient bounds.</param>
+        /// <param name="secondPoint">The second point used to determine the gradient bounds.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetBounds(Position2D firstPoint, Position2D secondPoint)
+        {
+            Interop.LinearGradient.SetBounds(BaseHandle.getCPtr(this), Position2D.getCPtr(firstPoint), Position2D.getCPtr(secondPoint));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// Gets the linear gradient bounds.
+        /// </summary>
+        /// <param name="firstPoint">The first point used to determine the gradient bounds.</param>
+        /// <param name="secondPoint">The second point used to determine the gradient bounds.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void GetBounds(ref Position2D firstPoint, ref Position2D secondPoint)
+        {
+            Interop.LinearGradient.GetBounds(BaseHandle.getCPtr(this), Position2D.getCPtr(firstPoint), Position2D.getCPtr(secondPoint));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+    }
+}
diff --git a/src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/RadialGradient .cs b/src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/RadialGradient .cs
new file mode 100755 (executable)
index 0000000..94890ad
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+* 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 representing the radial gradient fill of the Shape object.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class RadialGradient : Gradient
+    {
+        /// <summary>
+        /// Creates an initialized radial gradient.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public RadialGradient() : this(Interop.RadialGradient.New(), true)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        internal RadialGradient(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        {
+        }
+
+        /// <summary>
+        /// Sets the radial gradient bounds.
+        /// 
+        /// The radial gradient bounds are defined as a circle centered in a given point of a given radius.
+        /// </summary>
+        /// <param name="centerPoint">The point of the center of the bounding circle.</param>
+        /// <param name="radius">The radius of the bounding circle.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetBounds(Position2D centerPoint, float radius)
+        {
+            Interop.RadialGradient.SetBounds(BaseHandle.getCPtr(this), Position2D.getCPtr(centerPoint), radius);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// Gets the radial gradient bounds.
+        /// </summary>
+        /// <param name="centerPoint">The point of the center of the bounding circle.</param>
+        /// <param name="radius">The radius of the bounding circle.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void GetBounds(ref Position2D centerPoint, ref float radius)
+        {
+            float ret = 0.0f;
+            unsafe
+            {
+                float* radiusPtr = &ret;
+                Interop.RadialGradient.GetBounds(BaseHandle.getCPtr(this), Position2D.getCPtr(centerPoint), radiusPtr);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+
+            }
+            radius = ret;
+        }
+
+    }
+}
index fc5256a..d533e43 100755 (executable)
@@ -28,6 +28,9 @@ namespace Tizen.NUI.BaseComponents.VectorGraphics
     /// <since_tizen> 9 </since_tizen>
     public class Shape : Drawable
     {
+        private Gradient fillGradient; //Added gradient
+        private Gradient strokeGradient; //Added gradient
+
         /// <summary>
         /// Creates an initialized Shape.
         /// </summary>
@@ -116,6 +119,30 @@ namespace Tizen.NUI.BaseComponents.VectorGraphics
         }
 
         /// <summary>
+        /// The gradient to use for filling the path.
+        /// Even if FillColor is set, Gradient setting takes precedence.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Gradient FillGradient
+        {
+            get
+            {
+                global::System.IntPtr cPtr = Interop.Shape.GetFillGradient(BaseHandle.getCPtr(this));
+                Gradient ret = new Gradient(cPtr, true);
+                return ret;
+            }
+            set
+            {
+                if (value != null)
+                {
+                    Interop.Shape.SetFillGradient(BaseHandle.getCPtr(this), BaseHandle.getCPtr(value));
+                    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                    fillGradient = value;
+                }       
+            }
+        }
+
+        /// <summary>
         /// The current fill rule of the shape.
         /// </summary>
         /// <since_tizen> 9 </since_tizen>
@@ -168,6 +195,30 @@ namespace Tizen.NUI.BaseComponents.VectorGraphics
         }
 
         /// <summary>
+        /// The gradient to use for stroking the path.
+        /// Even if StrokeColor is set, Gradient setting takes precedence.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Gradient StrokeGradient
+        {
+            get
+            {
+                global::System.IntPtr cPtr = Interop.Shape.GetStrokeGradient(BaseHandle.getCPtr(this));
+                Gradient ret = new Gradient(cPtr, true);
+                return ret;
+            }
+            set
+            {
+                if (value != null)
+                {
+                    Interop.Shape.SetStrokeGradient(BaseHandle.getCPtr(this), BaseHandle.getCPtr(value));
+                    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                    strokeGradient = value;
+                }       
+            }
+        }
+
+        /// <summary>
         /// The cap style to use for stroking the path. The cap will be used for capping the end point of a open subpath.
         /// </summary>
         /// <since_tizen> 9 </since_tizen>
index c494838..0a74246 100644 (file)
@@ -3,6 +3,8 @@ using System.Collections.Generic;
 using Tizen.NUI.BaseComponents;
 using Tizen.NUI.BaseComponents.VectorGraphics;
 
+using System.Collections.ObjectModel;
+
 namespace Tizen.NUI.Samples
 {
     using log = Tizen.Log;
@@ -43,11 +45,24 @@ namespace Tizen.NUI.Samples
                 PositionUsesPivotPoint = true,
             };
 
+            RadialGradient roundedRectFillRadialGradient = new RadialGradient()
+            {
+                ColorStops = new List<ColorStop>()
+                {
+                    new ColorStop(0.0f, new Color(1.0f,0.0f,0.0f,1.0f)),
+                    new ColorStop(0.5f, new Color(0.0f,1.0f,0.0f,1.0f)),
+                    new ColorStop(1.0f, new Color(0.0f,0.0f,1.0f,1.0f))
+                }.AsReadOnly(),
+                Spread = Gradient.SpreadType.Reflect,
+            };
+            roundedRectFillRadialGradient.SetBounds(new Position2D(0, 0), 30);
+
             roundedRectShape = new Shape()
             {
                 FillColor = new Color(0.5f, 1.0f, 0.0f, 1.0f),
                 StrokeColor = new Color(0.5f, 0.0f, 0.0f, 0.5f),
                 StrokeWidth = 10.0f,
+                FillGradient = roundedRectFillRadialGradient,
             };
             roundedRectShape.Translate(100.0f, 100.0f);
             roundedRectShape.Scale(1.2f);
@@ -110,6 +125,27 @@ namespace Tizen.NUI.Samples
             starClipper.AddCircle(0.0f, 0.0f, 160.0f, 160.0f);
             starClipper.Translate(250.0f, 550.0f);
 
+            LinearGradient starFillLinearGradient = new LinearGradient()
+            {
+                ColorStops = new List<ColorStop>()
+                {
+                    new ColorStop(0.0f, new Color(1.0f,0.0f,0.0f,1.0f)),
+                    new ColorStop(0.5f, new Color(0.0f,1.0f,0.0f,1.0f)),
+                    new ColorStop(1.0f, new Color(0.0f,0.0f,1.0f,1.0f))
+                }.AsReadOnly()
+            };
+            starFillLinearGradient.SetBounds(new Position2D(-50, -50), new Position2D(50, 50));
+
+            LinearGradient starStrokeLinearGradient = new LinearGradient()
+            {
+                ColorStops = new List<ColorStop>()
+                {
+                    new ColorStop(0.0f, new Color(1.0f,0.0f,1.0f,1.0f)),
+                    new ColorStop(1.0f, new Color(0.0f,1.0f,1.0f,1.0f))
+                }.AsReadOnly()
+            };
+            starStrokeLinearGradient.SetBounds(new Position2D(0, -50), new Position2D(50, 50));
+
             starShape = new Shape()
             {
                 Opacity = 0.5f,
@@ -117,7 +153,10 @@ namespace Tizen.NUI.Samples
                 StrokeColor = new Color(0.5f, 1.0f, 0.5f, 1.0f),
                 StrokeWidth = 30.0f,
                 StrokeCap = Shape.StrokeCapType.Round,
+                FillGradient = starFillLinearGradient,
+                StrokeGradient = starStrokeLinearGradient,
             };
+
             starShape.Translate(250.0f, 550.0f);
             starShape.Scale(0.5f);
             starShape.AddMoveTo(-1.0f, -165.0f);
@@ -146,6 +185,16 @@ namespace Tizen.NUI.Samples
             canvasView.AddDrawable(group2);
 
             // Test Getter
+            Position2D p1 = new Position2D(9, 9), p2 = new Position2D(8, 8);
+            starFillLinearGradient.GetBounds(ref p1, ref p2);
+            log.Debug(tag, "Gradient Bounds : P1 :" + p1.X + " " + p1.Y + " / P2 :" + p2.X + " " + p2.Y + "\n");
+
+            ReadOnlyCollection<ColorStop> stops = starShape.FillGradient.ColorStops;
+            for (int i = 0; i < stops.Count; i++)
+            {
+                log.Debug(tag, "Gradient Stops :" + i + " " + stops[i].Offset + " " + stops[i].Color.R + " " + stops[i].Color.G + " " + stops[i].Color.B + " " + stops[i].Color.A + "\n");
+            }
+
             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");