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();
294 /// Removes a child view from this layer. If the view was not a child of this layer, this is a no-op.
296 /// <seealso cref="Container.Remove">
298 /// <since_tizen> 4 </since_tizen>
299 public override void Remove(View child)
301 Interop.Actor.Actor_Remove( swigCPtr, View.getCPtr(child));
302 if (NDalicPINVOKE.SWIGPendingException.Pending)
303 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305 Children.Remove(child);
306 child.InternalParent = null;
310 /// Retrieves a child view by the index.
312 /// <pre>The view has been initialized.</pre>
313 /// <param name="index">The index of the child to retrieve.</param>
314 /// <returns>The view for the given index or empty handle if children not initialized.</returns>
315 /// <since_tizen> 4 </since_tizen>
316 public override View GetChildAt(uint index)
318 if (index < Children.Count)
320 return Children[Convert.ToInt32(index)];
329 /// Get parent of the layer.
331 /// <returns>The view's container</returns>
332 /// <since_tizen> 4 </since_tizen>
333 public override Container GetParent()
339 /// Get the child count of the layer.
341 /// <returns>The child count of the layer.</returns>
342 /// <since_tizen> 4 </since_tizen>
343 public override uint GetChildCount()
345 return Convert.ToUInt32(Children.Count);
349 /// Downcasts a handle to layer handle.
351 /// <since_tizen> 3 </since_tizen>
352 /// Please do not use! this will be deprecated!
353 /// Instead please use as keyword.
354 [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead!")]
355 [EditorBrowsable(EditorBrowsableState.Never)]
356 public static Layer DownCast(BaseHandle handle)
358 Layer ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as Layer;
359 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
364 /// Search through this layer's hierarchy for a view with the given unique ID.
366 /// <pre>This layer (the parent) has been initialized.</pre>
367 /// <remarks>The actor itself is also considered in the search.</remarks>
368 /// <param name="id">The id of the child to find</param>
369 /// <returns> A handle to the view if found, or an empty handle if not. </returns>
370 /// <since_tizen> 3 </since_tizen>
371 public View FindChildById(uint id)
373 //to fix memory leak issue, match the handle count with native side.
374 IntPtr cPtr = Interop.Actor.Actor_FindChildById(swigCPtr, id);
375 HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
376 View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
377 Interop.BaseHandle.delete_BaseHandle(CPtr);
378 CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
380 if (NDalicPINVOKE.SWIGPendingException.Pending)
381 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
385 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
386 [EditorBrowsable(EditorBrowsableState.Never)]
387 public View FindChildByName(string viewName)
389 //to fix memory leak issue, match the handle count with native side.
390 IntPtr cPtr = Interop.Actor.Actor_FindChildByName(swigCPtr, viewName);
391 HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
392 View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
393 Interop.BaseHandle.delete_BaseHandle(CPtr);
394 CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
396 if (NDalicPINVOKE.SWIGPendingException.Pending)
397 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
402 /// Increments the depth of the layer.
404 /// <since_tizen> 3 </since_tizen>
407 var parentChildren = window?.LayersChildren;
408 if (parentChildren != null)
410 int currentIdx = parentChildren.IndexOf(this);
412 if (currentIdx >= 0 && currentIdx < parentChildren.Count - 1)
414 var upper = parentChildren[currentIdx + 1];
421 /// Decrements the depth of the layer.
423 /// <since_tizen> 3 </since_tizen>
426 var parentChildren = window?.LayersChildren;
427 if (parentChildren != null)
429 int currentIdx = parentChildren.IndexOf(this);
431 if (currentIdx > 0 && currentIdx < parentChildren.Count)
433 var low = parentChildren[currentIdx - 1];
440 /// Raises the layer to the top.
442 /// <since_tizen> 3 </since_tizen>
443 public void RaiseToTop()
445 var parentChildren = window?.LayersChildren;
447 if (parentChildren != null)
449 parentChildren.Remove(this);
450 parentChildren.Add(this);
452 Interop.Layer.Layer_RaiseToTop(swigCPtr);
453 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
458 /// Lowers the layer to the bottom.
460 /// <since_tizen> 3 </since_tizen>
461 public void LowerToBottom()
463 var parentChildren = window?.LayersChildren;
465 if (parentChildren != null)
467 parentChildren.Remove(this);
468 parentChildren.Insert(0, this);
470 Interop.Layer.Layer_LowerToBottom(swigCPtr);
471 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
477 /// Moves the layer directly above the given layer.<br />
478 /// After the call, this layer's depth will be immediately above target.<br />
480 /// <param name="target">The layer to get on top of.</param>
481 /// <since_tizen> 3 </since_tizen>
482 public void MoveAbove(Layer target)
484 Interop.Layer.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
485 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
489 /// Moves the layer directly below the given layer.<br />
490 /// After the call, this layer's depth will be immediately below target.<br />
492 /// <param name="target">The layer to get below of.</param>
493 /// <since_tizen> 3 </since_tizen>
494 public void MoveBelow(Layer target)
496 Interop.Layer.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
497 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
500 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Layer obj)
502 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
505 internal void SetAnchorPoint(Vector3 anchorPoint)
507 Interop.Actor.Actor_SetAnchorPoint(swigCPtr, Vector3.getCPtr(anchorPoint));
508 if (NDalicPINVOKE.SWIGPendingException.Pending)
509 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
512 internal void SetResizePolicy(ResizePolicyType policy, DimensionType dimension)
514 Interop.Actor.Actor_SetResizePolicy(swigCPtr, (int)policy, (int)dimension);
515 if (NDalicPINVOKE.SWIGPendingException.Pending)
516 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
519 internal uint GetDepth()
521 var parentChildren = window?.LayersChildren;
522 if (parentChildren != null)
524 int idx = parentChildren.IndexOf(this);
527 return Convert.ToUInt32(idx); ;
532 internal void RaiseAbove(Layer target)
534 var parentChildren = window?.LayersChildren;
535 if (parentChildren != null)
537 int currentIndex = parentChildren.IndexOf(this);
538 int targetIndex = parentChildren.IndexOf(target);
540 if (currentIndex < 0 || targetIndex < 0 ||
541 currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count)
543 NUILog.Error("index should be bigger than 0 and less than children of layer count");
547 // If the currentIndex is less than the target index and the target has the same parent.
548 if (currentIndex < targetIndex)
550 parentChildren.Remove(this);
551 parentChildren.Insert(targetIndex, this);
553 Interop.Layer.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
554 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
559 internal void LowerBelow(Layer target)
561 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 not already the 0th index and the target has the same parent.
576 if ((currentIndex != 0) && (targetIndex != -1) &&
577 (currentIndex > targetIndex))
579 parentChildren.Remove(this);
580 parentChildren.Insert(targetIndex, this);
582 Interop.Layer.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
583 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
588 internal void SetSortFunction(SWIGTYPE_p_f_r_q_const__Dali__Vector3__float function)
590 Interop.Layer.Layer_SetSortFunction(swigCPtr, SWIGTYPE_p_f_r_q_const__Dali__Vector3__float.getCPtr(function));
591 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
594 internal void SetTouchConsumed(bool consume)
596 Interop.Layer.Layer_SetTouchConsumed(swigCPtr, consume);
597 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
600 internal bool IsTouchConsumed()
602 bool ret = Interop.Layer.Layer_IsTouchConsumed(swigCPtr);
603 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
607 internal void SetHoverConsumed(bool consume)
609 Interop.Layer.Layer_SetHoverConsumed(swigCPtr, consume);
610 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
613 internal bool IsHoverConsumed()
615 bool ret = Interop.Layer.Layer_IsHoverConsumed(swigCPtr);
616 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
620 internal void AddViewToLayerList(View view)
625 internal void RemoveViewFromLayerList(View view)
627 Children.Remove(view);
630 internal string GetName()
632 string ret = Interop.Actor.Actor_GetName(swigCPtr);
633 if (NDalicPINVOKE.SWIGPendingException.Pending)
634 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
638 internal void SetName(string name)
640 Interop.Actor.Actor_SetName(swigCPtr, name);
641 if (NDalicPINVOKE.SWIGPendingException.Pending)
642 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
645 internal void SetWindow(Window win)
653 /// <since_tizen> 3 </since_tizen>
654 protected override void Dispose(DisposeTypes type)
661 if (type == DisposeTypes.Explicit)
664 //Release your own managed resources here.
665 //You should release all of your own disposable objects here.
668 //Release your own unmanaged resources here.
669 //You should not access any managed member here except static instance.
670 //because the execution order of Finalizes is non-deterministic.
672 if (swigCPtr.Handle != global::System.IntPtr.Zero)
677 Interop.Layer.delete_Layer(swigCPtr);
679 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
686 private void SetBehavior(LayerBehavior behavior)
688 Interop.Layer.Layer_SetBehavior(swigCPtr, (int)behavior);
689 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
692 private LayerBehavior GetBehavior()
694 Layer.LayerBehavior ret = (Layer.LayerBehavior)Interop.Layer.Layer_GetBehavior(swigCPtr);
695 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
699 internal class Property
701 internal static readonly int BEHAVIOR = Interop.Layer.Layer_Property_BEHAVIOR_get();