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