2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Runtime.InteropServices;
21 internal static partial class Interop
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);
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);
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);
32 internal static ErrorCode GetFillColor(this PolygonHandle /* maps_view_object_h */ polygon, out Color color)
35 var err = polygon.GetFillColor(out r, out g, out b, out a);
36 color = new Color(r, g, b, a);
40 internal static ErrorCode SetFillColor(this PolygonHandle /* maps_view_object_h */ polygon, Color color)
42 return polygon.SetFillColor((byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A);
45 internal class PolygonHandle : ViewObjectHandle
47 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
48 internal delegate bool CoordinatesCallback(int index, IntPtr /* maps_coordinates_h */ coordinates, IntPtr /* void */ userData);
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);
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);
56 internal Color FillColor
58 get { return NativeGet<Color>(this.GetFillColor); }
59 set { NativeSet(this.SetFillColor, value); }
62 internal PolygonHandle(CoordinatesListHandle coordinates, Color color) : base(IntPtr.Zero, true)
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;
68 internal void ForeachPoint(Action<CoordinatesHandle> action)
70 CoordinatesCallback callback = (index, handle, userData) =>
72 action(CoordinatesHandle.CloneFrom(handle));
76 ForeachPoint(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get coordinates list from native handle");