2 * Copyright(c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 extern alias TizenSystemInformation;
19 using TizenSystemInformation.Tizen.System;
21 using System.ComponentModel;
22 using System.Collections.Generic;
23 using global::System.Runtime.InteropServices;
24 using Tizen.NUI.BaseComponents;
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 />
34 [EditorBrowsable(EditorBrowsableState.Never)]
35 public partial class GLWindow : BaseHandle
37 internal GLWindow(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.GLWindow.GlWindow_SWIGUpcast(cPtr), cMemoryOwn)
43 /// Creates an initialized handle to a new GLWindow.<br />
44 /// This creates an GLWindow with default options.!--<br />
46 /// <returns>A new GLWindow.</returns>
47 [EditorBrowsable(EditorBrowsableState.Never)]
48 public GLWindow() : this(Interop.GLWindow.GlWindow_New__SWIG_0(), true)
50 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
54 /// Creates an initialized handle to a new GLWindow.<br />
55 /// This API can create GLWindow with specifc option.<br />
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)
64 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
68 /// Enumeration for orientation of the window is the way in which a rectangular page is oriented for normal viewing.
70 [EditorBrowsable(EditorBrowsableState.Never)]
71 public enum GLWindowOrientation
74 /// Portrait orientation. The height of the display area is greater than the width.
76 [EditorBrowsable(EditorBrowsableState.Never)]
80 /// Landscape orientation. A wide view area is needed.
82 [EditorBrowsable(EditorBrowsableState.Never)]
86 /// Portrait inverse orientation.
88 [EditorBrowsable(EditorBrowsableState.Never)]
89 PortraitInverse = 180,
92 /// Landscape inverse orientation.
94 [EditorBrowsable(EditorBrowsableState.Never)]
95 LandscapeInverse = 270,
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.
102 [EditorBrowsable(EditorBrowsableState.Never)]
103 NoOrientationPreference = -1
107 /// Gets or sets a size of the window.
109 /// <exception cref="ArgumentNullException"> Thrown when value is null. </exception>
110 [EditorBrowsable(EditorBrowsableState.Never)]
111 public Size2D WindowSize
115 global::System.IntPtr intPtr = Interop.GLWindow.GlWindow_GetPositionSize(swigCPtr);
116 var val = new Rectangle(intPtr, true);
117 Size2D ret = new Size2D(val.Width, val.Height);
126 throw new ArgumentNullException(nameof(value));
129 global::System.IntPtr intPtr = Interop.GLWindow.GlWindow_GetPositionSize(swigCPtr);
130 Rectangle val = new Rectangle(intPtr, true);
131 Rectangle ret = new Rectangle(val.X, val.Y, value.Width, value.Height);
134 Interop.GLWindow.GlWindow_SetPositionSize(swigCPtr, Rectangle.getCPtr(ret));
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 />
143 [EditorBrowsable(EditorBrowsableState.Never)]
144 public enum GLESVersion
149 [EditorBrowsable(EditorBrowsableState.Never)]
155 [EditorBrowsable(EditorBrowsableState.Never)]
160 /// Sets egl configuration for GLWindow
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)
169 Interop.GLWindow.GlWindow_SetEglConfig(swigCPtr, depth, stencil, msaa, (int)version);
170 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
174 /// Shows the GLWindow if it is hidden.
176 [EditorBrowsable(EditorBrowsableState.Never)]
179 Interop.GLWindow.GlWindow_Show(swigCPtr);
180 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
184 /// Hides the GLWindow if it is showing.
186 [EditorBrowsable(EditorBrowsableState.Never)]
189 Interop.GLWindow.GlWindow_Hide(swigCPtr);
190 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194 /// Raises the window to the top of the window stack.
196 [EditorBrowsable(EditorBrowsableState.Never)]
199 Interop.GLWindow.GlWindow_Raise(swigCPtr);
200 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
204 /// Lowers the window to the bottom of the window stack.
206 [EditorBrowsable(EditorBrowsableState.Never)]
209 Interop.GLWindow.GlWindow_Lower(swigCPtr);
210 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214 /// Activates the window to the top of the window stack even it is iconified.
216 [EditorBrowsable(EditorBrowsableState.Never)]
217 public void Activate()
219 Interop.GLWindow.GlWindow_Activate(swigCPtr);
220 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
227 [EditorBrowsable(EditorBrowsableState.Never)]
228 public Rectangle WindowPositionSize
232 global::System.IntPtr intPtr = Interop.GLWindow.GlWindow_GetPositionSize(swigCPtr);
233 Rectangle val = new Rectangle(intPtr, true);
234 Rectangle ret = new Rectangle(val.X, val.Y, val.Width, val.Height);
241 Interop.GLWindow.GlWindow_SetPositionSize(swigCPtr, Rectangle.getCPtr(value));
246 /// Gets the count of supported auxiliary hints of the GLWindow.
248 /// <returns>The number of supported auxiliary hints.</returns>
249 [EditorBrowsable(EditorBrowsableState.Never)]
250 public uint GetSupportedAuxiliaryHintCount()
252 uint ret = Interop.GLWindow.GlWindow_GetSupportedAuxiliaryHintCount(swigCPtr);
253 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258 /// Gets the supported auxiliary hint string of the GLWindow.
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)
265 string ret = Interop.GLWindow.GlWindow_GetSupportedAuxiliaryHint(swigCPtr, index);
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271 /// Creates an auxiliary hint of the GLWindow.
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)
279 uint ret = Interop.GLWindow.GlWindow_AddAuxiliaryHint(swigCPtr, hint, value);
280 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285 /// Removes an auxiliary hint of the GLWindow.
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)
292 bool ret = Interop.GLWindow.GlWindow_RemoveAuxiliaryHint(swigCPtr, id);
293 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
298 /// Changes a value of the auxiliary hint.
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)
306 bool ret = Interop.GLWindow.GlWindow_SetAuxiliaryHintValue(swigCPtr, id, value);
307 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
312 /// Gets a value of the auxiliary hint.
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)
319 string ret = Interop.GLWindow.GlWindow_GetAuxiliaryHintValue(swigCPtr, id);
320 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325 /// Gets an ID of the auxiliary hint string.
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)
332 uint ret = Interop.GLWindow.GlWindow_GetAuxiliaryHintId(swigCPtr, hint);
333 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338 /// Sets a region to accept input events.
340 /// <param name="inputRegion">The region to accept input events.</param>
341 [EditorBrowsable(EditorBrowsableState.Never)]
342 public void SetInputRegion(Rectangle inputRegion)
344 Interop.GLWindow.GlWindow_SetInputRegion(swigCPtr, Rectangle.getCPtr(inputRegion));
345 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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.
357 [EditorBrowsable(EditorBrowsableState.Never)]
358 public void SetOpaqueState(bool opaque)
360 Interop.GLWindow.GlWindow_SetOpaqueState(swigCPtr, opaque);
361 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
365 /// Returns whether a transparent window's visual state is opaque or not.
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()
372 bool ret = Interop.GLWindow.GlWindow_IsOpaqueState(swigCPtr);
373 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378 /// Sets a preferred orientation.
380 /// <param name="orientation">The preferred orientation.</param>
381 [EditorBrowsable(EditorBrowsableState.Never)]
382 public void SetPreferredOrientation(GLWindow.GLWindowOrientation orientation)
384 Interop.GLWindow.GlWindow_SetPreferredOrientation(swigCPtr, (int)orientation);
385 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
389 /// Gets current orientation of the window.
391 /// <returns>The current window orientation if previously set, or none.</returns>
392 [EditorBrowsable(EditorBrowsableState.Never)]
393 public GLWindow.GLWindowOrientation GetCurrentOrientation()
395 GLWindow.GLWindowOrientation ret = (GLWindow.GLWindowOrientation)Interop.GLWindow.GlWindow_GetCurrentOrientation(swigCPtr);
396 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
401 /// Sets available orientations of the window.
402 /// This API is for setting several orientations one time.
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)
409 if (null == orientations)
411 throw new ArgumentNullException(nameof(orientations));
414 PropertyArray orientationArray = new PropertyArray();
415 for (int i = 0; i < orientations.Count; i++)
417 PropertyValue val = new PropertyValue((int)orientations[i]);
418 orientationArray.PushBack(val);
422 Interop.GLWindow.GlWindow_SetAvailableOrientations(swigCPtr, PropertyArray.getCPtr(orientationArray), orientations.Count);
423 orientationArray.Dispose();
424 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
428 /// Allows at least one more render, even when paused.
429 /// The window should be shown, not minimised.
431 [EditorBrowsable(EditorBrowsableState.Never)]
432 public void RenderOnce()
434 Interop.GLWindow.GlWindow_RenderOnce(swigCPtr);
435 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
439 /// Type of callback to initialize native GL code.
441 [EditorBrowsable(EditorBrowsableState.Never)]
442 public delegate void GLInitializeCallbackType();
444 GLInitializeCallbackType GLInitializeCallback;
445 HandleRef InitHandleRef;
448 /// Type of callback to render to frame to use native GL code.
450 [EditorBrowsable(EditorBrowsableState.Never)]
451 public delegate int GLRenderFrameCallbackType();
453 GLRenderFrameCallbackType GLRenderFrameCallback;
454 HandleRef RenderHandlerRef;
458 /// Type of callback to cleanup native GL resource.
460 [EditorBrowsable(EditorBrowsableState.Never)]
461 public delegate void GLTerminateCallbackType();
463 GLTerminateCallbackType GLTerminateCallback;
464 HandleRef TerminateHandlerRef;
467 /// Registers a GL callback function for application.
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)
475 GLInitializeCallback = glInit;
476 InitHandleRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(GLInitializeCallback));
478 GLRenderFrameCallback = glRenderFrame;
479 RenderHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(GLRenderFrameCallback));
481 GLTerminateCallback = glTerminate;
482 TerminateHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(GLTerminateCallback));
484 Interop.GLWindow.GlWindow_RegisterGlCallback(swigCPtr, InitHandleRef, RenderHandlerRef, TerminateHandlerRef);
486 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
490 /// Destroy the window immediately.
492 [EditorBrowsable(EditorBrowsableState.Never)]
493 public void Destroy()
499 /// Dispose for Window
501 protected override void Dispose(DisposeTypes type)
508 this.DisconnectNativeSignals();
513 /// This will not be public opened.
514 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
516 Interop.Window.delete_Window(swigCPtr);