Add CircleSurface and Change Every circle object
[platform/core/csapi/tizenfx.git] / src / ElmSharp.Wearable / ElmSharp.Wearable / CircleScroller.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 scroller provides scrollbar with circular movement and is scrolled by rotary event.
24     /// </summary>
25     public class CircleScroller : Scroller, IRotaryActionWidget
26     {
27         IntPtr _circleHandle;
28         CircleSurface _surface;
29
30         /// <summary>
31         /// Creates and initializes a new instance of the CircleScroller class.
32         /// </summary>
33         /// <param name="parent">The <see cref="EvasObject"/> to which the new CircleScroller will be attached as a child.</param>
34         /// <param name="surface">The surface for drawing circle features for this widget.</param>
35         public CircleScroller(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         /// Gets the handle for Circle Widget.
44         /// </summary>
45         public virtual IntPtr CircleHandle => _circleHandle;
46
47         /// <summary>
48         /// Gets the handle for Circle Surface used in this widget
49         /// </summary>
50         public virtual CircleSurface CircleSurface => _surface;
51
52         /// <summary>
53         /// Sets or gets the state of the widget, which might be enabled or disabled.
54         /// </summary>
55         public override bool IsEnabled
56         {
57             get
58             {
59                 return !Interop.Eext.eext_circle_object_disabled_get(Handle);
60             }
61             set
62             {
63                 Interop.Eext.eext_circle_object_disabled_set(Handle, !value);
64             }
65         }
66
67         /// <summary>
68         /// Sets or gets the value of HorizontalScrollBarVisiblePolicy
69         /// </summary>
70         /// <remarks>
71         /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden.
72         /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
73         /// </remarks>
74         public override ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy
75         {
76             get
77             {
78                 int policy;
79                 Interop.Eext.eext_circle_object_scroller_policy_get(CircleHandle, out policy, IntPtr.Zero);
80                 return (ScrollBarVisiblePolicy)policy;
81             }
82             set
83             {
84                 ScrollBarVisiblePolicy v = VerticalScrollBarVisiblePolicy;
85                 Interop.Eext.eext_circle_object_scroller_policy_set(CircleHandle, (int)value, (int)v);
86             }
87         }
88
89         /// <summary>
90         /// Sets or gets the value of VerticalScrollBarVisiblePolicy
91         /// </summary>
92         /// <remarks>
93         /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden.
94         /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
95         /// </remarks>
96         public override ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy
97         {
98             get
99             {
100                 int policy;
101                 Interop.Eext.eext_circle_object_scroller_policy_get(CircleHandle, IntPtr.Zero, out policy);
102                 return (ScrollBarVisiblePolicy)policy;
103             }
104             set
105             {
106                 ScrollBarVisiblePolicy h = HorizontalScrollBarVisiblePolicy;
107                 Interop.Eext.eext_circle_object_scroller_policy_set(CircleHandle, (int)h, (int)value);
108             }
109         }
110
111         /// <summary>
112         /// Sets or gets color of the vertical scroll bar.
113         /// </summary>
114         public Color VerticalScrollBarColor
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_color_get(CircleHandle, 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_color_set(CircleHandle, value.R, value.G, value.B, value.A);
128             }
129         }
130
131         /// <summary>
132         /// Sets or gets color of the horizontal scroll bar.
133         /// </summary>
134         public Color HorizontalScrollBarColor
135         {
136             get
137             {
138                 int r = 0;
139                 int g = 0;
140                 int b = 0;
141                 int a = 0;
142                 Interop.Eext.eext_circle_object_item_color_get(CircleHandle, "horizontal,scroll,bar", out r, out g, out b, out a);
143                 return Color.FromRgba(r, g, b, a);
144             }
145             set
146             {
147                 Interop.Eext.eext_circle_object_item_color_set(CircleHandle, "horizontal,scroll,bar", value.R, value.G, value.B, value.A);
148             }
149         }
150
151         /// <summary>
152         /// Sets or gets color of the vertical scroll background.
153         /// </summary>
154         public Color VerticalScrollBackgroundColor
155         {
156             get
157             {
158                 int r = 0;
159                 int g = 0;
160                 int b = 0;
161                 int a = 0;
162                 Interop.Eext.eext_circle_object_item_color_get(CircleHandle, "vertical,scroll,bg", out r, out g, out b, out a);
163                 return Color.FromRgba(r, g, b, a);
164             }
165             set
166             {
167                 Interop.Eext.eext_circle_object_item_color_set(CircleHandle, "vertical,scroll,bg", value.R, value.G, value.B, value.A);
168             }
169         }
170
171         /// <summary>
172         /// Sets or gets color of the horizontal scroll background.
173         /// </summary>
174         public Color HorizontalScrollBackgroundColor
175         {
176             get
177             {
178                 int r = 0;
179                 int g = 0;
180                 int b = 0;
181                 int a = 0;
182                 Interop.Eext.eext_circle_object_item_color_get(CircleHandle, "horizontal,scroll,bg", out r, out g, out b, out a);
183                 return Color.FromRgba(r, g, b, a);
184             }
185             set
186             {
187                 Interop.Eext.eext_circle_object_item_color_set(CircleHandle, "horizontal,scroll,bg", value.R, value.G, value.B, value.A);
188             }
189         }
190
191         /// <summary>
192         /// Sets or gets line width of the vertical scroll bar.
193         /// </summary>
194         public int VerticalScrollBarLineWidth
195         {
196             get
197             {
198                 return Interop.Eext.eext_circle_object_line_width_get(CircleHandle);
199             }
200             set
201             {
202                 Interop.Eext.eext_circle_object_line_width_set(CircleHandle, value);
203             }
204         }
205
206         /// <summary>
207         /// Sets or gets line width of the horizontal scroll bar.
208         /// </summary>
209         public int HorizontalScrollBarLineWidth
210         {
211             get
212             {
213                 return Interop.Eext.eext_circle_object_item_line_width_get(CircleHandle, "horizontal,scroll,bar");
214             }
215             set
216             {
217                 Interop.Eext.eext_circle_object_item_line_width_set(CircleHandle, "horizontal,scroll,bar", value);
218             }
219         }
220
221         /// <summary>
222         /// Sets or gets line width of the vertical scroll background.
223         /// </summary>
224         public int VerticalScrollBackgroundLineWidth
225         {
226             get
227             {
228                 return Interop.Eext.eext_circle_object_item_line_width_get(CircleHandle, "vertical,scroll,bg");
229             }
230             set
231             {
232                 Interop.Eext.eext_circle_object_item_line_width_set(CircleHandle, "vertical,scroll,bg", value);
233             }
234         }
235
236         /// <summary>
237         /// Sets or gets line width of the horizontal scroll background.
238         /// </summary>
239         public int HorizontalScrollBackgroundLineWidth
240         {
241             get
242             {
243                 return Interop.Eext.eext_circle_object_item_line_width_get(CircleHandle, "horizontal,scroll,bg");
244             }
245             set
246             {
247                 Interop.Eext.eext_circle_object_item_line_width_set(CircleHandle, "horizontal,scroll,bg", value);
248             }
249         }
250
251         /// <summary>
252         /// Sets or gets radius of the vertical scroll bar.
253         /// </summary>
254         public double VerticalScrollBarRadius
255         {
256             get
257             {
258                 return Interop.Eext.eext_circle_object_radius_get(CircleHandle);
259             }
260             set
261             {
262                 Interop.Eext.eext_circle_object_radius_set(CircleHandle, value);
263             }
264         }
265
266         /// <summary>
267         /// Sets or gets radius of the horizontal scroll bar.
268         /// </summary>
269         public double HorizontalScrollBarRadius
270         {
271             get
272             {
273                 return Interop.Eext.eext_circle_object_item_radius_get(CircleHandle, "horizontal,scroll,bar");
274             }
275             set
276             {
277                 Interop.Eext.eext_circle_object_item_radius_set(CircleHandle, "horizontal,scroll,bar", value);
278             }
279         }
280
281         /// <summary>
282         /// Sets or gets radius of the vertical scroll background.
283         /// </summary>
284         public double VerticalScrollBackgroundRadius
285         {
286             get
287             {
288                 return Interop.Eext.eext_circle_object_item_radius_get(CircleHandle, "vertical,scroll,bg");
289             }
290             set
291             {
292                 Interop.Eext.eext_circle_object_item_radius_set(CircleHandle, "vertical,scroll,bg", value);
293             }
294         }
295
296         /// <summary>
297         /// Sets or gets radius of the horizontal scroll background.
298         /// </summary>
299         public double HorizontalScrollBackgroundRadius
300         {
301             get
302             {
303                 return Interop.Eext.eext_circle_object_item_radius_get(CircleHandle, "horizontal,scroll,bg");
304             }
305             set
306             {
307                 Interop.Eext.eext_circle_object_item_radius_set(CircleHandle, "horizontal,scroll,bg", value);
308             }
309         }
310
311         /// <summary>
312         /// Creates a widget handle.
313         /// </summary>
314         /// <param name="parent">Parent EvasObject</param>
315         /// <returns>Handle IntPtr</returns>
316         protected override IntPtr CreateHandle(EvasObject parent)
317         {
318             IntPtr handle = base.CreateHandle(parent);
319             _circleHandle = Interop.Eext.eext_circle_object_scroller_add(RealHandle == IntPtr.Zero ? Handle : RealHandle, CircleSurface.Handle);
320             return handle;
321         }
322     }
323 }