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 public class Layer : Container
29 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
31 internal Layer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Layer_SWIGUpcast(cPtr), cMemoryOwn)
33 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
36 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Layer obj)
38 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
41 /// From the Container base class.
44 /// Adds a child view to this layer.
46 /// <seealso cref="Container.Add">
48 /// <since_tizen> 4 </since_tizen>
49 public override void Add(View child)
51 NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
52 if (NDalicPINVOKE.SWIGPendingException.Pending)
53 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
59 /// Removes a child view from this layer. If the view was not a child of this layer, this is a no-op.
61 /// <seealso cref="Container.Remove">
63 /// <since_tizen> 4 </since_tizen>
64 public override void Remove(View child)
66 NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child));
67 if (NDalicPINVOKE.SWIGPendingException.Pending)
68 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
70 Children.Remove(child);
74 /// Retrieves a child view by the index.
76 /// <pre>The view has been initialized.</pre>
77 /// <param name="index">The index of the child to retrieve.</param>
78 /// <returns>The view for the given index or empty handle if children not initialized.</returns>
79 /// <since_tizen> 4 </since_tizen>
80 public override View GetChildAt(uint index)
82 if (index < Children.Count)
84 return Children[Convert.ToInt32(index)];
94 /// Get parent of the layer.
96 /// <returns>The view's container</returns>
97 /// <since_tizen> 3 </since_tizen>
98 public override Container GetParent()
104 /// Get the child count of the layer.
106 /// <returns>The child count of the layer.</returns>
107 /// <since_tizen> 3 </since_tizen>
108 public override uint GetChildCount()
110 return Convert.ToUInt32(Children.Count);
116 /// <since_tizen> 3 </since_tizen>
117 protected override void Dispose(DisposeTypes type)
124 if(type == DisposeTypes.Explicit)
127 //Release your own managed resources here.
128 //You should release all of your own disposable objects here.
131 //Release your own unmanaged resources here.
132 //You should not access any managed member here except static instance.
133 //because the execution order of Finalizes is non-deterministic.
135 if (swigCPtr.Handle != global::System.IntPtr.Zero)
140 NDalicPINVOKE.delete_Layer(swigCPtr);
142 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
150 internal class Property
152 internal static readonly int BEHAVIOR = NDalicPINVOKE.Layer_Property_BEHAVIOR_get();
156 /// Creates a Layer object.
158 /// <since_tizen> 3 </since_tizen>
159 public Layer() : this(NDalicPINVOKE.Layer_New(), true)
161 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
162 if(Window.Instance != null)
164 this.SetAnchorPoint(Tizen.NUI.PivotPoint.TopLeft);
165 this.SetResizePolicy(ResizePolicyType.FillToParent, DimensionType.AllDimensions);
168 internal void SetAnchorPoint(Vector3 anchorPoint)
170 NDalicPINVOKE.Actor_SetAnchorPoint(swigCPtr, Vector3.getCPtr(anchorPoint));
171 if (NDalicPINVOKE.SWIGPendingException.Pending)
172 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
174 internal void SetResizePolicy(ResizePolicyType policy, DimensionType dimension)
176 NDalicPINVOKE.Actor_SetResizePolicy(swigCPtr, (int)policy, (int)dimension);
177 if (NDalicPINVOKE.SWIGPendingException.Pending)
178 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, instead please USE as keyword.")]
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 uint ret = NDalicPINVOKE.Layer_GetDepth(swigCPtr);
231 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
236 /// Increments the depth of the layer.
238 /// <since_tizen> 3 </since_tizen>
241 NDalicPINVOKE.Layer_Raise(swigCPtr);
242 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
246 /// Decrements the depth of the layer.
248 /// <since_tizen> 3 </since_tizen>
251 NDalicPINVOKE.Layer_Lower(swigCPtr);
252 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255 internal void RaiseAbove(Layer target)
257 NDalicPINVOKE.Layer_RaiseAbove(swigCPtr, Layer.getCPtr(target));
258 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261 internal void LowerBelow(Layer target)
263 NDalicPINVOKE.Layer_LowerBelow(swigCPtr, Layer.getCPtr(target));
264 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
268 /// Raises the layer to the top.
270 /// <since_tizen> 3 </since_tizen>
271 public void RaiseToTop()
273 NDalicPINVOKE.Layer_RaiseToTop(swigCPtr);
274 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
278 /// Lowers the layer to the bottom.
280 /// <since_tizen> 3 </since_tizen>
281 public void LowerToBottom()
283 NDalicPINVOKE.Layer_LowerToBottom(swigCPtr);
284 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288 /// Moves the layer directly above the given layer.<br />
289 /// After the call, this layer's depth will be immediately above target.<br />
291 /// <param name="target">The layer to get on top of.</param>
292 /// <since_tizen> 3 </since_tizen>
293 public void MoveAbove(Layer target)
295 NDalicPINVOKE.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
296 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300 /// Moves the layer directly below the given layer.<br />
301 /// After the call, this layer's depth will be immediately below target.<br />
303 /// <param name="target">The layer to get below of.</param>
304 /// <since_tizen> 3 </since_tizen>
305 public void MoveBelow(Layer target)
307 NDalicPINVOKE.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
308 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
311 private void SetBehavior(LayerBehavior behavior)
313 NDalicPINVOKE.Layer_SetBehavior(swigCPtr, (int)behavior);
314 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317 private LayerBehavior GetBehavior()
319 Layer.LayerBehavior ret = (Layer.LayerBehavior)NDalicPINVOKE.Layer_GetBehavior(swigCPtr);
320 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
324 internal void SetSortFunction(SWIGTYPE_p_f_r_q_const__Dali__Vector3__float function)
326 NDalicPINVOKE.Layer_SetSortFunction(swigCPtr, SWIGTYPE_p_f_r_q_const__Dali__Vector3__float.getCPtr(function));
327 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
330 internal void SetTouchConsumed(bool consume)
332 NDalicPINVOKE.Layer_SetTouchConsumed(swigCPtr, consume);
333 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
336 internal bool IsTouchConsumed()
338 bool ret = NDalicPINVOKE.Layer_IsTouchConsumed(swigCPtr);
339 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
343 internal void SetHoverConsumed(bool consume)
345 NDalicPINVOKE.Layer_SetHoverConsumed(swigCPtr, consume);
346 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
349 internal bool IsHoverConsumed()
351 bool ret = NDalicPINVOKE.Layer_IsHoverConsumed(swigCPtr);
352 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
357 /// Enumeration for the behavior of the layer.
359 /// <since_tizen> 3 </since_tizen>
360 public enum LayerBehavior
363 /// UI control rendering mode.
365 /// <since_tizen> 3 </since_tizen>
368 /// UI control rendering mode (default mode).
369 /// This mode is designed for UI controls that can overlap. In this
370 /// mode renderer order will be respective to the tree hierarchy of
372 /// The rendering order is depth first, so for the following actor tree,
373 /// A will be drawn first, then B, D, E, then C, F. This ensures that
374 /// overlapping actors are drawn as expected (whereas, with breadth first
375 /// traversal, the actors would interleave).<br />
377 /// <since_tizen> 3 </since_tizen>
380 /// Layer will use depth test.
381 /// This mode is designed for a 3 dimensional scene where actors in front
382 /// of other actors will obscure them, i.e. the actors are sorted by the
383 /// distance from the camera.<br />
384 /// When using this mode, a depth test will be used. A depth clear will
385 /// happen for each layer, which means actors in a layer "above" other
386 /// layers will be rendered in front of actors in those layers regardless
387 /// of their Z positions (see Layer::Raise() and Layer::Lower()).<br />
388 /// Opaque renderers are drawn first and write to the depth buffer. Then
389 /// transparent renderers are drawn with depth test enabled but depth
390 /// write switched off. Transparent renderers are drawn based on their
391 /// distance from the camera. A renderer's DEPTH_INDEX property is used to
392 /// offset the distance to the camera when ordering transparent renderers.
393 /// This is useful if you want to define the draw order of two or more
394 /// transparent renderers that are equal distance from the camera. Unlike
395 /// LAYER_UI, parent-child relationship does not affect rendering order at
398 /// <since_tizen> 3 </since_tizen>
402 internal enum TreeDepthMultiplier
404 TREE_DEPTH_MULTIPLIER = 10000
408 /// Layer behavior, type String (Layer.LayerBehavior).
410 /// <since_tizen> 3 </since_tizen>
411 public Layer.LayerBehavior Behavior
415 return GetBehavior();
424 /// Internal only property to enable or disable clipping, type boolean.
425 /// By default, this is false, i.e., the viewport of the layer is the entire window.
427 internal bool ClippingEnabled
431 bool ret = NDalicPINVOKE.Layer_IsClipping(swigCPtr);
432 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
437 NDalicPINVOKE.Layer_SetClipping(swigCPtr, value);
438 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
443 /// Sets the viewport (in window coordinates), type rectangle.
444 /// The contents of the layer will not be visible outside this box, when ViewportEnabled is true.
446 /// <since_tizen> 4 </since_tizen>
447 public Rectangle Viewport
451 if( ClippingEnabled )
453 Rectangle ret = new Rectangle(NDalicPINVOKE.Layer_GetClippingBox(swigCPtr), true);
454 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
459 // Clipping not enabled so return the window size
460 Size2D windowSize = Window.Instance.Size;
461 Rectangle ret = new Rectangle(0, 0, windowSize.Width, windowSize.Height);
467 NDalicPINVOKE.Layer_SetClippingBox__SWIG_1(swigCPtr, Rectangle.getCPtr(value));
468 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
469 ClippingEnabled = true;
474 /// Retrieves and sets the layer's opacity.<br />
476 /// <since_tizen> 3 </since_tizen>
482 GetProperty(View.Property.OPACITY).Get(out temp);
487 SetProperty(View.Property.OPACITY, new Tizen.NUI.PropertyValue(value));
492 /// Retrieves and sets the layer's visibility.
494 /// <since_tizen> 3 </since_tizen>
495 public bool Visibility
500 GetProperty(View.Property.VISIBLE).Get(out temp);
505 SetProperty(View.Property.VISIBLE, new Tizen.NUI.PropertyValue(value));
510 /// Get the number of children held by the layer.
512 /// <since_tizen> 3 </since_tizen>
513 public new uint ChildCount
517 return Convert.ToUInt32(Children.Count);
522 /// Gets or sets the layer's name.
524 /// <since_tizen> 3 </since_tizen>
537 internal string GetName()
539 string ret = NDalicPINVOKE.Actor_GetName(swigCPtr);
540 if (NDalicPINVOKE.SWIGPendingException.Pending)
541 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
545 internal void SetName(string name)
547 NDalicPINVOKE.Actor_SetName(swigCPtr, name);
548 if (NDalicPINVOKE.SWIGPendingException.Pending)
549 throw NDalicPINVOKE.SWIGPendingException.Retrieve();