[NUI] TCSACR-226 code change (#1032)
[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 using System.ComponentModel;
19 using System.Diagnostics;
20
21 namespace ElmSharp.Wearable
22 {
23     /// <summary>
24     /// Circle slider is a circular designed widget used to select a value in a range by the Rotary event.
25     /// </summary>
26     /// <since_tizen> preview </since_tizen>
27     public class CircleSlider : Widget, IRotaryActionWidget
28     {
29         SmartEvent _changedEvent;
30         CircleSurface _surface;
31
32         /// <summary>
33         /// Creates and initializes a new instance of the CircleSlider class.
34         /// </summary>
35         /// <param name="parent">The EvasObject to which the new CircleSlider will be attached as a child.</param>
36         /// <param name="surface">The surface for drawing the circle features for this widget.</param>
37         /// <since_tizen> preview </since_tizen>
38         public CircleSlider(EvasObject parent, CircleSurface surface) : base()
39         {
40             Debug.Assert(parent == null || surface == null || parent.IsRealized);
41             _surface = surface;
42             Realize(parent);
43         }
44
45         /// <summary>
46         /// Creates and initializes a new instance of the Circle Slider class.
47         /// </summary>
48         /// <param name="parent">The parent of the new Circle CircleSlider instance.</param>
49         /// <since_tizen> preview </since_tizen>
50         [Obsolete("It is not safe for guess circle surface from parent and create new surface by every new widget")]
51         [EditorBrowsable(EditorBrowsableState.Never)]
52         public CircleSlider(EvasObject parent) : this(parent, CircleSurface.CreateCircleSurface(parent))
53         {
54             ((IRotaryActionWidget)this).Activate();
55         }
56
57         /// <summary>
58         /// Changed will be triggered when the circle slider value changes.
59         /// </summary>
60         /// <since_tizen> preview </since_tizen>
61         public event EventHandler ValueChanged;
62
63         /// <summary>
64         /// Gets the handle for the Circle widget.
65         /// </summary>
66         /// <since_tizen> preview </since_tizen>
67         public virtual IntPtr CircleHandle => RealHandle;
68
69         /// <summary>
70         /// Gets the handle for the circle surface used in this widget.
71         /// </summary>
72         /// <since_tizen> preview </since_tizen>
73         public virtual CircleSurface CircleSurface => _surface;
74
75         /// <summary>
76         /// Sets or gets the step by which the circle slider bar moves.
77         /// </summary>
78         /// <remarks>
79         /// This value is used when the circle slider value is changed by a drag or the Rotary event.
80         /// The value of the slider is increased/decreased by the step value.
81         /// </remarks>
82         /// <since_tizen> preview </since_tizen>
83         public double Step
84         {
85             get
86             {
87                 return Interop.Eext.eext_circle_object_slider_step_get(CircleHandle);
88             }
89             set
90             {
91                 Interop.Eext.eext_circle_object_slider_step_set(CircleHandle, (double)value);
92             }
93         }
94
95         /// <summary>
96         /// Sets or gets the disabled state of this widget.
97         /// </summary>
98         /// <since_tizen> preview </since_tizen>
99         [Obsolete("Use IsEnabled")]
100         [EditorBrowsable(EditorBrowsableState.Never)]
101         public bool Disabled
102         {
103             get => !IsEnabled;
104             set => IsEnabled = !value;
105         }
106
107         /// <summary>
108         /// Sets or gets the state of the widget, which might be enabled or disabled.
109         /// </summary>
110         /// <since_tizen> preview </since_tizen>
111         public override bool IsEnabled
112         {
113             get
114             {
115                 return !Interop.Eext.eext_circle_object_disabled_get(CircleHandle);
116             }
117             set
118             {
119                 Interop.Eext.eext_circle_object_disabled_set(CircleHandle, !value);
120             }
121         }
122
123         /// <summary>
124         /// Sets or gets the color of the circle slider bar.
125         /// </summary>
126         /// <since_tizen> preview </since_tizen>
127         public Color BarColor
128         {
129             get
130             {
131                 int r = 0;
132                 int g = 0;
133                 int b = 0;
134                 int a = 0;
135                 Interop.Eext.eext_circle_object_color_get(CircleHandle, out r, out g, out b, out a);
136                 return Color.FromRgba(r, g, b, a);
137             }
138             set
139             {
140                 Interop.Eext.eext_circle_object_color_set(CircleHandle, value.R, value.G, value.B, value.A);
141             }
142         }
143
144         /// <summary>
145         /// Sets or gets the color of the circle slider background.
146         /// </summary>
147         /// <since_tizen> preview </since_tizen>
148         public override Color BackgroundColor
149         {
150             get
151             {
152                 int r = 0;
153                 int g = 0;
154                 int b = 0;
155                 int a = 0;
156                 Interop.Eext.eext_circle_object_item_color_get(CircleHandle, "bg", out r, out g, out b, out a);
157                 return Color.FromRgba(r, g, b, a);
158             }
159             set
160             {
161                 Interop.Eext.eext_circle_object_item_color_set(CircleHandle, "bg", value.R, value.G, value.B, value.A);
162             }
163         }
164
165         /// <summary>
166         /// Sets or gets the line width of the circle slider bar.
167         /// </summary>
168         /// <since_tizen> preview </since_tizen>
169         public int BarLineWidth
170         {
171             get
172             {
173                 return Interop.Eext.eext_circle_object_line_width_get(CircleHandle);
174             }
175             set
176             {
177                 Interop.Eext.eext_circle_object_line_width_set(CircleHandle, value);
178             }
179         }
180
181         /// <summary>
182         /// Sets or gets the line width of the circle slider background.
183         /// </summary>
184         /// <since_tizen> preview </since_tizen>
185         public int BackgroundLineWidth
186         {
187             get
188             {
189                 return Interop.Eext.eext_circle_object_item_line_width_get(CircleHandle, "bg");
190             }
191             set
192             {
193                 Interop.Eext.eext_circle_object_item_line_width_set(CircleHandle, "bg", value);
194             }
195         }
196
197         /// <summary>
198         /// Sets or gets the angle in degree of the circle slider bar.
199         /// </summary>
200         /// <since_tizen> preview </since_tizen>
201         public double BarAngle
202         {
203             get
204             {
205                 return Interop.Eext.eext_circle_object_angle_get(CircleHandle);
206             }
207             set
208             {
209                 Interop.Eext.eext_circle_object_angle_set(CircleHandle, value);
210             }
211         }
212
213         /// <summary>
214         /// Sets or gets the angle in degree of the circle slider background.
215         /// </summary>
216         /// <since_tizen> preview </since_tizen>
217         public double BackgroundAngle
218         {
219             get
220             {
221                 return Interop.Eext.eext_circle_object_item_angle_get(CircleHandle, "bg");
222             }
223             set
224             {
225                 Interop.Eext.eext_circle_object_item_angle_set(CircleHandle, "bg", value);
226             }
227         }
228
229         /// <summary>
230         /// Sets or gets the angle offset for the slider bar.
231         /// Offset value means start position of the slider bar.
232         /// </summary>
233         /// <since_tizen> preview </since_tizen>
234         public double BarAngleOffset
235         {
236             get
237             {
238                 return Interop.Eext.eext_circle_object_angle_offset_get(CircleHandle);
239             }
240             set
241             {
242                 Interop.Eext.eext_circle_object_angle_offset_set(CircleHandle, value);
243             }
244         }
245
246         /// <summary>
247         /// Sets or gets the angle offset for the circle slider background.
248         /// Offset value means start position of the slider background.
249         /// </summary>
250         /// <since_tizen> preview </since_tizen>
251         public double BackgroundAngleOffset
252         {
253             get
254             {
255                 return Interop.Eext.eext_circle_object_item_angle_offset_get(CircleHandle, "bg");
256             }
257             set
258             {
259                 Interop.Eext.eext_circle_object_item_angle_offset_set(CircleHandle, "bg", value);
260             }
261         }
262
263         /// <summary>
264         /// Sets or gets the minimum angle of the circle slider bar.
265         /// </summary>
266         /// <since_tizen> preview </since_tizen>
267         public double BarAngleMinimum
268         {
269             get
270             {
271                 double min;
272                 double max;
273                 Interop.Eext.eext_circle_object_angle_min_max_get(CircleHandle, out min, out max);
274                 return min;
275             }
276             set
277             {
278                 double max = BarAngleMaximum;
279                 Interop.Eext.eext_circle_object_angle_min_max_set(CircleHandle, (double)value, max);
280             }
281         }
282
283         /// <summary>
284         /// Sets or gets the maximum angle of the circle slider bar.
285         /// </summary>
286         /// <since_tizen> preview </since_tizen>
287         public double BarAngleMaximum
288         {
289             get
290             {
291                 double min;
292                 double max;
293                 Interop.Eext.eext_circle_object_angle_min_max_get(CircleHandle, out min, out max);
294                 return max;
295             }
296             set
297             {
298                 double min = BarAngleMinimum;
299                 Interop.Eext.eext_circle_object_angle_min_max_set(CircleHandle, min, (double)value);
300             }
301         }
302
303         /// <summary>
304         /// Sets or gets the minimum values for the circle slider.
305         /// </summary>
306         /// <remarks>
307         /// This defines the allowed minimum values to be selected by the user.
308         /// If the actual value is less than the minimum value, it is updated to the minimum value.
309         /// Actual value can be obtained with Value. By default, minimum value is equal to 0.0.
310         /// </remarks>
311         /// <since_tizen> preview </since_tizen>
312         public double Minimum
313         {
314             get
315             {
316                 double min;
317                 double max;
318                 Interop.Eext.eext_circle_object_value_min_max_get(CircleHandle, out min, out max);
319                 return min;
320             }
321             set
322             {
323                 double max = Maximum;
324                 Interop.Eext.eext_circle_object_value_min_max_set(CircleHandle, (double)value, max);
325             }
326         }
327
328         /// <summary>
329         /// Sets or gets the maximum values for the circle slider.
330         /// </summary>
331         /// <remarks>
332         /// This defines the allowed maximum values to be selected by the user.
333         /// If the actual value is bigger than the maximum value, it is updated to the maximum value.
334         /// Actual value can be obtained with Value. By default, the minimum value is equal to 0.0, and the maximum value is equal to 1.0.
335         /// Maximum must be greater than minimum, otherwise the behavior is undefined.
336         /// </remarks>
337         /// <since_tizen> preview </since_tizen>
338         public double Maximum
339         {
340             get
341             {
342                 double min;
343                 double max;
344                 Interop.Eext.eext_circle_object_value_min_max_get(CircleHandle, out min, out max);
345                 return max;
346             }
347             set
348             {
349                 double min = Minimum;
350                 Interop.Eext.eext_circle_object_value_min_max_set(CircleHandle, min, (double)value);
351             }
352         }
353
354         /// <summary>
355         /// Gets or sets the value displayed by the circle slider.
356         /// </summary>
357         /// <remarks>
358         /// The value must be between minimum and maximum.
359         /// </remarks>
360         /// <since_tizen> preview </since_tizen>
361         public double Value
362         {
363             get
364             {
365                 return Interop.Eext.eext_circle_object_value_get(CircleHandle);
366             }
367             set
368             {
369                 Interop.Eext.eext_circle_object_value_set(CircleHandle, (double)value);
370             }
371         }
372
373         /// <summary>
374         /// Gets or sets the radius value for the circle slider bar.
375         /// </summary>
376         /// <since_tizen> preview </since_tizen>
377         public double BarRadius
378         {
379             get
380             {
381                 return Interop.Eext.eext_circle_object_radius_get(CircleHandle);
382             }
383             set
384             {
385                 Interop.Eext.eext_circle_object_radius_set(CircleHandle, value);
386             }
387         }
388
389         /// <summary>
390         /// Gets or sets the radius value for the circle slider background.
391         /// </summary>
392         /// <since_tizen> preview </since_tizen>
393         public double BackgroundRadius
394         {
395             get
396             {
397                 return Interop.Eext.eext_circle_object_item_radius_get(CircleHandle, "bg");
398             }
399             set
400             {
401                 Interop.Eext.eext_circle_object_item_radius_set(CircleHandle, "bg", value);
402             }
403         }
404
405         /// <summary>
406         /// The callback of the Realized event.
407         /// </summary>
408         /// <since_tizen> preview </since_tizen>
409         protected override void OnRealized()
410         {
411             base.OnRealized();
412             _changedEvent = new SmartEvent(this, "value,changed");
413             _changedEvent.On += (s, e) => ValueChanged?.Invoke(this, EventArgs.Empty);
414         }
415
416         /// <summary>
417         /// Creates a widget handle.
418         /// </summary>
419         /// <param name="parent">Parent EvasObject</param>
420         /// <returns>Handle IntPtr.</returns>
421         /// <since_tizen> preview </since_tizen>
422         protected override IntPtr CreateHandle(EvasObject parent)
423         {
424             return Interop.Eext.eext_circle_object_slider_add(parent, CircleSurface.Handle);
425         }
426     }
427 }