659aac0e043defa80fc0e3ff11340a675723d596
[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         }
147
148
149         internal class Property
150         {
151             internal static readonly int BEHAVIOR = NDalicPINVOKE.Layer_Property_BEHAVIOR_get();
152         }
153
154         /// <summary>
155         /// Creates a Layer object.
156         /// </summary>
157         /// <since_tizen> 3 </since_tizen>
158         public Layer() : this(NDalicPINVOKE.Layer_New(), true)
159         {
160             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
161             if(Window.Instance != null)
162             {
163                 this.SetAnchorPoint(Tizen.NUI.PivotPoint.TopLeft);
164                 this.SetResizePolicy(ResizePolicyType.FillToParent, DimensionType.AllDimensions);
165             }
166         }
167         internal void SetAnchorPoint(Vector3 anchorPoint)
168         {
169             NDalicPINVOKE.Actor_SetAnchorPoint(swigCPtr, Vector3.getCPtr(anchorPoint));
170             if (NDalicPINVOKE.SWIGPendingException.Pending)
171                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
172         }
173         internal void SetResizePolicy(ResizePolicyType policy, DimensionType dimension)
174         {
175             NDalicPINVOKE.Actor_SetResizePolicy(swigCPtr, (int)policy, (int)dimension);
176             if (NDalicPINVOKE.SWIGPendingException.Pending)
177                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
178         }
179
180
181         /// <summary>
182         /// [Obsolete("Please do not use! this will be deprecated")]
183         /// </summary>
184         /// <since_tizen> 3 </since_tizen>
185         [Obsolete("Please do not use! this will be deprecated")]
186         public static Layer DownCast(BaseHandle handle)
187         {
188             Layer ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as Layer;
189             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
190             return ret;
191         }
192
193         /// <summary>
194         /// Search through this layer's hierarchy for a view with the given unique ID.
195         /// </summary>
196         /// <pre>This layer (the parent) has been initialized.</pre>
197         /// <remarks>The actor itself is also considered in the search.</remarks>
198         /// <param name="id">The id of the child to find</param>
199         /// <returns> A handle to the view if found, or an empty handle if not. </returns>
200         /// <since_tizen> 3 </since_tizen>
201         public View FindChildById(uint id)
202         {
203             IntPtr cPtr = NDalicPINVOKE.Actor_FindChildById(swigCPtr, id);
204             View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
205
206             if (NDalicPINVOKE.SWIGPendingException.Pending)
207                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208             return ret;
209         }
210
211         /// <summary>
212         /// Queries the depth of the layer.<br />
213         /// 0 is the bottommost layer, higher number is on the top.<br />
214         /// </summary>
215         /// <since_tizen> 3 </since_tizen>
216         public uint Depth
217         {
218             get
219             {
220                 return GetDepth();
221             }
222         }
223
224         internal uint GetDepth()
225         {
226             uint ret = NDalicPINVOKE.Layer_GetDepth(swigCPtr);
227             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228             return ret;
229         }
230
231         /// <summary>
232         /// Increments the depth of the layer.
233         /// </summary>
234         /// <since_tizen> 3 </since_tizen>
235         public void Raise()
236         {
237             NDalicPINVOKE.Layer_Raise(swigCPtr);
238             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239         }
240
241         /// <summary>
242         /// Decrements the depth of the layer.
243         /// </summary>
244         /// <since_tizen> 3 </since_tizen>
245         public void Lower()
246         {
247             NDalicPINVOKE.Layer_Lower(swigCPtr);
248             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249         }
250
251         internal void RaiseAbove(Layer target)
252         {
253             NDalicPINVOKE.Layer_RaiseAbove(swigCPtr, Layer.getCPtr(target));
254             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255         }
256
257         internal void LowerBelow(Layer target)
258         {
259             NDalicPINVOKE.Layer_LowerBelow(swigCPtr, Layer.getCPtr(target));
260             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261         }
262
263         /// <summary>
264         /// Raises the layer to the top.
265         /// </summary>
266         /// <since_tizen> 3 </since_tizen>
267         public void RaiseToTop()
268         {
269             NDalicPINVOKE.Layer_RaiseToTop(swigCPtr);
270             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271         }
272
273         /// <summary>
274         /// Lowers the layer to the bottom.
275         /// </summary>
276         /// <since_tizen> 3 </since_tizen>
277         public void LowerToBottom()
278         {
279             NDalicPINVOKE.Layer_LowerToBottom(swigCPtr);
280             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281         }
282
283         /// <summary>
284         /// Moves the layer directly above the given layer.<br />
285         /// After the call, this layer's depth will be immediately above target.<br />
286         /// </summary>
287         /// <param name="target">The layer to get on top of.</param>
288         /// <since_tizen> 3 </since_tizen>
289         public void MoveAbove(Layer target)
290         {
291             NDalicPINVOKE.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
292             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
293         }
294
295         /// <summary>
296         /// Moves the layer directly below the given layer.<br />
297         /// After the call, this layer's depth will be immediately below target.<br />
298         /// </summary>
299         /// <param name="target">The layer to get below of.</param>
300         /// <since_tizen> 3 </since_tizen>
301         public void MoveBelow(Layer target)
302         {
303             NDalicPINVOKE.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
304             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305         }
306
307         private void SetBehavior(LayerBehavior behavior)
308         {
309             NDalicPINVOKE.Layer_SetBehavior(swigCPtr, (int)behavior);
310             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
311         }
312
313         private LayerBehavior GetBehavior()
314         {
315             Layer.LayerBehavior ret = (Layer.LayerBehavior)NDalicPINVOKE.Layer_GetBehavior(swigCPtr);
316             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317             return ret;
318         }
319
320         internal void SetSortFunction(SWIGTYPE_p_f_r_q_const__Dali__Vector3__float function)
321         {
322             NDalicPINVOKE.Layer_SetSortFunction(swigCPtr, SWIGTYPE_p_f_r_q_const__Dali__Vector3__float.getCPtr(function));
323             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
324         }
325
326         internal void SetTouchConsumed(bool consume)
327         {
328             NDalicPINVOKE.Layer_SetTouchConsumed(swigCPtr, consume);
329             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
330         }
331
332         internal bool IsTouchConsumed()
333         {
334             bool ret = NDalicPINVOKE.Layer_IsTouchConsumed(swigCPtr);
335             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
336             return ret;
337         }
338
339         internal void SetHoverConsumed(bool consume)
340         {
341             NDalicPINVOKE.Layer_SetHoverConsumed(swigCPtr, consume);
342             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
343         }
344
345         internal bool IsHoverConsumed()
346         {
347             bool ret = NDalicPINVOKE.Layer_IsHoverConsumed(swigCPtr);
348             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
349             return ret;
350         }
351
352         /// <summary>
353         /// Enumeration for the behavior of the layer.
354         /// </summary>
355         /// <since_tizen> 3 </since_tizen>
356         public enum LayerBehavior
357         {
358             /// <summary>
359             /// UI control rendering mode.
360             /// </summary>
361             /// <since_tizen> 3 </since_tizen>
362             Layer2D,
363             /// <summary>
364             /// UI control rendering mode (default mode).
365             /// This mode is designed for UI controls that can overlap. In this
366             /// mode renderer order will be respective to the tree hierarchy of
367             /// Actors.<br />
368             /// The rendering order is depth first, so for the following actor tree,
369             /// A will be drawn first, then B, D, E, then C, F.  This ensures that
370             /// overlapping actors are drawn as expected (whereas, with breadth first
371             /// traversal, the actors would interleave).<br />
372             /// </summary>
373             /// <since_tizen> 3 </since_tizen>
374             LayerUI = Layer2D,
375             /// <summary>
376             /// Layer will use depth test.
377             /// This mode is designed for a 3 dimensional scene where actors in front
378             /// of other actors will obscure them, i.e. the actors are sorted by the
379             /// distance from the camera.<br />
380             /// When using this mode, a depth test will be used. A depth clear will
381             /// happen for each layer, which means actors in a layer "above" other
382             /// layers will be rendered in front of actors in those layers regardless
383             /// of their Z positions (see Layer::Raise() and Layer::Lower()).<br />
384             /// Opaque renderers are drawn first and write to the depth buffer.  Then
385             /// transparent renderers are drawn with depth test enabled but depth
386             /// write switched off.  Transparent renderers are drawn based on their
387             /// distance from the camera.  A renderer's DEPTH_INDEX property is used to
388             /// offset the distance to the camera when ordering transparent renderers.
389             /// This is useful if you want to define the draw order of two or more
390             /// transparent renderers that are equal distance from the camera.  Unlike
391             /// LAYER_UI, parent-child relationship does not affect rendering order at
392             /// all.
393             /// </summary>
394             /// <since_tizen> 3 </since_tizen>
395             Layer3D
396         }
397
398         internal enum TreeDepthMultiplier
399         {
400             TREE_DEPTH_MULTIPLIER = 10000
401         }
402
403         /// <summary>
404         /// Layer behavior, type String (Layer.LayerBehavior).
405         /// </summary>
406         /// <since_tizen> 3 </since_tizen>
407         public Layer.LayerBehavior Behavior
408         {
409             get
410             {
411                 return GetBehavior();
412             }
413             set
414             {
415                 SetBehavior(value);
416             }
417         }
418
419         /// <summary>
420         /// Internal only property to enable or disable clipping, type boolean.
421         /// By default, this is false, i.e., the viewport of the layer is the entire window.
422         /// </summary>
423         internal bool ClippingEnabled
424         {
425             get
426             {
427                 bool ret = NDalicPINVOKE.Layer_IsClipping(swigCPtr);
428                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
429                 return ret;
430             }
431             set
432             {
433                 NDalicPINVOKE.Layer_SetClipping(swigCPtr, value);
434                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
435             }
436         }
437
438         /// <summary>
439         /// Sets the viewport (in window coordinates), type rectangle.
440         /// The contents of the layer will not be visible outside this box, when ViewportEnabled is true.
441         /// </summary>
442         /// <since_tizen> 4 </since_tizen>
443         public Rectangle Viewport
444         {
445             get
446             {
447                 if( ClippingEnabled )
448                 {
449                   Rectangle ret = new Rectangle(NDalicPINVOKE.Layer_GetClippingBox(swigCPtr), true);
450                   if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
451                   return ret;
452                 }
453                 else
454                 {
455                   // Clipping not enabled so return the window size
456                   Size2D windowSize = Window.Instance.Size;
457                   Rectangle ret = new Rectangle(0, 0, windowSize.Width, windowSize.Height);
458                   return ret;
459                 }
460             }
461             set
462             {
463                 NDalicPINVOKE.Layer_SetClippingBox__SWIG_1(swigCPtr, Rectangle.getCPtr(value));
464                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
465                 ClippingEnabled = true;
466             }
467         }
468
469         /// <summary>
470         /// Retrieves and sets the layer's opacity.<br />
471         /// </summary>
472         /// <since_tizen> 3 </since_tizen>
473         public float Opacity
474         {
475             get
476             {
477                 float temp = 0.0f;
478                 GetProperty(View.Property.OPACITY).Get(out temp);
479                 return temp;
480             }
481             set
482             {
483                 SetProperty(View.Property.OPACITY, new Tizen.NUI.PropertyValue(value));
484             }
485         }
486
487         /// <summary>
488         /// Retrieves and sets the layer's visibility.
489         /// </summary>
490         /// <since_tizen> 3 </since_tizen>
491         public bool Visibility
492         {
493             get
494             {
495                 bool temp = false;
496                 GetProperty(View.Property.VISIBLE).Get(out temp);
497                 return temp;
498             }
499             set
500             {
501                 SetProperty(View.Property.VISIBLE, new Tizen.NUI.PropertyValue(value));
502             }
503         }
504
505         /// <summary>
506         /// Get the number of children held by the layer.
507         /// </summary>
508         /// <since_tizen> 3 </since_tizen>
509         public new uint ChildCount
510         {
511             get
512             {
513                 return Convert.ToUInt32(Children.Count);
514             }
515         }
516
517         /// <summary>
518         /// Gets or sets the layer's name.
519         /// </summary>
520         /// <since_tizen> 3 </since_tizen>
521         public string Name
522         {
523             get
524             {
525                 return GetName();
526             }
527             set
528             {
529                 SetName(value);
530             }
531         }
532
533         internal string GetName()
534         {
535             string ret = NDalicPINVOKE.Actor_GetName(swigCPtr);
536             if (NDalicPINVOKE.SWIGPendingException.Pending)
537                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
538             return ret;
539         }
540
541         internal void SetName(string name)
542         {
543             NDalicPINVOKE.Actor_SetName(swigCPtr, name);
544             if (NDalicPINVOKE.SWIGPendingException.Pending)
545                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
546         }
547
548     }
549 }