Add Evas Polygon class
authorPiotr Szydelko <p.szydelko@samsung.com>
Thu, 22 Sep 2016 08:43:07 +0000 (10:43 +0200)
committerPiotr Szydelko <p.szydelko@samsung.com>
Fri, 23 Sep 2016 12:54:56 +0000 (14:54 +0200)
Change-Id: Ic8c20b1e7da8ee77f0fc4244843533b9c92b90af
Signed-off-by: Piotr Szydelko <p.szydelko@samsung.com>
src/ElmSharp/ElmSharp.Net45.csproj
src/ElmSharp/ElmSharp.csproj
src/ElmSharp/ElmSharp/Polygon.cs [new file with mode: 0644]
src/ElmSharp/Interop/Interop.Evas.cs
test/ElmSharp.Test/ElmSharp.Test.csproj
test/ElmSharp.Test/TC/PolygonTest1.cs [new file with mode: 0644]

index 7ee9b6d..92a8f32 100644 (file)
@@ -94,6 +94,7 @@
     <Compile Include="ElmSharp\Panes.cs" />\r
     <Compile Include="ElmSharp\Point.cs" />\r
     <Compile Include="ElmSharp\Point3D.cs" />\r
+    <Compile Include="ElmSharp\Polygon.cs" />\r
     <Compile Include="ElmSharp\Popup.cs" />\r
     <Compile Include="ElmSharp\PopupItem.cs" />\r
     <Compile Include="ElmSharp\ProgressBar.cs" />\r
index 4803ec2..8af1fd5 100644 (file)
@@ -91,6 +91,7 @@
     <Compile Include="ElmSharp\Panes.cs" />\r
     <Compile Include="ElmSharp\Point.cs" />\r
     <Compile Include="ElmSharp\Point3D.cs" />\r
+    <Compile Include="ElmSharp\Polygon.cs" />\r
     <Compile Include="ElmSharp\Popup.cs" />\r
     <Compile Include="ElmSharp\PopupItem.cs" />\r
     <Compile Include="ElmSharp\ProgressBar.cs" />\r
diff --git a/src/ElmSharp/ElmSharp/Polygon.cs b/src/ElmSharp/ElmSharp/Polygon.cs
new file mode 100644 (file)
index 0000000..8aa7282
--- /dev/null
@@ -0,0 +1,59 @@
+// Copyright 2016 by Samsung Electronics, Inc.,
+//
+// This software is the confidential and proprietary information
+// of Samsung Electronics, Inc. ("Confidential Information"). You
+// shall not disclose such Confidential Information and shall use
+// it only in accordance with the terms of the license agreement
+// you entered into with Samsung.
+
+using System;
+
+namespace ElmSharp
+{
+    /// <summary>
+    /// A view used to draw a polygon (filled).
+    /// </summary>
+    public class Polygon : EvasObject
+    {
+        /// <summary>
+        /// Create a new Polygon widget.
+        /// <param name="p">The EvasObject to which the new Polygon will be attached as a child.</param>
+        /// </summary>
+        public Polygon (EvasObject parent) : base(parent)
+        {
+        }
+
+        /// <summary>
+        /// Adds a new vertex to the polygon.
+        /// <param name="x">The X coordinate of the new vertex.</param>
+        /// <param name="y">The Y coordinate of the new vertex.</param>
+        /// </summary>
+        public void AddPoint(int x, int y)
+        {
+            Interop.Evas.evas_object_polygon_point_add(Handle, x, y);
+        }
+
+        /// <summary>
+        /// Adds a new vertex to the polygon.
+        /// <param name="p">The coordinates of the new vertex.</param>
+        /// </summary>
+        public void AddPoint(Point p)
+        {
+            AddPoint(p.X, p.Y);
+        }
+
+        /// <summary>
+        /// Removes all the vertices of the polygon, making it empty.
+        /// </summary>
+        public void ClearPoints()
+        {
+            Interop.Evas.evas_object_polygon_points_clear(Handle);
+        }
+
+        protected override IntPtr CreateHandle(EvasObject parent)
+        {
+            IntPtr evas = Interop.Evas.evas_object_evas_get(parent.Handle);
+            return Interop.Evas.evas_object_polygon_add(evas);
+        }
+    }
+}
index e63db3d..c8c3667 100755 (executable)
@@ -213,6 +213,15 @@ internal static partial class Interop
         internal static extern void evas_map_free(IntPtr map);
 
         [DllImport(Libraries.Evas)]
+        internal static extern IntPtr evas_object_polygon_add(IntPtr evas);
+
+        [DllImport(Libraries.Evas)]
+        internal static extern IntPtr evas_object_polygon_point_add(IntPtr evas, int x, int y);
+
+        [DllImport(Libraries.Evas)]
+        internal static extern IntPtr evas_object_polygon_points_clear(IntPtr evas);
+
+        [DllImport(Libraries.Evas)]
         internal static extern IntPtr evas_object_rectangle_add(IntPtr evas);
 
         [DllImport(Libraries.Evas)]
index e610825..57edf88 100644 (file)
@@ -70,6 +70,7 @@
     <Compile Include="TC\PanelTest1.cs" />\r
     <Compile Include="TC\PanelTest2.cs" />\r
     <Compile Include="TC\PanesTest1.cs" />\r
+    <Compile Include="TC\PolygonTest1.cs" />\r
     <Compile Include="TC\PopupTest1.cs" />\r
     <Compile Include="TC\ProgressBarTest1.cs" />\r
     <Compile Include="TC\RadioTest1.cs" />\r
diff --git a/test/ElmSharp.Test/TC/PolygonTest1.cs b/test/ElmSharp.Test/TC/PolygonTest1.cs
new file mode 100644 (file)
index 0000000..1823b4f
--- /dev/null
@@ -0,0 +1,49 @@
+using System;
+using ElmSharp;
+
+namespace ElmSharp.Test
+{
+    class PolygonTest1 : TestCaseBase
+    {
+        public override string TestName => "PolygonTest1";
+        public override string TestDescription => "To test basic operation of Polygon";
+
+        public override void Run(Window window)
+        {
+            Background bg = new Background(window);
+            bg.Color = Color.White;
+            bg.Move(0, 0);
+            bg.Resize(window.ScreenSize.Width, window.ScreenSize.Height);
+            bg.Show();
+
+            Polygon triangle1 = new Polygon(window);
+            triangle1.Color = Color.Blue;
+            triangle1.AddPoint(100, 100);
+            triangle1.AddPoint(100, 500);
+            triangle1.AddPoint(500, 500);
+            triangle1.Show();
+
+            Polygon triange2 = new Polygon(window);
+            triange2.AddPoint(300, 300);
+            triange2.AddPoint(new Point{X=600, Y=300});
+            triange2.AddPoint(new Point{X=600, Y=600});
+            triange2.Color = Color.Green;
+            triange2.Show();
+
+            Polygon hexagon = new Polygon(window);
+            hexagon.Color = Color.Pink;
+            hexagon.AddPoint(0, 0);
+            hexagon.AddPoint(700, 0);
+            hexagon.ClearPoints();
+            for (double a=0; a < 2 * Math.PI; a += Math.PI / 3)
+            {
+                hexagon.AddPoint(
+                    300 + (int)(120 * Math.Sin(a)),
+                    580 + (int)(120 * Math.Cos(a))
+                );
+            }
+            hexagon.Show();
+        }
+
+    }
+}