Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Interop / Interop.View.Polyline.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_polyline_set_polyline")]
24     internal static extern ErrorCode SetPolyline(this PolylineHandle /* maps_view_object_h */ polyline, CoordinatesListHandle /* maps_coordinates_list_h */ points);
25
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);
28
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);
31
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);
34
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);
37
38     internal static ErrorCode GetColor(this PolylineHandle /* maps_view_object_h */ polyline, out Color color)
39     {
40         byte r, g, b, a;
41         var err = polyline.GetColor(out r, out g, out b, out a);
42         color = new Color(r, g, b, a);
43         return err;
44     }
45
46     internal static ErrorCode SetColor(this PolylineHandle /* maps_view_object_h */ polyline, Color color)
47     {
48         return polyline.SetColor((byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A);
49     }
50
51     internal class PolylineHandle : ViewObjectHandle
52     {
53         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
54         internal delegate bool CoordinatesCallback(int index, IntPtr /* maps_coordinates_h */ coordinates, IntPtr /* void */ userData);
55
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);
58
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);
61
62         internal Color LineColor
63         {
64             get { return NativeGet<Color>(this.GetColor); }
65             set { NativeSet(this.SetColor, value); }
66         }
67
68         internal int LineWidth
69         {
70             get { return NativeGet<int>(this.GetWidth); }
71             set { NativeSet(this.SetWidth, value); }
72         }
73
74         internal PolylineHandle(CoordinatesListHandle coordinates, Color color, int width) : base(IntPtr.Zero, true)
75         {
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;
78         }
79
80         internal void ForeachPoint(Action<CoordinatesHandle> action)
81         {
82             CoordinatesCallback callback = (index, handle, userData) =>
83             {
84                 action(CoordinatesHandle.CloneFrom(handle));
85                 return true;
86             };
87
88             ForeachPoint(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get coordinates list from native handle");
89         }
90     }
91 }