Skip to content

class SF::Cursor
inherits Reference #

Cursor defines the appearance of a system cursor

Warning: Features related to Cursor are not supported on iOS and Android.

This class abstracts the operating system resources associated with either a native system cursor or a custom cursor.

After loading the cursor the graphical appearance with either load_from_pixels() or load_from_system(), the cursor can be changed with SF::Window.mouse_cursor=().

The behaviour is undefined if the cursor is destroyed while in use by the window.

Usage example:

sf::Window window;

// ... create window as usual ...

sf::Cursor cursor;
if (cursor.loadFromSystem(sf::Cursor::Hand))
    window.setMouseCursor(cursor);

See also: SF::Window.mouse_cursor=

Included modules

SF::NonCopyable

Class methods#

.from_pixels(*args, **kwargs) : self #

Shorthand for cursor = Cursor.new; cursor.load_from_pixels(...); cursor

Raises InitError on failure

View source

.from_system(*args, **kwargs) : self #

Shorthand for cursor = Cursor.new; cursor.load_from_system(...); cursor

Raises InitError on failure

View source

.new #

Default constructor

This constructor doesn't actually create the cursor; initially the new instance is invalid and must not be used until either load_from_pixels() or load_from_system() is called and successfully created a cursor.

View source

Methods#

#finalize #

Destructor

This destructor releases the system resources associated with this cursor, if any.

View source

#load_from_pixels(pixels : Pointer(UInt8), size : Vector2 | Tuple, hotspot : Vector2 | Tuple) : Bool #

Create a cursor with the provided image

pixels must be an array of width by height pixels in 32-bit RGBA format. If not, this will cause undefined behavior.

If pixels is null or either width or height are 0, the current cursor is left unchanged and the function will return false.

In addition to specifying the pixel data, you can also specify the location of the hotspot of the cursor. The hotspot is the pixel coordinate within the cursor image which will be located exactly where the mouse pointer position is. Any mouse actions that are performed will return the window/screen location of the hotspot.

Warning: On Unix, the pixels are mapped into a monochrome bitmap: pixels with an alpha channel to 0 are transparent, black if the RGB channel are close to zero, and white otherwise.

  • pixels - Array of pixels of the image
  • size - Width and height of the image
  • hotspot - (x,y) location of the hotspot

Returns: true if the cursor was successfully loaded; false otherwise

View source

#load_from_system(type : Cursor::Type) : Bool #

Create a native system cursor

Refer to the list of cursor available on each system (see SF::Cursor::Type) to know whether a given cursor is expected to load successfully or is not supported by the operating system.

  • type - Native system cursor type

Returns: true if and only if the corresponding cursor is natively supported by the operating system; false otherwise

View source