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 [EditorBrowsable(EditorBrowsableState.Never)]
110 public Size2D WindowSize
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);
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);
128 Interop.GLWindow.GlWindow_SetPositionSize(swigCPtr, Rectangle.getCPtr(ret));
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 />
137 [EditorBrowsable(EditorBrowsableState.Never)]
138 public enum GLESVersion
143 [EditorBrowsable(EditorBrowsableState.Never)]
149 [EditorBrowsable(EditorBrowsableState.Never)]
154 /// Sets egl configuration for GLWindow
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 )
163 Interop.GLWindow.GlWindow_SetEglConfig(swigCPtr, depth, stencil, msaa, (int)version);
164 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168 /// Shows the GLWindow if it is hidden.
170 [EditorBrowsable(EditorBrowsableState.Never)]
173 Interop.GLWindow.GlWindow_Show(swigCPtr);
174 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
178 /// Hides the GLWindow if it is showing.
180 [EditorBrowsable(EditorBrowsableState.Never)]
183 Interop.GLWindow.GlWindow_Hide(swigCPtr);
184 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188 /// Raises the window to the top of the window stack.
190 [EditorBrowsable(EditorBrowsableState.Never)]
193 Interop.GLWindow.GlWindow_Raise(swigCPtr);
194 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198 /// Lowers the window to the bottom of the window stack.
200 [EditorBrowsable(EditorBrowsableState.Never)]
203 Interop.GLWindow.GlWindow_Lower(swigCPtr);
204 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208 /// Activates the window to the top of the window stack even it is iconified.
210 [EditorBrowsable(EditorBrowsableState.Never)]
211 public void Activate()
213 Interop.GLWindow.GlWindow_Activate(swigCPtr);
214 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
221 [EditorBrowsable(EditorBrowsableState.Never)]
222 public Rectangle WindowPositionSize
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 );
235 Interop.GLWindow.GlWindow_SetPositionSize(swigCPtr, Rectangle.getCPtr(value));
240 /// Gets the count of supported auxiliary hints of the GLWindow.
242 /// <returns>The number of supported auxiliary hints.</returns>
243 [EditorBrowsable(EditorBrowsableState.Never)]
244 public uint GetSupportedAuxiliaryHintCount()
246 uint ret = Interop.GLWindow.GlWindow_GetSupportedAuxiliaryHintCount(swigCPtr);
247 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
252 /// Gets the supported auxiliary hint string of the GLWindow.
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)
259 string ret = Interop.GLWindow.GlWindow_GetSupportedAuxiliaryHint(swigCPtr, index);
260 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265 /// Creates an auxiliary hint of the GLWindow.
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)
273 uint ret = Interop.GLWindow.GlWindow_AddAuxiliaryHint(swigCPtr, hint, value);
274 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
279 /// Removes an auxiliary hint of the GLWindow.
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)
286 bool ret = Interop.GLWindow.GlWindow_RemoveAuxiliaryHint(swigCPtr, id);
287 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292 /// Changes a value of the auxiliary hint.
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)
300 bool ret = Interop.GLWindow.GlWindow_SetAuxiliaryHintValue(swigCPtr, id, value);
301 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
306 /// Gets a value of the auxiliary hint.
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)
313 string ret = Interop.GLWindow.GlWindow_GetAuxiliaryHintValue(swigCPtr, id);
314 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
319 /// Gets an ID of the auxiliary hint string.
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)
326 uint ret = Interop.GLWindow.GlWindow_GetAuxiliaryHintId(swigCPtr, hint);
327 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332 /// Sets a region to accept input events.
334 /// <param name="inputRegion">The region to accept input events.</param>
335 [EditorBrowsable(EditorBrowsableState.Never)]
336 public void SetInputRegion(Rectangle inputRegion)
338 Interop.GLWindow.GlWindow_SetInputRegion(swigCPtr, Rectangle.getCPtr(inputRegion));
339 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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.
351 [EditorBrowsable(EditorBrowsableState.Never)]
352 public void SetOpaqueState(bool opaque)
354 Interop.GLWindow.GlWindow_SetOpaqueState(swigCPtr, opaque);
355 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359 /// Returns whether a transparent window's visual state is opaque or not.
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()
366 bool ret = Interop.GLWindow.GlWindow_IsOpaqueState(swigCPtr);
367 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
372 /// Sets a preferred orientation.
374 /// <param name="orientation">The preferred orientation.</param>
375 [EditorBrowsable(EditorBrowsableState.Never)]
376 public void SetPreferredOrientation(GLWindow.GLWindowOrientation orientation)
378 Interop.GLWindow.GlWindow_SetPreferredOrientation(swigCPtr, (int)orientation);
379 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
383 /// Gets current orientation of the window.
385 /// <returns>The current window orientation if previously set, or none.</returns>
386 [EditorBrowsable(EditorBrowsableState.Never)]
387 public GLWindow.GLWindowOrientation GetCurrentOrientation()
389 GLWindow.GLWindowOrientation ret = (GLWindow.GLWindowOrientation)Interop.GLWindow.GlWindow_GetCurrentOrientation(swigCPtr);
390 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
395 /// Sets available orientations of the window.
396 /// This API is for setting several orientations one time.
398 /// <param name="orientations">The list of orientations.</param>
399 [EditorBrowsable(EditorBrowsableState.Never)]
400 public void SetAvailableOrientations(List<GLWindow.GLWindowOrientation> orientations)
402 PropertyArray orientationArray = new PropertyArray();
403 for (int i = 0; i < orientations.Count; i++)
405 PropertyValue val = new PropertyValue((int)orientations[i]);
406 orientationArray.PushBack(val);
410 Interop.GLWindow.GlWindow_SetAvailableOrientations(swigCPtr, PropertyArray.getCPtr(orientationArray), orientations.Count);
411 orientationArray.Dispose();
412 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
416 /// Allows at least one more render, even when paused.
417 /// The window should be shown, not minimised.
419 [EditorBrowsable(EditorBrowsableState.Never)]
420 public void RenderOnce()
422 Interop.GLWindow.GlWindow_RenderOnce(swigCPtr);
423 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
427 /// Type of callback to initialize native GL code.
429 [EditorBrowsable(EditorBrowsableState.Never)]
430 public delegate void GLInitializeCallbackType();
432 GLInitializeCallbackType GLInitializeCallback;
433 HandleRef InitHandleRef;
436 /// Type of callback to render to frame to use native GL code.
438 [EditorBrowsable(EditorBrowsableState.Never)]
439 public delegate int GLRenderFrameCallbackType();
441 GLRenderFrameCallbackType GLRenderFrameCallback;
442 HandleRef RenderHandlerRef;
446 /// Type of callback to cleanup native GL resource.
448 [EditorBrowsable(EditorBrowsableState.Never)]
449 public delegate void GLTerminateCallbackType();
451 GLTerminateCallbackType GLTerminateCallback;
452 HandleRef TerminateHandlerRef;
455 /// Registers a GL callback function for application.
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 )
463 GLInitializeCallback = glInit;
464 InitHandleRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(GLInitializeCallback));
466 GLRenderFrameCallback = glRenderFrame;
467 RenderHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(GLRenderFrameCallback));
469 GLTerminateCallback = glTerminate;
470 TerminateHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(GLTerminateCallback));
472 Interop.GLWindow.GlWindow_RegisterGlCallback(swigCPtr, InitHandleRef, RenderHandlerRef, TerminateHandlerRef);
474 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
478 /// Destroy the window immediately.
480 [EditorBrowsable(EditorBrowsableState.Never)]
481 public void Destroy()
487 /// Dispose for Window
489 protected override void Dispose(DisposeTypes type)
496 this.DisconnectNativeSignals();
501 /// This will not be public opened.
502 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
504 Interop.Window.delete_Window(swigCPtr);