Merge branch 'devel/master' into tizen
[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 System;
20     using Tizen.NUI.BaseComponents;
21
22     /// <summary>
23     /// Layers provide a mechanism for overlaying groups of actors on top of each other.
24     /// </summary>
25     public class Layer : Animatable
26     {
27         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
28
29         internal Layer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Layer_SWIGUpcast(cPtr), cMemoryOwn)
30         {
31             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
32         }
33
34         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Layer obj)
35         {
36             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
37         }
38
39         protected override void Dispose(DisposeTypes type)
40         {
41             if(disposed)
42             {
43                 return;
44             }
45
46             if(type == DisposeTypes.Explicit)
47             {
48                 //Called by User
49                 //Release your own managed resources here.
50                 //You should release all of your own disposable objects here.
51             }
52
53             //Release your own unmanaged resources here.
54             //You should not access any managed member here except static instance.
55             //because the execution order of Finalizes is non-deterministic.
56
57             if (swigCPtr.Handle != global::System.IntPtr.Zero)
58             {
59                 if (swigCMemOwn)
60                 {
61                     swigCMemOwn = false;
62                     NDalicPINVOKE.delete_Layer(swigCPtr);
63                 }
64                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
65             }
66
67             base.Dispose(type);
68         }
69
70
71         internal class Property
72         {
73             internal static readonly int BEHAVIOR = NDalicPINVOKE.Layer_Property_BEHAVIOR_get();
74         }
75
76         /// <summary>
77         /// Creates a Layer object.
78         /// </summary>
79         public Layer() : this(NDalicPINVOKE.Layer_New(), true)
80         {
81             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
82             if(Window.Instance != null)
83             {
84                 this.SetAnchorPoint(Tizen.NUI.PivotPoint.TopLeft);
85                 this.SetResizePolicy(ResizePolicyType.FillToParent, DimensionType.AllDimensions);
86             }
87         }
88         internal void SetAnchorPoint(Vector3 anchorPoint)
89         {
90             NDalicPINVOKE.Actor_SetAnchorPoint(swigCPtr, Vector3.getCPtr(anchorPoint));
91             if (NDalicPINVOKE.SWIGPendingException.Pending)
92                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
93         }
94         internal void SetResizePolicy(ResizePolicyType policy, DimensionType dimension)
95         {
96             NDalicPINVOKE.Actor_SetResizePolicy(swigCPtr, (int)policy, (int)dimension);
97             if (NDalicPINVOKE.SWIGPendingException.Pending)
98                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
99         }
100
101
102
103         [Obsolete("Please do not use! this will be deprecated")]
104         public new static Layer DownCast(BaseHandle handle)
105         {
106             Layer ret = new Layer(NDalicPINVOKE.Layer_DownCast(BaseHandle.getCPtr(handle)), true);
107             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
108             return ret;
109         }
110
111         /// <summary>
112         /// Search through this layer's hierarchy for an view with the given unique ID.
113         /// </summary>
114         /// <pre>This layer(the parent) has been initialized.</pre>
115         /// <remarks>The actor itself is also considered in the search.</remarks>
116         /// <param name="child">The id of the child to find</param>
117         /// <returns> A handle to the view if found, or an empty handle if not. </returns>
118         public View FindChildById(uint id)
119         {
120             View ret = new View(NDalicPINVOKE.Actor_FindChildById(swigCPtr, id), true);
121             if (NDalicPINVOKE.SWIGPendingException.Pending)
122                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
123             return ret;
124         }
125
126         /// <summary>
127         /// Adds a child view to this layer.
128         /// </summary>
129         /// <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>
130         /// <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>
131         /// <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>
132         /// <param name="child">The child</param>
133         public void Add(View child)
134         {
135             NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
136             if (NDalicPINVOKE.SWIGPendingException.Pending)
137                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
138         }
139
140         /// <summary>
141         /// Removes a child View from this layer. If the view was not a child of this layer, this is a no-op.
142         /// </summary>
143         /// <pre>This layer(the parent) has been initialized. The child view is not the same as the parent view.</pre>
144         /// <param name="child">The child</param>
145         public void Remove(View child)
146         {
147             NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child));
148             if (NDalicPINVOKE.SWIGPendingException.Pending)
149                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
150         }
151
152         /// <summary>
153         /// Queries the depth of the layer.<br>
154         /// 0 is the bottom most layer, higher number is on top.<br>
155         /// </summary>
156         public uint Depth
157         {
158             get
159             {
160                 return GetDepth();
161             }
162         }
163
164         internal uint GetDepth()
165         {
166             uint ret = NDalicPINVOKE.Layer_GetDepth(swigCPtr);
167             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168             return ret;
169         }
170
171         /// <summary>
172         /// Increments the depth of the layer.
173         /// </summary>
174         public void Raise()
175         {
176             NDalicPINVOKE.Layer_Raise(swigCPtr);
177             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
178         }
179
180         /// <summary>
181         /// Decrements the depth of the layer.
182         /// </summary>
183         public void Lower()
184         {
185             NDalicPINVOKE.Layer_Lower(swigCPtr);
186             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187         }
188
189         internal void RaiseAbove(Layer target)
190         {
191             NDalicPINVOKE.Layer_RaiseAbove(swigCPtr, Layer.getCPtr(target));
192             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193         }
194
195         internal void LowerBelow(Layer target)
196         {
197             NDalicPINVOKE.Layer_LowerBelow(swigCPtr, Layer.getCPtr(target));
198             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199         }
200
201         /// <summary>
202         /// Raises the layer to the top.
203         /// </summary>
204         public void RaiseToTop()
205         {
206             NDalicPINVOKE.Layer_RaiseToTop(swigCPtr);
207             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208         }
209
210         /// <summary>
211         /// Lowers the layer to the bottom.
212         /// </summary>
213         public void LowerToBottom()
214         {
215             NDalicPINVOKE.Layer_LowerToBottom(swigCPtr);
216             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
217         }
218
219         /// <summary>
220         /// Moves the layer directly above the given layer.<br>
221         /// After the call, this layers depth will be immediately above target.<br>
222         /// </summary>
223         /// <param name="target">Layer to get on top of</param>
224         public void MoveAbove(Layer target)
225         {
226             NDalicPINVOKE.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
227             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228         }
229
230         /// <summary>
231         /// Moves the layer directly below the given layer.<br>
232         /// After the call, this layers depth will be immediately below target.<br>
233         /// </summary>
234         /// <param name="target">Layer to get below of</param>
235         public void MoveBelow(Layer target)
236         {
237             NDalicPINVOKE.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
238             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239         }
240
241         private void SetBehavior(LayerBehavior behavior)
242         {
243             NDalicPINVOKE.Layer_SetBehavior(swigCPtr, (int)behavior);
244             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245         }
246
247         private LayerBehavior GetBehavior()
248         {
249             Layer.LayerBehavior ret = (Layer.LayerBehavior)NDalicPINVOKE.Layer_GetBehavior(swigCPtr);
250             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
251             return ret;
252         }
253
254         internal void SetSortFunction(SWIGTYPE_p_f_r_q_const__Dali__Vector3__float function)
255         {
256             NDalicPINVOKE.Layer_SetSortFunction(swigCPtr, SWIGTYPE_p_f_r_q_const__Dali__Vector3__float.getCPtr(function));
257             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258         }
259
260         internal void SetTouchConsumed(bool consume)
261         {
262             NDalicPINVOKE.Layer_SetTouchConsumed(swigCPtr, consume);
263             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
264         }
265
266         internal bool IsTouchConsumed()
267         {
268             bool ret = NDalicPINVOKE.Layer_IsTouchConsumed(swigCPtr);
269             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
270             return ret;
271         }
272
273         internal void SetHoverConsumed(bool consume)
274         {
275             NDalicPINVOKE.Layer_SetHoverConsumed(swigCPtr, consume);
276             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
277         }
278
279         internal bool IsHoverConsumed()
280         {
281             bool ret = NDalicPINVOKE.Layer_IsHoverConsumed(swigCPtr);
282             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
283             return ret;
284         }
285
286         /// <summary>
287         /// Retrieves child view by index.
288         /// </summary>
289         /// <pre>The View has been initialized.</pre>
290         /// <param name="index">The index of the child to retrieve</param>
291         /// <returns>The view for the given index or empty handle if children not initialized</returns>
292         public View GetChildAt(uint index)
293         {
294             System.IntPtr cPtr = NDalicPINVOKE.Actor_GetChildAt(swigCPtr, index);
295
296             View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
297
298             if (NDalicPINVOKE.SWIGPendingException.Pending)
299                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300
301             return ret ?? null;
302         }
303
304         /// <summary>
305         /// Enumeration for the behavior of the layer.
306         /// </summary>
307         public enum LayerBehavior
308         {
309             Layer2D,
310             LayerUI = Layer2D,
311             Layer3D
312         }
313
314         internal enum TreeDepthMultiplier
315         {
316             TREE_DEPTH_MULTIPLIER = 10000
317         }
318
319         /// <summary>
320         /// Layer Behavior, type String(Layer.LayerBehavior)
321         /// </summary>
322         public Layer.LayerBehavior Behavior
323         {
324             get
325             {
326                 return GetBehavior();
327             }
328             set
329             {
330                 SetBehavior(value);
331             }
332         }
333
334         /// <summary>
335         /// Internal only property to Enable/Disable Clipping, type Boolean.
336         /// By default this is false, i.e. the viewport of the Layer is the entire window.
337         /// </summary>
338         internal bool ClippingEnabled
339         {
340             get
341             {
342                 bool ret = NDalicPINVOKE.Layer_IsClipping(swigCPtr);
343                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
344                 return ret;
345             }
346             set
347             {
348                 NDalicPINVOKE.Layer_SetClipping(swigCPtr, value);
349                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
350             }
351         }
352
353         /// <summary>
354         /// Sets the Viewport (in window coordinates), type Rectangle.
355         /// The contents of the layer will not be visible outside this box, when ViewportEnabled is true.
356         /// </summary>
357         public Rectangle Viewport
358         {
359             get
360             {
361                 if( ClippingEnabled )
362                 {
363                   Rectangle ret = new Rectangle(NDalicPINVOKE.Layer_GetClippingBox(swigCPtr), true);
364                   if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
365                   return ret;
366                 }
367                 else
368                 {
369                   // Clipping not enabled so return the window size
370                   Size2D windowSize = Window.Instance.Size;
371                   Rectangle ret = new Rectangle(0, 0, windowSize.Width, windowSize.Height);
372                   return ret;
373                 }
374             }
375             set
376             {
377                 NDalicPINVOKE.Layer_SetClippingBox__SWIG_1(swigCPtr, Rectangle.getCPtr(value));
378                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
379                 ClippingEnabled = true;
380             }
381         }
382
383         /// <summary>
384         /// Retrieves and sets the Layer's opacity.<br>
385         /// </summary>
386         public float Opacity
387         {
388             get
389             {
390                 float temp = 0.0f;
391                 GetProperty(View.Property.OPACITY).Get(out temp);
392                 return temp;
393             }
394             set
395             {
396                 SetProperty(View.Property.OPACITY, new Tizen.NUI.PropertyValue(value));
397             }
398         }
399
400         /// <summary>
401         /// Retrieves and sets the Layer's visibility.
402         /// </summary>
403         public bool Visibility
404         {
405             get
406             {
407                 bool temp = false;
408                 GetProperty(View.Property.VISIBLE).Get(out temp);
409                 return temp;
410             }
411             set
412             {
413                 SetProperty(View.Property.VISIBLE, new Tizen.NUI.PropertyValue(value));
414             }
415         }
416
417         /// <summary>
418         /// Get the number of children held by the layer.
419         /// </summary>
420         public uint ChildCount
421         {
422             get
423             {
424                 uint ret = NDalicPINVOKE.Actor_GetChildCount(swigCPtr);
425                 if (NDalicPINVOKE.SWIGPendingException.Pending)
426                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
427                 return ret;
428             }
429         }
430     }
431 }