Class NativeWindow
Instances of this class implement the INativeWindow interface on the current platform.
Inherited Members
Namespace: OpenTK
Assembly: OpenTK.dll
Syntax
public class NativeWindow : INativeWindow, IDisposable
Constructors
NativeWindow()
Constructs a new NativeWindow with default attributes without enabling events.
Declaration
public NativeWindow()
NativeWindow(Int32, Int32, Int32, Int32, String, GameWindowFlags, GraphicsMode, DisplayDevice)
Constructs a new NativeWindow with the specified attributes.
Declaration
public NativeWindow(int x, int y, int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
Parameters
Type | Name | Description |
---|---|---|
Int32 | x | Horizontal screen space coordinate of the NativeWindow's origin. |
Int32 | y | Vertical screen space coordinate of the NativeWindow's origin. |
Int32 | width | The width of the NativeWindow in pixels. |
Int32 | height | The height of the NativeWindow in pixels. |
String | title | The title of the NativeWindow. |
GameWindowFlags | options | GameWindow options specifying window appearance and behavior. |
GraphicsMode | mode | The OpenTK.Graphics.GraphicsMode of the NativeWindow. |
DisplayDevice | device | The OpenTK.Graphics.DisplayDevice to construct the NativeWindow in. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | If width or height is less than 1. |
ArgumentNullException | If mode or device is null. |
NativeWindow(Int32, Int32, String, GameWindowFlags, GraphicsMode, DisplayDevice)
Constructs a new centered NativeWindow with the specified attributes.
Declaration
public NativeWindow(int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
Parameters
Type | Name | Description |
---|---|---|
Int32 | width | The width of the NativeWindow in pixels. |
Int32 | height | The height of the NativeWindow in pixels. |
String | title | The title of the NativeWindow. |
GameWindowFlags | options | GameWindow options specifying window appearance and behavior. |
GraphicsMode | mode | The OpenTK.Graphics.GraphicsMode of the NativeWindow. |
DisplayDevice | device | The OpenTK.Graphics.DisplayDevice to construct the NativeWindow in. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | If width or height is less than 1. |
ArgumentNullException | If mode or device is null. |
Properties
Bounds
Gets or sets a Rectangle structure that specifies the external bounds of this window, in screen coordinates. The coordinates are specified in device-independent points and include the title bar, borders and drawing area of the window.
Declaration
public Rectangle Bounds { get; set; }
Property Value
Type | Description |
---|---|
Rectangle |
ClientRectangle
Gets or sets a Rectangle structure that defines the bounds of the OpenGL surface, in window coordinates. The coordinates are specified in device-dependent pixels.
Declaration
public Rectangle ClientRectangle { get; set; }
Property Value
Type | Description |
---|---|
Rectangle |
ClientSize
Gets or sets a Size structure that defines the size of the OpenGL surface in window coordinates. The coordinates are specified in device-dependent pixels.
Declaration
public Size ClientSize { get; set; }
Property Value
Type | Description |
---|---|
Size |
Cursor
Gets or sets the MouseCursor for this window.
Declaration
public MouseCursor Cursor { get; set; }
Property Value
Type | Description |
---|---|
MouseCursor |
CursorGrabbed
Gets or sets a value indicating whether the mouse cursor is grabbed.
Declaration
public bool CursorGrabbed { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Exceptions
Type | Condition |
---|---|
PlatformNotSupportedException | Throw on native Linux platform when trying to set false value |
CursorVisible
Gets or sets a value indicating whether the mouse cursor is visible.
Declaration
public bool CursorVisible { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Exists
Gets a value indicating whether a render window exists.
Declaration
public bool Exists { get; }
Property Value
Type | Description |
---|---|
Boolean |
Focused
Gets a System.Boolean that indicates whether this NativeWindow has input focus.
Declaration
public bool Focused { get; }
Property Value
Type | Description |
---|---|
Boolean |
Height
Gets or sets the height of the OpenGL surface in window coordinates. The coordinates are specified in device-dependent pixels.
Declaration
public int Height { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
Icon
Gets or sets the System.Drawing.Icon for this GameWindow.
Declaration
public Icon Icon { get; set; }
Property Value
Type | Description |
---|---|
Icon |
IsDisposed
Gets or sets a Boolean, which indicates whether this instance has been disposed.
Declaration
protected bool IsDisposed { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Location
Gets or sets a Point structure that contains the location of this window on the desktop.
Declaration
public Point Location { get; set; }
Property Value
Type | Description |
---|---|
Point |
Size
Gets or sets a Size structure that contains the external size of this window.
Declaration
public Size Size { get; set; }
Property Value
Type | Description |
---|---|
Size |
Title
Gets or sets the NativeWindow title.
Declaration
public string Title { get; set; }
Property Value
Type | Description |
---|---|
String |
Visible
Gets or sets a System.Boolean that indicates whether this NativeWindow is visible.
Declaration
public bool Visible { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Width
Gets or sets the width of the OpenGL surface in window coordinates. The coordinates are specified in device-dependent pixels.
Declaration
public int Width { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
WindowBorder
Gets or sets the border of the NativeWindow.
Declaration
public WindowBorder WindowBorder { get; set; }
Property Value
Type | Description |
---|---|
WindowBorder |
WindowInfo
Gets the IWindowInfo of this window.
Declaration
public IWindowInfo WindowInfo { get; }
Property Value
Type | Description |
---|---|
IWindowInfo |
WindowState
Gets or sets the state of the NativeWindow.
Declaration
public virtual WindowState WindowState { get; set; }
Property Value
Type | Description |
---|---|
WindowState |
X
Gets or sets the horizontal location of this window in screen coordinates. The coordinates are specified in device-independent points.
Declaration
public int X { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
Y
Gets or sets the vertical location of this window in screen coordinates. The coordinates are specified in device-independent points.
Declaration
public int Y { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
Close()
Closes the NativeWindow.
Declaration
public void Close()
Dispose()
Releases all non-managed resources belonging to this NativeWindow.
Declaration
public virtual void Dispose()
EnsureUndisposed()
Ensures that this NativeWindow has not been disposed.
Declaration
protected void EnsureUndisposed()
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | If this NativeWindow has been disposed. |
OnClosed(EventArgs)
Called when the NativeWindow has closed.
Declaration
protected virtual void OnClosed(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
EventArgs | e | Not used. |
OnClosing(CancelEventArgs)
Called when the NativeWindow is about to close.
Declaration
protected virtual void OnClosing(CancelEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
CancelEventArgs | e | The CancelEventArgs for this event. Set e.Cancel to true in order to stop the NativeWindow from closing. |
OnDisposed(EventArgs)
Called when the NativeWindow is disposed.
Declaration
protected virtual void OnDisposed(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
EventArgs | e | Not used. |
OnFileDrop(FileDropEventArgs)
Raises the FileDrop event.
Declaration
protected virtual void OnFileDrop(FileDropEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
FileDropEventArgs | e | A FileDropEventArgs instance carrying file name. The information carried by this instance is only valid within this method body. |
OnFocusedChanged(EventArgs)
Called when the Focused property of the NativeWindow has changed.
Declaration
protected virtual void OnFocusedChanged(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
EventArgs | e | Not used. |
OnIconChanged(EventArgs)
Called when the Icon property of the NativeWindow has changed.
Declaration
protected virtual void OnIconChanged(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
EventArgs | e | Not used. |
OnKeyDown(KeyboardKeyEventArgs)
Occurs whenever a keyboard key is pressed.
Declaration
protected virtual void OnKeyDown(KeyboardKeyEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
KeyboardKeyEventArgs | e |
OnKeyPress(KeyPressEventArgs)
Called when a character is typed.
Declaration
protected virtual void OnKeyPress(KeyPressEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
KeyPressEventArgs | e | The KeyPressEventArgs for this event. |
OnKeyUp(KeyboardKeyEventArgs)
Called when a keyboard key is released.
Declaration
protected virtual void OnKeyUp(KeyboardKeyEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
KeyboardKeyEventArgs | e | The KeyboardKeyEventArgs for this event. |
OnMouseDown(MouseButtonEventArgs)
Raises the MouseDown event.
Declaration
protected virtual void OnMouseDown(MouseButtonEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
MouseButtonEventArgs | e | A MouseButtonEventArgs instance carrying mouse state information. The information carried by this instance is only valid within this method body. |
OnMouseEnter(EventArgs)
Called whenever the mouse cursor reenters the window Bounds.
Declaration
protected virtual void OnMouseEnter(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
EventArgs | e | Not used. |
OnMouseLeave(EventArgs)
Called whenever the mouse cursor leaves the window Bounds.
Declaration
protected virtual void OnMouseLeave(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
EventArgs | e | Not used. |
OnMouseMove(MouseMoveEventArgs)
Raises the MouseMove event.
Declaration
protected virtual void OnMouseMove(MouseMoveEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
MouseMoveEventArgs | e | A MouseMoveEventArgs instance carrying mouse state information. The information carried by this instance is only valid within this method body. |
OnMouseUp(MouseButtonEventArgs)
Raises the MouseUp event.
Declaration
protected virtual void OnMouseUp(MouseButtonEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
MouseButtonEventArgs | e | A MouseButtonEventArgs instance carrying mouse state information. The information carried by this instance is only valid within this method body. |
OnMouseWheel(MouseWheelEventArgs)
Raises the MouseWheel event.
Declaration
protected virtual void OnMouseWheel(MouseWheelEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
MouseWheelEventArgs | e | A MouseWheelEventArgs instance carrying mouse state information. The information carried by this instance is only valid within this method body. |
OnMove(EventArgs)
Called when the NativeWindow is moved.
Declaration
protected virtual void OnMove(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
EventArgs | e | Not used. |
OnResize(EventArgs)
Called when the NativeWindow is resized.
Declaration
protected virtual void OnResize(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
EventArgs | e | Not used. |
OnTitleChanged(EventArgs)
Called when the Title property of the NativeWindow has changed.
Declaration
protected virtual void OnTitleChanged(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
EventArgs | e | Not used. |
OnVisibleChanged(EventArgs)
Called when the Visible property of the NativeWindow has changed.
Declaration
protected virtual void OnVisibleChanged(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
EventArgs | e | Not used. |
OnWindowBorderChanged(EventArgs)
Called when the WindowBorder of this NativeWindow has changed.
Declaration
protected virtual void OnWindowBorderChanged(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
EventArgs | e | Not used. |
OnWindowStateChanged(EventArgs)
Called when the WindowState of this NativeWindow has changed.
Declaration
protected virtual void OnWindowStateChanged(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
EventArgs | e | Not used. |
PointToClient(Point)
Transforms the specified point from screen to client coordinates.
Declaration
public Point PointToClient(Point point)
Parameters
Type | Name | Description |
---|---|---|
Point | point | A Point to transform. |
Returns
Type | Description |
---|---|
Point | The point transformed to client coordinates. |
PointToScreen(Point)
Transforms the specified point from client to screen coordinates.
Declaration
public Point PointToScreen(Point point)
Parameters
Type | Name | Description |
---|---|---|
Point | point | A Point to transform. |
Returns
Type | Description |
---|---|
Point | The point transformed to screen coordinates. |
ProcessEvents()
Processes operating system events until the NativeWindow becomes idle.
Declaration
public void ProcessEvents()
ProcessEvents(Boolean)
Processes operating system events until the NativeWindow becomes idle.
Declaration
protected void ProcessEvents(bool retainEvents)
Parameters
Type | Name | Description |
---|---|---|
Boolean | retainEvents | If true, the state of underlying system event propagation will be preserved, otherwise event propagation will be enabled if it has not been already. |
Events
Closed
Occurs after the window has closed.
Declaration
public event EventHandler<EventArgs> Closed
Event Type
Type | Description |
---|---|
EventHandler<EventArgs> |
Closing
Occurs when the window is about to close.
Declaration
public event EventHandler<CancelEventArgs> Closing
Event Type
Type | Description |
---|---|
EventHandler<CancelEventArgs> |
Disposed
Occurs when the window is disposed.
Declaration
public event EventHandler<EventArgs> Disposed
Event Type
Type | Description |
---|---|
EventHandler<EventArgs> |
FileDrop
Occurs whenever a file dropped on window;
Declaration
public event EventHandler<FileDropEventArgs> FileDrop
Event Type
Type | Description |
---|---|
EventHandler<FileDropEventArgs> |
FocusedChanged
Occurs when the Focused property of the window changes.
Declaration
public event EventHandler<EventArgs> FocusedChanged
Event Type
Type | Description |
---|---|
EventHandler<EventArgs> |
IconChanged
Occurs when the Icon property of the window changes.
Declaration
public event EventHandler<EventArgs> IconChanged
Event Type
Type | Description |
---|---|
EventHandler<EventArgs> |
KeyDown
Occurs whenever a keyboard key is pressed.
Declaration
public event EventHandler<KeyboardKeyEventArgs> KeyDown
Event Type
Type | Description |
---|---|
EventHandler<KeyboardKeyEventArgs> |
KeyPress
Occurs whenever a character is typed.
Declaration
public event EventHandler<KeyPressEventArgs> KeyPress
Event Type
Type | Description |
---|---|
EventHandler<KeyPressEventArgs> |
KeyUp
Occurs whenever a keyboard key is released.
Declaration
public event EventHandler<KeyboardKeyEventArgs> KeyUp
Event Type
Type | Description |
---|---|
EventHandler<KeyboardKeyEventArgs> |
MouseDown
Occurs when a MouseButton is pressed.
Declaration
public event EventHandler<MouseButtonEventArgs> MouseDown
Event Type
Type | Description |
---|---|
EventHandler<MouseButtonEventArgs> |
MouseEnter
Occurs whenever the mouse cursor enters the window Bounds.
Declaration
public event EventHandler<EventArgs> MouseEnter
Event Type
Type | Description |
---|---|
EventHandler<EventArgs> |
MouseLeave
Occurs whenever the mouse cursor leaves the window Bounds.
Declaration
public event EventHandler<EventArgs> MouseLeave
Event Type
Type | Description |
---|---|
EventHandler<EventArgs> |
MouseMove
Occurs whenever the mouse is moved.
Declaration
public event EventHandler<MouseMoveEventArgs> MouseMove
Event Type
Type | Description |
---|---|
EventHandler<MouseMoveEventArgs> |
MouseUp
Occurs when a MouseButton is released.
Declaration
public event EventHandler<MouseButtonEventArgs> MouseUp
Event Type
Type | Description |
---|---|
EventHandler<MouseButtonEventArgs> |
MouseWheel
Occurs whenever a mouse wheel is moved;
Declaration
public event EventHandler<MouseWheelEventArgs> MouseWheel
Event Type
Type | Description |
---|---|
EventHandler<MouseWheelEventArgs> |
Move
Occurs whenever the window is moved.
Declaration
public event EventHandler<EventArgs> Move
Event Type
Type | Description |
---|---|
EventHandler<EventArgs> |
Resize
Occurs whenever the window is resized.
Declaration
public event EventHandler<EventArgs> Resize
Event Type
Type | Description |
---|---|
EventHandler<EventArgs> |
TitleChanged
Occurs when the Title property of the window changes.
Declaration
public event EventHandler<EventArgs> TitleChanged
Event Type
Type | Description |
---|---|
EventHandler<EventArgs> |
VisibleChanged
Occurs when the Visible property of the window changes.
Declaration
public event EventHandler<EventArgs> VisibleChanged
Event Type
Type | Description |
---|---|
EventHandler<EventArgs> |
WindowBorderChanged
Occurs when the WindowBorder property of the window changes.
Declaration
public event EventHandler<EventArgs> WindowBorderChanged
Event Type
Type | Description |
---|---|
EventHandler<EventArgs> |
WindowStateChanged
Occurs when the WindowState property of the window changes.
Declaration
public event EventHandler<EventArgs> WindowStateChanged
Event Type
Type | Description |
---|---|
EventHandler<EventArgs> |