2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using Tizen.NUI.BaseComponents;
19 using System.ComponentModel;
20 using System.Runtime.InteropServices;
21 using Tizen.NUI.Binding;
26 /// Layers provide a mechanism for overlaying groups of actors on top of each other.
28 /// <since_tizen> 3 </since_tizen>
29 public class Layer : Container
31 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
32 private Window window;
35 /// Creates a Layer object.
37 /// <since_tizen> 3 </since_tizen>
38 public Layer() : this(Interop.Layer.Layer_New(), true)
40 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
41 if (Window.Instance != null)
43 this.SetAnchorPoint(Tizen.NUI.PivotPoint.TopLeft);
44 this.SetResizePolicy(ResizePolicyType.FillToParent, DimensionType.AllDimensions);
48 internal Layer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Layer.Layer_SWIGUpcast(cPtr), cMemoryOwn)
50 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
54 /// Enumeration for the behavior of the layer.
56 /// <since_tizen> 3 </since_tizen>
57 public enum LayerBehavior
60 /// UI control rendering mode (default mode).
61 /// This mode is designed for UI controls that can overlap. In this
62 /// mode renderer order will be respective to the tree hierarchy of
64 /// The rendering order is depth first, so for the following actor tree,
65 /// A will be drawn first, then B, D, E, then C, F. This ensures that
66 /// overlapping actors are drawn as expected (whereas, with breadth first
67 /// traversal, the actors would interleave).<br />
69 /// <since_tizen> 3 </since_tizen>
73 /// Deprecated in API6; Will be removed in API9. Please use LayerUI instead.
75 /// <since_tizen> 3 </since_tizen>
76 [Obsolete("Deprecated in API6; Will be removed in API9. Please use LayerUI instead.")]
77 [EditorBrowsable(EditorBrowsableState.Never)]
81 /// Layer will use depth test.
82 /// This mode is designed for a 3 dimensional scene where actors in front
83 /// of other actors will obscure them, i.e. the actors are sorted by the
84 /// distance from the camera.<br />
85 /// When using this mode, a depth test will be used. A depth clear will
86 /// happen for each layer, which means actors in a layer "above" other
87 /// layers will be rendered in front of actors in those layers regardless
88 /// of their Z positions (see Layer::Raise() and Layer::Lower()).<br />
89 /// Opaque renderers are drawn first and write to the depth buffer. Then
90 /// transparent renderers are drawn with depth test enabled but depth
91 /// write switched off. Transparent renderers are drawn based on their
92 /// distance from the camera. A renderer's DEPTH_INDEX property is used to
93 /// offset the distance to the camera when ordering transparent renderers.
94 /// This is useful if you want to define the draw order of two or more
95 /// transparent renderers that are equal distance from the camera. Unlike
96 /// LAYER_UI, parent-child relationship does not affect rendering order at
99 /// <since_tizen> 3 </since_tizen>
103 internal enum TreeDepthMultiplier
105 TREE_DEPTH_MULTIPLIER = 10000
109 /// Layer behavior, type String (Layer.LayerBehavior).
111 /// <since_tizen> 3 </since_tizen>
112 public Layer.LayerBehavior Behavior
116 return GetBehavior();
125 /// Sets the viewport (in window coordinates), type rectangle.
126 /// The contents of the layer will not be visible outside this box, when ViewportEnabled is true.
128 /// <since_tizen> 4 </since_tizen>
129 public Rectangle Viewport
135 Rectangle ret = new Rectangle(Interop.Layer.Layer_GetClippingBox(swigCPtr), true);
136 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
141 // Clipping not enabled so return the window size
142 Size2D windowSize = window?.Size;
143 Rectangle ret = new Rectangle(0, 0, windowSize.Width, windowSize.Height);
149 Interop.Layer.Layer_SetClippingBox__SWIG_1(swigCPtr, Rectangle.getCPtr(value));
150 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
151 ClippingEnabled = true;
156 /// Retrieves and sets the layer's opacity.<br />
158 /// <since_tizen> 3 </since_tizen>
164 GetProperty(View.Property.OPACITY).Get(out temp);
169 SetProperty(View.Property.OPACITY, new Tizen.NUI.PropertyValue(value));
174 /// Retrieves and sets the layer's visibility.
176 /// <since_tizen> 3 </since_tizen>
177 public bool Visibility
182 GetProperty(View.Property.VISIBLE).Get(out temp);
187 SetProperty(View.Property.VISIBLE, new Tizen.NUI.PropertyValue(value));
192 /// Get the number of children held by the layer.
194 /// <since_tizen> 3 </since_tizen>
195 public new uint ChildCount
199 return Convert.ToUInt32(Children.Count);
204 /// Gets or sets the layer's name.
206 /// <since_tizen> 3 </since_tizen>
220 /// Queries the depth of the layer.<br />
221 /// 0 is the bottommost layer, higher number is on the top.<br />
223 /// <since_tizen> 3 </since_tizen>
233 /// Internal only property to enable or disable clipping, type boolean.
234 /// By default, this is false, i.e., the viewport of the layer is the entire window.
236 internal bool ClippingEnabled
240 bool ret = Interop.Layer.Layer_IsClipping(swigCPtr);
241 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
246 Interop.Layer.Layer_SetClipping(swigCPtr, value);
247 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
251 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
252 [EditorBrowsable(EditorBrowsableState.Never)]
253 public ResourceDictionary XamlResources
257 return Application.Current.XamlResources;
261 Application.Current.XamlResources = value;
265 /// From the Container base class.
268 /// Adds a child view to this layer.
270 /// <seealso cref="Container.Add">
272 /// <since_tizen> 4 </since_tizen>
273 public override void Add(View child)
275 Container oldParent = child.GetParent();
277 if (oldParent != this)
279 if (oldParent != null)
281 oldParent.Remove(child);
285 child.InternalParent = this;
287 Interop.Actor.Actor_Add( swigCPtr , View.getCPtr(child));
288 if (NDalicPINVOKE.SWIGPendingException.Pending)
289 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291 BindableObject.SetInheritedBindingContext(child, this?.BindingContext);
296 /// Removes a child view from this layer. If the view was not a child of this layer, this is a no-op.
298 /// <seealso cref="Container.Remove">
300 /// <since_tizen> 4 </since_tizen>
301 public override void Remove(View child)
303 Interop.Actor.Actor_Remove( swigCPtr, View.getCPtr(child));
304 if (NDalicPINVOKE.SWIGPendingException.Pending)
305 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
307 Children.Remove(child);
308 child.InternalParent = null;
312 /// Retrieves a child view by the index.
314 /// <pre>The view has been initialized.</pre>
315 /// <param name="index">The index of the child to retrieve.</param>
316 /// <returns>The view for the given index or empty handle if children not initialized.</returns>
317 /// <since_tizen> 4 </since_tizen>
318 public override View GetChildAt(uint index)
320 if (index < Children.Count)
322 return Children[Convert.ToInt32(index)];
331 /// Get parent of the layer.
333 /// <returns>The view's container</returns>
334 /// <since_tizen> 4 </since_tizen>
335 public override Container GetParent()
341 /// Get the child count of the layer.
343 /// <returns>The child count of the layer.</returns>
344 /// <since_tizen> 4 </since_tizen>
345 public override uint GetChildCount()
347 return Convert.ToUInt32(Children.Count);
351 /// Downcasts a handle to layer handle.
353 /// <since_tizen> 3 </since_tizen>
354 /// Please do not use! this will be deprecated!
355 /// Instead please use as keyword.
356 [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead!")]
357 [EditorBrowsable(EditorBrowsableState.Never)]
358 public static Layer DownCast(BaseHandle handle)
360 Layer ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as Layer;
361 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
366 /// Search through this layer's hierarchy for a view with the given unique ID.
368 /// <pre>This layer (the parent) has been initialized.</pre>
369 /// <remarks>The actor itself is also considered in the search.</remarks>
370 /// <param name="id">The id of the child to find</param>
371 /// <returns> A handle to the view if found, or an empty handle if not. </returns>
372 /// <since_tizen> 3 </since_tizen>
373 public View FindChildById(uint id)
375 //to fix memory leak issue, match the handle count with native side.
376 IntPtr cPtr = Interop.Actor.Actor_FindChildById(swigCPtr, id);
377 HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
378 View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
379 Interop.BaseHandle.delete_BaseHandle(CPtr);
380 CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
382 if (NDalicPINVOKE.SWIGPendingException.Pending)
383 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
387 internal override View FindCurrentChildById(uint id)
389 return FindChildById(id);
392 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
393 [EditorBrowsable(EditorBrowsableState.Never)]
394 public View FindChildByName(string viewName)
396 //to fix memory leak issue, match the handle count with native side.
397 IntPtr cPtr = Interop.Actor.Actor_FindChildByName(swigCPtr, viewName);
398 HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
399 View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
400 Interop.BaseHandle.delete_BaseHandle(CPtr);
401 CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
403 if (NDalicPINVOKE.SWIGPendingException.Pending)
404 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
409 /// Increments the depth of the layer.
411 /// <since_tizen> 3 </since_tizen>
414 var parentChildren = window?.LayersChildren;
415 if (parentChildren != null)
417 int currentIdx = parentChildren.IndexOf(this);
419 if (currentIdx >= 0 && currentIdx < parentChildren.Count - 1)
421 var upper = parentChildren[currentIdx + 1];
428 /// Decrements the depth of the layer.
430 /// <since_tizen> 3 </since_tizen>
433 var parentChildren = window?.LayersChildren;
434 if (parentChildren != null)
436 int currentIdx = parentChildren.IndexOf(this);
438 if (currentIdx > 0 && currentIdx < parentChildren.Count)
440 var low = parentChildren[currentIdx - 1];
447 /// Raises the layer to the top.
449 /// <since_tizen> 3 </since_tizen>
450 public void RaiseToTop()
452 var parentChildren = window?.LayersChildren;
454 if (parentChildren != null)
456 parentChildren.Remove(this);
457 parentChildren.Add(this);
459 Interop.Layer.Layer_RaiseToTop(swigCPtr);
460 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
465 /// Lowers the layer to the bottom.
467 /// <since_tizen> 3 </since_tizen>
468 public void LowerToBottom()
470 var parentChildren = window?.LayersChildren;
472 if (parentChildren != null)
474 parentChildren.Remove(this);
475 parentChildren.Insert(0, this);
477 Interop.Layer.Layer_LowerToBottom(swigCPtr);
478 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
484 /// Moves the layer directly above the given layer.<br />
485 /// After the call, this layer's depth will be immediately above target.<br />
487 /// <param name="target">The layer to get on top of.</param>
488 /// <since_tizen> 3 </since_tizen>
489 public void MoveAbove(Layer target)
491 Interop.Layer.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
492 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
496 /// Moves the layer directly below the given layer.<br />
497 /// After the call, this layer's depth will be immediately below target.<br />
499 /// <param name="target">The layer to get below of.</param>
500 /// <since_tizen> 3 </since_tizen>
501 public void MoveBelow(Layer target)
503 Interop.Layer.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
504 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
507 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Layer obj)
509 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
512 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
513 [EditorBrowsable(EditorBrowsableState.Never)]
514 public void SetAnchorPoint(Vector3 anchorPoint)
516 Interop.Actor.Actor_SetAnchorPoint(swigCPtr, Vector3.getCPtr(anchorPoint));
517 if (NDalicPINVOKE.SWIGPendingException.Pending)
518 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
521 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
522 [EditorBrowsable(EditorBrowsableState.Never)]
523 public void SetSize(float width, float height)
525 Interop.ActorInternal.Actor_SetSize__SWIG_0(swigCPtr, width, height);
526 if (NDalicPINVOKE.SWIGPendingException.Pending)
527 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
530 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
531 [EditorBrowsable(EditorBrowsableState.Never)]
532 public void SetParentOrigin(Vector3 parentOrigin)
534 Interop.ActorInternal.Actor_SetParentOrigin(swigCPtr, Vector3.getCPtr(parentOrigin));
535 if (NDalicPINVOKE.SWIGPendingException.Pending)
536 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
539 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
540 [EditorBrowsable(EditorBrowsableState.Never)]
541 public void SetResizePolicy(ResizePolicyType policy, DimensionType dimension)
543 Interop.Actor.Actor_SetResizePolicy(swigCPtr, (int)policy, (int)dimension);
544 if (NDalicPINVOKE.SWIGPendingException.Pending)
545 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
548 internal uint GetDepth()
550 var parentChildren = window?.LayersChildren;
551 if (parentChildren != null)
553 int idx = parentChildren.IndexOf(this);
556 return Convert.ToUInt32(idx); ;
561 internal void RaiseAbove(Layer target)
563 var parentChildren = window?.LayersChildren;
564 if (parentChildren != null)
566 int currentIndex = parentChildren.IndexOf(this);
567 int targetIndex = parentChildren.IndexOf(target);
569 if (currentIndex < 0 || targetIndex < 0 ||
570 currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count)
572 NUILog.Error("index should be bigger than 0 and less than children of layer count");
576 // If the currentIndex is less than the target index and the target has the same parent.
577 if (currentIndex < targetIndex)
579 parentChildren.Remove(this);
580 parentChildren.Insert(targetIndex, this);
582 Interop.Layer.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
583 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
588 internal void LowerBelow(Layer target)
590 var parentChildren = window?.LayersChildren;
592 if (parentChildren != null)
594 int currentIndex = parentChildren.IndexOf(this);
595 int targetIndex = parentChildren.IndexOf(target);
597 if (currentIndex < 0 || targetIndex < 0 ||
598 currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count)
600 NUILog.Error("index should be bigger than 0 and less than children of layer count");
604 // If the currentIndex is not already the 0th index and the target has the same parent.
605 if ((currentIndex != 0) && (targetIndex != -1) &&
606 (currentIndex > targetIndex))
608 parentChildren.Remove(this);
609 parentChildren.Insert(targetIndex, this);
611 Interop.Layer.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
612 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
617 internal void SetSortFunction(SWIGTYPE_p_f_r_q_const__Dali__Vector3__float function)
619 Interop.Layer.Layer_SetSortFunction(swigCPtr, SWIGTYPE_p_f_r_q_const__Dali__Vector3__float.getCPtr(function));
620 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
623 internal void SetTouchConsumed(bool consume)
625 Interop.Layer.Layer_SetTouchConsumed(swigCPtr, consume);
626 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
629 internal bool IsTouchConsumed()
631 bool ret = Interop.Layer.Layer_IsTouchConsumed(swigCPtr);
632 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
636 internal void SetHoverConsumed(bool consume)
638 Interop.Layer.Layer_SetHoverConsumed(swigCPtr, consume);
639 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
642 internal bool IsHoverConsumed()
644 bool ret = Interop.Layer.Layer_IsHoverConsumed(swigCPtr);
645 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
649 internal void AddViewToLayerList(View view)
654 internal void RemoveViewFromLayerList(View view)
656 Children.Remove(view);
659 internal string GetName()
661 string ret = Interop.Actor.Actor_GetName(swigCPtr);
662 if (NDalicPINVOKE.SWIGPendingException.Pending)
663 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
667 internal void SetName(string name)
669 Interop.Actor.Actor_SetName(swigCPtr, name);
670 if (NDalicPINVOKE.SWIGPendingException.Pending)
671 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
674 internal void SetWindow(Window win)
682 /// <since_tizen> 3 </since_tizen>
683 protected override void Dispose(DisposeTypes type)
690 //Release your own unmanaged resources here.
691 //You should not access any managed member here except static instance.
692 //because the execution order of Finalizes is non-deterministic.
694 if (swigCPtr.Handle != global::System.IntPtr.Zero)
699 Interop.Layer.delete_Layer(swigCPtr);
701 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
707 private void SetBehavior(LayerBehavior behavior)
709 Interop.Layer.Layer_SetBehavior(swigCPtr, (int)behavior);
710 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
713 private LayerBehavior GetBehavior()
715 Layer.LayerBehavior ret = (Layer.LayerBehavior)Interop.Layer.Layer_GetBehavior(swigCPtr);
716 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
720 internal class Property
722 internal static readonly int BEHAVIOR = Interop.Layer.Layer_Property_BEHAVIOR_get();