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