Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / ElmSharp.Wearable / ElmSharp.Wearable / CircleSpinner.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
19 namespace ElmSharp.Wearable
20 {
21
22     /// <summary>
23     /// The Circle Spinner is a widget to display and handle spinner value by rotary event
24     /// Inherits <see cref="Spinner"/>.
25     /// </summary>
26     public class CircleSpinner : Spinner
27     {
28         private IntPtr _circleHandle;
29         private double _angleRatio = 1.0;
30
31         /// <summary>
32         /// Creates and initializes a new instance of the Circle Spinner class.
33         /// </summary>
34         /// <param name="parent">The parent of new Circle Spinner instance</param>
35         public CircleSpinner(EvasObject parent) : base(parent)
36         {
37         }
38
39         /// <summary>
40         /// Sets or gets the circle spinner angle per each spinner value.
41         /// </summary>
42         public double AngleRatio
43         {
44             get
45             {
46                 return _angleRatio;
47             }
48             set
49             {
50                 _angleRatio = value;
51                 Interop.Eext.eext_circle_object_spinner_angle_set(_circleHandle, _angleRatio);
52             }
53         }
54
55         /// <summary>
56         /// Sets or gets disabled state of the circle spinner object.
57         /// </summary>
58         public bool Disabled
59         {
60             get
61             {
62                 return Interop.Eext.eext_circle_object_disabled_get(_circleHandle); ;
63             }
64             set
65             {
66                 Interop.Eext.eext_circle_object_disabled_set(_circleHandle, value);
67             }
68         }
69
70         /// <summary>
71         /// Sets or gets the line width of the marker
72         /// </summary>
73         public int MarkerLineWidth
74         {
75             get
76             {
77                 return Interop.Eext.eext_circle_object_item_line_width_get(_circleHandle, "default");
78             }
79             set
80             {
81                 Interop.Eext.eext_circle_object_item_line_width_set(_circleHandle, "default", value);
82             }
83         }
84
85         /// <summary>
86         /// Sets or gets the color of the marker
87         /// </summary>
88         public Color MarkerColor
89         {
90             get
91             {
92                 int r, g, b, a;
93                 Interop.Eext.eext_circle_object_item_color_get(_circleHandle, "default", out r, out g, out b, out a);
94                 return new Color(r, g, b, a);
95             }
96             set
97             {
98                 Interop.Eext.eext_circle_object_item_color_set(_circleHandle, "default", value.R, value.G, value.B, value.A);
99             }
100         }
101
102         /// <summary>
103         /// Sets or gets the radius at which the center of the marker lies
104         /// </summary>
105         public double MarkerRadius
106         {
107             get
108             {
109                 return Interop.Eext.eext_circle_object_item_radius_get(_circleHandle, "default");
110             }
111             set
112             {
113                 Interop.Eext.eext_circle_object_item_radius_set(_circleHandle, "default", value);
114             }
115         }
116
117         protected override IntPtr CreateHandle(EvasObject parent)
118         {
119             IntPtr handle = base.CreateHandle(parent);
120
121             IntPtr surface = IntPtr.Zero;
122
123             if (parent is Conformant)
124             {
125                 surface = Interop.Eext.eext_circle_surface_conformant_add(parent.Handle);
126             }
127             else if (parent is Naviframe)
128             {
129                 surface = Interop.Eext.eext_circle_surface_naviframe_add(parent.RealHandle);
130             }
131             else if (parent is Layout)
132             {
133                 surface = Interop.Eext.eext_circle_surface_layout_add(parent.Handle);
134             }
135
136             _circleHandle = Interop.Eext.eext_circle_object_spinner_add(RealHandle, surface);
137             if (surface == IntPtr.Zero)
138             {
139                 EvasObject p = parent;
140                 while (!(p is Window))
141                 {
142                     p = p.Parent;
143                 }
144                 var w = (p as Window).ScreenSize.Width;
145                 var h = (p as Window).ScreenSize.Height;
146                 Interop.Evas.evas_object_resize(_circleHandle, w, h);
147             }
148
149             Interop.Eext.eext_rotary_object_event_activated_set(_circleHandle, true);
150             return handle;
151         }
152     }
153 }