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.New(), true)
38 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
39 this.SetAnchorPoint(Tizen.NUI.PivotPoint.TopLeft);
40 this.SetResizePolicy(ResizePolicyType.FillToParent, DimensionType.AllDimensions);
43 internal Layer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Layer.Upcast(cPtr), cMemoryOwn)
48 /// Enumeration for the behavior of the layer.
50 /// <since_tizen> 3 </since_tizen>
51 public enum LayerBehavior
54 /// UI control rendering mode (default mode).
55 /// This mode is designed for UI controls that can overlap. In this
56 /// mode renderer order will be respective to the tree hierarchy of
58 /// The rendering order is depth first, so for the following actor tree,
59 /// A will be drawn first, then B, D, E, then C, F. This ensures that
60 /// overlapping actors are drawn as expected (whereas, with breadth first
61 /// traversal, the actors would interleave).<br />
63 /// <since_tizen> 3 </since_tizen>
67 /// Deprecated in API6; Will be removed in API9. Please use LayerUI instead.
69 /// <since_tizen> 3 </since_tizen>
70 [Obsolete("Deprecated in API6; Will be removed in API9. Please use LayerUI instead.")]
71 [EditorBrowsable(EditorBrowsableState.Never)]
75 /// Layer will use depth test.
76 /// This mode is designed for a 3 dimensional scene where actors in front
77 /// of other actors will obscure them, i.e. the actors are sorted by the
78 /// distance from the camera.<br />
79 /// When using this mode, a depth test will be used. A depth clear will
80 /// happen for each layer, which means actors in a layer "above" other
81 /// layers will be rendered in front of actors in those layers regardless
82 /// of their Z positions (see Layer::Raise() and Layer::Lower()).<br />
83 /// Opaque renderers are drawn first and write to the depth buffer. Then
84 /// transparent renderers are drawn with depth test enabled but depth
85 /// write switched off. Transparent renderers are drawn based on their
86 /// distance from the camera. A renderer's DEPTH_INDEX property is used to
87 /// offset the distance to the camera when ordering transparent renderers.
88 /// This is useful if you want to define the draw order of two or more
89 /// transparent renderers that are equal distance from the camera. Unlike
90 /// LAYER_UI, parent-child relationship does not affect rendering order at
93 /// <since_tizen> 3 </since_tizen>
97 internal enum TreeDepthMultiplier
99 TREE_DEPTH_MULTIPLIER = 10000
103 /// Layer behavior, type String (Layer.LayerBehavior).
105 /// <since_tizen> 3 </since_tizen>
106 public Layer.LayerBehavior Behavior
110 return GetBehavior();
119 /// Sets the viewport (in window coordinates), type rectangle.
120 /// The contents of the layer will not be visible outside this box, when ViewportEnabled is true.
122 /// <since_tizen> 4 </since_tizen>
123 public Rectangle Viewport
129 Rectangle ret = new Rectangle(Interop.Layer.GetClippingBox(swigCPtr), true);
130 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
135 // Clipping not enabled so return the window size
136 Size2D windowSize = window?.Size;
137 Rectangle ret = new Rectangle(0, 0, windowSize.Width, windowSize.Height);
143 Interop.Layer.SetClippingBox(swigCPtr, Rectangle.getCPtr(value));
144 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
145 ClippingEnabled = true;
150 /// Retrieves and sets the layer's opacity.<br />
152 /// <since_tizen> 3 </since_tizen>
158 GetProperty(View.Property.OPACITY).Get(out temp);
163 SetProperty(View.Property.OPACITY, new Tizen.NUI.PropertyValue(value));
168 /// Retrieves and sets the layer's visibility.
170 /// <since_tizen> 3 </since_tizen>
171 public bool Visibility
176 GetProperty(View.Property.VISIBLE).Get(out temp);
181 SetProperty(View.Property.VISIBLE, new Tizen.NUI.PropertyValue(value));
186 /// Get the number of children held by the layer.
188 /// <since_tizen> 3 </since_tizen>
189 public new uint ChildCount
193 return Convert.ToUInt32(Children.Count);
198 /// Gets or sets the layer's name.
200 /// <since_tizen> 3 </since_tizen>
214 /// Queries the depth of the layer.<br />
215 /// 0 is the bottommost layer, higher number is on the top.<br />
217 /// <since_tizen> 3 </since_tizen>
227 /// Internal only property to enable or disable clipping, type boolean.
228 /// By default, this is false, i.e., the viewport of the layer is the entire window.
230 internal bool ClippingEnabled
234 bool ret = Interop.Layer.IsClipping(swigCPtr);
235 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
240 Interop.Layer.SetClipping(swigCPtr, value);
241 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
246 [EditorBrowsable(EditorBrowsableState.Never)]
247 public ResourceDictionary XamlResources
251 return Application.Current.XamlResources;
255 Application.Current.XamlResources = value;
259 /// From the Container base class.
262 /// Adds a child view to this layer.
264 /// <seealso cref="Container.Add">
266 /// <exception cref="ArgumentNullException"> Thrown when child is null. </exception>
267 /// <since_tizen> 4 </since_tizen>
268 public override void Add(View child)
272 throw new ArgumentNullException(nameof(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.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 /// <exception cref="ArgumentNullException"> Thrown when child is null. </exception>
301 /// <since_tizen> 4 </since_tizen>
302 public override void Remove(View child)
306 throw new ArgumentNullException(nameof(child));
308 Interop.Actor.Remove( swigCPtr, View.getCPtr(child));
309 if (NDalicPINVOKE.SWIGPendingException.Pending)
310 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
312 Children.Remove(child);
313 child.InternalParent = null;
317 /// Retrieves a child view by the index.
319 /// <pre>The view has been initialized.</pre>
320 /// <param name="index">The index of the child to retrieve.</param>
321 /// <returns>The view for the given index or empty handle if children not initialized.</returns>
322 /// <since_tizen> 4 </since_tizen>
323 public override View GetChildAt(uint index)
325 if (index < Children.Count)
327 return Children[Convert.ToInt32(index)];
336 /// Get parent of the layer.
338 /// <returns>The view's container</returns>
339 /// <since_tizen> 4 </since_tizen>
340 public override Container GetParent()
346 /// Get the child count of the layer.
348 /// <returns>The child count of the layer.</returns>
349 /// <since_tizen> 4 </since_tizen>
350 public override uint GetChildCount()
352 return Convert.ToUInt32(Children.Count);
356 /// Downcasts a handle to layer handle.
358 /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
359 /// <since_tizen> 3 </since_tizen>
360 /// Please do not use! this will be deprecated!
361 /// Instead please use as keyword.
362 [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead!")]
363 [EditorBrowsable(EditorBrowsableState.Never)]
364 public static Layer DownCast(BaseHandle handle)
368 throw new ArgumentNullException(nameof(handle));
370 Layer ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as Layer;
371 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376 /// Search through this layer's hierarchy for a view with the given unique ID.
378 /// <pre>This layer (the parent) has been initialized.</pre>
379 /// <remarks>The actor itself is also considered in the search.</remarks>
380 /// <param name="id">The id of the child to find</param>
381 /// <returns> A handle to the view if found, or an empty handle if not. </returns>
382 /// <since_tizen> 3 </since_tizen>
383 public View FindChildById(uint id)
385 //to fix memory leak issue, match the handle count with native side.
386 IntPtr cPtr = Interop.Actor.FindChildById(swigCPtr, id);
387 View ret = this.GetInstanceSafely<View>(cPtr);
388 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
392 internal override View FindCurrentChildById(uint id)
394 return FindChildById(id);
397 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
398 [EditorBrowsable(EditorBrowsableState.Never)]
399 public View FindChildByName(string viewName)
401 //to fix memory leak issue, match the handle count with native side.
402 IntPtr cPtr = Interop.Actor.FindChildByName(swigCPtr, viewName);
403 View ret = this.GetInstanceSafely<View>(cPtr);
404 if (NDalicPINVOKE.SWIGPendingException.Pending) 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.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.LowerToBottom(swigCPtr);
478 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
483 /// Moves the layer directly above the given layer.<br />
484 /// After the call, this layer's depth will be immediately above target.<br />
486 /// <param name="target">The layer to get on top of.</param>
487 /// <since_tizen> 3 </since_tizen>
488 public void MoveAbove(Layer target)
490 Interop.Layer.MoveAbove(swigCPtr, Layer.getCPtr(target));
491 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
495 /// Moves the layer directly below the given layer.<br />
496 /// After the call, this layer's depth will be immediately below target.<br />
498 /// <param name="target">The layer to get below of.</param>
499 /// <since_tizen> 3 </since_tizen>
500 public void MoveBelow(Layer target)
502 Interop.Layer.MoveBelow(swigCPtr, Layer.getCPtr(target));
503 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
506 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Layer obj)
508 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
511 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
512 [EditorBrowsable(EditorBrowsableState.Never)]
513 public void SetAnchorPoint(Vector3 anchorPoint)
515 Interop.Actor.SetAnchorPoint(swigCPtr, Vector3.getCPtr(anchorPoint));
516 if (NDalicPINVOKE.SWIGPendingException.Pending)
517 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
520 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
521 [EditorBrowsable(EditorBrowsableState.Never)]
522 public void SetSize(float width, float height)
524 Interop.ActorInternal.SetSize(swigCPtr, width, height);
525 if (NDalicPINVOKE.SWIGPendingException.Pending)
526 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
529 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
530 [EditorBrowsable(EditorBrowsableState.Never)]
531 public void SetParentOrigin(Vector3 parentOrigin)
533 Interop.ActorInternal.SetParentOrigin(swigCPtr, Vector3.getCPtr(parentOrigin));
534 if (NDalicPINVOKE.SWIGPendingException.Pending)
535 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
538 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
539 [EditorBrowsable(EditorBrowsableState.Never)]
540 public void SetResizePolicy(ResizePolicyType policy, DimensionType dimension)
542 Interop.Actor.SetResizePolicy(swigCPtr, (int)policy, (int)dimension);
543 if (NDalicPINVOKE.SWIGPendingException.Pending)
544 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
549 /// This allows the user to specify whether this layer should consume touch (including gestures).
550 /// If set, any layers behind this layer will not be hit-test.
552 /// <param name="consume">Whether the layer should consume touch (including gestures).</param>
553 [EditorBrowsable(EditorBrowsableState.Never)]
554 public void SetTouchConsumed(bool consume)
556 Interop.Layer.SetTouchConsumed(swigCPtr, consume);
557 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
562 /// This allows the user to specify whether this layer should consume hover.
563 /// If set, any layers behind this layer will not be hit-test.
565 /// <param name="consume">Whether the layer should consume hover</param>
566 [EditorBrowsable(EditorBrowsableState.Never)]
567 public void SetHoverConsumed(bool consume)
569 Interop.Layer.SetHoverConsumed(swigCPtr, consume);
570 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
573 internal uint GetDepth()
575 var parentChildren = window?.LayersChildren;
576 if (parentChildren != null)
578 int idx = parentChildren.IndexOf(this);
581 return Convert.ToUInt32(idx); ;
586 internal void RaiseAbove(Layer target)
588 var parentChildren = window?.LayersChildren;
589 if (parentChildren != null)
591 int currentIndex = parentChildren.IndexOf(this);
592 int targetIndex = parentChildren.IndexOf(target);
594 if (currentIndex < 0 || targetIndex < 0 ||
595 currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count)
597 NUILog.Error("index should be bigger than 0 and less than children of layer count");
601 // If the currentIndex is less than the target index and the target has the same parent.
602 if (currentIndex < targetIndex)
604 parentChildren.Remove(this);
605 parentChildren.Insert(targetIndex, this);
607 Interop.Layer.MoveAbove(swigCPtr, Layer.getCPtr(target));
608 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
613 internal void LowerBelow(Layer target)
615 var parentChildren = window?.LayersChildren;
617 if (parentChildren != null)
619 int currentIndex = parentChildren.IndexOf(this);
620 int targetIndex = parentChildren.IndexOf(target);
622 if (currentIndex < 0 || targetIndex < 0 ||
623 currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count)
625 NUILog.Error("index should be bigger than 0 and less than children of layer count");
629 // If the currentIndex is not already the 0th index and the target has the same parent.
630 if ((currentIndex != 0) && (targetIndex != -1) &&
631 (currentIndex > targetIndex))
633 parentChildren.Remove(this);
634 parentChildren.Insert(targetIndex, this);
636 Interop.Layer.MoveBelow(swigCPtr, Layer.getCPtr(target));
637 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
642 internal void SetSortFunction(SWIGTYPE_p_f_r_q_const__Dali__Vector3__float function)
644 Interop.Layer.SetSortFunction(swigCPtr, SWIGTYPE_p_f_r_q_const__Dali__Vector3__float.getCPtr(function));
645 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
648 internal bool IsTouchConsumed()
650 bool ret = Interop.Layer.IsTouchConsumed(swigCPtr);
651 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
654 internal bool IsHoverConsumed()
656 bool ret = Interop.Layer.IsHoverConsumed(swigCPtr);
657 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
661 internal void AddViewToLayerList(View view)
666 internal void RemoveViewFromLayerList(View view)
668 Children.Remove(view);
671 internal string GetName()
673 string ret = Interop.Actor.GetName(swigCPtr);
674 if (NDalicPINVOKE.SWIGPendingException.Pending)
675 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
679 internal void SetName(string name)
681 Interop.Actor.SetName(swigCPtr, name);
682 if (NDalicPINVOKE.SWIGPendingException.Pending)
683 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
686 internal void SetWindow(Window win)
691 /// This will not be public opened.
692 [EditorBrowsable(EditorBrowsableState.Never)]
693 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
695 Interop.Layer.DeleteLayer(swigCPtr);
698 private void SetBehavior(LayerBehavior behavior)
700 Interop.Layer.SetBehavior(swigCPtr, (int)behavior);
701 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
704 private LayerBehavior GetBehavior()
706 Layer.LayerBehavior ret = (Layer.LayerBehavior)Interop.Layer.GetBehavior(swigCPtr);
707 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
711 internal class Property
713 internal static readonly int BEHAVIOR = Interop.Layer.BehaviorGet();