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