Follow formatting NUI
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / GLWindow.cs
1 /*
2  * Copyright(c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 extern alias TizenSystemInformation;
19 using TizenSystemInformation.Tizen.System;
20 using global::System;
21 using System.ComponentModel;
22 using System.Collections.Generic;
23 using global::System.Runtime.InteropServices;
24 using Tizen.NUI.BaseComponents;
25
26 namespace Tizen.NUI
27 {
28     /// <summary>
29     /// The GLWindow class is to draw with native GLES.<br />
30     /// This class is the special window. It is for native GLES application.<br />
31     /// So, some special funtions and type are supported.<br />
32     /// In addition, basic window's functions are supported, too.<br />
33     /// </summary>
34     [EditorBrowsable(EditorBrowsableState.Never)]
35     public partial class GLWindow : BaseHandle
36     {
37         internal GLWindow(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.GLWindow.GlWindow_SWIGUpcast(cPtr), cMemoryOwn)
38         {
39
40         }
41
42         /// <summary>
43         /// Creates an initialized handle to a new GLWindow.<br />
44         /// This creates an GLWindow with default options.!--<br />
45         /// </summary>
46         /// <returns>A new GLWindow.</returns>
47         [EditorBrowsable(EditorBrowsableState.Never)]
48         public GLWindow() : this(Interop.GLWindow.GlWindow_New__SWIG_0(), true)
49         {
50             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
51         }
52
53         /// <summary>
54         /// Creates an initialized handle to a new GLWindow.<br />
55         /// This API can create GLWindow with specifc option.<br />
56         /// </summary>
57         /// <param name="name">The name for GL window. </param>
58         /// <param name="windowPosition">The position and size of the Window.</param>
59         /// <param name="isTranslucent">Whether Window is translucent.</param>
60         /// <returns>A new Window.</returns>
61         [EditorBrowsable(EditorBrowsableState.Never)]
62         public GLWindow(string name, Rectangle windowPosition = null, bool isTranslucent = false) : this(Interop.GLWindow.GlWindow_New__SWIG_1(Rectangle.getCPtr(windowPosition), name, "", isTranslucent), true)
63         {
64             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
65         }
66
67         /// <summary>
68         /// Enumeration for orientation of the window is the way in which a rectangular page is oriented for normal viewing.
69         /// </summary>
70         [EditorBrowsable(EditorBrowsableState.Never)]
71         public enum GLWindowOrientation
72         {
73             /// <summary>
74             /// Portrait orientation. The height of the display area is greater than the width.
75             /// </summary>
76             [EditorBrowsable(EditorBrowsableState.Never)]
77             Portrait = 0,
78
79             /// <summary>
80             /// Landscape orientation. A wide view area is needed.
81             /// </summary>
82             [EditorBrowsable(EditorBrowsableState.Never)]
83             Landscape = 90,
84
85             /// <summary>
86             /// Portrait inverse orientation.
87             /// </summary>
88             [EditorBrowsable(EditorBrowsableState.Never)]
89             PortraitInverse = 180,
90
91             /// <summary>
92             /// Landscape inverse orientation.
93             /// </summary>
94             [EditorBrowsable(EditorBrowsableState.Never)]
95             LandscapeInverse = 270,
96
97             /// <summary>
98             /// No orientation. It is for the preferred orientation
99             /// Especially, NoOrientationPreference only has the effect for the preferred orientation.
100             /// It is used to unset the preferred orientation with SetPreferredOrientation.
101             /// </summary>
102             [EditorBrowsable(EditorBrowsableState.Never)]
103             NoOrientationPreference = -1
104         }
105
106         /// <summary>
107         /// Gets or sets a size of the window.
108         /// </summary>
109         [EditorBrowsable(EditorBrowsableState.Never)]
110         public Size2D WindowSize
111         {
112             get
113             {
114                 global::System.IntPtr intPtr = Interop.GLWindow.GlWindow_GetPositionSize(swigCPtr);
115                 var val = new Rectangle(intPtr, true);
116                 Size2D ret = new Size2D(val.Width, val.Height);
117                 val.Dispose();
118
119                 return ret;
120             }
121             set
122             {
123                 global::System.IntPtr intPtr = Interop.GLWindow.GlWindow_GetPositionSize(swigCPtr);
124                 Rectangle val = new Rectangle(intPtr, true);
125                 Rectangle ret = new Rectangle(val.X, val.Y, value.Width, value.Height);
126                 val.Dispose();
127
128                 Interop.GLWindow.GlWindow_SetPositionSize(swigCPtr, Rectangle.getCPtr(ret));
129                 ret.Dispose();
130             }
131         }
132
133         /// <summary>
134         /// This Enumeration is used the GLES version for EGL configuration.<br />
135         /// If the device can not support GLES version 3.0 over, the version will be chosen with GLES version 2.0<br />
136         /// </summary>
137         [EditorBrowsable(EditorBrowsableState.Never)]
138         public enum GLESVersion
139         {
140             /// <summary>
141             /// GLES version 2.0
142             /// </summary>
143             [EditorBrowsable(EditorBrowsableState.Never)]
144             Version_2_0 = 0,
145
146             /// <summary>
147             /// GLES version 3.0
148             /// </summary>
149             [EditorBrowsable(EditorBrowsableState.Never)]
150             Version_3_0
151         }
152
153         /// <summary>
154         /// Sets egl configuration for GLWindow
155         /// </summary>
156         /// <param name="depth">The flag of depth buffer. If true is set, 24bit depth buffer is enabled.</param>
157         /// <param name="stencil">The flag of stencil. it true is set, 8bit stencil buffer is enabled.</param>
158         /// <param name="msaa">The bit of msaa.</param>
159         /// <param name="version">The GLES version.</param>
160         [EditorBrowsable(EditorBrowsableState.Never)]
161         public void SetEglConfig(bool depth, bool stencil, int msaa, GLESVersion version)
162         {
163             Interop.GLWindow.GlWindow_SetEglConfig(swigCPtr, depth, stencil, msaa, (int)version);
164             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
165         }
166
167         /// <summary>
168         /// Shows the GLWindow if it is hidden.
169         /// </summary>
170         [EditorBrowsable(EditorBrowsableState.Never)]
171         public void Show()
172         {
173             Interop.GLWindow.GlWindow_Show(swigCPtr);
174             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175         }
176
177         /// <summary>
178         /// Hides the GLWindow if it is showing.
179         /// </summary>
180         [EditorBrowsable(EditorBrowsableState.Never)]
181         public void Hide()
182         {
183             Interop.GLWindow.GlWindow_Hide(swigCPtr);
184             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
185         }
186
187         /// <summary>
188         /// Raises the window to the top of the window stack.
189         /// </summary>
190         [EditorBrowsable(EditorBrowsableState.Never)]
191         public void Raise()
192         {
193             Interop.GLWindow.GlWindow_Raise(swigCPtr);
194             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
195         }
196
197         /// <summary>
198         /// Lowers the window to the bottom of the window stack.
199         /// </summary>
200         [EditorBrowsable(EditorBrowsableState.Never)]
201         public void Lower()
202         {
203             Interop.GLWindow.GlWindow_Lower(swigCPtr);
204             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
205         }
206
207         /// <summary>
208         /// Activates the window to the top of the window stack even it is iconified.
209         /// </summary>
210         [EditorBrowsable(EditorBrowsableState.Never)]
211         public void Activate()
212         {
213             Interop.GLWindow.GlWindow_Activate(swigCPtr);
214             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
215         }
216
217         /// <summary>
218         /// Sets position and size of the window. This API guarantees that
219         /// both moving and resizing of window will appear on the screen at once.
220         /// </summary>
221         [EditorBrowsable(EditorBrowsableState.Never)]
222         public Rectangle WindowPositionSize
223         {
224             get
225             {
226                 global::System.IntPtr intPtr = Interop.GLWindow.GlWindow_GetPositionSize(swigCPtr);
227                 Rectangle val = new Rectangle(intPtr, true);
228                 Rectangle ret = new Rectangle(val.X, val.Y, val.Width, val.Height);
229                 val.Dispose();
230
231                 return ret;
232             }
233             set
234             {
235                 Interop.GLWindow.GlWindow_SetPositionSize(swigCPtr, Rectangle.getCPtr(value));
236             }
237         }
238
239         /// <summary>
240         /// Gets the count of supported auxiliary hints of the GLWindow.
241         /// </summary>
242         /// <returns>The number of supported auxiliary hints.</returns>
243         [EditorBrowsable(EditorBrowsableState.Never)]
244         public uint GetSupportedAuxiliaryHintCount()
245         {
246             uint ret = Interop.GLWindow.GlWindow_GetSupportedAuxiliaryHintCount(swigCPtr);
247             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248             return ret;
249         }
250
251         /// <summary>
252         /// Gets the supported auxiliary hint string of the GLWindow.
253         /// </summary>
254         /// <param name="index">The index of the supported auxiliary hint lists.</param>
255         /// <returns>The auxiliary hint string of the index.</returns>
256         [EditorBrowsable(EditorBrowsableState.Never)]
257         public string GetSupportedAuxiliaryHint(uint index)
258         {
259             string ret = Interop.GLWindow.GlWindow_GetSupportedAuxiliaryHint(swigCPtr, index);
260             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261             return ret;
262         }
263
264         /// <summary>
265         /// Creates an auxiliary hint of the GLWindow.
266         /// </summary>
267         /// <param name="hint">The auxiliary hint string.</param>
268         /// <param name="value">The value string.</param>
269         /// <returns>The ID of created auxiliary hint, or 0 on failure.</returns>
270         [EditorBrowsable(EditorBrowsableState.Never)]
271         public uint AddAuxiliaryHint(string hint, string value)
272         {
273             uint ret = Interop.GLWindow.GlWindow_AddAuxiliaryHint(swigCPtr, hint, value);
274             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275             return ret;
276         }
277
278         /// <summary>
279         /// Removes an auxiliary hint of the GLWindow.
280         /// </summary>
281         /// <param name="id">The ID of the auxiliary hint.</param>
282         /// <returns>True if no error occurred, false otherwise.</returns>
283         [EditorBrowsable(EditorBrowsableState.Never)]
284         public bool RemoveAuxiliaryHint(uint id)
285         {
286             bool ret = Interop.GLWindow.GlWindow_RemoveAuxiliaryHint(swigCPtr, id);
287             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288             return ret;
289         }
290
291         /// <summary>
292         /// Changes a value of the auxiliary hint.
293         /// </summary>
294         /// <param name="id">The auxiliary hint ID.</param>
295         /// <param name="value">The value string to be set.</param>
296         /// <returns>True if no error occurred, false otherwise.</returns>
297         [EditorBrowsable(EditorBrowsableState.Never)]
298         public bool SetAuxiliaryHintValue(uint id, string value)
299         {
300             bool ret = Interop.GLWindow.GlWindow_SetAuxiliaryHintValue(swigCPtr, id, value);
301             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
302             return ret;
303         }
304
305         /// <summary>
306         /// Gets a value of the auxiliary hint.
307         /// </summary>
308         /// <param name="id">The auxiliary hint ID.</param>
309         /// <returns>The string value of the auxiliary hint ID, or an empty string if none exists.</returns>
310         [EditorBrowsable(EditorBrowsableState.Never)]
311         public string GetAuxiliaryHintValue(uint id)
312         {
313             string ret = Interop.GLWindow.GlWindow_GetAuxiliaryHintValue(swigCPtr, id);
314             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
315             return ret;
316         }
317
318         /// <summary>
319         /// Gets an ID of the auxiliary hint string.
320         /// </summary>
321         /// <param name="hint">The auxiliary hint string.</param>
322         /// <returns>The ID of auxiliary hint string, or 0 on failure.</returns>
323         [EditorBrowsable(EditorBrowsableState.Never)]
324         public uint GetAuxiliaryHintId(string hint)
325         {
326             uint ret = Interop.GLWindow.GlWindow_GetAuxiliaryHintId(swigCPtr, hint);
327             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
328             return ret;
329         }
330
331         /// <summary>
332         /// Sets a region to accept input events.
333         /// </summary>
334         /// <param name="inputRegion">The region to accept input events.</param>
335         [EditorBrowsable(EditorBrowsableState.Never)]
336         public void SetInputRegion(Rectangle inputRegion)
337         {
338             Interop.GLWindow.GlWindow_SetInputRegion(swigCPtr, Rectangle.getCPtr(inputRegion));
339             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
340         }
341
342         /// <summary>
343         /// Sets a transparent window's visual state to opaque. <br />
344         /// If a visual state of a transparent window is opaque, <br />
345         /// then the window manager could handle it as an opaque window when calculating visibility.
346         /// </summary>
347         /// <param name="opaque">Whether the window's visual state is opaque.</param>
348         /// <remarks>This will have no effect on an opaque window. <br />
349         /// It doesn't change transparent window to opaque window but lets the window manager know the visual state of the window.
350         /// </remarks>
351         [EditorBrowsable(EditorBrowsableState.Never)]
352         public void SetOpaqueState(bool opaque)
353         {
354             Interop.GLWindow.GlWindow_SetOpaqueState(swigCPtr, opaque);
355             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
356         }
357
358         /// <summary>
359         /// Returns whether a transparent window's visual state is opaque or not.
360         /// </summary>
361         /// <returns>True if the window's visual state is opaque, false otherwise.</returns>
362         /// <remarks> The return value has no meaning on an opaque window. </remarks>
363         [EditorBrowsable(EditorBrowsableState.Never)]
364         public bool IsOpaqueState()
365         {
366             bool ret = Interop.GLWindow.GlWindow_IsOpaqueState(swigCPtr);
367             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368             return ret;
369         }
370
371         /// <summary>
372         /// Sets a preferred orientation.
373         /// </summary>
374         /// <param name="orientation">The preferred orientation.</param>
375         [EditorBrowsable(EditorBrowsableState.Never)]
376         public void SetPreferredOrientation(GLWindow.GLWindowOrientation orientation)
377         {
378             Interop.GLWindow.GlWindow_SetPreferredOrientation(swigCPtr, (int)orientation);
379             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380         }
381
382         /// <summary>
383         /// Gets current orientation of the window.
384         /// </summary>
385         /// <returns>The current window orientation if previously set, or none.</returns>
386         [EditorBrowsable(EditorBrowsableState.Never)]
387         public GLWindow.GLWindowOrientation GetCurrentOrientation()
388         {
389             GLWindow.GLWindowOrientation ret = (GLWindow.GLWindowOrientation)Interop.GLWindow.GlWindow_GetCurrentOrientation(swigCPtr);
390             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
391             return ret;
392         }
393
394         /// <summary>
395         /// Sets available orientations of the window.
396         /// This API is for setting several orientations one time.
397         /// </summary>
398         /// <param name="orientations">The list of orientations.</param>
399         [EditorBrowsable(EditorBrowsableState.Never)]
400         public void SetAvailableOrientations(List<GLWindow.GLWindowOrientation> orientations)
401         {
402             PropertyArray orientationArray = new PropertyArray();
403             for (int i = 0; i < orientations.Count; i++)
404             {
405                 PropertyValue val = new PropertyValue((int)orientations[i]);
406                 orientationArray.PushBack(val);
407                 val.Dispose();
408             }
409
410             Interop.GLWindow.GlWindow_SetAvailableOrientations(swigCPtr, PropertyArray.getCPtr(orientationArray), orientations.Count);
411             orientationArray.Dispose();
412             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
413         }
414
415         /// <summary>
416         /// Allows at least one more render, even when paused.
417         /// The window should be shown, not minimised.
418         /// </summary>
419         [EditorBrowsable(EditorBrowsableState.Never)]
420         public void RenderOnce()
421         {
422             Interop.GLWindow.GlWindow_RenderOnce(swigCPtr);
423             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
424         }
425
426         /// <summary>
427         /// Type of callback to initialize native GL code.
428         /// </summary>
429         [EditorBrowsable(EditorBrowsableState.Never)]
430         public delegate void GLInitializeCallbackType();
431
432         GLInitializeCallbackType GLInitializeCallback;
433         HandleRef InitHandleRef;
434
435         /// <summary>
436         /// Type of callback to render to frame to use native GL code.
437         /// </summary>
438         [EditorBrowsable(EditorBrowsableState.Never)]
439         public delegate int GLRenderFrameCallbackType();
440
441         GLRenderFrameCallbackType GLRenderFrameCallback;
442         HandleRef RenderHandlerRef;
443
444
445         /// <summary>
446         /// Type of callback to cleanup native GL resource.
447         /// </summary>
448         [EditorBrowsable(EditorBrowsableState.Never)]
449         public delegate void GLTerminateCallbackType();
450
451         GLTerminateCallbackType GLTerminateCallback;
452         HandleRef TerminateHandlerRef;
453
454         /// <summary>
455         /// Registers a GL callback function for application.
456         /// </summary>
457         /// <param name="glInit">The callback function for application initialize</param>
458         /// <param name="glRenderFrame">The callback function to render to the frame</param>
459         /// <param name="glTerminate">The callback function to clean-up application GL resource</param>
460         [EditorBrowsable(EditorBrowsableState.Never)]
461         public void RegisterGlCallback(GLInitializeCallbackType glInit, GLRenderFrameCallbackType glRenderFrame, GLTerminateCallbackType glTerminate)
462         {
463             GLInitializeCallback = glInit;
464             InitHandleRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(GLInitializeCallback));
465
466             GLRenderFrameCallback = glRenderFrame;
467             RenderHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(GLRenderFrameCallback));
468
469             GLTerminateCallback = glTerminate;
470             TerminateHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(GLTerminateCallback));
471
472             Interop.GLWindow.GlWindow_RegisterGlCallback(swigCPtr, InitHandleRef, RenderHandlerRef, TerminateHandlerRef);
473
474             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
475         }
476
477         /// <summary>
478         /// Destroy the window immediately.
479         /// </summary>
480         [EditorBrowsable(EditorBrowsableState.Never)]
481         public void Destroy()
482         {
483             this.Dispose();
484         }
485
486         /// <summary>
487         /// Dispose for Window
488         /// </summary>
489         protected override void Dispose(DisposeTypes type)
490         {
491             if (disposed)
492             {
493                 return;
494             }
495
496             this.DisconnectNativeSignals();
497
498             base.Dispose(type);
499         }
500
501         /// This will not be public opened.
502         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
503         {
504             Interop.Window.delete_Window(swigCPtr);
505         }
506     }
507 }