Release 4.0.0-preview1-00271
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Layer.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
17 namespace Tizen.NUI
18 {
19     using System;
20     using Tizen.NUI.BaseComponents;
21
22     /// <summary>
23     /// Layers provide a mechanism for overlaying groups of actors on top of each other.
24     /// </summary>
25     public class Layer : Container
26     {
27         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
28
29         internal Layer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Layer_SWIGUpcast(cPtr), cMemoryOwn)
30         {
31             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
32         }
33
34         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Layer obj)
35         {
36             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
37         }
38
39         /// From the Container base class.
40
41         /// <summary>
42         /// Adds a child view to this layer.
43         /// </summary>
44         /// <seealso cref="Container.Add">
45         /// </seealso>
46         /// <since_tizen> 4 </since_tizen>
47         public override void Add(View child)
48         {
49             NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
50             if (NDalicPINVOKE.SWIGPendingException.Pending)
51                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
52         }
53
54         /// <summary>
55         /// Removes a child view from this layer. If the view was not a child of this layer, this is a no-op.
56         /// </summary>
57         /// <seealso cref="Container.Remove">
58         /// </seealso>
59         /// <since_tizen> 4 </since_tizen>
60         public override void Remove(View child)
61         {
62             NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child));
63             if (NDalicPINVOKE.SWIGPendingException.Pending)
64                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
65         }
66
67         /// <summary>
68         /// Retrieves a child view by the index.
69         /// </summary>
70         /// <pre>The view has been initialized.</pre>
71         /// <param name="index">The index of the child to retrieve.</param>
72         /// <returns>The view for the given index or empty handle if children not initialized.</returns>
73         /// <since_tizen> 4 </since_tizen>
74         public override View GetChildAt(uint index)
75         {
76             System.IntPtr cPtr = NDalicPINVOKE.Actor_GetChildAt(swigCPtr, index);
77
78             View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
79
80             if (NDalicPINVOKE.SWIGPendingException.Pending)
81                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
82
83             return ret ?? null;
84         }
85
86
87         protected override Container GetParent()
88         {
89             return null;
90         }
91
92         protected override uint GetChildCount()
93         {
94             uint ret = NDalicPINVOKE.Actor_GetChildCount(swigCPtr);
95             if (NDalicPINVOKE.SWIGPendingException.Pending)
96                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
97             return ret;
98         }
99
100         protected override void Dispose(DisposeTypes type)
101         {
102             if(disposed)
103             {
104                 return;
105             }
106
107             if(type == DisposeTypes.Explicit)
108             {
109                 //Called by User
110                 //Release your own managed resources here.
111                 //You should release all of your own disposable objects here.
112             }
113
114             //Release your own unmanaged resources here.
115             //You should not access any managed member here except static instance.
116             //because the execution order of Finalizes is non-deterministic.
117
118             if (swigCPtr.Handle != global::System.IntPtr.Zero)
119             {
120                 if (swigCMemOwn)
121                 {
122                     swigCMemOwn = false;
123                     NDalicPINVOKE.delete_Layer(swigCPtr);
124                 }
125                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
126             }
127
128             base.Dispose(type);
129         }
130
131
132         internal class Property
133         {
134             internal static readonly int BEHAVIOR = NDalicPINVOKE.Layer_Property_BEHAVIOR_get();
135         }
136
137         /// <summary>
138         /// Creates a Layer object.
139         /// </summary>
140         /// <since_tizen> 3 </since_tizen>
141         public Layer() : this(NDalicPINVOKE.Layer_New(), true)
142         {
143             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
144             if(Window.Instance != null)
145             {
146                 this.SetAnchorPoint(Tizen.NUI.PivotPoint.TopLeft);
147                 this.SetResizePolicy(ResizePolicyType.FillToParent, DimensionType.AllDimensions);
148             }
149         }
150         internal void SetAnchorPoint(Vector3 anchorPoint)
151         {
152             NDalicPINVOKE.Actor_SetAnchorPoint(swigCPtr, Vector3.getCPtr(anchorPoint));
153             if (NDalicPINVOKE.SWIGPendingException.Pending)
154                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
155         }
156         internal void SetResizePolicy(ResizePolicyType policy, DimensionType dimension)
157         {
158             NDalicPINVOKE.Actor_SetResizePolicy(swigCPtr, (int)policy, (int)dimension);
159             if (NDalicPINVOKE.SWIGPendingException.Pending)
160                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
161         }
162
163
164
165         [Obsolete("Please do not use! this will be deprecated")]
166         public static Layer DownCast(BaseHandle handle)
167         {
168             Layer ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as Layer;
169             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170             return ret;
171         }
172
173         /// <summary>
174         /// Search through this layer's hierarchy for a view with the given unique ID.
175         /// </summary>
176         /// <pre>This layer (the parent) has been initialized.</pre>
177         /// <remarks>The actor itself is also considered in the search.</remarks>
178         /// <param name="id">The id of the child to find</param>
179         /// <returns> A handle to the view if found, or an empty handle if not. </returns>
180         /// <since_tizen> 3 </since_tizen>
181         public View FindChildById(uint id)
182         {
183             IntPtr cPtr = NDalicPINVOKE.Actor_FindChildById(swigCPtr, id);
184             View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
185
186             if (NDalicPINVOKE.SWIGPendingException.Pending)
187                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188             return ret;
189         }
190
191         /// <summary>
192         /// Queries the depth of the layer.<br>
193         /// 0 is the bottommost layer, higher number is on the top.<br>
194         /// </summary>
195         /// <since_tizen> 3 </since_tizen>
196         public uint Depth
197         {
198             get
199             {
200                 return GetDepth();
201             }
202         }
203
204         internal uint GetDepth()
205         {
206             uint ret = NDalicPINVOKE.Layer_GetDepth(swigCPtr);
207             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208             return ret;
209         }
210
211         /// <summary>
212         /// Increments the depth of the layer.
213         /// </summary>
214         /// <since_tizen> 3 </since_tizen>
215         public void Raise()
216         {
217             NDalicPINVOKE.Layer_Raise(swigCPtr);
218             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219         }
220
221         /// <summary>
222         /// Decrements the depth of the layer.
223         /// </summary>
224         /// <since_tizen> 3 </since_tizen>
225         public void Lower()
226         {
227             NDalicPINVOKE.Layer_Lower(swigCPtr);
228             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229         }
230
231         internal void RaiseAbove(Layer target)
232         {
233             NDalicPINVOKE.Layer_RaiseAbove(swigCPtr, Layer.getCPtr(target));
234             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235         }
236
237         internal void LowerBelow(Layer target)
238         {
239             NDalicPINVOKE.Layer_LowerBelow(swigCPtr, Layer.getCPtr(target));
240             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241         }
242
243         /// <summary>
244         /// Raises the layer to the top.
245         /// </summary>
246         /// <since_tizen> 3 </since_tizen>
247         public void RaiseToTop()
248         {
249             NDalicPINVOKE.Layer_RaiseToTop(swigCPtr);
250             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
251         }
252
253         /// <summary>
254         /// Lowers the layer to the bottom.
255         /// </summary>
256         /// <since_tizen> 3 </since_tizen>
257         public void LowerToBottom()
258         {
259             NDalicPINVOKE.Layer_LowerToBottom(swigCPtr);
260             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261         }
262
263         /// <summary>
264         /// Moves the layer directly above the given layer.<br>
265         /// After the call, this layer's depth will be immediately above target.<br>
266         /// </summary>
267         /// <param name="target">The layer to get on top of.</param>
268         /// <since_tizen> 3 </since_tizen>
269         public void MoveAbove(Layer target)
270         {
271             NDalicPINVOKE.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
272             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273         }
274
275         /// <summary>
276         /// Moves the layer directly below the given layer.<br>
277         /// After the call, this layer's depth will be immediately below target.<br>
278         /// </summary>
279         /// <param name="target">The layer to get below of.</param>
280         /// <since_tizen> 3 </since_tizen>
281         public void MoveBelow(Layer target)
282         {
283             NDalicPINVOKE.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
284             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285         }
286
287         private void SetBehavior(LayerBehavior behavior)
288         {
289             NDalicPINVOKE.Layer_SetBehavior(swigCPtr, (int)behavior);
290             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291         }
292
293         private LayerBehavior GetBehavior()
294         {
295             Layer.LayerBehavior ret = (Layer.LayerBehavior)NDalicPINVOKE.Layer_GetBehavior(swigCPtr);
296             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297             return ret;
298         }
299
300         internal void SetSortFunction(SWIGTYPE_p_f_r_q_const__Dali__Vector3__float function)
301         {
302             NDalicPINVOKE.Layer_SetSortFunction(swigCPtr, SWIGTYPE_p_f_r_q_const__Dali__Vector3__float.getCPtr(function));
303             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304         }
305
306         internal void SetTouchConsumed(bool consume)
307         {
308             NDalicPINVOKE.Layer_SetTouchConsumed(swigCPtr, consume);
309             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
310         }
311
312         internal bool IsTouchConsumed()
313         {
314             bool ret = NDalicPINVOKE.Layer_IsTouchConsumed(swigCPtr);
315             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316             return ret;
317         }
318
319         internal void SetHoverConsumed(bool consume)
320         {
321             NDalicPINVOKE.Layer_SetHoverConsumed(swigCPtr, consume);
322             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
323         }
324
325         internal bool IsHoverConsumed()
326         {
327             bool ret = NDalicPINVOKE.Layer_IsHoverConsumed(swigCPtr);
328             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
329             return ret;
330         }
331
332         /// <summary>
333         /// Enumeration for the behavior of the layer.
334         /// </summary>
335         /// <since_tizen> 3 </since_tizen>
336         public enum LayerBehavior
337         {
338             Layer2D,
339             LayerUI = Layer2D,
340             Layer3D
341         }
342
343         internal enum TreeDepthMultiplier
344         {
345             TREE_DEPTH_MULTIPLIER = 10000
346         }
347
348         /// <summary>
349         /// Layer behavior, type String (Layer.LayerBehavior).
350         /// </summary>
351         /// <since_tizen> 3 </since_tizen>
352         public Layer.LayerBehavior Behavior
353         {
354             get
355             {
356                 return GetBehavior();
357             }
358             set
359             {
360                 SetBehavior(value);
361             }
362         }
363
364         /// <summary>
365         /// Internal only property to enable or disable clipping, type boolean.
366         /// By default, this is false, i.e., the viewport of the layer is the entire window.
367         /// </summary>
368         internal bool ClippingEnabled
369         {
370             get
371             {
372                 bool ret = NDalicPINVOKE.Layer_IsClipping(swigCPtr);
373                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
374                 return ret;
375             }
376             set
377             {
378                 NDalicPINVOKE.Layer_SetClipping(swigCPtr, value);
379                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380             }
381         }
382
383         /// <summary>
384         /// Sets the viewport (in window coordinates), type rectangle.
385         /// The contents of the layer will not be visible outside this box, when ViewportEnabled is true.
386         /// </summary>
387         /// <since_tizen> 4 </since_tizen>
388         public Rectangle Viewport
389         {
390             get
391             {
392                 if( ClippingEnabled )
393                 {
394                   Rectangle ret = new Rectangle(NDalicPINVOKE.Layer_GetClippingBox(swigCPtr), true);
395                   if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
396                   return ret;
397                 }
398                 else
399                 {
400                   // Clipping not enabled so return the window size
401                   Size2D windowSize = Window.Instance.Size;
402                   Rectangle ret = new Rectangle(0, 0, windowSize.Width, windowSize.Height);
403                   return ret;
404                 }
405             }
406             set
407             {
408                 NDalicPINVOKE.Layer_SetClippingBox__SWIG_1(swigCPtr, Rectangle.getCPtr(value));
409                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
410                 ClippingEnabled = true;
411             }
412         }
413
414         /// <summary>
415         /// Retrieves and sets the layer's opacity.<br>
416         /// </summary>
417         /// <since_tizen> 3 </since_tizen>
418         public float Opacity
419         {
420             get
421             {
422                 float temp = 0.0f;
423                 GetProperty(View.Property.OPACITY).Get(out temp);
424                 return temp;
425             }
426             set
427             {
428                 SetProperty(View.Property.OPACITY, new Tizen.NUI.PropertyValue(value));
429             }
430         }
431
432         /// <summary>
433         /// Retrieves and sets the layer's visibility.
434         /// </summary>
435         /// <since_tizen> 3 </since_tizen>
436         public bool Visibility
437         {
438             get
439             {
440                 bool temp = false;
441                 GetProperty(View.Property.VISIBLE).Get(out temp);
442                 return temp;
443             }
444             set
445             {
446                 SetProperty(View.Property.VISIBLE, new Tizen.NUI.PropertyValue(value));
447             }
448         }
449
450         /// <summary>
451         /// Get the number of children held by the layer.
452         /// </summary>
453         /// <since_tizen> 3 </since_tizen>
454         public new uint ChildCount
455         {
456             get
457             {
458                 uint ret = NDalicPINVOKE.Actor_GetChildCount(swigCPtr);
459                 if (NDalicPINVOKE.SWIGPendingException.Pending)
460                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
461                 return ret;
462             }
463         }
464
465         /// <summary>
466         /// Gets or sets the layer's name.
467         /// </summary>
468         /// <since_tizen> 3 </since_tizen>
469         public string Name
470         {
471             get
472             {
473                 return GetName();
474             }
475             set
476             {
477                 SetName(value);
478             }
479         }
480
481         internal string GetName()
482         {
483             string ret = NDalicPINVOKE.Actor_GetName(swigCPtr);
484             if (NDalicPINVOKE.SWIGPendingException.Pending)
485                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
486             return ret;
487         }
488
489         internal void SetName(string name)
490         {
491             NDalicPINVOKE.Actor_SetName(swigCPtr, name);
492             if (NDalicPINVOKE.SWIGPendingException.Pending)
493                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
494         }
495
496     }
497 }