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