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 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.Layer_SWIGUpcast(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.Layer_GetClippingBox(swigCPtr), true);
130 if (NDalicPINVOKE.SWIGPendingException.Pending) throw 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.Layer_SetClippingBox__SWIG_1(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.Layer_IsClipping(swigCPtr);
235 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
240 Interop.Layer.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 /// <since_tizen> 4 </since_tizen>
267 public override void Add(View child)
269 Container oldParent = child.GetParent();
271 if (oldParent != this)
273 if (oldParent != null)
275 oldParent.Remove(child);
279 child.InternalParent = this;
281 Interop.Actor.Actor_Add( swigCPtr , View.getCPtr(child));
282 if (NDalicPINVOKE.SWIGPendingException.Pending)
283 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285 BindableObject.SetInheritedBindingContext(child, this?.BindingContext);
290 /// Removes a child view from this layer. If the view was not a child of this layer, this is a no-op.
292 /// <seealso cref="Container.Remove">
294 /// <since_tizen> 4 </since_tizen>
295 public override void Remove(View child)
297 Interop.Actor.Actor_Remove( swigCPtr, View.getCPtr(child));
298 if (NDalicPINVOKE.SWIGPendingException.Pending)
299 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301 Children.Remove(child);
302 child.InternalParent = null;
306 /// Retrieves a child view by the index.
308 /// <pre>The view has been initialized.</pre>
309 /// <param name="index">The index of the child to retrieve.</param>
310 /// <returns>The view for the given index or empty handle if children not initialized.</returns>
311 /// <since_tizen> 4 </since_tizen>
312 public override View GetChildAt(uint index)
314 if (index < Children.Count)
316 return Children[Convert.ToInt32(index)];
325 /// Get parent of the layer.
327 /// <returns>The view's container</returns>
328 /// <since_tizen> 4 </since_tizen>
329 public override Container GetParent()
335 /// Get the child count of the layer.
337 /// <returns>The child count of the layer.</returns>
338 /// <since_tizen> 4 </since_tizen>
339 public override uint GetChildCount()
341 return Convert.ToUInt32(Children.Count);
345 /// Downcasts a handle to layer handle.
347 /// <since_tizen> 3 </since_tizen>
348 /// Please do not use! this will be deprecated!
349 /// Instead please use as keyword.
350 [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead!")]
351 [EditorBrowsable(EditorBrowsableState.Never)]
352 public static Layer DownCast(BaseHandle handle)
354 Layer ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as Layer;
355 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
360 /// Search through this layer's hierarchy for a view with the given unique ID.
362 /// <pre>This layer (the parent) has been initialized.</pre>
363 /// <remarks>The actor itself is also considered in the search.</remarks>
364 /// <param name="id">The id of the child to find</param>
365 /// <returns> A handle to the view if found, or an empty handle if not. </returns>
366 /// <since_tizen> 3 </since_tizen>
367 public View FindChildById(uint id)
369 //to fix memory leak issue, match the handle count with native side.
370 IntPtr cPtr = Interop.Actor.Actor_FindChildById(swigCPtr, id);
371 View ret = this.GetInstanceSafely<View>(cPtr);
372 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376 internal override View FindCurrentChildById(uint id)
378 return FindChildById(id);
381 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
382 [EditorBrowsable(EditorBrowsableState.Never)]
383 public View FindChildByName(string viewName)
385 //to fix memory leak issue, match the handle count with native side.
386 IntPtr cPtr = Interop.Actor.Actor_FindChildByName(swigCPtr, viewName);
387 View ret = this.GetInstanceSafely<View>(cPtr);
388 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
393 /// Increments the depth of the layer.
395 /// <since_tizen> 3 </since_tizen>
398 var parentChildren = window?.LayersChildren;
399 if (parentChildren != null)
401 int currentIdx = parentChildren.IndexOf(this);
403 if (currentIdx >= 0 && currentIdx < parentChildren.Count - 1)
405 var upper = parentChildren[currentIdx + 1];
412 /// Decrements the depth of the layer.
414 /// <since_tizen> 3 </since_tizen>
417 var parentChildren = window?.LayersChildren;
418 if (parentChildren != null)
420 int currentIdx = parentChildren.IndexOf(this);
422 if (currentIdx > 0 && currentIdx < parentChildren.Count)
424 var low = parentChildren[currentIdx - 1];
431 /// Raises the layer to the top.
433 /// <since_tizen> 3 </since_tizen>
434 public void RaiseToTop()
436 var parentChildren = window?.LayersChildren;
438 if (parentChildren != null)
440 parentChildren.Remove(this);
441 parentChildren.Add(this);
443 Interop.Layer.Layer_RaiseToTop(swigCPtr);
444 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
449 /// Lowers the layer to the bottom.
451 /// <since_tizen> 3 </since_tizen>
452 public void LowerToBottom()
454 var parentChildren = window?.LayersChildren;
456 if (parentChildren != null)
458 parentChildren.Remove(this);
459 parentChildren.Insert(0, this);
461 Interop.Layer.Layer_LowerToBottom(swigCPtr);
462 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
467 /// Moves the layer directly above the given layer.<br />
468 /// After the call, this layer's depth will be immediately above target.<br />
470 /// <param name="target">The layer to get on top of.</param>
471 /// <since_tizen> 3 </since_tizen>
472 public void MoveAbove(Layer target)
474 Interop.Layer.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
475 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
479 /// Moves the layer directly below the given layer.<br />
480 /// After the call, this layer's depth will be immediately below target.<br />
482 /// <param name="target">The layer to get below of.</param>
483 /// <since_tizen> 3 </since_tizen>
484 public void MoveBelow(Layer target)
486 Interop.Layer.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
487 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
490 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Layer obj)
492 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
495 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
496 [EditorBrowsable(EditorBrowsableState.Never)]
497 public void SetAnchorPoint(Vector3 anchorPoint)
499 Interop.Actor.Actor_SetAnchorPoint(swigCPtr, Vector3.getCPtr(anchorPoint));
500 if (NDalicPINVOKE.SWIGPendingException.Pending)
501 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
504 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
505 [EditorBrowsable(EditorBrowsableState.Never)]
506 public void SetSize(float width, float height)
508 Interop.ActorInternal.Actor_SetSize__SWIG_0(swigCPtr, width, height);
509 if (NDalicPINVOKE.SWIGPendingException.Pending)
510 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
513 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
514 [EditorBrowsable(EditorBrowsableState.Never)]
515 public void SetParentOrigin(Vector3 parentOrigin)
517 Interop.ActorInternal.Actor_SetParentOrigin(swigCPtr, Vector3.getCPtr(parentOrigin));
518 if (NDalicPINVOKE.SWIGPendingException.Pending)
519 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
522 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
523 [EditorBrowsable(EditorBrowsableState.Never)]
524 public void SetResizePolicy(ResizePolicyType policy, DimensionType dimension)
526 Interop.Actor.Actor_SetResizePolicy(swigCPtr, (int)policy, (int)dimension);
527 if (NDalicPINVOKE.SWIGPendingException.Pending)
528 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
531 internal uint GetDepth()
533 var parentChildren = window?.LayersChildren;
534 if (parentChildren != null)
536 int idx = parentChildren.IndexOf(this);
539 return Convert.ToUInt32(idx); ;
544 internal void RaiseAbove(Layer target)
546 var parentChildren = window?.LayersChildren;
547 if (parentChildren != null)
549 int currentIndex = parentChildren.IndexOf(this);
550 int targetIndex = parentChildren.IndexOf(target);
552 if (currentIndex < 0 || targetIndex < 0 ||
553 currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count)
555 NUILog.Error("index should be bigger than 0 and less than children of layer count");
559 // If the currentIndex is less than the target index and the target has the same parent.
560 if (currentIndex < targetIndex)
562 parentChildren.Remove(this);
563 parentChildren.Insert(targetIndex, this);
565 Interop.Layer.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
566 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
571 internal void LowerBelow(Layer target)
573 var parentChildren = window?.LayersChildren;
575 if (parentChildren != null)
577 int currentIndex = parentChildren.IndexOf(this);
578 int targetIndex = parentChildren.IndexOf(target);
580 if (currentIndex < 0 || targetIndex < 0 ||
581 currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count)
583 NUILog.Error("index should be bigger than 0 and less than children of layer count");
587 // If the currentIndex is not already the 0th index and the target has the same parent.
588 if ((currentIndex != 0) && (targetIndex != -1) &&
589 (currentIndex > targetIndex))
591 parentChildren.Remove(this);
592 parentChildren.Insert(targetIndex, this);
594 Interop.Layer.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
595 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
600 internal void SetSortFunction(SWIGTYPE_p_f_r_q_const__Dali__Vector3__float function)
602 Interop.Layer.Layer_SetSortFunction(swigCPtr, SWIGTYPE_p_f_r_q_const__Dali__Vector3__float.getCPtr(function));
603 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
606 internal void SetTouchConsumed(bool consume)
608 Interop.Layer.Layer_SetTouchConsumed(swigCPtr, consume);
609 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
612 internal bool IsTouchConsumed()
614 bool ret = Interop.Layer.Layer_IsTouchConsumed(swigCPtr);
615 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
619 internal void SetHoverConsumed(bool consume)
621 Interop.Layer.Layer_SetHoverConsumed(swigCPtr, consume);
622 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
625 internal bool IsHoverConsumed()
627 bool ret = Interop.Layer.Layer_IsHoverConsumed(swigCPtr);
628 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
632 internal void AddViewToLayerList(View view)
637 internal void RemoveViewFromLayerList(View view)
639 Children.Remove(view);
642 internal string GetName()
644 string ret = Interop.Actor.Actor_GetName(swigCPtr);
645 if (NDalicPINVOKE.SWIGPendingException.Pending)
646 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
650 internal void SetName(string name)
652 Interop.Actor.Actor_SetName(swigCPtr, name);
653 if (NDalicPINVOKE.SWIGPendingException.Pending)
654 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
657 internal void SetWindow(Window win)
662 /// This will not be public opened.
663 [EditorBrowsable(EditorBrowsableState.Never)]
664 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
666 Interop.Layer.delete_Layer(swigCPtr);
669 private void SetBehavior(LayerBehavior behavior)
671 Interop.Layer.Layer_SetBehavior(swigCPtr, (int)behavior);
672 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
675 private LayerBehavior GetBehavior()
677 Layer.LayerBehavior ret = (Layer.LayerBehavior)Interop.Layer.Layer_GetBehavior(swigCPtr);
678 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
682 internal class Property
684 internal static readonly int BEHAVIOR = Interop.Layer.Layer_Property_BEHAVIOR_get();