Setting since_tizen 3/4 on Tizen.NET API
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Tizen.Maps / Polygon.cs
index 2f78c2b..599dd8e 100755 (executable)
@@ -23,18 +23,22 @@ using Color = ElmSharp.Color;
 namespace Tizen.Maps
 {
     /// <summary>
-    /// Polygon map object
+    /// The polygon map object.
     /// </summary>
-    public class Polygon : MapObject
+    /// <since_tizen> 3 </since_tizen>
+    public class Polygon : MapObject, IDisposable
     {
+        internal Interop.PolygonHandle handle;
         private List<Geocoordinates> _coordinateList;
 
         /// <summary>
-        /// Creates a polygon visual object
+        /// Creates a polygon visual object.
         /// </summary>
-        /// <param name="coordinates">list of geographical coordinates</param>
-        /// <param name="color">background color</param>
-        public Polygon(IEnumerable<Geocoordinates> coordinates, Color color) : base(CreateNativeHandle(coordinates, color))
+        /// <since_tizen> 3 </since_tizen>
+        /// <param name="coordinates">List of geographical coordinates.</param>
+        /// <param name="color">Background color.</param>
+        /// <exception cref="ArgumentException">Thrown when input values are invalid.</exception>
+        public Polygon(IEnumerable<Geocoordinates> coordinates, Color color) : base()
         {
             var err = Interop.ErrorCode.InvalidParameter;
             if (coordinates == null || coordinates.Count() < 3)
@@ -42,43 +46,47 @@ namespace Tizen.Maps
                 err.ThrowIfFailed("given coordinates list should contain at least 3 coordinates");
             }
             _coordinateList = coordinates.ToList();
+            var geocoordinateList = new GeocoordinatesList(_coordinateList, false);
+            handle = new Interop.PolygonHandle(geocoordinateList.handle, color);
         }
 
-        internal Polygon(Interop.ViewObjectHandle nativeHandle) : base(nativeHandle)
+        /// <summary>
+        /// Adds or removes the clicked event handlers.
+        /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        public event EventHandler Clicked;
+
+        /// <summary>
+        /// Gets or sets visibility for the polygon.
+        /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        public override bool IsVisible
         {
+            get { return handle.IsVisible; }
+            set { handle.IsVisible = value; }
         }
 
         /// <summary>
-        /// List of geographical coordinates of polygon vertices
+        /// Gets or sets a list of geographical coordinates for polygon vertices.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
         public IEnumerable<Geocoordinates> Coordinates
         {
             get
             {
-                if (_coordinateList == null)
-                {
-                    _coordinateList = new List<Geocoordinates>();
-                    Interop.ViewObject.CoordinatesCallback callback = (index, nativeHandle, userData) =>
-                    {
-                        _coordinateList.Add(new Geocoordinates(nativeHandle));
-                        return true;
-                    };
-                    Interop.ViewObject.PolygonForeachPoint(handle, callback, IntPtr.Zero);
-                }
                 return _coordinateList;
             }
             set
             {
                 var coordinates = value.ToList();
-
                 var err = Interop.ErrorCode.InvalidParameter;
                 if (coordinates == null || coordinates.Count() < 3)
                 {
                     err.ThrowIfFailed("given coordinates list should contain at least 3 coordinates");
                 }
 
-                var coordinateList = new GeocoordinatesList(coordinates, false);
-                if (Interop.ViewObject.PolygonSetPolygon(handle, coordinateList.handle).IsSuccess())
+                var geocoordinateList = new GeocoordinatesList(coordinates, false);
+                if (handle.SetPolygon(geocoordinateList.handle).IsSuccess())
                 {
                     _coordinateList = coordinates;
                 }
@@ -86,31 +94,66 @@ namespace Tizen.Maps
         }
 
         /// <summary>
-        /// Background fill color
+        /// Gets or sets a background color to fill the polygon.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
         public Color FillColor
         {
             get
             {
-                byte r, g, b, a;
-                Interop.ViewObject.PolygonGetFillColor(handle, out r, out g, out b, out a);
-                return new Color(r, g, b, a);
+                return handle.FillColor;
             }
             set
             {
-                Interop.ViewObject.PolygonSetFillColor(handle, (byte)value.R, (byte)value.G, (byte)value.B, (byte)value.A);
+                handle.FillColor = value;
             }
         }
 
-        private static Interop.ViewObjectHandle CreateNativeHandle(IEnumerable<Geocoordinates> coordinates, Color color)
+        internal override void HandleClickedEvent()
+        {
+            Clicked?.Invoke(this, EventArgs.Empty);
+        }
+
+        internal override void InvalidateMapObject()
+        {
+            handle = null;
+        }
+
+        internal override Interop.ViewObjectHandle GetHandle()
         {
-            if (coordinates == null || coordinates.Count() < 3) return new Interop.ViewObjectHandle(IntPtr.Zero);
+            return handle;
+        }
+
+        #region IDisposable Support
+        private bool _disposedValue = false;
+
+        /// <summary>
+        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+        /// </summary>
+        /// <param name="disposing">If true, managed and unmanaged resources can be disposed, otherwise only unmanaged resources can be disposed.</param>
+        /// <since_tizen> 3 </since_tizen>
+        protected virtual void Dispose(bool disposing)
+        {
+            if (!_disposedValue)
+            {
+                if (disposing)
+                {
+                    _coordinateList.Clear();
+                }
+                handle.Dispose();
+                _disposedValue = true;
+            }
+        }
 
-            IntPtr nativeHandle;
-            var geocoordinateList = new GeocoordinatesList(coordinates.ToList(), false);
-            var err = Interop.ViewObject.CreatePolygon(geocoordinateList.handle, (byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A, out nativeHandle);
-            err.ThrowIfFailed("Failed to create native handle for polygon");
-            return new Interop.ViewObjectHandle(nativeHandle);
+        /// <summary>
+        /// Releases all the resources used by this object.
+        /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
         }
+        #endregion
     }
 }