[ElmSharp] Mark ElmSharp API as API Level: preview
[platform/core/csapi/tizenfx.git] / src / ElmSharp.Wearable / ElmSharp.Wearable / CircleSpinner.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
24     /// <summary>
25     /// The Circle Spinner is a widget to display and handle spinner value by rotary event
26     /// Inherits <see cref="Spinner"/>.
27     /// </summary>
28     /// <since_tizen> preview </since_tizen>
29     public class CircleSpinner : Spinner, IRotaryActionWidget
30     {
31         IntPtr _circleHandle;
32         double _angleRatio = 1.0;
33         CircleSurface _surface;
34
35         /// <summary>
36         /// Creates and initializes a new instance of the Circle Spinner class.
37         /// </summary>
38         /// <param name="parent">The parent of new Circle Spinner instance</param>
39         /// <param name="surface">The surface for drawing circle features for this widget.</param>
40         /// <since_tizen> preview </since_tizen>
41         public CircleSpinner(EvasObject parent, CircleSurface surface) : base()
42         {
43             Debug.Assert(parent == null || surface == null || parent.IsRealized);
44             _surface = surface;
45             Realize(parent);
46         }
47
48         /// <summary>
49         /// Creates and initializes a new instance of the Circle Spinner class.
50         /// </summary>
51         /// <param name="parent">The parent of new Circle CircleSpinner instance</param>
52         /// <since_tizen> preview </since_tizen>
53         [Obsolete("It is not safe for guess circle surface from parent and create new surface by every new widget")]
54         [EditorBrowsable(EditorBrowsableState.Never)]
55         public CircleSpinner(EvasObject parent) : this(parent, CircleSurface.CreateCircleSurface(parent))
56         {
57             ((IRotaryActionWidget)this).Activate();
58         }
59
60         /// <summary>
61         /// Gets the handle for Circle Widget.
62         /// </summary>
63         /// <since_tizen> preview </since_tizen>
64         public virtual IntPtr CircleHandle => _circleHandle;
65
66         /// <summary>
67         /// Gets the handle for Circle Surface used in this widget
68         /// </summary>
69         /// <since_tizen> preview </since_tizen>
70         public virtual CircleSurface CircleSurface => _surface;
71
72         /// <summary>
73         /// Sets or gets the circle spinner angle per each spinner value.
74         /// </summary>
75         /// <since_tizen> preview </since_tizen>
76         public double AngleRatio
77         {
78             get
79             {
80                 return _angleRatio;
81             }
82             set
83             {
84                 _angleRatio = value;
85                 Interop.Eext.eext_circle_object_spinner_angle_set(CircleHandle, _angleRatio);
86             }
87         }
88
89         /// <summary>
90         /// Sets or gets disabled state of this widget.
91         /// </summary>
92         /// <since_tizen> preview </since_tizen>
93         [Obsolete("Use IsEnabled")]
94         [EditorBrowsable(EditorBrowsableState.Never)]
95         public bool Disabled
96         {
97             get => !IsEnabled;
98             set => IsEnabled = !value;
99         }
100
101         /// <summary>
102         /// Sets or gets the state of the widget, which might be enabled or disabled.
103         /// </summary>
104         /// <since_tizen> preview </since_tizen>
105         public override bool IsEnabled
106         {
107             get
108             {
109                 return !Interop.Eext.eext_circle_object_disabled_get(CircleHandle);
110             }
111             set
112             {
113                 Interop.Eext.eext_circle_object_disabled_set(CircleHandle, !value);
114             }
115         }
116
117         /// <summary>
118         /// Sets or gets the line width of the marker
119         /// </summary>
120         /// <since_tizen> preview </since_tizen>
121         public int MarkerLineWidth
122         {
123             get
124             {
125                 return Interop.Eext.eext_circle_object_item_line_width_get(CircleHandle, "default");
126             }
127             set
128             {
129                 Interop.Eext.eext_circle_object_item_line_width_set(CircleHandle, "default", value);
130             }
131         }
132
133         /// <summary>
134         /// Sets or gets the color of the marker
135         /// </summary>
136         /// <since_tizen> preview </since_tizen>
137         public Color MarkerColor
138         {
139             get
140             {
141                 int r, g, b, a;
142                 Interop.Eext.eext_circle_object_item_color_get(CircleHandle, "default", out r, out g, out b, out a);
143                 return new Color(r, g, b, a);
144             }
145             set
146             {
147                 Interop.Eext.eext_circle_object_item_color_set(CircleHandle, "default", value.R, value.G, value.B, value.A);
148             }
149         }
150
151         /// <summary>
152         /// Sets or gets the radius at which the center of the marker lies
153         /// </summary>
154         /// <since_tizen> preview </since_tizen>
155         public double MarkerRadius
156         {
157             get
158             {
159                 return Interop.Eext.eext_circle_object_item_radius_get(CircleHandle, "default");
160             }
161             set
162             {
163                 Interop.Eext.eext_circle_object_item_radius_set(CircleHandle, "default", value);
164             }
165         }
166
167         /// <summary>
168         /// Creates a widget handle.
169         /// </summary>
170         /// <param name="parent">Parent EvasObject</param>
171         /// <returns>Handle IntPtr</returns>
172         /// <since_tizen> preview </since_tizen>
173         protected override IntPtr CreateHandle(EvasObject parent)
174         {
175             IntPtr handle = base.CreateHandle(parent);
176             _circleHandle = Interop.Eext.eext_circle_object_spinner_add(RealHandle == IntPtr.Zero ? handle : RealHandle, CircleSurface.Handle);
177             return handle;
178         }
179     }
180 }