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;
27 /// Layers provide a mechanism for overlaying groups of actors on top of each other.
29 /// <since_tizen> 3 </since_tizen>
30 public class Layer : Container
32 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
33 private Window window;
36 /// Creates a Layer object.
38 /// <since_tizen> 3 </since_tizen>
39 public Layer() : this(Interop.Layer.Layer_New(), true)
41 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
42 if (Window.Instance != null)
44 this.SetAnchorPoint(Tizen.NUI.PivotPoint.TopLeft);
45 this.SetResizePolicy(ResizePolicyType.FillToParent, DimensionType.AllDimensions);
49 internal Layer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Layer.Layer_SWIGUpcast(cPtr), cMemoryOwn)
51 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
55 /// Enumeration for the behavior of the layer.
57 /// <since_tizen> 3 </since_tizen>
58 public enum LayerBehavior
61 /// UI control rendering mode (default mode).
62 /// This mode is designed for UI controls that can overlap. In this
63 /// mode renderer order will be respective to the tree hierarchy of
65 /// The rendering order is depth first, so for the following actor tree,
66 /// A will be drawn first, then B, D, E, then C, F. This ensures that
67 /// overlapping actors are drawn as expected (whereas, with breadth first
68 /// traversal, the actors would interleave).<br />
70 /// <since_tizen> 3 </since_tizen>
74 /// UI control rendering mode.
76 /// <since_tizen> 3 </since_tizen>
80 /// Layer will use depth test.
81 /// This mode is designed for a 3 dimensional scene where actors in front
82 /// of other actors will obscure them, i.e. the actors are sorted by the
83 /// distance from the camera.<br />
84 /// When using this mode, a depth test will be used. A depth clear will
85 /// happen for each layer, which means actors in a layer "above" other
86 /// layers will be rendered in front of actors in those layers regardless
87 /// of their Z positions (see Layer::Raise() and Layer::Lower()).<br />
88 /// Opaque renderers are drawn first and write to the depth buffer. Then
89 /// transparent renderers are drawn with depth test enabled but depth
90 /// write switched off. Transparent renderers are drawn based on their
91 /// distance from the camera. A renderer's DEPTH_INDEX property is used to
92 /// offset the distance to the camera when ordering transparent renderers.
93 /// This is useful if you want to define the draw order of two or more
94 /// transparent renderers that are equal distance from the camera. Unlike
95 /// LAYER_UI, parent-child relationship does not affect rendering order at
98 /// <since_tizen> 3 </since_tizen>
102 internal enum TreeDepthMultiplier
104 TREE_DEPTH_MULTIPLIER = 10000
108 /// Layer behavior, type String (Layer.LayerBehavior).
110 /// <since_tizen> 3 </since_tizen>
111 public Layer.LayerBehavior Behavior
115 return GetBehavior();
124 /// Sets the viewport (in window coordinates), type rectangle.
125 /// The contents of the layer will not be visible outside this box, when ViewportEnabled is true.
127 /// <since_tizen> 4 </since_tizen>
128 public Rectangle Viewport
134 Rectangle ret = new Rectangle(Interop.Layer.Layer_GetClippingBox(swigCPtr), true);
135 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140 // Clipping not enabled so return the window size
141 Size2D windowSize = window?.Size;
142 Rectangle ret = new Rectangle(0, 0, windowSize.Width, windowSize.Height);
148 Interop.Layer.Layer_SetClippingBox__SWIG_1(swigCPtr, Rectangle.getCPtr(value));
149 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
150 ClippingEnabled = true;
155 /// Retrieves and sets the layer's opacity.<br />
157 /// <since_tizen> 3 </since_tizen>
163 GetProperty(View.Property.OPACITY).Get(out temp);
168 SetProperty(View.Property.OPACITY, new Tizen.NUI.PropertyValue(value));
173 /// Retrieves and sets the layer's visibility.
175 /// <since_tizen> 3 </since_tizen>
176 public bool Visibility
181 GetProperty(View.Property.VISIBLE).Get(out temp);
186 SetProperty(View.Property.VISIBLE, new Tizen.NUI.PropertyValue(value));
191 /// Get the number of children held by the layer.
193 /// <since_tizen> 3 </since_tizen>
194 public new uint ChildCount
198 return Convert.ToUInt32(Children.Count);
203 /// Gets or sets the layer's name.
205 /// <since_tizen> 3 </since_tizen>
219 /// Queries the depth of the layer.<br />
220 /// 0 is the bottommost layer, higher number is on the top.<br />
222 /// <since_tizen> 3 </since_tizen>
232 /// Internal only property to enable or disable clipping, type boolean.
233 /// By default, this is false, i.e., the viewport of the layer is the entire window.
235 internal bool ClippingEnabled
239 bool ret = Interop.Layer.Layer_IsClipping(swigCPtr);
240 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245 Interop.Layer.Layer_SetClipping(swigCPtr, value);
246 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
251 [EditorBrowsable(EditorBrowsableState.Never)]
252 public ResourceDictionary XamlResources
256 return Application.Current.XamlResources;
260 Application.Current.XamlResources = value;
264 /// From the Container base class.
267 /// Adds a child view to this layer.
269 /// <seealso cref="Container.Add">
271 /// <since_tizen> 4 </since_tizen>
272 public override void Add(View child)
274 Container oldParent = child.GetParent();
276 if (oldParent != this)
278 if (oldParent != null)
280 oldParent.Remove(child);
284 child.InternalParent = this;
286 Interop.Actor.Actor_Add( swigCPtr , View.getCPtr(child));
287 if (NDalicPINVOKE.SWIGPendingException.Pending)
288 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
290 BindableObject.SetInheritedBindingContext(child, this?.BindingContext);
295 /// Removes a child view from this layer. If the view was not a child of this layer, this is a no-op.
297 /// <seealso cref="Container.Remove">
299 /// <since_tizen> 4 </since_tizen>
300 public override void Remove(View child)
302 Interop.Actor.Actor_Remove( swigCPtr, View.getCPtr(child));
303 if (NDalicPINVOKE.SWIGPendingException.Pending)
304 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
306 Children.Remove(child);
307 child.InternalParent = null;
311 /// Retrieves a child view by the index.
313 /// <pre>The view has been initialized.</pre>
314 /// <param name="index">The index of the child to retrieve.</param>
315 /// <returns>The view for the given index or empty handle if children not initialized.</returns>
316 /// <since_tizen> 4 </since_tizen>
317 public override View GetChildAt(uint index)
319 if (index < Children.Count)
321 return Children[Convert.ToInt32(index)];
330 /// Get parent of the layer.
332 /// <returns>The view's container</returns>
333 /// <since_tizen> 4 </since_tizen>
334 public override Container GetParent()
340 /// Get the child count of the layer.
342 /// <returns>The child count of the layer.</returns>
343 /// <since_tizen> 4 </since_tizen>
344 public override uint GetChildCount()
346 return Convert.ToUInt32(Children.Count);
350 /// Downcasts a handle to layer handle.
352 /// <since_tizen> 3 </since_tizen>
353 /// Please do not use! this will be deprecated!
354 /// Instead please use as keyword.
355 [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead!")]
356 [EditorBrowsable(EditorBrowsableState.Never)]
357 public static Layer DownCast(BaseHandle handle)
359 Layer ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as Layer;
360 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
365 /// Search through this layer's hierarchy for a view with the given unique ID.
367 /// <pre>This layer (the parent) has been initialized.</pre>
368 /// <remarks>The actor itself is also considered in the search.</remarks>
369 /// <param name="id">The id of the child to find</param>
370 /// <returns> A handle to the view if found, or an empty handle if not. </returns>
371 /// <since_tizen> 3 </since_tizen>
372 public View FindChildById(uint id)
374 //to fix memory leak issue, match the handle count with native side.
375 IntPtr cPtr = Interop.Actor.Actor_FindChildById(swigCPtr, id);
376 HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
377 View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
378 Interop.BaseHandle.delete_BaseHandle(CPtr);
379 CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
381 if (NDalicPINVOKE.SWIGPendingException.Pending)
382 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
386 internal override View FindCurrentChildById(uint id)
388 return FindChildById(id);
391 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
392 [EditorBrowsable(EditorBrowsableState.Never)]
393 public View FindChildByName(string viewName)
395 //to fix memory leak issue, match the handle count with native side.
396 IntPtr cPtr = Interop.Actor.Actor_FindChildByName(swigCPtr, viewName);
397 HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
398 View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
399 Interop.BaseHandle.delete_BaseHandle(CPtr);
400 CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
402 if (NDalicPINVOKE.SWIGPendingException.Pending)
403 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
408 /// Increments the depth of the layer.
410 /// <since_tizen> 3 </since_tizen>
413 var parentChildren = window?.LayersChildren;
414 if (parentChildren != null)
416 int currentIdx = parentChildren.IndexOf(this);
418 if (currentIdx >= 0 && currentIdx < parentChildren.Count - 1)
420 var upper = parentChildren[currentIdx + 1];
427 /// Decrements the depth of the layer.
429 /// <since_tizen> 3 </since_tizen>
432 var parentChildren = window?.LayersChildren;
433 if (parentChildren != null)
435 int currentIdx = parentChildren.IndexOf(this);
437 if (currentIdx > 0 && currentIdx < parentChildren.Count)
439 var low = parentChildren[currentIdx - 1];
446 /// Raises the layer to the top.
448 /// <since_tizen> 3 </since_tizen>
449 public void RaiseToTop()
451 var parentChildren = window?.LayersChildren;
453 if (parentChildren != null)
455 parentChildren.Remove(this);
456 parentChildren.Add(this);
458 Interop.Layer.Layer_RaiseToTop(swigCPtr);
459 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
464 /// Lowers the layer to the bottom.
466 /// <since_tizen> 3 </since_tizen>
467 public void LowerToBottom()
469 var parentChildren = window?.LayersChildren;
471 if (parentChildren != null)
473 parentChildren.Remove(this);
474 parentChildren.Insert(0, this);
476 Interop.Layer.Layer_LowerToBottom(swigCPtr);
477 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.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.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.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.Actor_SetSize__SWIG_0(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.Actor_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.Actor_SetResizePolicy(swigCPtr, (int)policy, (int)dimension);
543 if (NDalicPINVOKE.SWIGPendingException.Pending)
544 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
547 internal uint GetDepth()
549 var parentChildren = window?.LayersChildren;
550 if (parentChildren != null)
552 int idx = parentChildren.IndexOf(this);
555 return Convert.ToUInt32(idx); ;
560 internal void RaiseAbove(Layer target)
562 var parentChildren = window?.LayersChildren;
563 if (parentChildren != null)
565 int currentIndex = parentChildren.IndexOf(this);
566 int targetIndex = parentChildren.IndexOf(target);
568 if (currentIndex < 0 || targetIndex < 0 ||
569 currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count)
571 NUILog.Error("index should be bigger than 0 and less than children of layer count");
575 // If the currentIndex is less than the target index and the target has the same parent.
576 if (currentIndex < targetIndex)
578 parentChildren.Remove(this);
579 parentChildren.Insert(targetIndex, this);
581 Interop.Layer.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
582 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
587 internal void LowerBelow(Layer target)
589 var parentChildren = window?.LayersChildren;
591 if (parentChildren != null)
593 int currentIndex = parentChildren.IndexOf(this);
594 int targetIndex = parentChildren.IndexOf(target);
596 if (currentIndex < 0 || targetIndex < 0 ||
597 currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count)
599 NUILog.Error("index should be bigger than 0 and less than children of layer count");
603 // If the currentIndex is not already the 0th index and the target has the same parent.
604 if ((currentIndex != 0) && (targetIndex != -1) &&
605 (currentIndex > targetIndex))
607 parentChildren.Remove(this);
608 parentChildren.Insert(targetIndex, this);
610 Interop.Layer.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
611 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
616 internal void SetSortFunction(SWIGTYPE_p_f_r_q_const__Dali__Vector3__float function)
618 Interop.Layer.Layer_SetSortFunction(swigCPtr, SWIGTYPE_p_f_r_q_const__Dali__Vector3__float.getCPtr(function));
619 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
622 internal void SetTouchConsumed(bool consume)
624 Interop.Layer.Layer_SetTouchConsumed(swigCPtr, consume);
625 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
628 internal bool IsTouchConsumed()
630 bool ret = Interop.Layer.Layer_IsTouchConsumed(swigCPtr);
631 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
635 internal void SetHoverConsumed(bool consume)
637 Interop.Layer.Layer_SetHoverConsumed(swigCPtr, consume);
638 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
641 internal bool IsHoverConsumed()
643 bool ret = Interop.Layer.Layer_IsHoverConsumed(swigCPtr);
644 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
648 internal void AddViewToLayerList(View view)
653 internal void RemoveViewFromLayerList(View view)
655 Children.Remove(view);
658 internal string GetName()
660 string ret = Interop.Actor.Actor_GetName(swigCPtr);
661 if (NDalicPINVOKE.SWIGPendingException.Pending)
662 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
666 internal void SetName(string name)
668 Interop.Actor.Actor_SetName(swigCPtr, name);
669 if (NDalicPINVOKE.SWIGPendingException.Pending)
670 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
673 internal void SetWindow(Window win)
681 /// <since_tizen> 3 </since_tizen>
682 protected override void Dispose(DisposeTypes type)
689 if (type == DisposeTypes.Explicit)
692 //Release your own managed resources here.
693 //You should release all of your own disposable objects here.
696 //Release your own unmanaged resources here.
697 //You should not access any managed member here except static instance.
698 //because the execution order of Finalizes is non-deterministic.
700 if (swigCPtr.Handle != global::System.IntPtr.Zero)
705 Interop.Layer.delete_Layer(swigCPtr);
707 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
714 private void SetBehavior(LayerBehavior behavior)
716 Interop.Layer.Layer_SetBehavior(swigCPtr, (int)behavior);
717 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
720 private LayerBehavior GetBehavior()
722 Layer.LayerBehavior ret = (Layer.LayerBehavior)Interop.Layer.Layer_GetBehavior(swigCPtr);
723 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
727 internal class Property
729 internal static readonly int BEHAVIOR = Interop.Layer.Layer_Property_BEHAVIOR_get();