SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SDL::Cursor Class Reference

The structure used to identify an SDL cursor. More...

Inheritance diagram for SDL::Cursor:
Inheritance graph
[legend]

Public Member Functions

constexpr Cursor ()=default
 Default ctor.
 
constexpr Cursor (const CursorRaw resource)
 Constructs from CursorParam. More...
 
constexpr Cursor (const Cursor &other)=delete
 Copy constructor.
 
constexpr Cursor (Cursor &&other)
 Move constructor.
 
constexpr Cursor (const CursorRef &other)=delete
 
constexpr Cursor (CursorRef &&other)=delete
 
 Cursor (const Uint8 *data, const Uint8 *mask, const PointRaw &size, const PointRaw &hot)
 Create a cursor using the specified bitmap data and mask (in MSB format). More...
 
 Cursor (SurfaceParam surface, const PointRaw &hot)
 Create a color cursor. More...
 
 Cursor (SystemCursor id)
 Create a system cursor. More...
 
 ~Cursor ()
 Destructor.
 
Cursoroperator= (Cursor other)
 Assignment operator.
 
constexpr CursorRaw get () const
 Retrieves underlying CursorRaw.
 
constexpr CursorRaw release ()
 Retrieves underlying CursorRaw and clear this.
 
constexpr auto operator<=> (const Cursor &other) const =default
 Comparison.
 
constexpr bool operator== (std::nullptr_t _) const
 Comparison.
 
constexpr operator bool () const
 Converts to bool.
 
constexpr operator CursorParam () const
 Converts to CursorParam.
 
void Destroy ()
 Free a previously-created cursor. More...
 
void Set ()
 Set the active cursor. More...
 

Detailed Description

This is opaque data.

Since
This struct is available since SDL 3.2.0.
Category:
Resource

Constructor & Destructor Documentation

◆ Cursor() [1/4]

constexpr SDL::Cursor::Cursor ( const CursorRaw  resource)
inlineexplicitconstexpr
Parameters
resourcea CursorRaw to be wrapped.

This assumes the ownership, call release() if you need to take back.

◆ Cursor() [2/4]

SDL::Cursor::Cursor ( const Uint8 data,
const Uint8 mask,
const PointRaw size,
const PointRaw hot 
)
inline

mask has to be in MSB (Most Significant Bit) format.

The cursor width (w) must be a multiple of 8 bits.

The cursor is created in black and white according to the following:

  • data=0, mask=1: white
  • data=1, mask=1: black
  • data=0, mask=0: transparent
  • data=1, mask=0: inverted color if possible, black if not.

Cursors created with this function must be freed with Cursor.Destroy().

If you want to have a color cursor, or create your cursor from an Surface, you should use Cursor.Cursor(). Alternately, you can hide the cursor and draw your own as part of your game's rendering, but it will be bound to the framerate.

Also, Cursor.Cursor() is available, which provides several readily-available system cursors to pick from.

Parameters
datathe color value for each pixel of the cursor.
maskthe mask value for each pixel of the cursor.
sizethe width and height of the cursor.
hotthe x position of the cursor hot spot, from the top-left, in the range of 0 to size.x - 1 and 0 to size.y - 1.
Postcondition
a new cursor with the specified parameters on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
Cursor.Cursor
Cursor.Cursor
Cursor.Destroy
Cursor.Set

◆ Cursor() [3/4]

SDL::Cursor::Cursor ( SurfaceParam  surface,
const PointRaw hot 
)
inline

If this function is passed a surface with alternate representations, the surface will be interpreted as the content to be used for 100% display scale, and the alternate representations will be used for high DPI situations. For example, if the original surface is 32x32, then on a 2x macOS display or 200% display scale on Windows, a 64x64 version of the image will be used, if available. If a matching version of the image isn't available, the closest larger size image will be downscaled to the appropriate size and be used instead, if available. Otherwise, the closest smaller image will be upscaled and be used instead.

Parameters
surfacean Surface structure representing the cursor image.
hotthe x, y position of the cursor hot spot.
Postcondition
the new cursor on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
Cursor.Cursor
Cursor.Cursor
Cursor.Destroy
Cursor.Set

◆ Cursor() [4/4]

SDL::Cursor::Cursor ( SystemCursor  id)
inline
Parameters
idan SystemCursor enum value.
Postcondition
a cursor on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
Cursor.Destroy

The documentation for this class was generated from the following file: