[NUI] Binds GetCurrentProperty to Animatable class
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Animation / Animatable.cs
1 /*
2  * Copyright(c) 2017 Samsung Electronics Co., Ltd.
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.ComponentModel;
18 using System.Text;
19
20 namespace Tizen.NUI
21 {
22
23     /// <summary>
24     /// Animatable.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     public class Animatable : BaseHandle
28     {
29
30         /// <summary>
31         /// Create an instance of animatable.
32         /// </summary>
33         /// <since_tizen> 3 </since_tizen>
34         public Animatable() : this(Interop.Handle.New(), true)
35         {
36             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
37
38         }
39
40         internal Animatable(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
41         {
42         }
43
44         /// <summary>
45         /// Enumeration for Handle's capabilities that can be queried.
46         /// </summary>
47         /// <since_tizen> 3 </since_tizen>
48         public enum Capability
49         {
50             /// <summary>
51             /// Some objects support dynamic property creation at run-time.
52             /// New properties are registered by calling RegisterProperty() with an unused property name.
53             /// </summary>
54             /// <since_tizen> 3 </since_tizen>
55             DYNAMIC_PROPERTIES = 0x01
56         }
57
58         /// <summary>
59         /// Queries the name of a property.
60         /// </summary>
61         /// <param name="index">The index of the property.</param>
62         /// <returns>The name of the property.</returns>
63         /// <since_tizen> 3 </since_tizen>
64         public string GetPropertyName(int index)
65         {
66             string ret = Interop.Handle.GetPropertyName(SwigCPtr, index);
67             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
68             return ret;
69         }
70
71         /// <summary>
72         /// Queries the index of a property.
73         /// </summary>
74         /// <param name="name">The name of the property.</param>
75         /// <returns>The index of the property.</returns>
76         /// <since_tizen> 3 </since_tizen>
77         public int GetPropertyIndex(string name)
78         {
79             // Convert property string to be lowercase
80             StringBuilder sb = new StringBuilder(name);
81             sb[0] = (char)(sb[0] | 0x20);
82             string str = sb.ToString();
83
84             int ret = Interop.Handle.GetPropertyIndex(SwigCPtr, str);
85             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
86             return ret;
87         }
88
89         /// <summary>
90         /// Queries whether a property can be writable.
91         /// </summary>
92         /// <param name="index">The index of the property.</param>
93         /// <returns>True if the property is writable.</returns>
94         /// <since_tizen> 3 </since_tizen>
95         public bool IsPropertyWritable(int index)
96         {
97             bool ret = Interop.Handle.IsPropertyWritable(SwigCPtr, index);
98             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
99             return ret;
100         }
101
102         /// <summary>
103         /// whether a writable property can be the target of an animation.
104         /// </summary>
105         /// <param name="index">The index of the property.</param>
106         /// <returns>True if the property is animatable.</returns>
107         /// <since_tizen> 3 </since_tizen>
108         public bool IsPropertyAnimatable(int index)
109         {
110             bool ret = Interop.Handle.IsPropertyAnimatable(SwigCPtr, index);
111             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
112             return ret;
113         }
114
115         /// <summary>
116         /// Queries the type of a property.
117         /// </summary>
118         /// <param name="index">The index of the property.</param>
119         /// <returns>The type of the property.</returns>
120         /// <since_tizen> 3 </since_tizen>
121         public PropertyType GetPropertyType(int index)
122         {
123             PropertyType ret = (PropertyType)Interop.Handle.GetPropertyType(SwigCPtr, index);
124             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
125             return ret;
126         }
127
128         /// <summary>
129         /// Sets the value of an existing property.
130         /// </summary>
131         /// <param name="index">The index of the property.</param>
132         /// <param name="propertyValue">The new value of the property.</param>
133         /// <since_tizen> 3 </since_tizen>
134         public void SetProperty(int index, PropertyValue propertyValue)
135         {
136             Tizen.NUI.Object.SetProperty(SwigCPtr, index, propertyValue);
137         }
138
139         /// <summary>
140         /// Sets the value of an existing property.
141         /// </summary>
142         /// <param name="name">The index of the property.</param>
143         /// <param name="propertyValue">The new value of the property.</param>
144         /// This will not be public opened.
145         [EditorBrowsable(EditorBrowsableState.Never)]
146         public void SetProperty(string name, PropertyValue propertyValue)
147         {
148             var propertyName = LowerFirstLetter(name);
149             Property property = new Property(this, propertyName);
150             if (property.PropertyIndex == Property.InvalidIndex)
151             {
152                 Tizen.Log.Error("NUI", "Invalid property name\n");
153             }
154             else
155             {
156                 Tizen.NUI.Object.SetProperty(SwigCPtr, property.PropertyIndex, propertyValue);
157             }
158             property.Dispose();
159         }
160
161         /// <summary>
162         /// Registers a new animatable property.
163         /// </summary>
164         /// <param name="name">The name of the property.</param>
165         /// <param name="propertyValue">The new value of the property.</param>
166         /// <returns>The type of the property.</returns>
167         /// <since_tizen> 3 </since_tizen>
168         public int RegisterProperty(string name, PropertyValue propertyValue)
169         {
170             int ret = Interop.Handle.RegisterProperty(SwigCPtr, name, PropertyValue.getCPtr(propertyValue));
171             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
172             return ret;
173         }
174
175         /// <summary>
176         /// Registers a new animatable property.
177         /// </summary>
178         /// <param name="name">The name of the property.</param>
179         /// <param name="propertyValue">The new value of the property.</param>
180         /// <param name="accessMode">The property access mode (writable, animatable etc).</param>
181         /// <returns>The type of the property.</returns>
182         /// <since_tizen> 3 </since_tizen>
183         public int RegisterProperty(string name, PropertyValue propertyValue, PropertyAccessMode accessMode)
184         {
185             int ret = Interop.Handle.RegisterProperty(SwigCPtr, name, PropertyValue.getCPtr(propertyValue), (int)accessMode);
186             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187             return ret;
188         }
189
190         /// <summary>
191         /// Retrieves a property value.
192         /// </summary>
193         /// <param name="index">The index of the property.</param>
194         /// <returns>The property value.</returns>
195         /// <since_tizen> 3 </since_tizen>
196         public PropertyValue GetProperty(int index)
197         {
198             PropertyValue ret = Tizen.NUI.Object.GetProperty(SwigCPtr, index);
199             return ret;
200         }
201
202         /// <summary>
203         /// Retrieves the latest rendered frame value of the property.
204         /// </summary>
205         /// <param name="index">The index of the property.</param>
206         /// <returns>The property value.</returns>
207         [EditorBrowsable(EditorBrowsableState.Never)]
208         public PropertyValue GetCurrentProperty(int index)
209         {
210             PropertyValue ret = Tizen.NUI.Object.GetCurrentProperty(SwigCPtr, index);
211             return ret;
212         }
213
214         /// <summary>
215         /// Adds a property notification to this object.
216         /// </summary>
217         /// <param name="property">The name of the property.</param>
218         /// <param name="condition">The notification will be triggered when this condition is satisfied.</param>
219         /// <returns>A handle to the newly created PropertyNotification.</returns>
220         /// <since_tizen> 4 </since_tizen>
221         public PropertyNotification AddPropertyNotification(string property, PropertyCondition condition)
222         {
223             Property properties = PropertyHelper.GetPropertyFromString(this, property);
224             PropertyNotification ret = new PropertyNotification(Interop.Handle.AddPropertyNotification(SwigCPtr, properties.PropertyIndex, PropertyCondition.getCPtr(condition)), true);
225             properties.Dispose();
226             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
227             return ret;
228         }
229
230         /// <summary>
231         /// Removes a property notification from this object.
232         /// </summary>
233         /// <param name="propertyNotification">The propertyNotification to be removed.</param>
234         /// <since_tizen> 4 </since_tizen>
235         public void RemovePropertyNotification(PropertyNotification propertyNotification)
236         {
237             Interop.Handle.RemovePropertyNotification(SwigCPtr, PropertyNotification.getCPtr(propertyNotification));
238             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239         }
240
241         /// <summary>
242         /// Removes a property notification from this object.
243         /// </summary>
244         /// <since_tizen> 4 </since_tizen>
245         public void RemovePropertyNotifications()
246         {
247             Interop.Handle.RemovePropertyNotifications(SwigCPtr);
248             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249         }
250
251         internal uint GetPropertyCount()
252         {
253             uint ret = Interop.HandleInternal.HandleGetPropertyCount(SwigCPtr);
254             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255             return ret;
256         }
257
258         internal PropertyNotification AddPropertyNotification(int index, int componentIndex, PropertyCondition condition)
259         {
260             PropertyNotification ret = new PropertyNotification(Interop.Handle.AddPropertyNotification(SwigCPtr, index, componentIndex, PropertyCondition.getCPtr(condition)), true);
261             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262             return ret;
263         }
264
265         internal void RemoveConstraints()
266         {
267             Interop.HandleInternal.HandleRemoveConstraints(SwigCPtr);
268             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269         }
270
271         internal void RemoveConstraints(uint tag)
272         {
273             Interop.HandleInternal.HandleRemoveConstraints(SwigCPtr, tag);
274             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275         }
276
277         private static string LowerFirstLetter(string original)
278         {
279             StringBuilder sb = new StringBuilder(original);
280             sb[0] = (char)(sb[0] | 0x20);
281             return sb.ToString();
282         }
283
284         /// This will not be public opened.
285         [EditorBrowsable(EditorBrowsableState.Never)]
286         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
287         {
288             Interop.Handle.DeleteHandle(swigCPtr);
289         }
290     }
291 }