Revert "[Tizen] to match previous version"
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Layer.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
17 namespace Tizen.NUI
18 {
19     using Tizen.NUI.BaseComponents;
20
21     /// <summary>
22     /// Layers provide a mechanism for overlaying groups of actors on top of each other.
23     /// </summary>
24     public class Layer : Animatable
25     {
26         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
27
28         internal Layer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Layer_SWIGUpcast(cPtr), cMemoryOwn)
29         {
30             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
31         }
32
33         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Layer obj)
34         {
35             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
36         }
37
38         protected override void Dispose(DisposeTypes type)
39         {
40             if (disposed)
41             {
42                 return;
43             }
44
45             if (type == DisposeTypes.Explicit)
46             {
47                 //Called by User
48                 //Release your own managed resources here.
49                 //You should release all of your own disposable objects here.
50             }
51
52             //Release your own unmanaged resources here.
53             //You should not access any managed member here except static instance.
54             //because the execution order of Finalizes is non-deterministic.
55
56             if (swigCPtr.Handle != global::System.IntPtr.Zero)
57             {
58                 if (swigCMemOwn)
59                 {
60                     swigCMemOwn = false;
61                     NDalicPINVOKE.delete_Layer(swigCPtr);
62                 }
63                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
64             }
65
66             base.Dispose(type);
67         }
68
69
70         internal class Property
71         {
72             internal static readonly int BEHAVIOR = NDalicPINVOKE.Layer_Property_BEHAVIOR_get();
73         }
74
75         /// <summary>
76         /// Creates a Layer object.
77         /// </summary>
78         public Layer() : this(NDalicPINVOKE.Layer_New(), true)
79         {
80             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
81
82         }
83         /// <summary>
84         /// Downcasts a handle to Layer handle.<br>
85         /// If handle points to a Layer, the downcast produces valid handle.<br>
86         /// If not, the returned handle is left uninitialized.<br>
87         /// </summary>
88         /// <param name="handle">Handle to an object</param>
89         /// <returns>Handle to a Layer or an uninitialized handle</returns>
90         internal new static Layer DownCast(BaseHandle handle)
91         {
92             Layer ret = new Layer(NDalicPINVOKE.Layer_DownCast(BaseHandle.getCPtr(handle)), true);
93             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
94             return ret;
95         }
96
97         /// <summary>
98         /// Search through this layer's hierarchy for an view with the given unique ID.
99         /// </summary>
100         /// <pre>This layer(the parent) has been initialized.</pre>
101         /// <remarks>The actor itself is also considered in the search.</remarks>
102         /// <param name="child">The id of the child to find</param>
103         /// <returns> A handle to the view if found, or an empty handle if not. </returns>
104         public View FindChildById(uint id)
105         {
106             View ret = new View(NDalicPINVOKE.Actor_FindChildById(swigCPtr, id), true);
107             if (NDalicPINVOKE.SWIGPendingException.Pending)
108                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
109             return ret;
110         }
111
112         /// <summary>
113         /// Adds a child view to this layer.
114         /// </summary>
115         /// <pre>This layer(the parent) has been initialized. The child view has been initialized. The child view is not the same as the parent layer.</pre>
116         /// <post>The child will be referenced by its parent. This means that the child will be kept alive, even if the handle passed into this method is reset or destroyed.</post>
117         /// <remarks>If the child already has a parent, it will be removed from old parent and reparented to this layer. This may change child's position, color, scale etc as it now inherits them from this layer.</remarks>
118         /// <param name="child">The child</param>
119         public void Add(View child)
120         {
121             NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
122             if (NDalicPINVOKE.SWIGPendingException.Pending)
123                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
124         }
125
126         /// <summary>
127         /// Removes a child View from this layer. If the view was not a child of this layer, this is a no-op.
128         /// </summary>
129         /// <pre>This layer(the parent) has been initialized. The child view is not the same as the parent view.</pre>
130         /// <param name="child">The child</param>
131         public void Remove(View child)
132         {
133             NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child));
134             if (NDalicPINVOKE.SWIGPendingException.Pending)
135                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
136         }
137
138         /// <summary>
139         /// Queries the depth of the layer.<br>
140         /// 0 is the bottom most layer, higher number is on top.<br>
141         /// </summary>
142         public uint Depth
143         {
144             get
145             {
146                 return GetDepth();
147             }
148         }
149
150         internal uint GetDepth()
151         {
152             uint ret = NDalicPINVOKE.Layer_GetDepth(swigCPtr);
153             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154             return ret;
155         }
156
157         /// <summary>
158         /// Increments the depth of the layer.
159         /// </summary>
160         public void Raise()
161         {
162             NDalicPINVOKE.Layer_Raise(swigCPtr);
163             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
164         }
165
166         /// <summary>
167         /// Decrements the depth of the layer.
168         /// </summary>
169         public void Lower()
170         {
171             NDalicPINVOKE.Layer_Lower(swigCPtr);
172             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
173         }
174
175         internal void RaiseAbove(Layer target)
176         {
177             NDalicPINVOKE.Layer_RaiseAbove(swigCPtr, Layer.getCPtr(target));
178             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179         }
180
181         internal void LowerBelow(Layer target)
182         {
183             NDalicPINVOKE.Layer_LowerBelow(swigCPtr, Layer.getCPtr(target));
184             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
185         }
186
187         /// <summary>
188         /// Raises the layer to the top.
189         /// </summary>
190         public void RaiseToTop()
191         {
192             NDalicPINVOKE.Layer_RaiseToTop(swigCPtr);
193             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194         }
195
196         /// <summary>
197         /// Lowers the layer to the bottom.
198         /// </summary>
199         public void LowerToBottom()
200         {
201             NDalicPINVOKE.Layer_LowerToBottom(swigCPtr);
202             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
203         }
204
205         /// <summary>
206         /// Moves the layer directly above the given layer.<br>
207         /// After the call, this layers depth will be immediately above target.<br>
208         /// </summary>
209         /// <param name="target">Layer to get on top of</param>
210         public void MoveAbove(Layer target)
211         {
212             NDalicPINVOKE.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
213             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214         }
215
216         /// <summary>
217         /// Moves the layer directly below the given layer.<br>
218         /// After the call, this layers depth will be immediately below target.<br>
219         /// </summary>
220         /// <param name="target">Layer to get below of</param>
221         public void MoveBelow(Layer target)
222         {
223             NDalicPINVOKE.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
224             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
225         }
226
227         private void SetBehavior(LayerBehavior behavior)
228         {
229             NDalicPINVOKE.Layer_SetBehavior(swigCPtr, (int)behavior);
230             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
231         }
232
233         private LayerBehavior GetBehavior()
234         {
235             Layer.LayerBehavior ret = (Layer.LayerBehavior)NDalicPINVOKE.Layer_GetBehavior(swigCPtr);
236             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237             return ret;
238         }
239
240         internal void SetSortFunction(SWIGTYPE_p_f_r_q_const__Dali__Vector3__float function)
241         {
242             NDalicPINVOKE.Layer_SetSortFunction(swigCPtr, SWIGTYPE_p_f_r_q_const__Dali__Vector3__float.getCPtr(function));
243             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244         }
245
246         internal void SetTouchConsumed(bool consume)
247         {
248             NDalicPINVOKE.Layer_SetTouchConsumed(swigCPtr, consume);
249             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250         }
251
252         internal bool IsTouchConsumed()
253         {
254             bool ret = NDalicPINVOKE.Layer_IsTouchConsumed(swigCPtr);
255             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256             return ret;
257         }
258
259         internal void SetHoverConsumed(bool consume)
260         {
261             NDalicPINVOKE.Layer_SetHoverConsumed(swigCPtr, consume);
262             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263         }
264
265         internal bool IsHoverConsumed()
266         {
267             bool ret = NDalicPINVOKE.Layer_IsHoverConsumed(swigCPtr);
268             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269             return ret;
270         }
271
272         /// <summary>
273         /// Retrieves child view by index.
274         /// </summary>
275         /// <pre>The View has been initialized.</pre>
276         /// <param name="index">The index of the child to retrieve</param>
277         /// <returns>The view for the given index or empty handle if children not initialized</returns>
278         public View GetChildAt(uint index)
279         {
280             System.IntPtr cPtr = NDalicPINVOKE.Actor_GetChildAt(swigCPtr, index);
281             cPtr = NDalicPINVOKE.View_SWIGUpcast(cPtr);
282             cPtr = NDalicPINVOKE.Handle_SWIGUpcast(cPtr);
283
284             BaseHandle ret = new BaseHandle(cPtr, false);
285
286             View temp = ViewRegistry.GetViewFromBaseHandle(ret);
287
288             if (NDalicPINVOKE.SWIGPendingException.Pending)
289                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
290
291             return temp ?? null;
292         }
293
294         /// <summary>
295         /// Enumeration for the behavior of the layer.
296         /// </summary>
297         public enum LayerBehavior
298         {
299             Layer2D,
300             LayerUI = Layer2D,
301             Layer3D
302         }
303
304         internal enum TreeDepthMultiplier
305         {
306             TREE_DEPTH_MULTIPLIER = 10000
307         }
308
309         /// <summary>
310         /// Layer Behavior, type String(Layer.LayerBehavior)
311         /// </summary>
312         public Layer.LayerBehavior Behavior
313         {
314             get
315             {
316                 return GetBehavior();
317             }
318             set
319             {
320                 SetBehavior(value);
321             }
322         }
323
324         /// <summary>
325         /// Retrieves and sets the Layer's opacity.<br>
326         /// </summary>
327         public float Opacity
328         {
329             get
330             {
331                 float temp = 0.0f;
332                 GetProperty(View.Property.OPACITY).Get(out temp);
333                 return temp;
334             }
335             set
336             {
337                 SetProperty(View.Property.OPACITY, new Tizen.NUI.PropertyValue(value));
338             }
339         }
340
341         /// <summary>
342         /// Retrieves and sets the Layer's visibility.
343         /// </summary>
344         public bool Visibility
345         {
346             get
347             {
348                 bool temp = false;
349                 GetProperty(View.Property.VISIBLE).Get(out temp);
350                 return temp;
351             }
352             set
353             {
354                 SetProperty(View.Property.VISIBLE, new Tizen.NUI.PropertyValue(value));
355             }
356         }
357
358         /// <summary>
359         /// Get the number of children held by the layer.
360         /// </summary>
361         public uint ChildCount
362         {
363             get
364             {
365                 uint ret = NDalicPINVOKE.Actor_GetChildCount(swigCPtr);
366                 if (NDalicPINVOKE.SWIGPendingException.Pending)
367                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368                 return ret;
369             }
370         }\r
371 \r
372         /// <summary>\r
373         /// Gets/Sets the Layer's name.\r
374         /// </summary>\r
375         public string Name\r
376         {\r
377             get\r
378             {\r
379                 return GetName();\r
380             }\r
381             set\r
382             {\r
383                 SetName(value);\r
384             }\r
385         }\r
386 \r
387         internal string GetName()\r
388         {\r
389             string ret = NDalicPINVOKE.Actor_GetName(swigCPtr);\r
390             if (NDalicPINVOKE.SWIGPendingException.Pending)\r
391                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();\r
392             return ret;\r
393         }\r
394 \r
395         internal void SetName(string name)\r
396         {\r
397             NDalicPINVOKE.Actor_SetName(swigCPtr, name);\r
398             if (NDalicPINVOKE.SWIGPendingException.Pending)\r
399                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();\r
400         }\r
401     }
402 }