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