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_polyline_set_polyline")]
24 internal static extern ErrorCode SetPolyline(this PolylineHandle /* maps_view_object_h */ polyline, CoordinatesListHandle /* maps_coordinates_list_h */ points);
26 [DllImport(Libraries.MapService, EntryPoint = "maps_view_object_polyline_set_color")]
27 internal static extern ErrorCode SetColor(this PolylineHandle /* maps_view_object_h */ polyline, byte r, byte g, byte b, byte a);
29 [DllImport(Libraries.MapService, EntryPoint = "maps_view_object_polyline_get_color")]
30 internal static extern ErrorCode GetColor(this PolylineHandle /* maps_view_object_h */ polyline, out byte r, out byte g, out byte b, out byte a);
32 [DllImport(Libraries.MapService, EntryPoint = "maps_view_object_polyline_set_width")]
33 internal static extern ErrorCode SetWidth(this PolylineHandle /* maps_view_object_h */ polyline, int width);
35 [DllImport(Libraries.MapService, EntryPoint = "maps_view_object_polyline_get_width")]
36 internal static extern ErrorCode GetWidth(this PolylineHandle /* maps_view_object_h */ polyline, out int width);
38 internal static ErrorCode GetColor(this PolylineHandle /* maps_view_object_h */ polyline, out Color color)
41 var err = polyline.GetColor(out r, out g, out b, out a);
42 color = new Color(r, g, b, a);
46 internal static ErrorCode SetColor(this PolylineHandle /* maps_view_object_h */ polyline, Color color)
48 return polyline.SetColor((byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A);
51 internal class PolylineHandle : ViewObjectHandle
53 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
54 internal delegate bool CoordinatesCallback(int index, IntPtr /* maps_coordinates_h */ coordinates, IntPtr /* void */ userData);
56 [DllImport(Libraries.MapService, EntryPoint = "maps_view_object_create_polyline")]
57 internal static extern ErrorCode CreatePolyline(CoordinatesListHandle /* maps_coordinates_list_h */ coordinates, byte r, byte g, byte b, byte a, int width, out IntPtr /* maps_view_object_h */ polyline);
59 [DllImport(Libraries.MapService, EntryPoint = "maps_view_object_polyline_foreach_point")]
60 internal static extern ErrorCode ForeachPoint(IntPtr /* maps_view_object_h */ polyline, CoordinatesCallback callback, IntPtr /* void */ userData);
62 internal Color LineColor
64 get { return NativeGet<Color>(this.GetColor); }
65 set { NativeSet(this.SetColor, value); }
68 internal int LineWidth
70 get { return NativeGet<int>(this.GetWidth); }
71 set { NativeSet(this.SetWidth, value); }
74 internal PolylineHandle(CoordinatesListHandle coordinates, Color color, int width) : base(IntPtr.Zero, true)
76 CreatePolyline(coordinates, (byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A, width, out handle).ThrowIfFailed("Failed to create native polyline handle");
77 coordinates.HasOwnership = false;
80 internal void ForeachPoint(Action<CoordinatesHandle> action)
82 CoordinatesCallback callback = (index, handle, userData) =>
84 action(CoordinatesHandle.CloneFrom(handle));
88 ForeachPoint(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get coordinates list from native handle");