Class NativeWindow
A Native Window.
Implements
Inherited Members
Namespace: OpenTK.Windowing.Desktop
Assembly: OpenTK.Windowing.Desktop.dll
Syntax
public class NativeWindow : IDisposable
Constructors
NativeWindow(NativeWindowSettings)
Initializes a new instance of the NativeWindow class.
Declaration
public NativeWindow(NativeWindowSettings settings)
Parameters
Type | Name | Description |
---|---|---|
NativeWindowSettings | settings | The NativeWindow related settings. |
Properties
API
Gets a value representing the current graphics API.
Declaration
public ContextAPI API { get; }
Property Value
Type | Description |
---|---|
ContextAPI |
APIVersion
Gets a value representing the current version of the graphics API.
Declaration
public Version APIVersion { get; }
Property Value
Type | Description |
---|---|
Version |
AspectRatio
Gets or sets the aspect ratio this window is locked to.
Declaration
public (int numerator, int denominator)? AspectRatio { get; set; }
Property Value
Type | Description |
---|---|
(int numerator, int denominator)? |
Remarks
Set to null
disable aspect ratio locking.
If you set size limits and an aspect ratio lock that conflict, the results are undefined.
AutoIconify
Gets or sets a value indicating whether the application window will be minimized if the
focus changes while the window is in fullscreen mode. The default value is true
.
Declaration
public bool AutoIconify { get; set; }
Property Value
Type | Description |
---|---|
bool |
Bounds
Gets or sets a Box2i structure the contains the external bounds of this window, in screen coordinates. External bounds include the title bar, borders and drawing area of the window.
Declaration
public Box2i Bounds { get; set; }
Property Value
Type | Description |
---|---|
Box2i |
ClientLocation
Gets or sets a Vector2i structure that contains the location of the client area of this window on the desktop.
Declaration
public Vector2i ClientLocation { get; set; }
Property Value
Type | Description |
---|---|
Vector2i |
ClientRectangle
Gets or sets a Box2i structure that contains the internal bounds of this window, in client coordinates. The internal bounds include the drawing area of the window, but exclude the title bar and window borders.
Declaration
public Box2i ClientRectangle { get; set; }
Property Value
Type | Description |
---|---|
Box2i |
ClientSize
Gets or sets a Vector2i structure that contains the client size of this window.
Declaration
public Vector2i ClientSize { get; set; }
Property Value
Type | Description |
---|---|
Vector2i |
ClipboardString
Gets or sets the clipboard string.
Declaration
public string ClipboardString { get; set; }
Property Value
Type | Description |
---|---|
string |
Context
Gets the graphics context associated with this NativeWindow.
Declaration
public IGLFWGraphicsContext Context { get; }
Property Value
Type | Description |
---|---|
IGLFWGraphicsContext |
CurrentMonitor
Gets or sets the current MonitorHandle.
Declaration
public MonitorHandle CurrentMonitor { get; set; }
Property Value
Type | Description |
---|---|
MonitorHandle |
Cursor
Gets or sets the MouseCursor for this window.
Declaration
public MouseCursor Cursor { get; set; }
Property Value
Type | Description |
---|---|
MouseCursor | The cursor. |
CursorState
Gets or sets the cursor state of the windows cursor.
Declaration
public CursorState CursorState { get; set; }
Property Value
Type | Description |
---|---|
CursorState |
Exists
Gets a value indicating whether the window has been created and has not been destroyed.
Declaration
public bool Exists { get; }
Property Value
Type | Description |
---|---|
bool |
Flags
Gets a value representing the current graphics profile flags.
Declaration
public ContextFlags Flags { get; }
Property Value
Type | Description |
---|---|
ContextFlags |
FramebufferSize
Gets a Vector2i structure that contains the framebuffer size of this window.
Declaration
public Vector2i FramebufferSize { get; }
Property Value
Type | Description |
---|---|
Vector2i |
HasTransparentFramebuffer
Whether or not the window has a transparent framebuffer. Check this after setting TransparentFramebuffer to check if a transparent framebuffer got created.
Declaration
public bool HasTransparentFramebuffer { get; }
Property Value
Type | Description |
---|---|
bool |
Icon
Gets or sets the current WindowIcon for this window.
Declaration
public WindowIcon Icon { get; set; }
Property Value
Type | Description |
---|---|
WindowIcon |
Remarks
This does nothing on macOS; on that platform, the icon is determined by the application bundle.
IsAnyKeyDown
Gets a value indicating whether any key is down.
Declaration
public bool IsAnyKeyDown { get; }
Property Value
Type | Description |
---|---|
bool |
|
IsAnyMouseButtonDown
Gets a value indicating whether any mouse button is pressed.
Declaration
public bool IsAnyMouseButtonDown { get; }
Property Value
Type | Description |
---|---|
bool |
|
IsEventDriven
Gets or sets a value indicating whether or not this window is event-driven. An event-driven window will wait for events before updating/rendering. It is useful for non-game applications, where the program only needs to do any processing after the user inputs something.
Declaration
public bool IsEventDriven { get; set; }
Property Value
Type | Description |
---|---|
bool |
IsExiting
Gets a value indicating whether the shutdown sequence has been initiated for this window, by calling NativeWindow.Close() or hitting the 'close' button.
Declaration
public bool IsExiting { get; }
Property Value
Type | Description |
---|---|
bool |
IsFocused
Gets a value indicating whether this window has input focus.
Declaration
public bool IsFocused { get; }
Property Value
Type | Description |
---|---|
bool |
IsFullscreen
Gets a value indicating whether the window is fullscreen or not. Use WindowState to set the window to fullscreen.
Declaration
public bool IsFullscreen { get; }
Property Value
Type | Description |
---|---|
bool |
IsVisible
Gets or sets a value indicating whether the window is visible.
Declaration
public bool IsVisible { get; set; }
Property Value
Type | Description |
---|---|
bool |
JoystickStates
Gets the current state of the joysticks as of the last time the window processed events.
Declaration
public IReadOnlyList<JoystickState> JoystickStates { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<JoystickState> |
KeyboardState
Gets the current state of the keyboard as of the last time the window processed events.
Declaration
public KeyboardState KeyboardState { get; }
Property Value
Type | Description |
---|---|
KeyboardState |
Location
Gets or sets a Vector2i structure that contains the location of this window on the desktop.
Declaration
public Vector2i Location { get; set; }
Property Value
Type | Description |
---|---|
Vector2i |
MaximumSize
Gets or sets a Vector2i structure that contains the maximum external size of this window.
Declaration
public Vector2i? MaximumSize { get; set; }
Property Value
Type | Description |
---|---|
Vector2i? |
Remarks
Set to null
to remove the maximum size constraint.
If you set size limits and an aspect ratio that conflict, the results are undefined.
MinimumSize
Gets or sets a Vector2i structure that contains the minimum external size of this window.
Declaration
public Vector2i? MinimumSize { get; set; }
Property Value
Type | Description |
---|---|
Vector2i? |
Remarks
Set to null
to remove the minimum size constraint.
If you set size limits and an aspect ratio that conflict, the results are undefined.
MousePosition
Gets or sets the position of the mouse relative to the content area of this window. NOTE: It is not necessary to center the mouse on each frame. Use CursorGrabbed = true; to enable this behavior.
Declaration
public Vector2 MousePosition { get; set; }
Property Value
Type | Description |
---|---|
Vector2 |
MouseState
Gets the current state of the mouse as of the last time the window processed events.
Declaration
public MouseState MouseState { get; }
Property Value
Type | Description |
---|---|
MouseState |
Profile
Gets a value representing the current graphics API profile.
Declaration
public ContextProfile Profile { get; }
Property Value
Type | Description |
---|---|
ContextProfile |
RawMouseInput
Enables or disables raw mouse input. Raw mouse input is only enabled when CursorState=Grabbed. Check SupportsRawMouseInput before settings this.
Declaration
public bool RawMouseInput { get; set; }
Property Value
Type | Description |
---|---|
bool |
Size
Gets or sets a Vector2i structure that contains the external size of this window.
Declaration
public Vector2i Size { get; set; }
Property Value
Type | Description |
---|---|
Vector2i |
SupportsRawMouseInput
Whether or not RawMouseInput is supported.
Declaration
public bool SupportsRawMouseInput { get; }
Property Value
Type | Description |
---|---|
bool |
Title
Gets or sets the title of the window.
Declaration
public string Title { get; set; }
Property Value
Type | Description |
---|---|
string |
VSync
Gets or sets the VSync state of this NativeWindow.
Declaration
public VSyncMode VSync { get; set; }
Property Value
Type | Description |
---|---|
VSyncMode | The VSync state. |
WindowBorder
Gets or sets the WindowBorder for this window.
Declaration
public WindowBorder WindowBorder { get; set; }
Property Value
Type | Description |
---|---|
WindowBorder |
WindowPtr
Declaration
public Window* WindowPtr { get; protected set; }
Property Value
Type | Description |
---|---|
Window* |
WindowState
Gets or sets the WindowState for this window.
Declaration
public WindowState WindowState { get; set; }
Property Value
Type | Description |
---|---|
WindowState |
Methods
CenterWindow()
Centers the NativeWindow on the monitor where resides.
Declaration
public void CenterWindow()
CenterWindow(Vector2i)
Centers and resizes the NativeWindow on the monitor where resides.
Declaration
public void CenterWindow(Vector2i newSize)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | newSize | The size to make the centered window. |
Close()
Closes this window.
Declaration
public virtual void Close()
Dispose()
Declaration
public virtual void Dispose()
Dispose(bool)
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing |
~NativeWindow()
Finalizes an instance of the NativeWindow class.
Declaration
protected ~NativeWindow()
Focus()
Brings the window into focus.
Declaration
public void Focus()
IsKeyDown(Keys)
Gets a bool indicating whether this key is currently down.
Declaration
public bool IsKeyDown(Keys key)
Parameters
Type | Name | Description |
---|---|---|
Keys | key | The key to check. |
Returns
Type | Description |
---|---|
bool |
|
IsKeyPressed(Keys)
Gets whether the specified key is pressed in the current frame but released in the previous frame.
Declaration
public bool IsKeyPressed(Keys key)
Parameters
Type | Name | Description |
---|---|---|
Keys | key | The key to check. |
Returns
Type | Description |
---|---|
bool | True if the key is pressed in this frame, but not the last frame. |
Remarks
"Frame" refers to invocations of
IsKeyReleased(Keys)
Gets whether the specified key is released in the current frame but pressed in the previous frame.
Declaration
public bool IsKeyReleased(Keys key)
Parameters
Type | Name | Description |
---|---|---|
Keys | key | The key to check. |
Returns
Type | Description |
---|---|
bool | True if the key is released in this frame, but pressed the last frame. |
Remarks
"Frame" refers to invocations of
IsMouseButtonDown(MouseButton)
Gets a bool indicating whether this button is currently down.
Declaration
public bool IsMouseButtonDown(MouseButton button)
Parameters
Type | Name | Description |
---|---|---|
MouseButton | button | The MouseButton to check. |
Returns
Type | Description |
---|---|
bool |
|
IsMouseButtonPressed(MouseButton)
Gets whether the specified mouse button is pressed in the current frame but released in the previous frame.
Declaration
public bool IsMouseButtonPressed(MouseButton button)
Parameters
Type | Name | Description |
---|---|---|
MouseButton | button | The button to check. |
Returns
Type | Description |
---|---|
bool | True if the button is pressed in this frame, but not the last frame. |
Remarks
"Frame" refers to invocations of
IsMouseButtonReleased(MouseButton)
Gets whether the specified mouse button is released in the current frame but pressed in the previous frame.
Declaration
public bool IsMouseButtonReleased(MouseButton button)
Parameters
Type | Name | Description |
---|---|---|
MouseButton | button | The button to check. |
Returns
Type | Description |
---|---|
bool | True if the button is released in this frame, but pressed the last frame. |
Remarks
"Frame" refers to invocations of
MakeCurrent()
Makes the GraphicsContext current on the calling thread.
Declaration
public void MakeCurrent()
NewInputFrame()
Updates the input state in preparation for a call to PollEvents() or WaitEvents().
Do not call this function if you are calling
Declaration
public void NewInputFrame()
OnClosing(CancelEventArgs)
Raises the Closing event.
Declaration
protected virtual void OnClosing(CancelEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
CancelEventArgs | e | A CancelEventArgs that contains the event data. |
OnFileDrop(FileDropEventArgs)
Raises the FileDrop event.
Declaration
protected virtual void OnFileDrop(FileDropEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
FileDropEventArgs | e | A FileDropEventArgs that contains the event data. |
OnFocusedChanged(FocusedChangedEventArgs)
Raises the FocusedChanged event.
Declaration
protected virtual void OnFocusedChanged(FocusedChangedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
FocusedChangedEventArgs | e | A FocusedChangedEventArgs that contains the event data. |
OnFramebufferResize(FramebufferResizeEventArgs)
Raises the FramebufferResize event.
Declaration
protected virtual void OnFramebufferResize(FramebufferResizeEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
FramebufferResizeEventArgs | e | A FramebufferResizeEventArgs that contains the event data. |
OnJoystickConnected(JoystickEventArgs)
Raises the JoystickConnected event.
Declaration
protected virtual void OnJoystickConnected(JoystickEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
JoystickEventArgs | e | A JoystickEventArgs that contains the event data. |
OnKeyDown(KeyboardKeyEventArgs)
Raises the KeyDown event.
Declaration
protected virtual void OnKeyDown(KeyboardKeyEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
KeyboardKeyEventArgs | e | A KeyboardKeyEventArgs that contains the event data. |
OnKeyUp(KeyboardKeyEventArgs)
Raises the KeyUp event.
Declaration
protected virtual void OnKeyUp(KeyboardKeyEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
KeyboardKeyEventArgs | e | A KeyboardKeyEventArgs that contains the event data. |
OnMaximized(MaximizedEventArgs)
Raises the OnMaximized(MaximizedEventArgs) event.
WARNING: During this callback ClientSize will not be guaranteed to contain the new size of the window.
Declaration
protected virtual void OnMaximized(MaximizedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
MaximizedEventArgs | e | A MaximizedEventArgs that contains the event data. |
OnMinimized(MinimizedEventArgs)
Raises the OnMinimized(MinimizedEventArgs) event.
WARNING: During this callback ClientSize will not be guaranteed to contain the new size of the window.
Declaration
protected virtual void OnMinimized(MinimizedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
MinimizedEventArgs | e | A MinimizedEventArgs that contains the event data. |
OnMouseDown(MouseButtonEventArgs)
Raises the MouseDown event.
Declaration
protected virtual void OnMouseDown(MouseButtonEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
MouseButtonEventArgs | e | A MouseButtonEventArgs that contains the event data. |
OnMouseEnter()
Raises the MouseEnter event.
Declaration
protected virtual void OnMouseEnter()
OnMouseLeave()
Raises the MouseLeave event.
Declaration
protected virtual void OnMouseLeave()
OnMouseMove(MouseMoveEventArgs)
Raises the MouseMove event.
Declaration
protected virtual void OnMouseMove(MouseMoveEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
MouseMoveEventArgs | e | A MouseMoveEventArgs that contains the event data. |
OnMouseUp(MouseButtonEventArgs)
Raises the MouseUp event.
Declaration
protected virtual void OnMouseUp(MouseButtonEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
MouseButtonEventArgs | e | A MouseButtonEventArgs that contains the event data. |
OnMouseWheel(MouseWheelEventArgs)
Raises the MouseWheel event.
Declaration
protected virtual void OnMouseWheel(MouseWheelEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
MouseWheelEventArgs | e | A MouseWheelEventArgs that contains the event data. |
OnMove(WindowPositionEventArgs)
Raises the Move event.
Declaration
protected virtual void OnMove(WindowPositionEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
WindowPositionEventArgs | e | A WindowPositionEventArgs that contains the event data. |
OnRefresh()
Raises the Refresh event.
Declaration
protected virtual void OnRefresh()
OnResize(ResizeEventArgs)
Raises the Resize event.
Declaration
protected virtual void OnResize(ResizeEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
ResizeEventArgs | e | A ResizeEventArgs that contains the event data. |
OnTextInput(TextInputEventArgs)
Raises the TextInput event.
Declaration
protected virtual void OnTextInput(TextInputEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
TextInputEventArgs | e | A TextInputEventArgs that contains the event data. |
PointToClient(Vector2i)
Transforms the specified point from screen to client coordinates.
Declaration
public Vector2i PointToClient(Vector2i point)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | point | A Vector2 to transform. |
Returns
Type | Description |
---|---|
Vector2i | The point transformed to client coordinates. |
PointToScreen(Vector2i)
Transforms the specified point from client to screen coordinates.
Declaration
public Vector2i PointToScreen(Vector2i point)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | point | A Vector2 to transform. |
Returns
Type | Description |
---|---|
Vector2i | The point transformed to screen coordinates. |
ProcessEvents(double)
Processes pending window events and waits timeout
seconds for events.
Declaration
public bool ProcessEvents(double timeout)
Parameters
Type | Name | Description |
---|---|---|
double | timeout | The timeout in seconds. |
Returns
Type | Description |
---|---|
bool | This function will always return true. |
ProcessWindowEvents(bool)
Processes pending window events, either by calling WaitEvents() or PollEvents() depending on if waitForEvents
is set to true or not.
Declaration
public static void ProcessWindowEvents(bool waitForEvents)
Parameters
Type | Name | Description |
---|---|---|
bool | waitForEvents | Whether to call WaitEvents() or PollEvents(). |
Remarks
This function should only be called from the main thread.
TryGetCurrentMonitorDpi(out float, out float)
Gets the dpi of the current monitor.
Declaration
public bool TryGetCurrentMonitorDpi(out float horizontalDpi, out float verticalDpi)
Parameters
Type | Name | Description |
---|---|---|
float | horizontalDpi | Horizontal dpi. |
float | verticalDpi | Vertical dpi. |
Returns
Type | Description |
---|---|
bool |
|
Remarks
This methods approximates the dpi of the monitor by multiplying the monitor scale received from TryGetCurrentMonitorScale(out float, out float) by each platforms respective default dpi (72 for macOS and 96 for other systems).
TryGetCurrentMonitorDpiRaw(out float, out float)
Gets the raw dpi of current monitor.
Declaration
public bool TryGetCurrentMonitorDpiRaw(out float horizontalRawDpi, out float verticalRawDpi)
Parameters
Type | Name | Description |
---|---|---|
float | horizontalRawDpi | Raw horizontal dpi. |
float | verticalRawDpi | Raw vertical dpi. |
Returns
Type | Description |
---|---|
bool |
|
Remarks
This method calculates dpi by retrieving monitor dimensions and resolution. However on certain platforms (such as Windows) these values may not be scaled correctly.
TryGetCurrentMonitorScale(out float, out float)
Gets the current monitor scale.
Declaration
public bool TryGetCurrentMonitorScale(out float horizontalScale, out float verticalScale)
Parameters
Type | Name | Description |
---|---|---|
float | horizontalScale | Horizontal scale. |
float | verticalScale | Vertical scale. |
Returns
Type | Description |
---|---|
bool |
|
Events
Closing
Occurs when the window is about to close.
Declaration
public event Action<CancelEventArgs> Closing
Event Type
Type | Description |
---|---|
Action<CancelEventArgs> |
FileDrop
Occurs whenever one or more files are dropped on the window.
Declaration
public event Action<FileDropEventArgs> FileDrop
Event Type
Type | Description |
---|---|
Action<FileDropEventArgs> |
FocusedChanged
Occurs when the IsFocused property of the window changes.
Declaration
public event Action<FocusedChangedEventArgs> FocusedChanged
Event Type
Type | Description |
---|---|
Action<FocusedChangedEventArgs> |
FramebufferResize
Occurs whenever the framebuffer is resized.
Declaration
public event Action<FramebufferResizeEventArgs> FramebufferResize
Event Type
Type | Description |
---|---|
Action<FramebufferResizeEventArgs> |
JoystickConnected
Occurs when a joystick is connected or disconnected.
Declaration
public event Action<JoystickEventArgs> JoystickConnected
Event Type
Type | Description |
---|---|
Action<JoystickEventArgs> |
KeyDown
Occurs whenever a keyboard key is pressed.
Declaration
public event Action<KeyboardKeyEventArgs> KeyDown
Event Type
Type | Description |
---|---|
Action<KeyboardKeyEventArgs> |
KeyUp
Occurs whenever a keyboard key is released.
Declaration
public event Action<KeyboardKeyEventArgs> KeyUp
Event Type
Type | Description |
---|---|
Action<KeyboardKeyEventArgs> |
Maximized
Occurs when the window is maximized.
Declaration
public event Action<MaximizedEventArgs> Maximized
Event Type
Type | Description |
---|---|
Action<MaximizedEventArgs> |
Minimized
Occurs when the window is minimized.
Declaration
public event Action<MinimizedEventArgs> Minimized
Event Type
Type | Description |
---|---|
Action<MinimizedEventArgs> |
MouseDown
Occurs whenever a MouseButton is clicked.
Declaration
public event Action<MouseButtonEventArgs> MouseDown
Event Type
Type | Description |
---|---|
Action<MouseButtonEventArgs> |
MouseEnter
Occurs whenever the mouse cursor enters the window Bounds.
Declaration
public event Action MouseEnter
Event Type
Type | Description |
---|---|
Action |
MouseLeave
Occurs whenever the mouse cursor leaves the window Bounds.
Declaration
public event Action MouseLeave
Event Type
Type | Description |
---|---|
Action |
MouseMove
Occurs whenever the mouse cursor is moved;
Declaration
public event Action<MouseMoveEventArgs> MouseMove
Event Type
Type | Description |
---|---|
Action<MouseMoveEventArgs> |
MouseUp
Occurs whenever a MouseButton is released.
Declaration
public event Action<MouseButtonEventArgs> MouseUp
Event Type
Type | Description |
---|---|
Action<MouseButtonEventArgs> |
MouseWheel
Occurs whenever a mouse wheel is moved;
Declaration
public event Action<MouseWheelEventArgs> MouseWheel
Event Type
Type | Description |
---|---|
Action<MouseWheelEventArgs> |
Move
Occurs whenever the window is moved.
Declaration
public event Action<WindowPositionEventArgs> Move
Event Type
Type | Description |
---|---|
Action<WindowPositionEventArgs> |
Refresh
Occurs whenever the window is refreshed.
Declaration
public event Action Refresh
Event Type
Type | Description |
---|---|
Action |
Resize
Occurs whenever the window is resized.
Declaration
public event Action<ResizeEventArgs> Resize
Event Type
Type | Description |
---|---|
Action<ResizeEventArgs> |
TextInput
Occurs whenever a Unicode code point is typed.
Declaration
public event Action<TextInputEventArgs> TextInput
Event Type
Type | Description |
---|---|
Action<TextInputEventArgs> |