[NUI]Remove some unused 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.SetParentOrigin(Tizen.NUI.ParentOrigin.TopLeft);
166                 this.SetAnchorPoint(Tizen.NUI.PivotPoint.TopLeft);
167                 this.SetResizePolicy(ResizePolicyType.FillToParent, DimensionType.AllDimensions);
168             }
169         }
170         internal void SetAnchorPoint(Vector3 anchorPoint)
171         {
172             NDalicPINVOKE.Actor_SetAnchorPoint(swigCPtr, Vector3.getCPtr(anchorPoint));
173             if (NDalicPINVOKE.SWIGPendingException.Pending)
174                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175         }
176         internal void SetResizePolicy(ResizePolicyType policy, DimensionType dimension)
177         {
178             NDalicPINVOKE.Actor_SetResizePolicy(swigCPtr, (int)policy, (int)dimension);
179             if (NDalicPINVOKE.SWIGPendingException.Pending)
180                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
181         }
182
183         internal void SetParentOrigin(Vector3 origin)
184         {
185             NDalicPINVOKE.Actor_SetParentOrigin(swigCPtr, Vector3.getCPtr(origin));
186             if (NDalicPINVOKE.SWIGPendingException.Pending)
187                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188         }
189
190         /// <summary>
191         /// Downcasts a handle to layer handle.
192         /// </summary>
193         /// <since_tizen> 3 </since_tizen>
194         /// Please do not use! this will be deprecated!
195         /// Instead please use as keyword.
196         [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead!")]
197         [EditorBrowsable(EditorBrowsableState.Never)]
198         public static Layer DownCast(BaseHandle handle)
199         {
200             Layer ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as Layer;
201             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202             return ret;
203         }
204
205         /// <summary>
206         /// Search through this layer's hierarchy for a view with the given unique ID.
207         /// </summary>
208         /// <pre>This layer (the parent) has been initialized.</pre>
209         /// <remarks>The actor itself is also considered in the search.</remarks>
210         /// <param name="id">The id of the child to find</param>
211         /// <returns> A handle to the view if found, or an empty handle if not. </returns>
212         /// <since_tizen> 3 </since_tizen>
213         public View FindChildById(uint id)
214         {
215             IntPtr cPtr = NDalicPINVOKE.Actor_FindChildById(swigCPtr, id);
216             View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
217
218             if (NDalicPINVOKE.SWIGPendingException.Pending)
219                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220             return ret;
221         }
222
223         /// <summary>
224         /// Queries the depth of the layer.<br />
225         /// 0 is the bottommost layer, higher number is on the top.<br />
226         /// </summary>
227         /// <since_tizen> 3 </since_tizen>
228         public uint Depth
229         {
230             get
231             {
232                 return GetDepth();
233             }
234         }
235
236         internal uint GetDepth()
237         {
238             var parentChildren = Window.Instance.LayersChildren;
239             if(parentChildren != null)
240             {
241                 int idx = parentChildren.IndexOf(this);
242                 if (idx >= 0)
243                 {
244                     return Convert.ToUInt32(idx); ;
245                 }
246             }
247             return 0u;
248         }
249
250         /// <summary>
251         /// Increments the depth of the layer.
252         /// </summary>
253         /// <since_tizen> 3 </since_tizen>
254         public void Raise()
255         {
256             var parentChildren = Window.Instance.LayersChildren;
257             if (parentChildren != null)
258             {
259                 int currentIdx = parentChildren.IndexOf(this);
260
261                 if (currentIdx != parentChildren.Count - 1)
262                 {
263                     RaiseAbove(parentChildren[currentIdx + 1]);
264
265                     Layer temp = parentChildren[currentIdx + 1];
266                     parentChildren[currentIdx + 1] = this;
267                     parentChildren[currentIdx] = temp;
268                 }
269             }
270         }
271
272         /// <summary>
273         /// Decrements the depth of the layer.
274         /// </summary>
275         /// <since_tizen> 3 </since_tizen>
276         public void Lower()
277         {
278             var parentChildren = Window.Instance.LayersChildren;
279             if (parentChildren != null)
280             {
281                 int currentIdx = parentChildren.IndexOf(this);
282
283                 if (currentIdx > 0)
284                 {
285                     LowerBelow(parentChildren[currentIdx - 1]);
286
287                     Layer temp = parentChildren[currentIdx - 1];
288                     parentChildren[currentIdx - 1] = this;
289                     parentChildren[currentIdx] = temp;
290
291                 }
292             }
293         }
294
295         internal void RaiseAbove(Layer target)
296         {
297             NDalicPINVOKE.Layer_RaiseAbove(swigCPtr, Layer.getCPtr(target));
298             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299         }
300
301         internal void LowerBelow(Layer target)
302         {
303             NDalicPINVOKE.Layer_LowerBelow(swigCPtr, Layer.getCPtr(target));
304             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305         }
306
307         /// <summary>
308         /// Raises the layer to the top.
309         /// </summary>
310         /// <since_tizen> 3 </since_tizen>
311         public void RaiseToTop()
312         {
313             var parentChildren = Window.Instance.LayersChildren;
314
315             if (parentChildren != null)
316             {
317                 parentChildren.Remove(this);
318                 parentChildren.Add(this);
319             }
320             NDalicPINVOKE.Layer_RaiseToTop(swigCPtr);
321             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
322         }
323
324         /// <summary>
325         /// Lowers the layer to the bottom.
326         /// </summary>
327         /// <since_tizen> 3 </since_tizen>
328         public void LowerToBottom()
329         {
330             var parentChildren = Window.Instance.LayersChildren;
331
332             if (parentChildren != null)
333             {
334                 parentChildren.Remove(this);
335                 parentChildren.Insert(0, this);
336             }
337
338             NDalicPINVOKE.Layer_LowerToBottom(swigCPtr);
339             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
340         }
341
342         /// <summary>
343         /// Moves the layer directly above the given layer.<br />
344         /// After the call, this layer's depth will be immediately above target.<br />
345         /// </summary>
346         /// <param name="target">The layer to get on top of.</param>
347         /// <since_tizen> 3 </since_tizen>
348         public void MoveAbove(Layer target)
349         {
350             NDalicPINVOKE.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
351             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352         }
353
354         /// <summary>
355         /// Moves the layer directly below the given layer.<br />
356         /// After the call, this layer's depth will be immediately below target.<br />
357         /// </summary>
358         /// <param name="target">The layer to get below of.</param>
359         /// <since_tizen> 3 </since_tizen>
360         public void MoveBelow(Layer target)
361         {
362             NDalicPINVOKE.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
363             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
364         }
365
366         private void SetBehavior(LayerBehavior behavior)
367         {
368             NDalicPINVOKE.Layer_SetBehavior(swigCPtr, (int)behavior);
369             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
370         }
371
372         private LayerBehavior GetBehavior()
373         {
374             Layer.LayerBehavior ret = (Layer.LayerBehavior)NDalicPINVOKE.Layer_GetBehavior(swigCPtr);
375             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376             return ret;
377         }
378
379         internal void SetSortFunction(SWIGTYPE_p_f_r_q_const__Dali__Vector3__float function)
380         {
381             NDalicPINVOKE.Layer_SetSortFunction(swigCPtr, SWIGTYPE_p_f_r_q_const__Dali__Vector3__float.getCPtr(function));
382             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
383         }
384
385         internal void SetTouchConsumed(bool consume)
386         {
387             NDalicPINVOKE.Layer_SetTouchConsumed(swigCPtr, consume);
388             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
389         }
390
391         internal bool IsTouchConsumed()
392         {
393             bool ret = NDalicPINVOKE.Layer_IsTouchConsumed(swigCPtr);
394             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
395             return ret;
396         }
397
398         internal void SetHoverConsumed(bool consume)
399         {
400             NDalicPINVOKE.Layer_SetHoverConsumed(swigCPtr, consume);
401             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
402         }
403
404         internal bool IsHoverConsumed()
405         {
406             bool ret = NDalicPINVOKE.Layer_IsHoverConsumed(swigCPtr);
407             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
408             return ret;
409         }
410
411         /// <summary>
412         /// Enumeration for the behavior of the layer.
413         /// </summary>
414         /// <since_tizen> 3 </since_tizen>
415         public enum LayerBehavior
416         {
417             /// <summary>
418             /// UI control rendering mode.
419             /// </summary>
420             /// <since_tizen> 3 </since_tizen>
421             Layer2D,
422             /// <summary>
423             /// UI control rendering mode (default mode).
424             /// This mode is designed for UI controls that can overlap. In this
425             /// mode renderer order will be respective to the tree hierarchy of
426             /// Actors.<br />
427             /// The rendering order is depth first, so for the following actor tree,
428             /// A will be drawn first, then B, D, E, then C, F.  This ensures that
429             /// overlapping actors are drawn as expected (whereas, with breadth first
430             /// traversal, the actors would interleave).<br />
431             /// </summary>
432             /// <since_tizen> 3 </since_tizen>
433             LayerUI = Layer2D,
434             /// <summary>
435             /// Layer will use depth test.
436             /// This mode is designed for a 3 dimensional scene where actors in front
437             /// of other actors will obscure them, i.e. the actors are sorted by the
438             /// distance from the camera.<br />
439             /// When using this mode, a depth test will be used. A depth clear will
440             /// happen for each layer, which means actors in a layer "above" other
441             /// layers will be rendered in front of actors in those layers regardless
442             /// of their Z positions (see Layer::Raise() and Layer::Lower()).<br />
443             /// Opaque renderers are drawn first and write to the depth buffer.  Then
444             /// transparent renderers are drawn with depth test enabled but depth
445             /// write switched off.  Transparent renderers are drawn based on their
446             /// distance from the camera.  A renderer's DEPTH_INDEX property is used to
447             /// offset the distance to the camera when ordering transparent renderers.
448             /// This is useful if you want to define the draw order of two or more
449             /// transparent renderers that are equal distance from the camera.  Unlike
450             /// LAYER_UI, parent-child relationship does not affect rendering order at
451             /// all.
452             /// </summary>
453             /// <since_tizen> 3 </since_tizen>
454             Layer3D
455         }
456
457         internal enum TreeDepthMultiplier
458         {
459             TREE_DEPTH_MULTIPLIER = 10000
460         }
461
462         /// <summary>
463         /// Layer behavior, type String (Layer.LayerBehavior).
464         /// </summary>
465         /// <since_tizen> 3 </since_tizen>
466         public Layer.LayerBehavior Behavior
467         {
468             get
469             {
470                 return GetBehavior();
471             }
472             set
473             {
474                 SetBehavior(value);
475             }
476         }
477
478         /// <summary>
479         /// Internal only property to enable or disable clipping, type boolean.
480         /// By default, this is false, i.e., the viewport of the layer is the entire window.
481         /// </summary>
482         internal bool ClippingEnabled
483         {
484             get
485             {
486                 bool ret = NDalicPINVOKE.Layer_IsClipping(swigCPtr);
487                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
488                 return ret;
489             }
490             set
491             {
492                 NDalicPINVOKE.Layer_SetClipping(swigCPtr, value);
493                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
494             }
495         }
496
497         /// <summary>
498         /// Sets the viewport (in window coordinates), type rectangle.
499         /// The contents of the layer will not be visible outside this box, when ViewportEnabled is true.
500         /// </summary>
501         /// <since_tizen> 4 </since_tizen>
502         public Rectangle Viewport
503         {
504             get
505             {
506                 if( ClippingEnabled )
507                 {
508                   Rectangle ret = new Rectangle(NDalicPINVOKE.Layer_GetClippingBox(swigCPtr), true);
509                   if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
510                   return ret;
511                 }
512                 else
513                 {
514                   // Clipping not enabled so return the window size
515                   Size2D windowSize = Window.Instance.Size;
516                   Rectangle ret = new Rectangle(0, 0, windowSize.Width, windowSize.Height);
517                   return ret;
518                 }
519             }
520             set
521             {
522                 NDalicPINVOKE.Layer_SetClippingBox__SWIG_1(swigCPtr, Rectangle.getCPtr(value));
523                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
524                 ClippingEnabled = true;
525             }
526         }
527
528         /// <summary>
529         /// Retrieves and sets the layer's opacity.<br />
530         /// </summary>
531         /// <since_tizen> 3 </since_tizen>
532         public float Opacity
533         {
534             get
535             {
536                 float temp = 0.0f;
537                 GetProperty(View.Property.OPACITY).Get(out temp);
538                 return temp;
539             }
540             set
541             {
542                 SetProperty(View.Property.OPACITY, new Tizen.NUI.PropertyValue(value));
543             }
544         }
545
546         /// <summary>
547         /// Retrieves and sets the layer's visibility.
548         /// </summary>
549         /// <since_tizen> 3 </since_tizen>
550         public bool Visibility
551         {
552             get
553             {
554                 bool temp = false;
555                 GetProperty(View.Property.VISIBLE).Get(out temp);
556                 return temp;
557             }
558             set
559             {
560                 SetProperty(View.Property.VISIBLE, new Tizen.NUI.PropertyValue(value));
561             }
562         }
563
564         /// <summary>
565         /// Get the number of children held by the layer.
566         /// </summary>
567         /// <since_tizen> 3 </since_tizen>
568         public new uint ChildCount
569         {
570             get
571             {
572                 return Convert.ToUInt32(Children.Count);
573             }
574         }
575
576         /// <summary>
577         /// Gets or sets the layer's name.
578         /// </summary>
579         /// <since_tizen> 3 </since_tizen>
580         public string Name
581         {
582             get
583             {
584                 return GetName();
585             }
586             set
587             {
588                 SetName(value);
589             }
590         }
591
592         internal string GetName()
593         {
594             string ret = NDalicPINVOKE.Actor_GetName(swigCPtr);
595             if (NDalicPINVOKE.SWIGPendingException.Pending)
596                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
597             return ret;
598         }
599
600         internal void SetName(string name)
601         {
602             NDalicPINVOKE.Actor_SetName(swigCPtr, name);
603             if (NDalicPINVOKE.SWIGPendingException.Pending)
604                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
605         }
606
607     }
608 }