/*
* Copyright(c) 2020 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
extern alias TizenSystemInformation;
using TizenSystemInformation.Tizen.System;
using global::System;
using System.ComponentModel;
using System.Collections.Generic;
using global::System.Runtime.InteropServices;
using Tizen.NUI.BaseComponents;
namespace Tizen.NUI
{
///
/// The GLWindow class is to draw with native GLES.
/// This class is the special window. It is for native GLES application.
/// So, some special funtions and type are supported.
/// In addition, basic window's functions are supported, too.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public partial class GLWindow : BaseHandle
{
internal GLWindow(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.GLWindow.GlWindowUpcast(cPtr), cMemoryOwn)
{
}
///
/// Creates an initialized handle to a new GLWindow.
/// This creates an GLWindow with default options.!--
///
/// A new GLWindow.
[EditorBrowsable(EditorBrowsableState.Never)]
public GLWindow() : this(Interop.GLWindow.GlWindowNew(), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Creates an initialized handle to a new GLWindow.
/// This API can create GLWindow with specifc option.
///
/// The name for GL window.
/// The position and size of the Window.
/// Whether Window is translucent.
/// A new Window.
[EditorBrowsable(EditorBrowsableState.Never)]
public GLWindow(string name, Rectangle windowPosition = null, bool isTranslucent = false) : this(Interop.GLWindow.GlWindowNew(Rectangle.getCPtr(windowPosition), name, "", isTranslucent), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Enumeration for orientation of the window is the way in which a rectangular page is oriented for normal viewing.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public enum GLWindowOrientation
{
///
/// Portrait orientation. The height of the display area is greater than the width.
///
[EditorBrowsable(EditorBrowsableState.Never)]
Portrait = 0,
///
/// Landscape orientation. A wide view area is needed.
///
[EditorBrowsable(EditorBrowsableState.Never)]
Landscape = 90,
///
/// Portrait inverse orientation.
///
[EditorBrowsable(EditorBrowsableState.Never)]
PortraitInverse = 180,
///
/// Landscape inverse orientation.
///
[EditorBrowsable(EditorBrowsableState.Never)]
LandscapeInverse = 270,
///
/// No orientation. It is for the preferred orientation
/// Especially, NoOrientationPreference only has the effect for the preferred orientation.
/// It is used to unset the preferred orientation with SetPreferredOrientation.
///
[EditorBrowsable(EditorBrowsableState.Never)]
NoOrientationPreference = -1
}
///
/// Gets or sets a size of the window.
///
/// Thrown when value is null.
[EditorBrowsable(EditorBrowsableState.Never)]
public Size2D WindowSize
{
get
{
global::System.IntPtr intPtr = Interop.GLWindow.GlWindowGetPositionSize(SwigCPtr);
var val = new Rectangle(intPtr, true);
Size2D ret = new Size2D(val.Width, val.Height);
val.Dispose();
return ret;
}
set
{
if (null == value)
{
throw new ArgumentNullException(nameof(value));
}
global::System.IntPtr intPtr = Interop.GLWindow.GlWindowGetPositionSize(SwigCPtr);
Rectangle val = new Rectangle(intPtr, true);
Rectangle ret = new Rectangle(val.X, val.Y, value.Width, value.Height);
val.Dispose();
Interop.GLWindow.GlWindowSetPositionSize(SwigCPtr, Rectangle.getCPtr(ret));
ret.Dispose();
}
}
///
/// This Enumeration is used the GLES version for EGL configuration.
/// If the device can not support GLES version 3.0 over, the version will be chosen with GLES version 2.0
///
[EditorBrowsable(EditorBrowsableState.Never)]
public enum GLESVersion
{
///
/// GLES version 2.0
///
[EditorBrowsable(EditorBrowsableState.Never)]
Version_2_0 = 0,
///
/// GLES version 3.0
///
[EditorBrowsable(EditorBrowsableState.Never)]
Version_3_0
}
///
/// Sets egl configuration for GLWindow
///
/// The flag of depth buffer. If true is set, 24bit depth buffer is enabled.
/// The flag of stencil. it true is set, 8bit stencil buffer is enabled.
/// The bit of msaa.
/// The GLES version.
[EditorBrowsable(EditorBrowsableState.Never)]
public void SetEglConfig(bool depth, bool stencil, int msaa, GLESVersion version)
{
Interop.GLWindow.GlWindowSetEglConfig(SwigCPtr, depth, stencil, msaa, (int)version);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Shows the GLWindow if it is hidden.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public void Show()
{
Interop.GLWindow.GlWindowShow(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Hides the GLWindow if it is showing.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public void Hide()
{
Interop.GLWindow.GlWindowHide(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Raises the window to the top of the window stack.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public void Raise()
{
Interop.GLWindow.GlWindowRaise(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Lowers the window to the bottom of the window stack.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public void Lower()
{
Interop.GLWindow.GlWindowLower(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Activates the window to the top of the window stack even it is iconified.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public void Activate()
{
Interop.GLWindow.GlWindowActivate(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Sets position and size of the window. This API guarantees that
/// both moving and resizing of window will appear on the screen at once.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public Rectangle WindowPositionSize
{
get
{
global::System.IntPtr intPtr = Interop.GLWindow.GlWindowGetPositionSize(SwigCPtr);
Rectangle val = new Rectangle(intPtr, true);
Rectangle ret = new Rectangle(val.X, val.Y, val.Width, val.Height);
val.Dispose();
return ret;
}
set
{
Interop.GLWindow.GlWindowSetPositionSize(SwigCPtr, Rectangle.getCPtr(value));
}
}
///
/// Gets the count of supported auxiliary hints of the GLWindow.
///
/// The number of supported auxiliary hints.
[EditorBrowsable(EditorBrowsableState.Never)]
public uint GetSupportedAuxiliaryHintCount()
{
uint ret = Interop.GLWindow.GlWindowGetSupportedAuxiliaryHintCount(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Gets the supported auxiliary hint string of the GLWindow.
///
/// The index of the supported auxiliary hint lists.
/// The auxiliary hint string of the index.
[EditorBrowsable(EditorBrowsableState.Never)]
public string GetSupportedAuxiliaryHint(uint index)
{
string ret = Interop.GLWindow.GlWindowGetSupportedAuxiliaryHint(SwigCPtr, index);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Creates an auxiliary hint of the GLWindow.
///
/// The auxiliary hint string.
/// The value string.
/// The ID of created auxiliary hint, or 0 on failure.
[EditorBrowsable(EditorBrowsableState.Never)]
public uint AddAuxiliaryHint(string hint, string value)
{
uint ret = Interop.GLWindow.GlWindowAddAuxiliaryHint(SwigCPtr, hint, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Removes an auxiliary hint of the GLWindow.
///
/// The ID of the auxiliary hint.
/// True if no error occurred, false otherwise.
[EditorBrowsable(EditorBrowsableState.Never)]
public bool RemoveAuxiliaryHint(uint id)
{
bool ret = Interop.GLWindow.GlWindowRemoveAuxiliaryHint(SwigCPtr, id);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Changes a value of the auxiliary hint.
///
/// The auxiliary hint ID.
/// The value string to be set.
/// True if no error occurred, false otherwise.
[EditorBrowsable(EditorBrowsableState.Never)]
public bool SetAuxiliaryHintValue(uint id, string value)
{
bool ret = Interop.GLWindow.GlWindowSetAuxiliaryHintValue(SwigCPtr, id, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Gets a value of the auxiliary hint.
///
/// The auxiliary hint ID.
/// The string value of the auxiliary hint ID, or an empty string if none exists.
[EditorBrowsable(EditorBrowsableState.Never)]
public string GetAuxiliaryHintValue(uint id)
{
string ret = Interop.GLWindow.GlWindowGetAuxiliaryHintValue(SwigCPtr, id);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Gets an ID of the auxiliary hint string.
///
/// The auxiliary hint string.
/// The ID of auxiliary hint string, or 0 on failure.
[EditorBrowsable(EditorBrowsableState.Never)]
public uint GetAuxiliaryHintId(string hint)
{
uint ret = Interop.GLWindow.GlWindowGetAuxiliaryHintId(SwigCPtr, hint);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Sets a region to accept input events.
///
/// The region to accept input events.
[EditorBrowsable(EditorBrowsableState.Never)]
public void SetInputRegion(Rectangle inputRegion)
{
Interop.GLWindow.GlWindowSetInputRegion(SwigCPtr, Rectangle.getCPtr(inputRegion));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Sets a transparent window's visual state to opaque.
/// If a visual state of a transparent window is opaque,
/// then the window manager could handle it as an opaque window when calculating visibility.
///
/// Whether the window's visual state is opaque.
/// This will have no effect on an opaque window.
/// It doesn't change transparent window to opaque window but lets the window manager know the visual state of the window.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public void SetOpaqueState(bool opaque)
{
Interop.GLWindow.GlWindowSetOpaqueState(SwigCPtr, opaque);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Returns whether a transparent window's visual state is opaque or not.
///
/// True if the window's visual state is opaque, false otherwise.
/// The return value has no meaning on an opaque window.
[EditorBrowsable(EditorBrowsableState.Never)]
public bool IsOpaqueState()
{
bool ret = Interop.GLWindow.GlWindowIsOpaqueState(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Sets a preferred orientation.
///
/// The preferred orientation.
[EditorBrowsable(EditorBrowsableState.Never)]
public void SetPreferredOrientation(GLWindow.GLWindowOrientation orientation)
{
Interop.GLWindow.GlWindowSetPreferredOrientation(SwigCPtr, (int)orientation);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Gets current orientation of the window.
///
/// The current window orientation if previously set, or none.
[EditorBrowsable(EditorBrowsableState.Never)]
public GLWindow.GLWindowOrientation GetCurrentOrientation()
{
GLWindow.GLWindowOrientation ret = (GLWindow.GLWindowOrientation)Interop.GLWindow.GlWindowGetCurrentOrientation(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Sets available orientations of the window.
/// This API is for setting several orientations one time.
///
/// The list of orientations.
/// Thrown when orientations is null.
[EditorBrowsable(EditorBrowsableState.Never)]
public void SetAvailableOrientations(List orientations)
{
if (null == orientations)
{
throw new ArgumentNullException(nameof(orientations));
}
PropertyArray orientationArray = new PropertyArray();
for (int i = 0; i < orientations.Count; i++)
{
PropertyValue val = new PropertyValue((int)orientations[i]);
orientationArray.PushBack(val);
val.Dispose();
}
Interop.GLWindow.GlWindowSetAvailableOrientations(SwigCPtr, PropertyArray.getCPtr(orientationArray), orientations.Count);
orientationArray.Dispose();
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Allows at least one more render, even when paused.
/// The window should be shown, not minimised.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public void RenderOnce()
{
Interop.GLWindow.GlWindowRenderOnce(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Type of callback to initialize native GL code.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public delegate void GLInitializeCallbackType();
GLInitializeCallbackType GLInitializeCallback;
HandleRef InitHandleRef;
///
/// Type of callback to render to frame to use native GL code.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public delegate int GLRenderFrameCallbackType();
GLRenderFrameCallbackType GLRenderFrameCallback;
HandleRef RenderHandlerRef;
///
/// Type of callback to cleanup native GL resource.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public delegate void GLTerminateCallbackType();
GLTerminateCallbackType GLTerminateCallback;
HandleRef TerminateHandlerRef;
///
/// Registers a GL callback function for application.
///
/// The callback function for application initialize
/// The callback function to render to the frame
/// The callback function to clean-up application GL resource
[EditorBrowsable(EditorBrowsableState.Never)]
public void RegisterGlCallback(GLInitializeCallbackType glInit, GLRenderFrameCallbackType glRenderFrame, GLTerminateCallbackType glTerminate)
{
GLInitializeCallback = glInit;
InitHandleRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate(GLInitializeCallback));
GLRenderFrameCallback = glRenderFrame;
RenderHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate(GLRenderFrameCallback));
GLTerminateCallback = glTerminate;
TerminateHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate(GLTerminateCallback));
Interop.GLWindow.GlWindowRegisterGlCallback(SwigCPtr, InitHandleRef, RenderHandlerRef, TerminateHandlerRef);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Destroy the window immediately.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public void Destroy()
{
this.Dispose();
}
///
/// Dispose for Window
///
protected override void Dispose(DisposeTypes type)
{
if (disposed)
{
return;
}
this.DisconnectNativeSignals();
base.Dispose(type);
}
/// This will not be public opened.
protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
{
Interop.Window.DeleteWindow(swigCPtr);
}
}
}