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