[NUI] change orientation angle in GLWindow
[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                 var val = new Rectangle(Interop.GLWindow.GlWindow_GetPositionSize(swigCPtr), true);
115                 Size2D ret = new Size2D(val.Width, val.Height);
116
117                 return ret;
118             }
119             set
120             {
121                 var val = new Rectangle(Interop.GLWindow.GlWindow_GetPositionSize(swigCPtr), true);
122                 Rectangle ret = new Rectangle(val.X, val.Y, value.Width, value.Height );
123
124                 Interop.GLWindow.GlWindow_SetPositionSize(swigCPtr, Rectangle.getCPtr(ret));
125             }
126         }
127
128         /// <summary>
129         /// This Enumeration is used the GLES version for EGL configuration.<br />
130         /// If the device can not support GLES version 3.0 over, the version will be chosen with GLES version 2.0<br />
131         /// </summary>
132         [EditorBrowsable(EditorBrowsableState.Never)]
133         public enum GLESVersion
134         {
135             /// <summary>
136             /// GLES version 2.0
137             /// </summary>
138             [EditorBrowsable(EditorBrowsableState.Never)]
139             Version_2_0 = 0,
140
141             /// <summary>
142             /// GLES version 3.0
143             /// </summary>
144             [EditorBrowsable(EditorBrowsableState.Never)]
145             Version_3_0
146         }
147
148         /// <summary>
149         /// Sets egl configuration for GLWindow
150         /// </summary>
151         /// <param name="depth">The flag of depth buffer. If true is set, 24bit depth buffer is enabled.</param>
152         /// <param name="stencil">The flag of stencil. it true is set, 8bit stencil buffer is enabled.</param>
153         /// <param name="msaa">The bit of msaa.</param>
154         /// <param name="version">The GLES version.</param>
155         [EditorBrowsable(EditorBrowsableState.Never)]
156         public void SetEglConfig( bool depth, bool stencil, int msaa, GLESVersion version )
157         {
158             Interop.GLWindow.GlWindow_SetEglConfig(swigCPtr, depth, stencil, msaa, (int)version);
159             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
160         }
161
162         /// <summary>
163         /// Shows the GLWindow if it is hidden.
164         /// </summary>
165         [EditorBrowsable(EditorBrowsableState.Never)]
166         public void Show()
167         {
168             Interop.GLWindow.GlWindow_Show(swigCPtr);
169             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170         }
171
172         /// <summary>
173         /// Hides the GLWindow if it is showing.
174         /// </summary>
175         [EditorBrowsable(EditorBrowsableState.Never)]
176         public void Hide()
177         {
178             Interop.GLWindow.GlWindow_Hide(swigCPtr);
179             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
180         }
181
182         /// <summary>
183         /// Raises the window to the top of the window stack.
184         /// </summary>
185         [EditorBrowsable(EditorBrowsableState.Never)]
186         public void Raise()
187         {
188             Interop.GLWindow.GlWindow_Raise(swigCPtr);
189             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
190         }
191
192         /// <summary>
193         /// Lowers the window to the bottom of the window stack.
194         /// </summary>
195         [EditorBrowsable(EditorBrowsableState.Never)]
196         public void Lower()
197         {
198             Interop.GLWindow.GlWindow_Lower(swigCPtr);
199             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
200         }
201
202         /// <summary>
203         /// Activates the window to the top of the window stack even it is iconified.
204         /// </summary>
205         [EditorBrowsable(EditorBrowsableState.Never)]
206         public void Activate()
207         {
208             Interop.GLWindow.GlWindow_Activate(swigCPtr);
209             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
210         }
211
212         /// <summary>
213         /// Sets position and size of the window. This API guarantees that
214         /// both moving and resizing of window will appear on the screen at once.
215         /// </summary>
216         [EditorBrowsable(EditorBrowsableState.Never)]
217         public Rectangle WindowPositionSize
218         {
219             get
220             {
221                 Rectangle val = new Rectangle(Interop.GLWindow.GlWindow_GetPositionSize(swigCPtr), true);
222                 Rectangle ret = new Rectangle(val.X, val.Y, val.Width, val.Height );
223
224                 return ret;
225             }
226             set
227             {
228                 Interop.GLWindow.GlWindow_SetPositionSize(swigCPtr, Rectangle.getCPtr(value));
229             }
230         }
231
232         /// <summary>
233         /// Gets the count of supported auxiliary hints of the GLWindow.
234         /// </summary>
235         /// <returns>The number of supported auxiliary hints.</returns>
236         [EditorBrowsable(EditorBrowsableState.Never)]
237         public uint GetSupportedAuxiliaryHintCount()
238         {
239             uint ret = Interop.GLWindow.GlWindow_GetSupportedAuxiliaryHintCount(swigCPtr);
240             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241             return ret;
242         }
243
244         /// <summary>
245         /// Gets the supported auxiliary hint string of the GLWindow.
246         /// </summary>
247         /// <param name="index">The index of the supported auxiliary hint lists.</param>
248         /// <returns>The auxiliary hint string of the index.</returns>
249         [EditorBrowsable(EditorBrowsableState.Never)]
250         public string GetSupportedAuxiliaryHint(uint index)
251         {
252             string ret = Interop.GLWindow.GlWindow_GetSupportedAuxiliaryHint(swigCPtr, index);
253             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254             return ret;
255         }
256
257         /// <summary>
258         /// Creates an auxiliary hint of the GLWindow.
259         /// </summary>
260         /// <param name="hint">The auxiliary hint string.</param>
261         /// <param name="value">The value string.</param>
262         /// <returns>The ID of created auxiliary hint, or 0 on failure.</returns>
263         [EditorBrowsable(EditorBrowsableState.Never)]
264         public uint AddAuxiliaryHint(string hint, string value)
265         {
266             uint ret = Interop.GLWindow.GlWindow_AddAuxiliaryHint(swigCPtr, hint, value);
267             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
268             return ret;
269         }
270
271         /// <summary>
272         /// Removes an auxiliary hint of the GLWindow.
273         /// </summary>
274         /// <param name="id">The ID of the auxiliary hint.</param>
275         /// <returns>True if no error occurred, false otherwise.</returns>
276         [EditorBrowsable(EditorBrowsableState.Never)]
277         public bool RemoveAuxiliaryHint(uint id)
278         {
279             bool ret = Interop.GLWindow.GlWindow_RemoveAuxiliaryHint(swigCPtr, id);
280             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281             return ret;
282         }
283
284         /// <summary>
285         /// Changes a value of the auxiliary hint.
286         /// </summary>
287         /// <param name="id">The auxiliary hint ID.</param>
288         /// <param name="value">The value string to be set.</param>
289         /// <returns>True if no error occurred, false otherwise.</returns>
290         [EditorBrowsable(EditorBrowsableState.Never)]
291         public bool SetAuxiliaryHintValue(uint id, string value)
292         {
293             bool ret = Interop.GLWindow.GlWindow_SetAuxiliaryHintValue(swigCPtr, id, value);
294             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
295             return ret;
296         }
297
298         /// <summary>
299         /// Gets a value of the auxiliary hint.
300         /// </summary>
301         /// <param name="id">The auxiliary hint ID.</param>
302         /// <returns>The string value of the auxiliary hint ID, or an empty string if none exists.</returns>
303         [EditorBrowsable(EditorBrowsableState.Never)]
304         public string GetAuxiliaryHintValue(uint id)
305         {
306             string ret = Interop.GLWindow.GlWindow_GetAuxiliaryHintValue(swigCPtr, id);
307             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308             return ret;
309         }
310
311         /// <summary>
312         /// Gets an ID of the auxiliary hint string.
313         /// </summary>
314         /// <param name="hint">The auxiliary hint string.</param>
315         /// <returns>The ID of auxiliary hint string, or 0 on failure.</returns>
316         [EditorBrowsable(EditorBrowsableState.Never)]
317         public uint GetAuxiliaryHintId(string hint)
318         {
319             uint ret = Interop.GLWindow.GlWindow_GetAuxiliaryHintId(swigCPtr, hint);
320             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
321             return ret;
322         }
323
324         /// <summary>
325         /// Sets a region to accept input events.
326         /// </summary>
327         /// <param name="inputRegion">The region to accept input events.</param>
328         [EditorBrowsable(EditorBrowsableState.Never)]
329         public void SetInputRegion(Rectangle inputRegion)
330         {
331             Interop.GLWindow.GlWindow_SetInputRegion(swigCPtr, Rectangle.getCPtr(inputRegion));
332             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333         }
334
335         /// <summary>
336         /// Sets a transparent window's visual state to opaque. <br />
337         /// If a visual state of a transparent window is opaque, <br />
338         /// then the window manager could handle it as an opaque window when calculating visibility.
339         /// </summary>
340         /// <param name="opaque">Whether the window's visual state is opaque.</param>
341         /// <remarks>This will have no effect on an opaque window. <br />
342         /// It doesn't change transparent window to opaque window but lets the window manager know the visual state of the window.
343         /// </remarks>
344         [EditorBrowsable(EditorBrowsableState.Never)]
345         public void SetOpaqueState(bool opaque)
346         {
347             Interop.GLWindow.GlWindow_SetOpaqueState(swigCPtr, opaque);
348             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
349         }
350
351         /// <summary>
352         /// Returns whether a transparent window's visual state is opaque or not.
353         /// </summary>
354         /// <returns>True if the window's visual state is opaque, false otherwise.</returns>
355         /// <remarks> The return value has no meaning on an opaque window. </remarks>
356         [EditorBrowsable(EditorBrowsableState.Never)]
357         public bool IsOpaqueState()
358         {
359             bool ret = Interop.GLWindow.GlWindow_IsOpaqueState(swigCPtr);
360             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361             return ret;
362         }
363
364         /// <summary>
365         /// Sets a preferred orientation.
366         /// </summary>
367         /// <param name="orientation">The preferred orientation.</param>
368         [EditorBrowsable(EditorBrowsableState.Never)]
369         public void SetPreferredOrientation(GLWindow.GLWindowOrientation orientation)
370         {
371             Interop.GLWindow.GlWindow_SetPreferredOrientation(swigCPtr, (int)orientation);
372             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373         }
374
375         /// <summary>
376         /// Gets current orientation of the window.
377         /// </summary>
378         /// <returns>The current window orientation if previously set, or none.</returns>
379         [EditorBrowsable(EditorBrowsableState.Never)]
380         public GLWindow.GLWindowOrientation GetCurrentOrientation()
381         {
382             GLWindow.GLWindowOrientation ret = (GLWindow.GLWindowOrientation)Interop.GLWindow.GlWindow_GetCurrentOrientation(swigCPtr);
383             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
384             return ret;
385         }
386
387         /// <summary>
388         /// Sets available orientations of the window.
389         /// This API is for setting several orientations one time.
390         /// </summary>
391         /// <param name="orientations">The list of orientations.</param>
392         [EditorBrowsable(EditorBrowsableState.Never)]
393         public void SetAvailableOrientations(List<GLWindow.GLWindowOrientation> orientations)
394         {
395             PropertyArray orientationArray = new PropertyArray();
396             for (int i = 0; i < orientations.Count; i++)
397             {
398                 orientationArray.PushBack(new PropertyValue((int)orientations[i]));
399             }
400
401             Interop.GLWindow.GlWindow_SetAvailableOrientations(swigCPtr, PropertyArray.getCPtr(orientationArray), orientations.Count);
402             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
403         }
404
405         /// <summary>
406         /// Allows at least one more render, even when paused.
407         /// The window should be shown, not minimised.
408         /// </summary>
409         [EditorBrowsable(EditorBrowsableState.Never)]
410         public void RenderOnce()
411         {
412             Interop.GLWindow.GlWindow_RenderOnce(swigCPtr);
413             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
414         }
415
416         /// <summary>
417         /// Type of callback to initialize native GL code.
418         /// </summary>
419         [EditorBrowsable(EditorBrowsableState.Never)]
420         public delegate void GLInitializeCallbackType();
421
422         GLInitializeCallbackType GLInitializeCallback;
423         HandleRef InitHandleRef;
424
425         /// <summary>
426         /// Type of callback to render to frame to use native GL code.
427         /// </summary>
428         [EditorBrowsable(EditorBrowsableState.Never)]
429         public delegate int GLRenderFrameCallbackType();
430
431         GLRenderFrameCallbackType GLRenderFrameCallback;
432         HandleRef RenderHandlerRef;
433
434
435         /// <summary>
436         /// Type of callback to cleanup native GL resource.
437         /// </summary>
438         [EditorBrowsable(EditorBrowsableState.Never)]
439         public delegate void GLTerminateCallbackType();
440
441         GLTerminateCallbackType GLTerminateCallback;
442         HandleRef TerminateHandlerRef;
443
444         /// <summary>
445         /// Registers a GL callback function for application.
446         /// </summary>
447         /// <param name="glInit">The callback function for application initialize</param>
448         /// <param name="glRenderFrame">The callback function to render to the frame</param>
449         /// <param name="glTerminate">The callback function to clean-up application GL resource</param>
450         [EditorBrowsable(EditorBrowsableState.Never)]
451         public void RegisterGlCallback( GLInitializeCallbackType glInit, GLRenderFrameCallbackType glRenderFrame, GLTerminateCallbackType glTerminate )
452         {
453             GLInitializeCallback = glInit;
454             InitHandleRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(GLInitializeCallback));
455
456             GLRenderFrameCallback = glRenderFrame;
457             RenderHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(GLRenderFrameCallback));
458
459             GLTerminateCallback = glTerminate;
460             TerminateHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(GLTerminateCallback));
461
462             Interop.GLWindow.GlWindow_RegisterGlCallback(swigCPtr, InitHandleRef, RenderHandlerRef, TerminateHandlerRef);
463
464             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
465         }
466
467         /// <summary>
468         /// Destroy the window immediately.
469         /// </summary>
470         [EditorBrowsable(EditorBrowsableState.Never)]
471         public void Destroy()
472         {
473             this.Dispose();
474         }
475
476         /// <summary>
477         /// Dispose for Window
478         /// </summary>
479         protected override void Dispose(DisposeTypes type)
480         {
481             if (disposed)
482             {
483                 return;
484             }
485
486             this.DisconnectNativeSignals();
487
488             base.Dispose(type);
489         }
490
491         /// This will not be public opened.
492         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
493         {
494             Interop.Window.delete_Window(swigCPtr);
495         }
496     }
497 }