Show / Hide Table of Contents

Class CursorComponent

Inheritance
object
CursorComponent
Implements
ICursorComponent
IPalComponent
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: OpenTK.Platform.Native.Windows
Assembly: OpenTK.Platform.dll
Syntax
public class CursorComponent : ICursorComponent, IPalComponent

Properties

CanInspectSystemCursors

True if the backend supports inspecting system cursor handles. If true, functions like GetSize(CursorHandle, out int, out int) and GetHotspot(CursorHandle, out int, out int) works on system cursors. If fals, these functions will fail.

Declaration
public bool CanInspectSystemCursors { get; }
Property Value
Type Description
bool
See Also
GetSize(CursorHandle, out int, out int)
GetHotspot(CursorHandle, out int, out int)
CanLoadSystemCursors
Create(SystemCursorType)

CanLoadSystemCursors

True if the driver can load system cursors.

Declaration
public bool CanLoadSystemCursors { get; }
Property Value
Type Description
bool
See Also
Create(SystemCursorType)

Logger

The logger that this component uses to log diagnostic messages.

Declaration
public ILogger? Logger { get; set; }
Property Value
Type Description
ILogger
See Also
ILogger
Logger

Name

Name of the abstraction layer component.

Declaration
public string Name { get; }
Property Value
Type Description
string

Provides

Specifies which PAL components this object provides.

Declaration
public PalComponents Provides { get; }
Property Value
Type Description
PalComponents

Methods

Create(SystemCursorType)

Create a standard system cursor.

Declaration
public CursorHandle Create(SystemCursorType systemCursor)
Parameters
Type Name Description
SystemCursorType systemCursor

Type of the standard cursor to load.

Returns
Type Description
CursorHandle

A handle to the created cursor.

Remarks

This function is only supported if CanLoadSystemCursors is true.

Exceptions
Type Condition
PlatformNotSupportedException

Driver does not implement this function. See CanLoadSystemCursors.

See Also
CanLoadSystemCursors
SystemCursorType
Destroy(CursorHandle)

Create(int, int, ReadOnlySpan<byte>, int, int)

Load a cursor image from memory.

Declaration
public CursorHandle Create(int width, int height, ReadOnlySpan<byte> image, int hotspotX, int hotspotY)
Parameters
Type Name Description
int width

Width of the cursor image.

int height

Height of the cursor image.

ReadOnlySpan<byte> image

Buffer containing image data in RGBA order.

int hotspotX

The x coordinate of the cursor hotspot.

int hotspotY

The y coordinate of the cursor hotspot.

Returns
Type Description
CursorHandle

A handle to the created cursor.

Exceptions
Type Condition
ArgumentOutOfRangeException

If width, height, hotspotX, or hotspotY are negative.

ArgumentOutOfRangeException

If hotspotX or hotspotY are greater than width or height respectively.

ArgumentException

image is smaller than specified dimensions.

See Also
Destroy(CursorHandle)

Create(int, int, ReadOnlySpan<byte>, ReadOnlySpan<byte>, int, int)

Load a cursor image from memory.

Declaration
public CursorHandle Create(int width, int height, ReadOnlySpan<byte> colorData, ReadOnlySpan<byte> maskData, int hotspotX, int hotspotY)
Parameters
Type Name Description
int width

Width of the cursor image.

int height

Height of the cursor image.

ReadOnlySpan<byte> colorData

Buffer containing RGB color data.

ReadOnlySpan<byte> maskData

Buffer containing mask data. Pixels where the mask is 1 will be visible while mask value of 0 is transparent.

int hotspotX

The x coordinate of the cursor hotspot.

int hotspotY

The y coordinate of the cursor hotspot.

Returns
Type Description
CursorHandle

A handle to the created handle.

Exceptions
Type Condition
ArgumentOutOfRangeException

If width, height, hotspotX, or hotspotY are negative.

ArgumentOutOfRangeException

If hotspotX or hotspotY are greater than width or height respectively.

ArgumentException

colorData or maskData is smaller than specified dimensions.

See Also
Destroy(CursorHandle)

CreateFromCurFile(string)

Creates a cursor from a .cur file.

Declaration
public CursorHandle CreateFromCurFile(string file)
Parameters
Type Name Description
string file

The .cur file to load.

Returns
Type Description
CursorHandle
Remarks

Handles created by this method will work in GetSize(CursorHandle, out int, out int) and GetHotspot(CursorHandle, out int, out int).

Exceptions
Type Condition
FileNotFoundException

CreateFromCurResorce(byte[])

Declaration
public CursorHandle CreateFromCurResorce(byte[] resource)
Parameters
Type Name Description
byte[] resource
Returns
Type Description
CursorHandle
Remarks

Currently this function does not work with .ani files.

CreateFromCurResorce(string)

Creates a cursor from a resource name.

Declaration
public CursorHandle CreateFromCurResorce(string resourceName)
Parameters
Type Name Description
string resourceName

The name of the icon resource to load.

Returns
Type Description
CursorHandle
Remarks

To use this function you need to create and include a resource file in your exe. To do this, first create a .rc resource definition file and include your icon. Then you need to compile that file into a .res file using rc.exe, the resource compiler. Lastly you need to include that .res file in your csproj using the <Win32Resource> property. FIXME: Write a guide on how to compile .rc files and include a .res file using <Win32Resource>.

Destroy(CursorHandle)

Destroy a cursor object.

Declaration
public void Destroy(CursorHandle handle)
Parameters
Type Name Description
CursorHandle handle

Handle to a cursor object.

See Also
Create(SystemCursorType)
Create(int, int, ReadOnlySpan<byte>, int, int)
Create(int, int, ReadOnlySpan<byte>, ReadOnlySpan<byte>, int, int)

GetHotspot(CursorHandle, out int, out int)

Get the hotspot location of the mouse cursor.

Declaration
public void GetHotspot(CursorHandle handle, out int x, out int y)
Parameters
Type Name Description
CursorHandle handle

Handle to a cursor object.

int x

X coordinate of the hotspot.

int y

Y coordinate of the hotspot.

Remarks

If handle is a system cursor and CanInspectSystemCursors is false this function will fail.

See Also
IsSystemCursor(CursorHandle)
CanInspectSystemCursors

GetImage(CursorHandle, Span<byte>)

Get the mouse cursor image.

Declaration
public void GetImage(CursorHandle handle, Span<byte> image)
Parameters
Type Name Description
CursorHandle handle

Handle to a cursor object.

Span<byte> image

Buffer to copy cursor image into.

Remarks

This method works for all cursors, even system cursors.

Exceptions
Type Condition
ArgumentNullException

handle is null.

GetSize(CursorHandle, out int, out int)

Get the size of the cursor image.

Declaration
public void GetSize(CursorHandle handle, out int width, out int height)
Parameters
Type Name Description
CursorHandle handle

Handle to a cursor object.

int width

Width of the cursor.

int height

Height of the cursor.

Remarks

If handle is a system cursor and CanInspectSystemCursors is false this function will fail.

See Also
IsSystemCursor(CursorHandle)
CanInspectSystemCursors

Initialize(ToolkitOptions)

Initialize the component.

Declaration
public void Initialize(ToolkitOptions options)
Parameters
Type Name Description
ToolkitOptions options

The options to initialize the component with.

See Also
ToolkitOptions
Init(ToolkitOptions)

IsSystemCursor(CursorHandle)

Returns true if this cursor is a system cursor.

Declaration
public bool IsSystemCursor(CursorHandle handle)
Parameters
Type Name Description
CursorHandle handle

Handle to a cursor.

Returns
Type Description
bool

If the cursor is a system cursor or not.

See Also
Create(SystemCursorType)
CanLoadSystemCursors

Uninitialize()

Uninitialize the component. Frees any native resources used by the component.

Declaration
public void Uninitialize()
See Also
Uninit()

Implements

ICursorComponent
IPalComponent
In this article
Back to top Generated by DocFX