Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / ElmSharp.Wearable / ElmSharp.Wearable / CircleSlider.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     /// <summary>
22     /// Circle slider is circular designed widget to select a value in a range by rotary event.
23     /// </summary>
24     public class CircleSlider : EvasObject
25     {
26         public event EventHandler Changed;
27
28         SmartEvent _changedEvent;
29
30         /// <summary>
31         /// Creates and initializes a new instance of the CircleSlider class.
32         /// </summary>
33         /// <param name="parent">The EvasObject to which the new CircleSlider will be attached as a child.</param>
34         public CircleSlider(EvasObject parent) : base(parent)
35         {
36             _changedEvent = new SmartEvent(this, "value,changed");
37
38             _changedEvent.On += (s, e) => Changed?.Invoke(this, EventArgs.Empty);
39         }
40
41         /// <summary>
42         /// Sets or gets the step by which the circle slider bar moves.
43         /// </summary>
44         /// <remarks>
45         /// This value is used when circle slider value is changed by an drag or rotary event
46         /// The value of the slider is increased/decreased by the step value.
47         /// </remarks>
48         public double Step
49         {
50             get
51             {
52                 return Interop.Eext.eext_circle_object_slider_step_get(RealHandle);
53             }
54             set
55             {
56                 Interop.Eext.eext_circle_object_slider_step_set(RealHandle, (double)value);
57             }
58         }
59
60         /// <summary>
61         /// Sets or gets disabled state of the circle slider object.
62         /// </summary>
63         public bool Disabled
64         {
65             get
66             {
67                 return Interop.Eext.eext_circle_object_disabled_get(RealHandle); ;
68             }
69             set
70             {
71                 Interop.Eext.eext_circle_object_disabled_set(RealHandle, value);
72             }
73         }
74
75         /// <summary>
76         /// Sets or gets color of the circle slider bar.
77         /// </summary>
78         public Color BarColor
79         {
80             get
81             {
82                 int r = 0;
83                 int g = 0;
84                 int b = 0;
85                 int a = 0;
86                 Interop.Eext.eext_circle_object_color_get(RealHandle, out r, out g, out b, out a);
87                 return Color.FromRgba(r, g, b, a);
88             }
89             set
90             {
91                 Interop.Eext.eext_circle_object_color_set(RealHandle, value.R, value.G, value.B, value.A);
92             }
93         }
94
95         /// <summary>
96         /// Sets or gets color of the circle slider background.
97         /// </summary>
98         public Color BackgroundColor
99         {
100             get
101             {
102                 int r = 0;
103                 int g = 0;
104                 int b = 0;
105                 int a = 0;
106                 Interop.Eext.eext_circle_object_item_color_get(RealHandle, "bg", out r, out g, out b, out a);
107                 return Color.FromRgba(r, g, b, a);
108             }
109             set
110             {
111                 Interop.Eext.eext_circle_object_item_color_set(RealHandle, "bg", value.R, value.G, value.B, value.A);
112             }
113         }
114
115         /// <summary>
116         /// Sets or gets the line with of the circle slider bar.
117         /// </summary>
118         public int BarLineWidth
119         {
120             get
121             {
122                 return Interop.Eext.eext_circle_object_line_width_get(RealHandle); ;
123             }
124             set
125             {
126                 Interop.Eext.eext_circle_object_line_width_set(RealHandle, value);
127             }
128         }
129
130         /// <summary>
131         /// Sets or gets the line with of the circle slider background.
132         /// </summary>
133         public int BackgroundLineWidth
134         {
135             get
136             {
137                 return Interop.Eext.eext_circle_object_item_line_width_get(RealHandle, "bg");
138             }
139             set
140             {
141                 Interop.Eext.eext_circle_object_item_line_width_set(RealHandle, "bg", value);
142             }
143         }
144
145         /// <summary>
146         /// Sets or gets the angle in degree of the circle slider bar.
147         /// </summary>
148         public double BarAngle
149         {
150             get
151             {
152                 return Interop.Eext.eext_circle_object_angle_get(RealHandle); ;
153             }
154             set
155             {
156                 Interop.Eext.eext_circle_object_angle_set(RealHandle, value);
157             }
158         }
159
160         /// <summary>
161         /// Sets or gets the angle in degree of the circle slider background.
162         /// </summary>
163         public double BackgroundAngle
164         {
165             get
166             {
167                 return Interop.Eext.eext_circle_object_item_angle_get(RealHandle, "bg");
168             }
169             set
170             {
171                 Interop.Eext.eext_circle_object_item_angle_set(RealHandle, "bg", value);
172             }
173         }
174
175         /// <summary>
176         /// Sets or gets the angle offset for the slider bar.
177         /// offset value means start position of the slider bar.
178         /// </summary>
179         public double BarAngleOffset
180         {
181             get
182             {
183                 return Interop.Eext.eext_circle_object_angle_offset_get(RealHandle); ;
184             }
185             set
186             {
187                 Interop.Eext.eext_circle_object_angle_offset_set(RealHandle, value);
188             }
189         }
190
191         /// <summary>
192         /// Sets or gets the angle offset for the circle slider background.
193         /// offset value means start position of the slider background.
194         /// </summary>
195         public double BackgroundAngleOffset
196         {
197             get
198             {
199                 return Interop.Eext.eext_circle_object_item_angle_offset_get(RealHandle, "bg");
200             }
201             set
202             {
203                 Interop.Eext.eext_circle_object_item_angle_offset_set(RealHandle, "bg", value);
204             }
205         }
206
207         /// <summary>
208         /// Sets or gets the minimum angle of the circle slider bar.
209         /// </summary>
210         public double BarAngleMinimum
211         {
212             get
213             {
214                 double min;
215                 double max;
216                 Interop.Eext.eext_circle_object_angle_min_max_get(RealHandle, out min, out max);
217                 return min;
218             }
219             set
220             {
221                 double max = BarAngleMaximum;
222                 Interop.Eext.eext_circle_object_angle_min_max_set(RealHandle, (double)value, max);
223             }
224         }
225
226         /// <summary>
227         /// Sets or gets the maximum angle of the circle slider bar.
228         /// </summary>
229         public double BarAngleMaximum
230         {
231             get
232             {
233                 double min;
234                 double max;
235                 Interop.Eext.eext_circle_object_angle_min_max_get(RealHandle, out min, out max);
236                 return max;
237             }
238             set
239             {
240                 double min = BarAngleMinimum;
241                 Interop.Eext.eext_circle_object_angle_min_max_set(RealHandle, min, (double)value);
242             }
243         }
244
245         /// <summary>
246         /// Sets or gets the minimum values for the circle slider.
247         /// </summary>
248         /// <remarks>
249         /// This defines the allowed minimum values to be selected by the user.
250         /// If the actual value is less than min, it is updated to min.
251         /// Actual value can be obtained with Value.By default, min is equal to 0.0.
252         /// </remarks>
253         public double Minimum
254         {
255             get
256             {
257                 double min;
258                 double max;
259                 Interop.Eext.eext_circle_object_value_min_max_get(RealHandle, out min, out max);
260                 return min;
261             }
262             set
263             {
264                 double max = Maximum;
265                 Interop.Eext.eext_circle_object_value_min_max_set(RealHandle, (double)value, max);
266             }
267         }
268
269         /// <summary>
270         /// Sets or gets the maximum values for the circle slider.
271         /// </summary>
272         /// <remarks>
273         /// This defines the allowed maximum values to be selected by the user.
274         /// If the actual value is bigger then max, it is updated to max.
275         /// Actual value can be obtained with Value.By default, min is equal to 0.0, and max is equal to 1.0.
276         /// Maximum must be greater than minimum, otherwise the behavior is undefined.
277         /// </remarks>
278         public double Maximum
279         {
280             get
281             {
282                 double min;
283                 double max;
284                 Interop.Eext.eext_circle_object_value_min_max_get(RealHandle, out min, out max);
285                 return max;
286             }
287             set
288             {
289                 double min = Minimum;
290                 Interop.Eext.eext_circle_object_value_min_max_set(RealHandle, min, (double)value);
291             }
292         }
293
294         /// <summary>
295         /// Gets or sets the value displayed by the circle slider.
296         /// </summary>
297         /// <remarks>
298         /// The value must to be between Minimum and Maximum values.
299         /// </remarks>
300         public double Value
301         {
302             get
303             {
304                 return Interop.Eext.eext_circle_object_value_get(RealHandle);
305             }
306             set
307             {
308                 Interop.Eext.eext_circle_object_value_set(RealHandle, (double)value);
309             }
310         }
311
312         /// <summary>
313         /// Gets or sets the radius value for the circle slider bar.
314         /// </summary>
315         public double BarRadius
316         {
317             get
318             {
319                 return Interop.Eext.eext_circle_object_radius_get(RealHandle); ;
320             }
321             set
322             {
323                 Interop.Eext.eext_circle_object_radius_set(RealHandle, value);
324             }
325         }
326
327         /// <summary>
328         /// Gets or sets the radius value for the circle slider background.
329         /// </summary>
330         public double BackgroundRadius
331         {
332             get
333             {
334                 return Interop.Eext.eext_circle_object_item_radius_get(RealHandle, "bg"); ;
335             }
336             set
337             {
338                 Interop.Eext.eext_circle_object_item_radius_set(RealHandle, "bg", value);
339             }
340         }
341
342         protected override IntPtr CreateHandle(EvasObject parent)
343         {
344             IntPtr surface = IntPtr.Zero;
345             if (parent is Conformant)
346             {
347                 surface = Interop.Eext.eext_circle_surface_conformant_add(parent);
348             }
349             else if (parent is Layout)
350             {
351                 surface = Interop.Eext.eext_circle_surface_layout_add(parent);
352             }
353             else if (parent is Naviframe)
354             {
355                 surface = Interop.Eext.eext_circle_surface_naviframe_add(parent.RealHandle);
356             }
357
358             IntPtr handle = Interop.Eext.eext_circle_object_slider_add(parent, surface);
359             if (surface == IntPtr.Zero)
360             {
361                 EvasObject p = parent;
362                 while (!(p is Window))
363                 {
364                     p = p.Parent;
365                 }
366                 var w = (p as Window).ScreenSize.Width;
367                 var h = (p as Window).ScreenSize.Height;
368                 Interop.Evas.evas_object_resize(handle, w, h);
369             }
370
371             Interop.Eext.eext_rotary_object_event_activated_set(handle, true);
372             return handle;
373         }
374     }
375 }