Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Interop / Interop.View.Polygon.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Runtime.InteropServices;
19 using ElmSharp;
20
21 internal static partial class Interop
22 {
23     [DllImport(Libraries.MapService, EntryPoint = "maps_view_object_polygon_set_polygon")]
24     internal static extern ErrorCode SetPolygon(this PolygonHandle /* maps_view_object_h */ polygon, CoordinatesListHandle /* maps_coordinates_list_h */ points);
25
26     [DllImport(Libraries.MapService, EntryPoint = "maps_view_object_polygon_get_fill_color")]
27     internal static extern ErrorCode GetFillColor(this PolygonHandle /* maps_view_object_h */ polygon, out byte r, out byte g, out byte b, out byte a);
28
29     [DllImport(Libraries.MapService, EntryPoint = "maps_view_object_polygon_set_fill_color")]
30     internal static extern ErrorCode SetFillColor(this PolygonHandle /* maps_view_object_h */ polygon, byte r, byte g, byte b, byte a);
31
32     internal static ErrorCode GetFillColor(this PolygonHandle /* maps_view_object_h */ polygon, out Color color)
33     {
34         byte r, g, b, a;
35         var err = polygon.GetFillColor(out r, out g, out b, out a);
36         color = new Color(r, g, b, a);
37         return err;
38     }
39
40     internal static ErrorCode SetFillColor(this PolygonHandle /* maps_view_object_h */ polygon, Color color)
41     {
42         return polygon.SetFillColor((byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A);
43     }
44
45     internal class PolygonHandle : ViewObjectHandle
46     {
47         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
48         internal delegate bool CoordinatesCallback(int index, IntPtr /* maps_coordinates_h */ coordinates, IntPtr /* void */ userData);
49
50         [DllImport(Libraries.MapService, EntryPoint = "maps_view_object_polygon_foreach_point")]
51         internal static extern ErrorCode ForeachPoint(IntPtr /* maps_view_object_h */ polygon, CoordinatesCallback callback, IntPtr /* void */ userData);
52
53         [DllImport(Libraries.MapService, EntryPoint = "maps_view_object_create_polygon")]
54         internal static extern ErrorCode CreatePolygon(CoordinatesListHandle /* maps_coordinates_list_h */ coordinates, byte r, byte g, byte b, byte a, out IntPtr /* maps_view_object_h */ polygon);
55
56         internal Color FillColor
57         {
58             get { return NativeGet<Color>(this.GetFillColor); }
59             set { NativeSet(this.SetFillColor, value); }
60         }
61
62         internal PolygonHandle(CoordinatesListHandle coordinates, Color color) : base(IntPtr.Zero, true)
63         {
64             CreatePolygon(coordinates, (byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A, out handle).ThrowIfFailed("Failed to create native polygon handle");
65             coordinates.HasOwnership = false;
66         }
67
68         internal void ForeachPoint(Action<CoordinatesHandle> action)
69         {
70             CoordinatesCallback callback = (index, handle, userData) =>
71             {
72                 action(CoordinatesHandle.CloneFrom(handle));
73                 return true;
74             };
75
76             ForeachPoint(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get coordinates list from native handle");
77         }
78     }
79 }