[NUI] Add Obsolete attributes for EditorBrowsable apis
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Layer.cs
1 /*
2  * Copyright(c) 2017 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 using System;
18 using Tizen.NUI.BaseComponents;
19 using System.ComponentModel;
20
21 namespace Tizen.NUI
22 {
23
24     /// <summary>
25     /// Layers provide a mechanism for overlaying groups of actors on top of each other.
26     /// </summary>
27     /// <since_tizen> 3 </since_tizen>
28     public class Layer : Container
29     {
30         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
31
32         internal Layer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Layer_SWIGUpcast(cPtr), cMemoryOwn)
33         {
34             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
35         }
36
37         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Layer obj)
38         {
39             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
40         }
41
42         /// From the Container base class.
43
44         /// <summary>
45         /// Adds a child view to this layer.
46         /// </summary>
47         /// <seealso cref="Container.Add">
48         /// </seealso>
49         /// <since_tizen> 4 </since_tizen>
50         public override void Add(View child)
51         {
52             NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
53             if (NDalicPINVOKE.SWIGPendingException.Pending)
54                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
55
56             Children.Add(child);
57         }
58
59         /// <summary>
60         /// Removes a child view from this layer. If the view was not a child of this layer, this is a no-op.
61         /// </summary>
62         /// <seealso cref="Container.Remove">
63         /// </seealso>
64         /// <since_tizen> 4 </since_tizen>
65         public override void Remove(View child)
66         {
67             NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child));
68             if (NDalicPINVOKE.SWIGPendingException.Pending)
69                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
70
71             Children.Remove(child);
72         }
73
74         /// <summary>
75         /// Retrieves a child view by the index.
76         /// </summary>
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)
82         {
83             if (index < Children.Count)
84             {
85                 return Children[Convert.ToInt32(index)];
86             }
87             else
88             {
89                 return null;
90             }
91         }
92
93
94         /// <summary>
95         /// Get parent of the layer.
96         /// </summary>
97         /// <returns>The view's container</returns>
98         /// <since_tizen> 4 </since_tizen>
99         public override Container GetParent()
100         {
101             return null;
102         }
103
104         /// <summary>
105         /// Get the child count of the layer.
106         /// </summary>
107         /// <returns>The child count of the layer.</returns>
108         /// <since_tizen> 4 </since_tizen>
109         public override uint GetChildCount()
110         {
111             return Convert.ToUInt32(Children.Count);
112         }
113
114         /// <summary>
115         /// Dispose.
116         /// </summary>
117         /// <since_tizen> 3 </since_tizen>
118         protected override void Dispose(DisposeTypes type)
119         {
120             if(disposed)
121             {
122                 return;
123             }
124
125             if(type == DisposeTypes.Explicit)
126             {
127                 //Called by User
128                 //Release your own managed resources here.
129                 //You should release all of your own disposable objects here.
130             }
131
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.
135
136             if (swigCPtr.Handle != global::System.IntPtr.Zero)
137             {
138                 if (swigCMemOwn)
139                 {
140                     swigCMemOwn = false;
141                     NDalicPINVOKE.delete_Layer(swigCPtr);
142                 }
143                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
144             }
145
146             base.Dispose(type);
147
148         }
149
150
151         internal class Property
152         {
153             internal static readonly int BEHAVIOR = NDalicPINVOKE.Layer_Property_BEHAVIOR_get();
154         }
155
156         /// <summary>
157         /// Creates a Layer object.
158         /// </summary>
159         /// <since_tizen> 3 </since_tizen>
160         public Layer() : this(NDalicPINVOKE.Layer_New(), true)
161         {
162             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163             if(Window.Instance != null)
164             {
165                 this.SetAnchorPoint(Tizen.NUI.PivotPoint.TopLeft);
166                 this.SetResizePolicy(ResizePolicyType.FillToParent, DimensionType.AllDimensions);
167             }
168         }
169         internal void SetAnchorPoint(Vector3 anchorPoint)
170         {
171             NDalicPINVOKE.Actor_SetAnchorPoint(swigCPtr, Vector3.getCPtr(anchorPoint));
172             if (NDalicPINVOKE.SWIGPendingException.Pending)
173                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
174         }
175         internal void SetResizePolicy(ResizePolicyType policy, DimensionType dimension)
176         {
177             NDalicPINVOKE.Actor_SetResizePolicy(swigCPtr, (int)policy, (int)dimension);
178             if (NDalicPINVOKE.SWIGPendingException.Pending)
179                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
180         }
181
182
183         /// <summary>
184         /// Downcasts a handle to layer handle.
185         /// </summary>
186         /// <since_tizen> 3 </since_tizen>
187         /// Please do not use! this will be deprecated!
188         /// Instead please use as keyword.
189         [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead!")]
190         [EditorBrowsable(EditorBrowsableState.Never)]
191         public static Layer DownCast(BaseHandle handle)
192         {
193             Layer ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as Layer;
194             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
195             return ret;
196         }
197
198         /// <summary>
199         /// Search through this layer's hierarchy for a view with the given unique ID.
200         /// </summary>
201         /// <pre>This layer (the parent) has been initialized.</pre>
202         /// <remarks>The actor itself is also considered in the search.</remarks>
203         /// <param name="id">The id of the child to find</param>
204         /// <returns> A handle to the view if found, or an empty handle if not. </returns>
205         /// <since_tizen> 3 </since_tizen>
206         public View FindChildById(uint id)
207         {
208             IntPtr cPtr = NDalicPINVOKE.Actor_FindChildById(swigCPtr, id);
209             View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
210
211             if (NDalicPINVOKE.SWIGPendingException.Pending)
212                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213             return ret;
214         }
215
216         /// <summary>
217         /// Queries the depth of the layer.<br />
218         /// 0 is the bottommost layer, higher number is on the top.<br />
219         /// </summary>
220         /// <since_tizen> 3 </since_tizen>
221         public uint Depth
222         {
223             get
224             {
225                 return GetDepth();
226             }
227         }
228
229         internal uint GetDepth()
230         {
231             uint ret = NDalicPINVOKE.Layer_GetDepth(swigCPtr);
232             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233             return ret;
234         }
235
236         /// <summary>
237         /// Increments the depth of the layer.
238         /// </summary>
239         /// <since_tizen> 3 </since_tizen>
240         public void Raise()
241         {
242             NDalicPINVOKE.Layer_Raise(swigCPtr);
243             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244         }
245
246         /// <summary>
247         /// Decrements the depth of the layer.
248         /// </summary>
249         /// <since_tizen> 3 </since_tizen>
250         public void Lower()
251         {
252             NDalicPINVOKE.Layer_Lower(swigCPtr);
253             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254         }
255
256         internal void RaiseAbove(Layer target)
257         {
258             NDalicPINVOKE.Layer_RaiseAbove(swigCPtr, Layer.getCPtr(target));
259             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260         }
261
262         internal void LowerBelow(Layer target)
263         {
264             NDalicPINVOKE.Layer_LowerBelow(swigCPtr, Layer.getCPtr(target));
265             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266         }
267
268         /// <summary>
269         /// Raises the layer to the top.
270         /// </summary>
271         /// <since_tizen> 3 </since_tizen>
272         public void RaiseToTop()
273         {
274             NDalicPINVOKE.Layer_RaiseToTop(swigCPtr);
275             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
276         }
277
278         /// <summary>
279         /// Lowers the layer to the bottom.
280         /// </summary>
281         /// <since_tizen> 3 </since_tizen>
282         public void LowerToBottom()
283         {
284             NDalicPINVOKE.Layer_LowerToBottom(swigCPtr);
285             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286         }
287
288         /// <summary>
289         /// Moves the layer directly above the given layer.<br />
290         /// After the call, this layer's depth will be immediately above target.<br />
291         /// </summary>
292         /// <param name="target">The layer to get on top of.</param>
293         /// <since_tizen> 3 </since_tizen>
294         public void MoveAbove(Layer target)
295         {
296             NDalicPINVOKE.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
297             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
298         }
299
300         /// <summary>
301         /// Moves the layer directly below the given layer.<br />
302         /// After the call, this layer's depth will be immediately below target.<br />
303         /// </summary>
304         /// <param name="target">The layer to get below of.</param>
305         /// <since_tizen> 3 </since_tizen>
306         public void MoveBelow(Layer target)
307         {
308             NDalicPINVOKE.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
309             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
310         }
311
312         private void SetBehavior(LayerBehavior behavior)
313         {
314             NDalicPINVOKE.Layer_SetBehavior(swigCPtr, (int)behavior);
315             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316         }
317
318         private LayerBehavior GetBehavior()
319         {
320             Layer.LayerBehavior ret = (Layer.LayerBehavior)NDalicPINVOKE.Layer_GetBehavior(swigCPtr);
321             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
322             return ret;
323         }
324
325         internal void SetSortFunction(SWIGTYPE_p_f_r_q_const__Dali__Vector3__float function)
326         {
327             NDalicPINVOKE.Layer_SetSortFunction(swigCPtr, SWIGTYPE_p_f_r_q_const__Dali__Vector3__float.getCPtr(function));
328             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
329         }
330
331         internal void SetTouchConsumed(bool consume)
332         {
333             NDalicPINVOKE.Layer_SetTouchConsumed(swigCPtr, consume);
334             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
335         }
336
337         internal bool IsTouchConsumed()
338         {
339             bool ret = NDalicPINVOKE.Layer_IsTouchConsumed(swigCPtr);
340             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
341             return ret;
342         }
343
344         internal void SetHoverConsumed(bool consume)
345         {
346             NDalicPINVOKE.Layer_SetHoverConsumed(swigCPtr, consume);
347             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348         }
349
350         internal bool IsHoverConsumed()
351         {
352             bool ret = NDalicPINVOKE.Layer_IsHoverConsumed(swigCPtr);
353             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
354             return ret;
355         }
356
357         /// <summary>
358         /// Enumeration for the behavior of the layer.
359         /// </summary>
360         /// <since_tizen> 3 </since_tizen>
361         public enum LayerBehavior
362         {
363             /// <summary>
364             /// UI control rendering mode.
365             /// </summary>
366             /// <since_tizen> 3 </since_tizen>
367             Layer2D,
368             /// <summary>
369             /// UI control rendering mode (default mode).
370             /// This mode is designed for UI controls that can overlap. In this
371             /// mode renderer order will be respective to the tree hierarchy of
372             /// Actors.<br />
373             /// The rendering order is depth first, so for the following actor tree,
374             /// A will be drawn first, then B, D, E, then C, F.  This ensures that
375             /// overlapping actors are drawn as expected (whereas, with breadth first
376             /// traversal, the actors would interleave).<br />
377             /// </summary>
378             /// <since_tizen> 3 </since_tizen>
379             LayerUI = Layer2D,
380             /// <summary>
381             /// Layer will use depth test.
382             /// This mode is designed for a 3 dimensional scene where actors in front
383             /// of other actors will obscure them, i.e. the actors are sorted by the
384             /// distance from the camera.<br />
385             /// When using this mode, a depth test will be used. A depth clear will
386             /// happen for each layer, which means actors in a layer "above" other
387             /// layers will be rendered in front of actors in those layers regardless
388             /// of their Z positions (see Layer::Raise() and Layer::Lower()).<br />
389             /// Opaque renderers are drawn first and write to the depth buffer.  Then
390             /// transparent renderers are drawn with depth test enabled but depth
391             /// write switched off.  Transparent renderers are drawn based on their
392             /// distance from the camera.  A renderer's DEPTH_INDEX property is used to
393             /// offset the distance to the camera when ordering transparent renderers.
394             /// This is useful if you want to define the draw order of two or more
395             /// transparent renderers that are equal distance from the camera.  Unlike
396             /// LAYER_UI, parent-child relationship does not affect rendering order at
397             /// all.
398             /// </summary>
399             /// <since_tizen> 3 </since_tizen>
400             Layer3D
401         }
402
403         internal enum TreeDepthMultiplier
404         {
405             TREE_DEPTH_MULTIPLIER = 10000
406         }
407
408         /// <summary>
409         /// Layer behavior, type String (Layer.LayerBehavior).
410         /// </summary>
411         /// <since_tizen> 3 </since_tizen>
412         public Layer.LayerBehavior Behavior
413         {
414             get
415             {
416                 return GetBehavior();
417             }
418             set
419             {
420                 SetBehavior(value);
421             }
422         }
423
424         /// <summary>
425         /// Internal only property to enable or disable clipping, type boolean.
426         /// By default, this is false, i.e., the viewport of the layer is the entire window.
427         /// </summary>
428         internal bool ClippingEnabled
429         {
430             get
431             {
432                 bool ret = NDalicPINVOKE.Layer_IsClipping(swigCPtr);
433                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
434                 return ret;
435             }
436             set
437             {
438                 NDalicPINVOKE.Layer_SetClipping(swigCPtr, value);
439                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
440             }
441         }
442
443         /// <summary>
444         /// Sets the viewport (in window coordinates), type rectangle.
445         /// The contents of the layer will not be visible outside this box, when ViewportEnabled is true.
446         /// </summary>
447         /// <since_tizen> 4 </since_tizen>
448         public Rectangle Viewport
449         {
450             get
451             {
452                 if( ClippingEnabled )
453                 {
454                   Rectangle ret = new Rectangle(NDalicPINVOKE.Layer_GetClippingBox(swigCPtr), true);
455                   if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
456                   return ret;
457                 }
458                 else
459                 {
460                   // Clipping not enabled so return the window size
461                   Size2D windowSize = Window.Instance.Size;
462                   Rectangle ret = new Rectangle(0, 0, windowSize.Width, windowSize.Height);
463                   return ret;
464                 }
465             }
466             set
467             {
468                 NDalicPINVOKE.Layer_SetClippingBox__SWIG_1(swigCPtr, Rectangle.getCPtr(value));
469                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
470                 ClippingEnabled = true;
471             }
472         }
473
474         /// <summary>
475         /// Retrieves and sets the layer's opacity.<br />
476         /// </summary>
477         /// <since_tizen> 3 </since_tizen>
478         public float Opacity
479         {
480             get
481             {
482                 float temp = 0.0f;
483                 GetProperty(View.Property.OPACITY).Get(out temp);
484                 return temp;
485             }
486             set
487             {
488                 SetProperty(View.Property.OPACITY, new Tizen.NUI.PropertyValue(value));
489             }
490         }
491
492         /// <summary>
493         /// Retrieves and sets the layer's visibility.
494         /// </summary>
495         /// <since_tizen> 3 </since_tizen>
496         public bool Visibility
497         {
498             get
499             {
500                 bool temp = false;
501                 GetProperty(View.Property.VISIBLE).Get(out temp);
502                 return temp;
503             }
504             set
505             {
506                 SetProperty(View.Property.VISIBLE, new Tizen.NUI.PropertyValue(value));
507             }
508         }
509
510         /// <summary>
511         /// Get the number of children held by the layer.
512         /// </summary>
513         /// <since_tizen> 3 </since_tizen>
514         public new uint ChildCount
515         {
516             get
517             {
518                 return Convert.ToUInt32(Children.Count);
519             }
520         }
521
522         /// <summary>
523         /// Gets or sets the layer's name.
524         /// </summary>
525         /// <since_tizen> 3 </since_tizen>
526         public string Name
527         {
528             get
529             {
530                 return GetName();
531             }
532             set
533             {
534                 SetName(value);
535             }
536         }
537
538         internal string GetName()
539         {
540             string ret = NDalicPINVOKE.Actor_GetName(swigCPtr);
541             if (NDalicPINVOKE.SWIGPendingException.Pending)
542                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
543             return ret;
544         }
545
546         internal void SetName(string name)
547         {
548             NDalicPINVOKE.Actor_SetName(swigCPtr, name);
549             if (NDalicPINVOKE.SWIGPendingException.Pending)
550                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
551         }
552
553     }
554 }