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