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 Tizen.NUI.Binding;
25 /// Layers provide a mechanism for overlaying groups of actors on top of each other.
27 /// <since_tizen> 3 </since_tizen>
28 public class Layer : Container
30 private Window window;
33 /// Creates a Layer object.
35 /// <since_tizen> 3 </since_tizen>
36 public Layer() : this(Interop.Layer.Layer_New(), true)
38 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
39 if (Window.Instance != null)
41 this.SetAnchorPoint(Tizen.NUI.PivotPoint.TopLeft);
42 this.SetResizePolicy(ResizePolicyType.FillToParent, DimensionType.AllDimensions);
46 internal Layer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Layer.Layer_SWIGUpcast(cPtr), cMemoryOwn)
51 /// Enumeration for the behavior of the layer.
53 /// <since_tizen> 3 </since_tizen>
54 public enum LayerBehavior
57 /// UI control rendering mode (default mode).
58 /// This mode is designed for UI controls that can overlap. In this
59 /// mode renderer order will be respective to the tree hierarchy of
61 /// The rendering order is depth first, so for the following actor tree,
62 /// A will be drawn first, then B, D, E, then C, F. This ensures that
63 /// overlapping actors are drawn as expected (whereas, with breadth first
64 /// traversal, the actors would interleave).<br />
66 /// <since_tizen> 3 </since_tizen>
70 /// Deprecated in API6; Will be removed in API9. Please use LayerUI instead.
72 /// <since_tizen> 3 </since_tizen>
73 [Obsolete("Deprecated in API6; Will be removed in API9. Please use LayerUI instead.")]
74 [EditorBrowsable(EditorBrowsableState.Never)]
78 /// Layer will use depth test.
79 /// This mode is designed for a 3 dimensional scene where actors in front
80 /// of other actors will obscure them, i.e. the actors are sorted by the
81 /// distance from the camera.<br />
82 /// When using this mode, a depth test will be used. A depth clear will
83 /// happen for each layer, which means actors in a layer "above" other
84 /// layers will be rendered in front of actors in those layers regardless
85 /// of their Z positions (see Layer::Raise() and Layer::Lower()).<br />
86 /// Opaque renderers are drawn first and write to the depth buffer. Then
87 /// transparent renderers are drawn with depth test enabled but depth
88 /// write switched off. Transparent renderers are drawn based on their
89 /// distance from the camera. A renderer's DEPTH_INDEX property is used to
90 /// offset the distance to the camera when ordering transparent renderers.
91 /// This is useful if you want to define the draw order of two or more
92 /// transparent renderers that are equal distance from the camera. Unlike
93 /// LAYER_UI, parent-child relationship does not affect rendering order at
96 /// <since_tizen> 3 </since_tizen>
100 internal enum TreeDepthMultiplier
102 TREE_DEPTH_MULTIPLIER = 10000
106 /// Layer behavior, type String (Layer.LayerBehavior).
108 /// <since_tizen> 3 </since_tizen>
109 public Layer.LayerBehavior Behavior
113 return GetBehavior();
122 /// Sets the viewport (in window coordinates), type rectangle.
123 /// The contents of the layer will not be visible outside this box, when ViewportEnabled is true.
125 /// <since_tizen> 4 </since_tizen>
126 public Rectangle Viewport
132 Rectangle ret = new Rectangle(Interop.Layer.Layer_GetClippingBox(swigCPtr), true);
133 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
138 // Clipping not enabled so return the window size
139 Size2D windowSize = window?.Size;
140 Rectangle ret = new Rectangle(0, 0, windowSize.Width, windowSize.Height);
146 Interop.Layer.Layer_SetClippingBox__SWIG_1(swigCPtr, Rectangle.getCPtr(value));
147 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
148 ClippingEnabled = true;
153 /// Retrieves and sets the layer's opacity.<br />
155 /// <since_tizen> 3 </since_tizen>
161 GetProperty(View.Property.OPACITY).Get(out temp);
166 SetProperty(View.Property.OPACITY, new Tizen.NUI.PropertyValue(value));
171 /// Retrieves and sets the layer's visibility.
173 /// <since_tizen> 3 </since_tizen>
174 public bool Visibility
179 GetProperty(View.Property.VISIBLE).Get(out temp);
184 SetProperty(View.Property.VISIBLE, new Tizen.NUI.PropertyValue(value));
189 /// Get the number of children held by the layer.
191 /// <since_tizen> 3 </since_tizen>
192 public new uint ChildCount
196 return Convert.ToUInt32(Children.Count);
201 /// Gets or sets the layer's name.
203 /// <since_tizen> 3 </since_tizen>
217 /// Queries the depth of the layer.<br />
218 /// 0 is the bottommost layer, higher number is on the top.<br />
220 /// <since_tizen> 3 </since_tizen>
230 /// Internal only property to enable or disable clipping, type boolean.
231 /// By default, this is false, i.e., the viewport of the layer is the entire window.
233 internal bool ClippingEnabled
237 bool ret = Interop.Layer.Layer_IsClipping(swigCPtr);
238 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
243 Interop.Layer.Layer_SetClipping(swigCPtr, value);
244 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
249 [EditorBrowsable(EditorBrowsableState.Never)]
250 public ResourceDictionary XamlResources
254 return Application.Current.XamlResources;
258 Application.Current.XamlResources = value;
262 /// From the Container base class.
265 /// Adds a child view to this layer.
267 /// <seealso cref="Container.Add">
269 /// <since_tizen> 4 </since_tizen>
270 public override void Add(View child)
272 Container oldParent = child.GetParent();
274 if (oldParent != this)
276 if (oldParent != null)
278 oldParent.Remove(child);
282 child.InternalParent = this;
284 Interop.Actor.Actor_Add( swigCPtr , View.getCPtr(child));
285 if (NDalicPINVOKE.SWIGPendingException.Pending)
286 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288 BindableObject.SetInheritedBindingContext(child, this?.BindingContext);
293 /// Removes a child view from this layer. If the view was not a child of this layer, this is a no-op.
295 /// <seealso cref="Container.Remove">
297 /// <since_tizen> 4 </since_tizen>
298 public override void Remove(View child)
300 Interop.Actor.Actor_Remove( swigCPtr, View.getCPtr(child));
301 if (NDalicPINVOKE.SWIGPendingException.Pending)
302 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304 Children.Remove(child);
305 child.InternalParent = null;
309 /// Retrieves a child view by the index.
311 /// <pre>The view has been initialized.</pre>
312 /// <param name="index">The index of the child to retrieve.</param>
313 /// <returns>The view for the given index or empty handle if children not initialized.</returns>
314 /// <since_tizen> 4 </since_tizen>
315 public override View GetChildAt(uint index)
317 if (index < Children.Count)
319 return Children[Convert.ToInt32(index)];
328 /// Get parent of the layer.
330 /// <returns>The view's container</returns>
331 /// <since_tizen> 4 </since_tizen>
332 public override Container GetParent()
338 /// Get the child count of the layer.
340 /// <returns>The child count of the layer.</returns>
341 /// <since_tizen> 4 </since_tizen>
342 public override uint GetChildCount()
344 return Convert.ToUInt32(Children.Count);
348 /// Downcasts a handle to layer handle.
350 /// <since_tizen> 3 </since_tizen>
351 /// Please do not use! this will be deprecated!
352 /// Instead please use as keyword.
353 [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead!")]
354 [EditorBrowsable(EditorBrowsableState.Never)]
355 public static Layer DownCast(BaseHandle handle)
357 Layer ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as Layer;
358 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
363 /// Search through this layer's hierarchy for a view with the given unique ID.
365 /// <pre>This layer (the parent) has been initialized.</pre>
366 /// <remarks>The actor itself is also considered in the search.</remarks>
367 /// <param name="id">The id of the child to find</param>
368 /// <returns> A handle to the view if found, or an empty handle if not. </returns>
369 /// <since_tizen> 3 </since_tizen>
370 public View FindChildById(uint id)
372 //to fix memory leak issue, match the handle count with native side.
373 IntPtr cPtr = Interop.Actor.Actor_FindChildById(swigCPtr, id);
374 View ret = this.GetInstanceSafely<View>(cPtr);
375 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
379 internal override View FindCurrentChildById(uint id)
381 return FindChildById(id);
384 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
385 [EditorBrowsable(EditorBrowsableState.Never)]
386 public View FindChildByName(string viewName)
388 //to fix memory leak issue, match the handle count with native side.
389 IntPtr cPtr = Interop.Actor.Actor_FindChildByName(swigCPtr, viewName);
390 View ret = this.GetInstanceSafely<View>(cPtr);
391 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
396 /// Increments the depth of the layer.
398 /// <since_tizen> 3 </since_tizen>
401 var parentChildren = window?.LayersChildren;
402 if (parentChildren != null)
404 int currentIdx = parentChildren.IndexOf(this);
406 if (currentIdx >= 0 && currentIdx < parentChildren.Count - 1)
408 var upper = parentChildren[currentIdx + 1];
415 /// Decrements the depth of the layer.
417 /// <since_tizen> 3 </since_tizen>
420 var parentChildren = window?.LayersChildren;
421 if (parentChildren != null)
423 int currentIdx = parentChildren.IndexOf(this);
425 if (currentIdx > 0 && currentIdx < parentChildren.Count)
427 var low = parentChildren[currentIdx - 1];
434 /// Raises the layer to the top.
436 /// <since_tizen> 3 </since_tizen>
437 public void RaiseToTop()
439 var parentChildren = window?.LayersChildren;
441 if (parentChildren != null)
443 parentChildren.Remove(this);
444 parentChildren.Add(this);
446 Interop.Layer.Layer_RaiseToTop(swigCPtr);
447 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
452 /// Lowers the layer to the bottom.
454 /// <since_tizen> 3 </since_tizen>
455 public void LowerToBottom()
457 var parentChildren = window?.LayersChildren;
459 if (parentChildren != null)
461 parentChildren.Remove(this);
462 parentChildren.Insert(0, this);
464 Interop.Layer.Layer_LowerToBottom(swigCPtr);
465 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
470 /// Moves the layer directly above the given layer.<br />
471 /// After the call, this layer's depth will be immediately above target.<br />
473 /// <param name="target">The layer to get on top of.</param>
474 /// <since_tizen> 3 </since_tizen>
475 public void MoveAbove(Layer target)
477 Interop.Layer.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
478 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
482 /// Moves the layer directly below the given layer.<br />
483 /// After the call, this layer's depth will be immediately below target.<br />
485 /// <param name="target">The layer to get below of.</param>
486 /// <since_tizen> 3 </since_tizen>
487 public void MoveBelow(Layer target)
489 Interop.Layer.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
490 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
493 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Layer obj)
495 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
498 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
499 [EditorBrowsable(EditorBrowsableState.Never)]
500 public void SetAnchorPoint(Vector3 anchorPoint)
502 Interop.Actor.Actor_SetAnchorPoint(swigCPtr, Vector3.getCPtr(anchorPoint));
503 if (NDalicPINVOKE.SWIGPendingException.Pending)
504 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
507 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
508 [EditorBrowsable(EditorBrowsableState.Never)]
509 public void SetSize(float width, float height)
511 Interop.ActorInternal.Actor_SetSize__SWIG_0(swigCPtr, width, height);
512 if (NDalicPINVOKE.SWIGPendingException.Pending)
513 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
516 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
517 [EditorBrowsable(EditorBrowsableState.Never)]
518 public void SetParentOrigin(Vector3 parentOrigin)
520 Interop.ActorInternal.Actor_SetParentOrigin(swigCPtr, Vector3.getCPtr(parentOrigin));
521 if (NDalicPINVOKE.SWIGPendingException.Pending)
522 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
525 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
526 [EditorBrowsable(EditorBrowsableState.Never)]
527 public void SetResizePolicy(ResizePolicyType policy, DimensionType dimension)
529 Interop.Actor.Actor_SetResizePolicy(swigCPtr, (int)policy, (int)dimension);
530 if (NDalicPINVOKE.SWIGPendingException.Pending)
531 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
534 internal uint GetDepth()
536 var parentChildren = window?.LayersChildren;
537 if (parentChildren != null)
539 int idx = parentChildren.IndexOf(this);
542 return Convert.ToUInt32(idx); ;
547 internal void RaiseAbove(Layer target)
549 var parentChildren = window?.LayersChildren;
550 if (parentChildren != null)
552 int currentIndex = parentChildren.IndexOf(this);
553 int targetIndex = parentChildren.IndexOf(target);
555 if (currentIndex < 0 || targetIndex < 0 ||
556 currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count)
558 NUILog.Error("index should be bigger than 0 and less than children of layer count");
562 // If the currentIndex is less than the target index and the target has the same parent.
563 if (currentIndex < targetIndex)
565 parentChildren.Remove(this);
566 parentChildren.Insert(targetIndex, this);
568 Interop.Layer.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
569 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
574 internal void LowerBelow(Layer target)
576 var parentChildren = window?.LayersChildren;
578 if (parentChildren != null)
580 int currentIndex = parentChildren.IndexOf(this);
581 int targetIndex = parentChildren.IndexOf(target);
583 if (currentIndex < 0 || targetIndex < 0 ||
584 currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count)
586 NUILog.Error("index should be bigger than 0 and less than children of layer count");
590 // If the currentIndex is not already the 0th index and the target has the same parent.
591 if ((currentIndex != 0) && (targetIndex != -1) &&
592 (currentIndex > targetIndex))
594 parentChildren.Remove(this);
595 parentChildren.Insert(targetIndex, this);
597 Interop.Layer.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
598 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
603 internal void SetSortFunction(SWIGTYPE_p_f_r_q_const__Dali__Vector3__float function)
605 Interop.Layer.Layer_SetSortFunction(swigCPtr, SWIGTYPE_p_f_r_q_const__Dali__Vector3__float.getCPtr(function));
606 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
609 internal void SetTouchConsumed(bool consume)
611 Interop.Layer.Layer_SetTouchConsumed(swigCPtr, consume);
612 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
615 internal bool IsTouchConsumed()
617 bool ret = Interop.Layer.Layer_IsTouchConsumed(swigCPtr);
618 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
622 internal void SetHoverConsumed(bool consume)
624 Interop.Layer.Layer_SetHoverConsumed(swigCPtr, consume);
625 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
628 internal bool IsHoverConsumed()
630 bool ret = Interop.Layer.Layer_IsHoverConsumed(swigCPtr);
631 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
635 internal void AddViewToLayerList(View view)
640 internal void RemoveViewFromLayerList(View view)
642 Children.Remove(view);
645 internal string GetName()
647 string ret = Interop.Actor.Actor_GetName(swigCPtr);
648 if (NDalicPINVOKE.SWIGPendingException.Pending)
649 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
653 internal void SetName(string name)
655 Interop.Actor.Actor_SetName(swigCPtr, name);
656 if (NDalicPINVOKE.SWIGPendingException.Pending)
657 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
660 internal void SetWindow(Window win)
665 /// This will not be public opened.
666 [EditorBrowsable(EditorBrowsableState.Never)]
667 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
669 Interop.Layer.delete_Layer(swigCPtr);
672 private void SetBehavior(LayerBehavior behavior)
674 Interop.Layer.Layer_SetBehavior(swigCPtr, (int)behavior);
675 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
678 private LayerBehavior GetBehavior()
680 Layer.LayerBehavior ret = (Layer.LayerBehavior)Interop.Layer.Layer_GetBehavior(swigCPtr);
681 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
685 internal class Property
687 internal static readonly int BEHAVIOR = Interop.Layer.Layer_Property_BEHAVIOR_get();