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