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