2 * Copyright(c) 2017 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;
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 global::System.Runtime.InteropServices.HandleRef swigCPtr;
32 internal Layer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Layer_SWIGUpcast(cPtr), cMemoryOwn)
34 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
37 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Layer obj)
39 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
42 /// From the Container base class.
45 /// Adds a child view to this layer.
47 /// <seealso cref="Container.Add">
49 /// <since_tizen> 4 </since_tizen>
50 public override void Add(View child)
52 NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
53 if (NDalicPINVOKE.SWIGPendingException.Pending)
54 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
60 /// Removes a child view from this layer. If the view was not a child of this layer, this is a no-op.
62 /// <seealso cref="Container.Remove">
64 /// <since_tizen> 4 </since_tizen>
65 public override void Remove(View child)
67 NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child));
68 if (NDalicPINVOKE.SWIGPendingException.Pending)
69 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
71 Children.Remove(child);
75 /// Retrieves a child view by the index.
77 /// <pre>The view has been initialized.</pre>
78 /// <param name="index">The index of the child to retrieve.</param>
79 /// <returns>The view for the given index or empty handle if children not initialized.</returns>
80 /// <since_tizen> 4 </since_tizen>
81 public override View GetChildAt(uint index)
83 if (index < Children.Count)
85 return Children[Convert.ToInt32(index)];
95 /// Get parent of the layer.
97 /// <returns>The view's container</returns>
98 /// <since_tizen> 4 </since_tizen>
99 public override Container GetParent()
105 /// Get the child count of the layer.
107 /// <returns>The child count of the layer.</returns>
108 /// <since_tizen> 4 </since_tizen>
109 public override uint GetChildCount()
111 return Convert.ToUInt32(Children.Count);
117 /// <since_tizen> 3 </since_tizen>
118 protected override void Dispose(DisposeTypes type)
125 if(type == DisposeTypes.Explicit)
128 //Release your own managed resources here.
129 //You should release all of your own disposable objects here.
132 //Release your own unmanaged resources here.
133 //You should not access any managed member here except static instance.
134 //because the execution order of Finalizes is non-deterministic.
136 if (swigCPtr.Handle != global::System.IntPtr.Zero)
141 NDalicPINVOKE.delete_Layer(swigCPtr);
143 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
151 internal class Property
153 internal static readonly int BEHAVIOR = NDalicPINVOKE.Layer_Property_BEHAVIOR_get();
157 /// Creates a Layer object.
159 /// <since_tizen> 3 </since_tizen>
160 public Layer() : this(NDalicPINVOKE.Layer_New(), true)
162 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163 if(Window.Instance != null)
165 this.SetAnchorPoint(Tizen.NUI.PivotPoint.TopLeft);
166 this.SetResizePolicy(ResizePolicyType.FillToParent, DimensionType.AllDimensions);
169 internal void SetAnchorPoint(Vector3 anchorPoint)
171 NDalicPINVOKE.Actor_SetAnchorPoint(swigCPtr, Vector3.getCPtr(anchorPoint));
172 if (NDalicPINVOKE.SWIGPendingException.Pending)
173 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175 internal void SetResizePolicy(ResizePolicyType policy, DimensionType dimension)
177 NDalicPINVOKE.Actor_SetResizePolicy(swigCPtr, (int)policy, (int)dimension);
178 if (NDalicPINVOKE.SWIGPendingException.Pending)
179 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
183 /// Downcasts a handle to layer handle.
185 /// <since_tizen> 3 </since_tizen>
186 /// Please do not use! this will be deprecated!
187 /// Instead please use as keyword.
188 [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead!")]
189 [EditorBrowsable(EditorBrowsableState.Never)]
190 public static Layer DownCast(BaseHandle handle)
192 Layer ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as Layer;
193 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198 /// Search through this layer's hierarchy for a view with the given unique ID.
200 /// <pre>This layer (the parent) has been initialized.</pre>
201 /// <remarks>The actor itself is also considered in the search.</remarks>
202 /// <param name="id">The id of the child to find</param>
203 /// <returns> A handle to the view if found, or an empty handle if not. </returns>
204 /// <since_tizen> 3 </since_tizen>
205 public View FindChildById(uint id)
207 IntPtr cPtr = NDalicPINVOKE.Actor_FindChildById(swigCPtr, id);
208 View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
210 if (NDalicPINVOKE.SWIGPendingException.Pending)
211 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216 /// Queries the depth of the layer.<br />
217 /// 0 is the bottommost layer, higher number is on the top.<br />
219 /// <since_tizen> 3 </since_tizen>
228 internal uint GetDepth()
230 var parentChildren = Window.Instance.LayersChildren;
231 if(parentChildren != null)
233 int idx = parentChildren.IndexOf(this);
236 return Convert.ToUInt32(idx); ;
243 /// Increments the depth of the layer.
245 /// <since_tizen> 3 </since_tizen>
248 var parentChildren = Window.Instance.LayersChildren;
249 if (parentChildren != null)
251 int currentIdx = parentChildren.IndexOf(this);
253 if (currentIdx != parentChildren.Count - 1)
255 RaiseAbove(parentChildren[currentIdx + 1]);
257 Layer temp = parentChildren[currentIdx + 1];
258 parentChildren[currentIdx + 1] = this;
259 parentChildren[currentIdx] = temp;
262 NDalicPINVOKE.Layer_Raise(swigCPtr);
263 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
267 /// Decrements the depth of the layer.
269 /// <since_tizen> 3 </since_tizen>
272 var parentChildren = Window.Instance.LayersChildren;
273 if (parentChildren != null)
275 int currentIdx = parentChildren.IndexOf(this);
279 LowerBelow(parentChildren[currentIdx - 1]);
281 Layer temp = parentChildren[currentIdx - 1];
282 parentChildren[currentIdx - 1] = this;
283 parentChildren[currentIdx] = temp;
287 NDalicPINVOKE.Layer_Lower(swigCPtr);
288 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291 internal void RaiseAbove(Layer target)
293 var parentChildren = Window.Instance.LayersChildren;
294 if (parentChildren != null)
296 int currentIndex = parentChildren.IndexOf(this);
297 int targetIndex = parentChildren.IndexOf(target);
299 // If the currentIndex is less than the target index and the target has the same parent.
300 if (currentIndex < targetIndex)
302 parentChildren.Remove(this);
303 parentChildren.Insert(targetIndex, this);
306 NDalicPINVOKE.Layer_RaiseAbove(swigCPtr, Layer.getCPtr(target));
307 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
310 internal void LowerBelow(Layer target)
312 var parentChildren = Window.Instance.LayersChildren;
314 if (parentChildren != null)
316 int currentIndex = parentChildren.IndexOf(this);
317 int targetIndex = parentChildren.IndexOf(target);
319 // If the currentIndex is not already the 0th index and the target has the same parent.
320 if ((currentIndex != 0) && (targetIndex != -1) &&
321 (currentIndex > targetIndex))
323 parentChildren.Remove(this);
324 parentChildren.Insert(targetIndex, this);
327 NDalicPINVOKE.Layer_LowerBelow(swigCPtr, Layer.getCPtr(target));
328 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332 /// Raises the layer to the top.
334 /// <since_tizen> 3 </since_tizen>
335 public void RaiseToTop()
337 var parentChildren = Window.Instance.LayersChildren;
339 if (parentChildren != null)
341 parentChildren.Remove(this);
342 parentChildren.Add(this);
344 NDalicPINVOKE.Layer_RaiseToTop(swigCPtr);
345 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
349 /// Lowers the layer to the bottom.
351 /// <since_tizen> 3 </since_tizen>
352 public void LowerToBottom()
354 var parentChildren = Window.Instance.LayersChildren;
356 if (parentChildren != null)
358 parentChildren.Remove(this);
359 parentChildren.Insert(0, this);
362 NDalicPINVOKE.Layer_LowerToBottom(swigCPtr);
363 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
367 /// Moves the layer directly above the given layer.<br />
368 /// After the call, this layer's depth will be immediately above target.<br />
370 /// <param name="target">The layer to get on top of.</param>
371 /// <since_tizen> 3 </since_tizen>
372 public void MoveAbove(Layer target)
374 NDalicPINVOKE.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
375 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
379 /// Moves the layer directly below the given layer.<br />
380 /// After the call, this layer's depth will be immediately below target.<br />
382 /// <param name="target">The layer to get below of.</param>
383 /// <since_tizen> 3 </since_tizen>
384 public void MoveBelow(Layer target)
386 NDalicPINVOKE.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
387 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
390 private void SetBehavior(LayerBehavior behavior)
392 NDalicPINVOKE.Layer_SetBehavior(swigCPtr, (int)behavior);
393 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
396 private LayerBehavior GetBehavior()
398 Layer.LayerBehavior ret = (Layer.LayerBehavior)NDalicPINVOKE.Layer_GetBehavior(swigCPtr);
399 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
403 internal void SetSortFunction(SWIGTYPE_p_f_r_q_const__Dali__Vector3__float function)
405 NDalicPINVOKE.Layer_SetSortFunction(swigCPtr, SWIGTYPE_p_f_r_q_const__Dali__Vector3__float.getCPtr(function));
406 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
409 internal void SetTouchConsumed(bool consume)
411 NDalicPINVOKE.Layer_SetTouchConsumed(swigCPtr, consume);
412 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
415 internal bool IsTouchConsumed()
417 bool ret = NDalicPINVOKE.Layer_IsTouchConsumed(swigCPtr);
418 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
422 internal void SetHoverConsumed(bool consume)
424 NDalicPINVOKE.Layer_SetHoverConsumed(swigCPtr, consume);
425 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
428 internal bool IsHoverConsumed()
430 bool ret = NDalicPINVOKE.Layer_IsHoverConsumed(swigCPtr);
431 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
436 /// Enumeration for the behavior of the layer.
438 /// <since_tizen> 3 </since_tizen>
439 public enum LayerBehavior
442 /// UI control rendering mode.
444 /// <since_tizen> 3 </since_tizen>
447 /// UI control rendering mode (default mode).
448 /// This mode is designed for UI controls that can overlap. In this
449 /// mode renderer order will be respective to the tree hierarchy of
451 /// The rendering order is depth first, so for the following actor tree,
452 /// A will be drawn first, then B, D, E, then C, F. This ensures that
453 /// overlapping actors are drawn as expected (whereas, with breadth first
454 /// traversal, the actors would interleave).<br />
456 /// <since_tizen> 3 </since_tizen>
459 /// Layer will use depth test.
460 /// This mode is designed for a 3 dimensional scene where actors in front
461 /// of other actors will obscure them, i.e. the actors are sorted by the
462 /// distance from the camera.<br />
463 /// When using this mode, a depth test will be used. A depth clear will
464 /// happen for each layer, which means actors in a layer "above" other
465 /// layers will be rendered in front of actors in those layers regardless
466 /// of their Z positions (see Layer::Raise() and Layer::Lower()).<br />
467 /// Opaque renderers are drawn first and write to the depth buffer. Then
468 /// transparent renderers are drawn with depth test enabled but depth
469 /// write switched off. Transparent renderers are drawn based on their
470 /// distance from the camera. A renderer's DEPTH_INDEX property is used to
471 /// offset the distance to the camera when ordering transparent renderers.
472 /// This is useful if you want to define the draw order of two or more
473 /// transparent renderers that are equal distance from the camera. Unlike
474 /// LAYER_UI, parent-child relationship does not affect rendering order at
477 /// <since_tizen> 3 </since_tizen>
481 internal enum TreeDepthMultiplier
483 TREE_DEPTH_MULTIPLIER = 10000
487 /// Layer behavior, type String (Layer.LayerBehavior).
489 /// <since_tizen> 3 </since_tizen>
490 public Layer.LayerBehavior Behavior
494 return GetBehavior();
503 /// Internal only property to enable or disable clipping, type boolean.
504 /// By default, this is false, i.e., the viewport of the layer is the entire window.
506 internal bool ClippingEnabled
510 bool ret = NDalicPINVOKE.Layer_IsClipping(swigCPtr);
511 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
516 NDalicPINVOKE.Layer_SetClipping(swigCPtr, value);
517 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
522 /// Sets the viewport (in window coordinates), type rectangle.
523 /// The contents of the layer will not be visible outside this box, when ViewportEnabled is true.
525 /// <since_tizen> 4 </since_tizen>
526 public Rectangle Viewport
530 if( ClippingEnabled )
532 Rectangle ret = new Rectangle(NDalicPINVOKE.Layer_GetClippingBox(swigCPtr), true);
533 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
538 // Clipping not enabled so return the window size
539 Size2D windowSize = Window.Instance.Size;
540 Rectangle ret = new Rectangle(0, 0, windowSize.Width, windowSize.Height);
546 NDalicPINVOKE.Layer_SetClippingBox__SWIG_1(swigCPtr, Rectangle.getCPtr(value));
547 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
548 ClippingEnabled = true;
553 /// Retrieves and sets the layer's opacity.<br />
555 /// <since_tizen> 3 </since_tizen>
561 GetProperty(View.Property.OPACITY).Get(out temp);
566 SetProperty(View.Property.OPACITY, new Tizen.NUI.PropertyValue(value));
571 /// Retrieves and sets the layer's visibility.
573 /// <since_tizen> 3 </since_tizen>
574 public bool Visibility
579 GetProperty(View.Property.VISIBLE).Get(out temp);
584 SetProperty(View.Property.VISIBLE, new Tizen.NUI.PropertyValue(value));
589 /// Get the number of children held by the layer.
591 /// <since_tizen> 3 </since_tizen>
592 public new uint ChildCount
596 return Convert.ToUInt32(Children.Count);
601 /// Gets or sets the layer's name.
603 /// <since_tizen> 3 </since_tizen>
616 internal string GetName()
618 string ret = NDalicPINVOKE.Actor_GetName(swigCPtr);
619 if (NDalicPINVOKE.SWIGPendingException.Pending)
620 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
624 internal void SetName(string name)
626 NDalicPINVOKE.Actor_SetName(swigCPtr, name);
627 if (NDalicPINVOKE.SWIGPendingException.Pending)
628 throw NDalicPINVOKE.SWIGPendingException.Retrieve();