Merge "Add C# binding for Extends type. Add C# binding for Margin and PaddingEX prope...
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Layer.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
18 namespace Tizen.NUI
19 {
20     using System;
21     using Tizen.NUI.BaseComponents;
22
23     /// <summary>
24     /// Layers provide a mechanism for overlaying groups of actors on top of each other.
25     /// </summary>
26     public class Layer : Container
27     {
28         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29
30         internal Layer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Layer_SWIGUpcast(cPtr), cMemoryOwn)
31         {
32             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
33         }
34
35         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Layer obj)
36         {
37             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
38         }
39
40         /// From the Container base class.
41
42         /// <summary>
43         /// Adds a child view to this layer.
44         /// </summary>
45         /// <seealso cref="Container.Add">
46         /// </seealso>
47         /// <since_tizen> 4 </since_tizen>
48         public override void Add(View child)
49         {
50             NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
51             if (NDalicPINVOKE.SWIGPendingException.Pending)
52                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
53
54             Children.Add(child);
55         }
56
57         /// <summary>
58         /// Removes a child view from this layer. If the view was not a child of this layer, this is a no-op.
59         /// </summary>
60         /// <seealso cref="Container.Remove">
61         /// </seealso>
62         /// <since_tizen> 4 </since_tizen>
63         public override void Remove(View child)
64         {
65             NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child));
66             if (NDalicPINVOKE.SWIGPendingException.Pending)
67                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
68
69             Children.Remove(child);
70         }
71
72         /// <summary>
73         /// Retrieves a child view by the index.
74         /// </summary>
75         /// <pre>The view has been initialized.</pre>
76         /// <param name="index">The index of the child to retrieve.</param>
77         /// <returns>The view for the given index or empty handle if children not initialized.</returns>
78         /// <since_tizen> 4 </since_tizen>
79         public override View GetChildAt(uint index)
80         {
81             if (index < Children.Count)
82             {
83                 return Children[Convert.ToInt32(index)];
84             }
85             else
86             {
87                 return null;
88             }
89         }
90
91
92         /// <summary>
93         /// Get parent of the layer.
94         /// </summary>
95         /// <returns>The view's container</returns>
96         /// <since_tizen> 3 </since_tizen>
97         public override Container GetParent()
98         {
99             return null;
100         }
101
102         /// <summary>
103         /// Get the child count of the layer.
104         /// </summary>
105         /// <returns>The child count of the layer.</returns>
106         /// <since_tizen> 3 </since_tizen>
107         public override uint GetChildCount()
108         {
109             return Convert.ToUInt32(Children.Count);
110         }
111
112         /// <summary>
113         /// Dispose.
114         /// </summary>
115         /// <since_tizen> 3 </since_tizen>
116         protected override void Dispose(DisposeTypes type)
117         {
118             if(disposed)
119             {
120                 return;
121             }
122
123             if(type == DisposeTypes.Explicit)
124             {
125                 //Called by User
126                 //Release your own managed resources here.
127                 //You should release all of your own disposable objects here.
128             }
129
130             //Release your own unmanaged resources here.
131             //You should not access any managed member here except static instance.
132             //because the execution order of Finalizes is non-deterministic.
133
134             if (swigCPtr.Handle != global::System.IntPtr.Zero)
135             {
136                 if (swigCMemOwn)
137                 {
138                     swigCMemOwn = false;
139                     NDalicPINVOKE.delete_Layer(swigCPtr);
140                 }
141                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
142             }
143
144             base.Dispose(type);
145
146             // Dispose all Children of this Layer.
147             foreach (View childView in Children)
148             {
149                 childView?.Dispose();
150             }
151             Children.Clear();
152         }
153
154
155         internal class Property
156         {
157             internal static readonly int BEHAVIOR = NDalicPINVOKE.Layer_Property_BEHAVIOR_get();
158         }
159
160         /// <summary>
161         /// Creates a Layer object.
162         /// </summary>
163         /// <since_tizen> 3 </since_tizen>
164         public Layer() : this(NDalicPINVOKE.Layer_New(), true)
165         {
166             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
167             if(Window.Instance != null)
168             {
169                 this.SetAnchorPoint(Tizen.NUI.PivotPoint.TopLeft);
170                 this.SetResizePolicy(ResizePolicyType.FillToParent, DimensionType.AllDimensions);
171             }
172         }
173         internal void SetAnchorPoint(Vector3 anchorPoint)
174         {
175             NDalicPINVOKE.Actor_SetAnchorPoint(swigCPtr, Vector3.getCPtr(anchorPoint));
176             if (NDalicPINVOKE.SWIGPendingException.Pending)
177                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
178         }
179         internal void SetResizePolicy(ResizePolicyType policy, DimensionType dimension)
180         {
181             NDalicPINVOKE.Actor_SetResizePolicy(swigCPtr, (int)policy, (int)dimension);
182             if (NDalicPINVOKE.SWIGPendingException.Pending)
183                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
184         }
185
186
187         /// <summary>
188         /// [Obsolete("Please do not use! this will be deprecated")]
189         /// </summary>
190         /// <since_tizen> 3 </since_tizen>
191         [Obsolete("Please do not use! this will be deprecated")]
192         public static Layer DownCast(BaseHandle handle)
193         {
194             Layer ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as Layer;
195             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196             return ret;
197         }
198
199         /// <summary>
200         /// Search through this layer's hierarchy for a view with the given unique ID.
201         /// </summary>
202         /// <pre>This layer (the parent) has been initialized.</pre>
203         /// <remarks>The actor itself is also considered in the search.</remarks>
204         /// <param name="id">The id of the child to find</param>
205         /// <returns> A handle to the view if found, or an empty handle if not. </returns>
206         /// <since_tizen> 3 </since_tizen>
207         public View FindChildById(uint id)
208         {
209             IntPtr cPtr = NDalicPINVOKE.Actor_FindChildById(swigCPtr, id);
210             View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
211
212             if (NDalicPINVOKE.SWIGPendingException.Pending)
213                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214             return ret;
215         }
216
217         /// <summary>
218         /// Queries the depth of the layer.<br />
219         /// 0 is the bottommost layer, higher number is on the top.<br />
220         /// </summary>
221         /// <since_tizen> 3 </since_tizen>
222         public uint Depth
223         {
224             get
225             {
226                 return GetDepth();
227             }
228         }
229
230         internal uint GetDepth()
231         {
232             uint ret = NDalicPINVOKE.Layer_GetDepth(swigCPtr);
233             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234             return ret;
235         }
236
237         /// <summary>
238         /// Increments the depth of the layer.
239         /// </summary>
240         /// <since_tizen> 3 </since_tizen>
241         public void Raise()
242         {
243             NDalicPINVOKE.Layer_Raise(swigCPtr);
244             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245         }
246
247         /// <summary>
248         /// Decrements the depth of the layer.
249         /// </summary>
250         /// <since_tizen> 3 </since_tizen>
251         public void Lower()
252         {
253             NDalicPINVOKE.Layer_Lower(swigCPtr);
254             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255         }
256
257         internal void RaiseAbove(Layer target)
258         {
259             NDalicPINVOKE.Layer_RaiseAbove(swigCPtr, Layer.getCPtr(target));
260             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261         }
262
263         internal void LowerBelow(Layer target)
264         {
265             NDalicPINVOKE.Layer_LowerBelow(swigCPtr, Layer.getCPtr(target));
266             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
267         }
268
269         /// <summary>
270         /// Raises the layer to the top.
271         /// </summary>
272         /// <since_tizen> 3 </since_tizen>
273         public void RaiseToTop()
274         {
275             NDalicPINVOKE.Layer_RaiseToTop(swigCPtr);
276             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
277         }
278
279         /// <summary>
280         /// Lowers the layer to the bottom.
281         /// </summary>
282         /// <since_tizen> 3 </since_tizen>
283         public void LowerToBottom()
284         {
285             NDalicPINVOKE.Layer_LowerToBottom(swigCPtr);
286             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
287         }
288
289         /// <summary>
290         /// Moves the layer directly above the given layer.<br />
291         /// After the call, this layer's depth will be immediately above target.<br />
292         /// </summary>
293         /// <param name="target">The layer to get on top of.</param>
294         /// <since_tizen> 3 </since_tizen>
295         public void MoveAbove(Layer target)
296         {
297             NDalicPINVOKE.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
298             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299         }
300
301         /// <summary>
302         /// Moves the layer directly below the given layer.<br />
303         /// After the call, this layer's depth will be immediately below target.<br />
304         /// </summary>
305         /// <param name="target">The layer to get below of.</param>
306         /// <since_tizen> 3 </since_tizen>
307         public void MoveBelow(Layer target)
308         {
309             NDalicPINVOKE.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
310             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
311         }
312
313         private void SetBehavior(LayerBehavior behavior)
314         {
315             NDalicPINVOKE.Layer_SetBehavior(swigCPtr, (int)behavior);
316             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317         }
318
319         private LayerBehavior GetBehavior()
320         {
321             Layer.LayerBehavior ret = (Layer.LayerBehavior)NDalicPINVOKE.Layer_GetBehavior(swigCPtr);
322             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
323             return ret;
324         }
325
326         internal void SetSortFunction(SWIGTYPE_p_f_r_q_const__Dali__Vector3__float function)
327         {
328             NDalicPINVOKE.Layer_SetSortFunction(swigCPtr, SWIGTYPE_p_f_r_q_const__Dali__Vector3__float.getCPtr(function));
329             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
330         }
331
332         internal void SetTouchConsumed(bool consume)
333         {
334             NDalicPINVOKE.Layer_SetTouchConsumed(swigCPtr, consume);
335             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
336         }
337
338         internal bool IsTouchConsumed()
339         {
340             bool ret = NDalicPINVOKE.Layer_IsTouchConsumed(swigCPtr);
341             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
342             return ret;
343         }
344
345         internal void SetHoverConsumed(bool consume)
346         {
347             NDalicPINVOKE.Layer_SetHoverConsumed(swigCPtr, consume);
348             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
349         }
350
351         internal bool IsHoverConsumed()
352         {
353             bool ret = NDalicPINVOKE.Layer_IsHoverConsumed(swigCPtr);
354             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355             return ret;
356         }
357
358         /// <summary>
359         /// Enumeration for the behavior of the layer.
360         /// </summary>
361         /// <since_tizen> 3 </since_tizen>
362         public enum LayerBehavior
363         {
364             /// <summary>
365             /// UI control rendering mode.
366             /// </summary>
367             /// <since_tizen> 3 </since_tizen>
368             Layer2D,
369             /// <summary>
370             /// UI control rendering mode (default mode).
371             /// This mode is designed for UI controls that can overlap. In this
372             /// mode renderer order will be respective to the tree hierarchy of
373             /// Actors.<br />
374             /// The rendering order is depth first, so for the following actor tree,
375             /// A will be drawn first, then B, D, E, then C, F.  This ensures that
376             /// overlapping actors are drawn as expected (whereas, with breadth first
377             /// traversal, the actors would interleave).<br />
378             /// </summary>
379             /// <since_tizen> 3 </since_tizen>
380             LayerUI = Layer2D,
381             /// <summary>
382             /// Layer will use depth test.
383             /// This mode is designed for a 3 dimensional scene where actors in front
384             /// of other actors will obscure them, i.e. the actors are sorted by the
385             /// distance from the camera.<br />
386             /// When using this mode, a depth test will be used. A depth clear will
387             /// happen for each layer, which means actors in a layer "above" other
388             /// layers will be rendered in front of actors in those layers regardless
389             /// of their Z positions (see Layer::Raise() and Layer::Lower()).<br />
390             /// Opaque renderers are drawn first and write to the depth buffer.  Then
391             /// transparent renderers are drawn with depth test enabled but depth
392             /// write switched off.  Transparent renderers are drawn based on their
393             /// distance from the camera.  A renderer's DEPTH_INDEX property is used to
394             /// offset the distance to the camera when ordering transparent renderers.
395             /// This is useful if you want to define the draw order of two or more
396             /// transparent renderers that are equal distance from the camera.  Unlike
397             /// LAYER_UI, parent-child relationship does not affect rendering order at
398             /// all.
399             /// </summary>
400             /// <since_tizen> 3 </since_tizen>
401             Layer3D
402         }
403
404         internal enum TreeDepthMultiplier
405         {
406             TREE_DEPTH_MULTIPLIER = 10000
407         }
408
409         /// <summary>
410         /// Layer behavior, type String (Layer.LayerBehavior).
411         /// </summary>
412         /// <since_tizen> 3 </since_tizen>
413         public Layer.LayerBehavior Behavior
414         {
415             get
416             {
417                 return GetBehavior();
418             }
419             set
420             {
421                 SetBehavior(value);
422             }
423         }
424
425         /// <summary>
426         /// Internal only property to enable or disable clipping, type boolean.
427         /// By default, this is false, i.e., the viewport of the layer is the entire window.
428         /// </summary>
429         internal bool ClippingEnabled
430         {
431             get
432             {
433                 bool ret = NDalicPINVOKE.Layer_IsClipping(swigCPtr);
434                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
435                 return ret;
436             }
437             set
438             {
439                 NDalicPINVOKE.Layer_SetClipping(swigCPtr, value);
440                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
441             }
442         }
443
444         /// <summary>
445         /// Sets the viewport (in window coordinates), type rectangle.
446         /// The contents of the layer will not be visible outside this box, when ViewportEnabled is true.
447         /// </summary>
448         /// <since_tizen> 4 </since_tizen>
449         public Rectangle Viewport
450         {
451             get
452             {
453                 if( ClippingEnabled )
454                 {
455                   Rectangle ret = new Rectangle(NDalicPINVOKE.Layer_GetClippingBox(swigCPtr), true);
456                   if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
457                   return ret;
458                 }
459                 else
460                 {
461                   // Clipping not enabled so return the window size
462                   Size2D windowSize = Window.Instance.Size;
463                   Rectangle ret = new Rectangle(0, 0, windowSize.Width, windowSize.Height);
464                   return ret;
465                 }
466             }
467             set
468             {
469                 NDalicPINVOKE.Layer_SetClippingBox__SWIG_1(swigCPtr, Rectangle.getCPtr(value));
470                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
471                 ClippingEnabled = true;
472             }
473         }
474
475         /// <summary>
476         /// Retrieves and sets the layer's opacity.<br />
477         /// </summary>
478         /// <since_tizen> 3 </since_tizen>
479         public float Opacity
480         {
481             get
482             {
483                 float temp = 0.0f;
484                 GetProperty(View.Property.OPACITY).Get(out temp);
485                 return temp;
486             }
487             set
488             {
489                 SetProperty(View.Property.OPACITY, new Tizen.NUI.PropertyValue(value));
490             }
491         }
492
493         /// <summary>
494         /// Retrieves and sets the layer's visibility.
495         /// </summary>
496         /// <since_tizen> 3 </since_tizen>
497         public bool Visibility
498         {
499             get
500             {
501                 bool temp = false;
502                 GetProperty(View.Property.VISIBLE).Get(out temp);
503                 return temp;
504             }
505             set
506             {
507                 SetProperty(View.Property.VISIBLE, new Tizen.NUI.PropertyValue(value));
508             }
509         }
510
511         /// <summary>
512         /// Get the number of children held by the layer.
513         /// </summary>
514         /// <since_tizen> 3 </since_tizen>
515         public new uint ChildCount
516         {
517             get
518             {
519                 uint ret = NDalicPINVOKE.Actor_GetChildCount(swigCPtr);
520                 if (NDalicPINVOKE.SWIGPendingException.Pending)
521                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
522                 return ret;
523             }
524         }
525
526         /// <summary>
527         /// Gets or sets the layer's name.
528         /// </summary>
529         /// <since_tizen> 3 </since_tizen>
530         public string Name
531         {
532             get
533             {
534                 return GetName();
535             }
536             set
537             {
538                 SetName(value);
539             }
540         }
541
542         internal string GetName()
543         {
544             string ret = NDalicPINVOKE.Actor_GetName(swigCPtr);
545             if (NDalicPINVOKE.SWIGPendingException.Pending)
546                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
547             return ret;
548         }
549
550         internal void SetName(string name)
551         {
552             NDalicPINVOKE.Actor_SetName(swigCPtr, name);
553             if (NDalicPINVOKE.SWIGPendingException.Pending)
554                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
555         }
556
557     }
558 }