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.
21 using Tizen.NUI.BaseComponents;
24 /// Layers provide a mechanism for overlaying groups of actors on top of each other.
26 public class Layer : Container
28 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30 internal Layer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Layer_SWIGUpcast(cPtr), cMemoryOwn)
32 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
35 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Layer obj)
37 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
40 /// From the Container base class.
43 /// Adds a child view to this layer.
45 /// <seealso cref="Container.Add">
47 /// <since_tizen> 4 </since_tizen>
48 public override void Add(View child)
50 NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
51 if (NDalicPINVOKE.SWIGPendingException.Pending)
52 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
58 /// Removes a child view from this layer. If the view was not a child of this layer, this is a no-op.
60 /// <seealso cref="Container.Remove">
62 /// <since_tizen> 4 </since_tizen>
63 public override void Remove(View child)
65 NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child));
66 if (NDalicPINVOKE.SWIGPendingException.Pending)
67 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
69 Children.Remove(child);
73 /// Retrieves a child view by the index.
75 /// <pre>The view has been initialized.</pre>
76 /// <param name="index">The index of the child to retrieve.</param>
77 /// <returns>The view for the given index or empty handle if children not initialized.</returns>
78 /// <since_tizen> 4 </since_tizen>
79 public override View GetChildAt(uint index)
81 if (index < Children.Count)
83 return Children[Convert.ToInt32(index)];
93 /// Get parent of the layer.
95 /// <returns>The view's container</returns>
96 /// <since_tizen> 3 </since_tizen>
97 protected override Container GetParent()
103 /// Get the child count of the layer.
105 /// <returns>The child count of the layer.</returns>
106 /// <since_tizen> 3 </since_tizen>
107 protected override uint GetChildCount()
109 return Convert.ToUInt32(Children.Count);
115 /// <since_tizen> 3 </since_tizen>
116 protected override void Dispose(DisposeTypes type)
123 if(type == DisposeTypes.Explicit)
126 //Release your own managed resources here.
127 //You should release all of your own disposable objects here.
130 //Release your own unmanaged resources here.
131 //You should not access any managed member here except static instance.
132 //because the execution order of Finalizes is non-deterministic.
134 if (swigCPtr.Handle != global::System.IntPtr.Zero)
139 NDalicPINVOKE.delete_Layer(swigCPtr);
141 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
146 // Dispose all Children of this Layer.
147 foreach (View childView in Children)
149 childView?.Dispose();
155 internal class Property
157 internal static readonly int BEHAVIOR = NDalicPINVOKE.Layer_Property_BEHAVIOR_get();
161 /// Creates a Layer object.
163 /// <since_tizen> 3 </since_tizen>
164 public Layer() : this(NDalicPINVOKE.Layer_New(), true)
166 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
167 if(Window.Instance != null)
169 this.SetAnchorPoint(Tizen.NUI.PivotPoint.TopLeft);
170 this.SetResizePolicy(ResizePolicyType.FillToParent, DimensionType.AllDimensions);
173 internal void SetAnchorPoint(Vector3 anchorPoint)
175 NDalicPINVOKE.Actor_SetAnchorPoint(swigCPtr, Vector3.getCPtr(anchorPoint));
176 if (NDalicPINVOKE.SWIGPendingException.Pending)
177 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179 internal void SetResizePolicy(ResizePolicyType policy, DimensionType dimension)
181 NDalicPINVOKE.Actor_SetResizePolicy(swigCPtr, (int)policy, (int)dimension);
182 if (NDalicPINVOKE.SWIGPendingException.Pending)
183 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188 /// [Obsolete("Please do not use! this will be deprecated")]
190 /// <since_tizen> 3 </since_tizen>
191 [Obsolete("Please do not use! this will be deprecated")]
192 public static Layer DownCast(BaseHandle handle)
194 Layer ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as Layer;
195 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
200 /// Search through this layer's hierarchy for a view with the given unique ID.
202 /// <pre>This layer (the parent) has been initialized.</pre>
203 /// <remarks>The actor itself is also considered in the search.</remarks>
204 /// <param name="id">The id of the child to find</param>
205 /// <returns> A handle to the view if found, or an empty handle if not. </returns>
206 /// <since_tizen> 3 </since_tizen>
207 public View FindChildById(uint id)
209 IntPtr cPtr = NDalicPINVOKE.Actor_FindChildById(swigCPtr, id);
210 View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
212 if (NDalicPINVOKE.SWIGPendingException.Pending)
213 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
218 /// Queries the depth of the layer.<br />
219 /// 0 is the bottommost layer, higher number is on the top.<br />
221 /// <since_tizen> 3 </since_tizen>
230 internal uint GetDepth()
232 uint ret = NDalicPINVOKE.Layer_GetDepth(swigCPtr);
233 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238 /// Increments the depth of the layer.
240 /// <since_tizen> 3 </since_tizen>
243 NDalicPINVOKE.Layer_Raise(swigCPtr);
244 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248 /// Decrements the depth of the layer.
250 /// <since_tizen> 3 </since_tizen>
253 NDalicPINVOKE.Layer_Lower(swigCPtr);
254 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257 internal void RaiseAbove(Layer target)
259 NDalicPINVOKE.Layer_RaiseAbove(swigCPtr, Layer.getCPtr(target));
260 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263 internal void LowerBelow(Layer target)
265 NDalicPINVOKE.Layer_LowerBelow(swigCPtr, Layer.getCPtr(target));
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
270 /// Raises the layer to the top.
272 /// <since_tizen> 3 </since_tizen>
273 public void RaiseToTop()
275 NDalicPINVOKE.Layer_RaiseToTop(swigCPtr);
276 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280 /// Lowers the layer to the bottom.
282 /// <since_tizen> 3 </since_tizen>
283 public void LowerToBottom()
285 NDalicPINVOKE.Layer_LowerToBottom(swigCPtr);
286 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
290 /// Moves the layer directly above the given layer.<br />
291 /// After the call, this layer's depth will be immediately above target.<br />
293 /// <param name="target">The layer to get on top of.</param>
294 /// <since_tizen> 3 </since_tizen>
295 public void MoveAbove(Layer target)
297 NDalicPINVOKE.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
298 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
302 /// Moves the layer directly below the given layer.<br />
303 /// After the call, this layer's depth will be immediately below target.<br />
305 /// <param name="target">The layer to get below of.</param>
306 /// <since_tizen> 3 </since_tizen>
307 public void MoveBelow(Layer target)
309 NDalicPINVOKE.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
310 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
313 private void SetBehavior(LayerBehavior behavior)
315 NDalicPINVOKE.Layer_SetBehavior(swigCPtr, (int)behavior);
316 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
319 private LayerBehavior GetBehavior()
321 Layer.LayerBehavior ret = (Layer.LayerBehavior)NDalicPINVOKE.Layer_GetBehavior(swigCPtr);
322 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
326 internal void SetSortFunction(SWIGTYPE_p_f_r_q_const__Dali__Vector3__float function)
328 NDalicPINVOKE.Layer_SetSortFunction(swigCPtr, SWIGTYPE_p_f_r_q_const__Dali__Vector3__float.getCPtr(function));
329 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332 internal void SetTouchConsumed(bool consume)
334 NDalicPINVOKE.Layer_SetTouchConsumed(swigCPtr, consume);
335 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338 internal bool IsTouchConsumed()
340 bool ret = NDalicPINVOKE.Layer_IsTouchConsumed(swigCPtr);
341 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345 internal void SetHoverConsumed(bool consume)
347 NDalicPINVOKE.Layer_SetHoverConsumed(swigCPtr, consume);
348 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
351 internal bool IsHoverConsumed()
353 bool ret = NDalicPINVOKE.Layer_IsHoverConsumed(swigCPtr);
354 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359 /// Enumeration for the behavior of the layer.
361 /// <since_tizen> 3 </since_tizen>
362 public enum LayerBehavior
365 /// UI control rendering mode.
367 /// <since_tizen> 3 </since_tizen>
370 /// UI control rendering mode (default mode).
371 /// This mode is designed for UI controls that can overlap. In this
372 /// mode renderer order will be respective to the tree hierarchy of
374 /// The rendering order is depth first, so for the following actor tree,
375 /// A will be drawn first, then B, D, E, then C, F. This ensures that
376 /// overlapping actors are drawn as expected (whereas, with breadth first
377 /// traversal, the actors would interleave).<br />
379 /// <since_tizen> 3 </since_tizen>
382 /// Layer will use depth test.
383 /// This mode is designed for a 3 dimensional scene where actors in front
384 /// of other actors will obscure them, i.e. the actors are sorted by the
385 /// distance from the camera.<br />
386 /// When using this mode, a depth test will be used. A depth clear will
387 /// happen for each layer, which means actors in a layer "above" other
388 /// layers will be rendered in front of actors in those layers regardless
389 /// of their Z positions (see Layer::Raise() and Layer::Lower()).<br />
390 /// Opaque renderers are drawn first and write to the depth buffer. Then
391 /// transparent renderers are drawn with depth test enabled but depth
392 /// write switched off. Transparent renderers are drawn based on their
393 /// distance from the camera. A renderer's DEPTH_INDEX property is used to
394 /// offset the distance to the camera when ordering transparent renderers.
395 /// This is useful if you want to define the draw order of two or more
396 /// transparent renderers that are equal distance from the camera. Unlike
397 /// LAYER_UI, parent-child relationship does not affect rendering order at
400 /// <since_tizen> 3 </since_tizen>
404 internal enum TreeDepthMultiplier
406 TREE_DEPTH_MULTIPLIER = 10000
410 /// Layer behavior, type String (Layer.LayerBehavior).
412 /// <since_tizen> 3 </since_tizen>
413 public Layer.LayerBehavior Behavior
417 return GetBehavior();
426 /// Internal only property to enable or disable clipping, type boolean.
427 /// By default, this is false, i.e., the viewport of the layer is the entire window.
429 internal bool ClippingEnabled
433 bool ret = NDalicPINVOKE.Layer_IsClipping(swigCPtr);
434 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
439 NDalicPINVOKE.Layer_SetClipping(swigCPtr, value);
440 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
445 /// Sets the viewport (in window coordinates), type rectangle.
446 /// The contents of the layer will not be visible outside this box, when ViewportEnabled is true.
448 /// <since_tizen> 4 </since_tizen>
449 public Rectangle Viewport
453 if( ClippingEnabled )
455 Rectangle ret = new Rectangle(NDalicPINVOKE.Layer_GetClippingBox(swigCPtr), true);
456 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
461 // Clipping not enabled so return the window size
462 Size2D windowSize = Window.Instance.Size;
463 Rectangle ret = new Rectangle(0, 0, windowSize.Width, windowSize.Height);
469 NDalicPINVOKE.Layer_SetClippingBox__SWIG_1(swigCPtr, Rectangle.getCPtr(value));
470 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
471 ClippingEnabled = true;
476 /// Retrieves and sets the layer's opacity.<br />
478 /// <since_tizen> 3 </since_tizen>
484 GetProperty(View.Property.OPACITY).Get(out temp);
489 SetProperty(View.Property.OPACITY, new Tizen.NUI.PropertyValue(value));
494 /// Retrieves and sets the layer's visibility.
496 /// <since_tizen> 3 </since_tizen>
497 public bool Visibility
502 GetProperty(View.Property.VISIBLE).Get(out temp);
507 SetProperty(View.Property.VISIBLE, new Tizen.NUI.PropertyValue(value));
512 /// Get the number of children held by the layer.
514 /// <since_tizen> 3 </since_tizen>
515 public new uint ChildCount
519 uint ret = NDalicPINVOKE.Actor_GetChildCount(swigCPtr);
520 if (NDalicPINVOKE.SWIGPendingException.Pending)
521 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
527 /// Gets or sets the layer's name.
529 /// <since_tizen> 3 </since_tizen>
542 internal string GetName()
544 string ret = NDalicPINVOKE.Actor_GetName(swigCPtr);
545 if (NDalicPINVOKE.SWIGPendingException.Pending)
546 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
550 internal void SetName(string name)
552 NDalicPINVOKE.Actor_SetName(swigCPtr, name);
553 if (NDalicPINVOKE.SWIGPendingException.Pending)
554 throw NDalicPINVOKE.SWIGPendingException.Retrieve();