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 public 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 public 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);
149 internal class Property
151 internal static readonly int BEHAVIOR = NDalicPINVOKE.Layer_Property_BEHAVIOR_get();
155 /// Creates a Layer object.
157 /// <since_tizen> 3 </since_tizen>
158 public Layer() : this(NDalicPINVOKE.Layer_New(), true)
160 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
161 if(Window.Instance != null)
163 this.SetAnchorPoint(Tizen.NUI.PivotPoint.TopLeft);
164 this.SetResizePolicy(ResizePolicyType.FillToParent, DimensionType.AllDimensions);
167 internal void SetAnchorPoint(Vector3 anchorPoint)
169 NDalicPINVOKE.Actor_SetAnchorPoint(swigCPtr, Vector3.getCPtr(anchorPoint));
170 if (NDalicPINVOKE.SWIGPendingException.Pending)
171 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
173 internal void SetResizePolicy(ResizePolicyType policy, DimensionType dimension)
175 NDalicPINVOKE.Actor_SetResizePolicy(swigCPtr, (int)policy, (int)dimension);
176 if (NDalicPINVOKE.SWIGPendingException.Pending)
177 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
182 /// [Obsolete("Please do not use! this will be deprecated")]
184 /// <since_tizen> 3 </since_tizen>
185 [Obsolete("Please do not use! this will be deprecated")]
186 public static Layer DownCast(BaseHandle handle)
188 Layer ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as Layer;
189 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194 /// Search through this layer's hierarchy for a view with the given unique ID.
196 /// <pre>This layer (the parent) has been initialized.</pre>
197 /// <remarks>The actor itself is also considered in the search.</remarks>
198 /// <param name="id">The id of the child to find</param>
199 /// <returns> A handle to the view if found, or an empty handle if not. </returns>
200 /// <since_tizen> 3 </since_tizen>
201 public View FindChildById(uint id)
203 IntPtr cPtr = NDalicPINVOKE.Actor_FindChildById(swigCPtr, id);
204 View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
206 if (NDalicPINVOKE.SWIGPendingException.Pending)
207 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
212 /// Queries the depth of the layer.<br />
213 /// 0 is the bottommost layer, higher number is on the top.<br />
215 /// <since_tizen> 3 </since_tizen>
224 internal uint GetDepth()
226 uint ret = NDalicPINVOKE.Layer_GetDepth(swigCPtr);
227 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
232 /// Increments the depth of the layer.
234 /// <since_tizen> 3 </since_tizen>
237 NDalicPINVOKE.Layer_Raise(swigCPtr);
238 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
242 /// Decrements the depth of the layer.
244 /// <since_tizen> 3 </since_tizen>
247 NDalicPINVOKE.Layer_Lower(swigCPtr);
248 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
251 internal void RaiseAbove(Layer target)
253 NDalicPINVOKE.Layer_RaiseAbove(swigCPtr, Layer.getCPtr(target));
254 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257 internal void LowerBelow(Layer target)
259 NDalicPINVOKE.Layer_LowerBelow(swigCPtr, Layer.getCPtr(target));
260 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
264 /// Raises the layer to the top.
266 /// <since_tizen> 3 </since_tizen>
267 public void RaiseToTop()
269 NDalicPINVOKE.Layer_RaiseToTop(swigCPtr);
270 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274 /// Lowers the layer to the bottom.
276 /// <since_tizen> 3 </since_tizen>
277 public void LowerToBottom()
279 NDalicPINVOKE.Layer_LowerToBottom(swigCPtr);
280 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284 /// Moves the layer directly above the given layer.<br />
285 /// After the call, this layer's depth will be immediately above target.<br />
287 /// <param name="target">The layer to get on top of.</param>
288 /// <since_tizen> 3 </since_tizen>
289 public void MoveAbove(Layer target)
291 NDalicPINVOKE.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
292 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
296 /// Moves the layer directly below the given layer.<br />
297 /// After the call, this layer's depth will be immediately below target.<br />
299 /// <param name="target">The layer to get below of.</param>
300 /// <since_tizen> 3 </since_tizen>
301 public void MoveBelow(Layer target)
303 NDalicPINVOKE.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
304 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
307 private void SetBehavior(LayerBehavior behavior)
309 NDalicPINVOKE.Layer_SetBehavior(swigCPtr, (int)behavior);
310 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
313 private LayerBehavior GetBehavior()
315 Layer.LayerBehavior ret = (Layer.LayerBehavior)NDalicPINVOKE.Layer_GetBehavior(swigCPtr);
316 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320 internal void SetSortFunction(SWIGTYPE_p_f_r_q_const__Dali__Vector3__float function)
322 NDalicPINVOKE.Layer_SetSortFunction(swigCPtr, SWIGTYPE_p_f_r_q_const__Dali__Vector3__float.getCPtr(function));
323 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
326 internal void SetTouchConsumed(bool consume)
328 NDalicPINVOKE.Layer_SetTouchConsumed(swigCPtr, consume);
329 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332 internal bool IsTouchConsumed()
334 bool ret = NDalicPINVOKE.Layer_IsTouchConsumed(swigCPtr);
335 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
339 internal void SetHoverConsumed(bool consume)
341 NDalicPINVOKE.Layer_SetHoverConsumed(swigCPtr, consume);
342 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345 internal bool IsHoverConsumed()
347 bool ret = NDalicPINVOKE.Layer_IsHoverConsumed(swigCPtr);
348 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
353 /// Enumeration for the behavior of the layer.
355 /// <since_tizen> 3 </since_tizen>
356 public enum LayerBehavior
359 /// UI control rendering mode.
361 /// <since_tizen> 3 </since_tizen>
364 /// UI control rendering mode (default mode).
365 /// This mode is designed for UI controls that can overlap. In this
366 /// mode renderer order will be respective to the tree hierarchy of
368 /// The rendering order is depth first, so for the following actor tree,
369 /// A will be drawn first, then B, D, E, then C, F. This ensures that
370 /// overlapping actors are drawn as expected (whereas, with breadth first
371 /// traversal, the actors would interleave).<br />
373 /// <since_tizen> 3 </since_tizen>
376 /// Layer will use depth test.
377 /// This mode is designed for a 3 dimensional scene where actors in front
378 /// of other actors will obscure them, i.e. the actors are sorted by the
379 /// distance from the camera.<br />
380 /// When using this mode, a depth test will be used. A depth clear will
381 /// happen for each layer, which means actors in a layer "above" other
382 /// layers will be rendered in front of actors in those layers regardless
383 /// of their Z positions (see Layer::Raise() and Layer::Lower()).<br />
384 /// Opaque renderers are drawn first and write to the depth buffer. Then
385 /// transparent renderers are drawn with depth test enabled but depth
386 /// write switched off. Transparent renderers are drawn based on their
387 /// distance from the camera. A renderer's DEPTH_INDEX property is used to
388 /// offset the distance to the camera when ordering transparent renderers.
389 /// This is useful if you want to define the draw order of two or more
390 /// transparent renderers that are equal distance from the camera. Unlike
391 /// LAYER_UI, parent-child relationship does not affect rendering order at
394 /// <since_tizen> 3 </since_tizen>
398 internal enum TreeDepthMultiplier
400 TREE_DEPTH_MULTIPLIER = 10000
404 /// Layer behavior, type String (Layer.LayerBehavior).
406 /// <since_tizen> 3 </since_tizen>
407 public Layer.LayerBehavior Behavior
411 return GetBehavior();
420 /// Internal only property to enable or disable clipping, type boolean.
421 /// By default, this is false, i.e., the viewport of the layer is the entire window.
423 internal bool ClippingEnabled
427 bool ret = NDalicPINVOKE.Layer_IsClipping(swigCPtr);
428 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
433 NDalicPINVOKE.Layer_SetClipping(swigCPtr, value);
434 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
439 /// Sets the viewport (in window coordinates), type rectangle.
440 /// The contents of the layer will not be visible outside this box, when ViewportEnabled is true.
442 /// <since_tizen> 4 </since_tizen>
443 public Rectangle Viewport
447 if( ClippingEnabled )
449 Rectangle ret = new Rectangle(NDalicPINVOKE.Layer_GetClippingBox(swigCPtr), true);
450 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
455 // Clipping not enabled so return the window size
456 Size2D windowSize = Window.Instance.Size;
457 Rectangle ret = new Rectangle(0, 0, windowSize.Width, windowSize.Height);
463 NDalicPINVOKE.Layer_SetClippingBox__SWIG_1(swigCPtr, Rectangle.getCPtr(value));
464 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
465 ClippingEnabled = true;
470 /// Retrieves and sets the layer's opacity.<br />
472 /// <since_tizen> 3 </since_tizen>
478 GetProperty(View.Property.OPACITY).Get(out temp);
483 SetProperty(View.Property.OPACITY, new Tizen.NUI.PropertyValue(value));
488 /// Retrieves and sets the layer's visibility.
490 /// <since_tizen> 3 </since_tizen>
491 public bool Visibility
496 GetProperty(View.Property.VISIBLE).Get(out temp);
501 SetProperty(View.Property.VISIBLE, new Tizen.NUI.PropertyValue(value));
506 /// Get the number of children held by the layer.
508 /// <since_tizen> 3 </since_tizen>
509 public new uint ChildCount
513 return Convert.ToUInt32(Children.Count);
518 /// Gets or sets the layer's name.
520 /// <since_tizen> 3 </since_tizen>
533 internal string GetName()
535 string ret = NDalicPINVOKE.Actor_GetName(swigCPtr);
536 if (NDalicPINVOKE.SWIGPendingException.Pending)
537 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
541 internal void SetName(string name)
543 NDalicPINVOKE.Actor_SetName(swigCPtr, name);
544 if (NDalicPINVOKE.SWIGPendingException.Pending)
545 throw NDalicPINVOKE.SWIGPendingException.Retrieve();