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

Handle to a non owned cursor. More...

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

Public Member Functions

constexpr CursorRef (const CursorRef &other)
 Copy constructor.
 
constexpr CursorRef (CursorRef &&other)
 Move constructor.
 
constexpr ~CursorRef ()=default
 Default constructor.
 
CursorRefoperator= (CursorRef other)
 Assignment operator.
 
void reset (SDL_Cursor *newResource={})
 Free a previously-created cursor.
 
 CursorBase (const Uint8 *data, const Uint8 *mask, int w, int h, int hot_x, int hot_y)
 Create a cursor using the specified bitmap data and mask (in MSB format).
 
 CursorBase (SurfaceBase &surface, int hot_x, int hot_y)
 Create a color cursor.
 
 CursorBase (SystemCursor id)
 Create a system cursor.
 
- Public Member Functions inherited from SDL::CursorBase
 CursorBase (const Uint8 *data, const Uint8 *mask, int w, int h, int hot_x, int hot_y)
 Create a cursor using the specified bitmap data and mask (in MSB format).
 
 CursorBase (SurfaceBase &surface, int hot_x, int hot_y)
 Create a color cursor.
 
 CursorBase (SystemCursor id)
 Create a system cursor.
 
constexpr Resource (T resource={})
 Constructs the underlying resource.
 
constexpr Resource (std::nullptr_t)
 Equivalent to default ctor.
 
constexpr Resource (std::nullopt_t)
 Equivalent to default ctor.
 
 Resource (const Resource &other)=delete
 
 Resource (Resource &&other)=delete
 
- Public Member Functions inherited from SDL::Resource< SDL_Cursor * >
constexpr Resource (SDL_Cursor * resource={})
 Constructs the underlying resource.
 
constexpr Resource (std::nullptr_t)
 Equivalent to default ctor.
 
constexpr Resource (std::nullopt_t)
 Equivalent to default ctor.
 
 Resource (const Resource &other)=delete
 
 Resource (Resource &&other)=delete
 
Resourceoperator= (const Resource &other)=delete
 
Resourceoperator= (Resource &&other)=delete
 
constexpr operator bool () const
 True if contains a valid resource.
 
constexpr bool operator== (const Resource &other) const=default
 Comparison.
 
constexpr bool operator== (std::nullopt_t) const
 Comparison.
 
constexpr bool operator== (std::nullptr_t) const
 Comparison.
 
constexpr SDL_Cursor * get () const
 Return contained resource;.
 
constexpr SDL_Cursor * release (SDL_Cursor * newResource={})
 Return contained resource and empties or replace value.
 
constexpr const SDL_Cursor * operator-> () const
 Access to fields.
 
constexpr SDL_Cursor * operator-> ()
 Access to fields.
 

Detailed Description

Category:
Resource
See also
CursorBase
Cursor

Member Function Documentation

◆ CursorBase() [1/3]

SDL::CursorBase::CursorBase ( const Uint8 *  data,
const Uint8 *  mask,
int  w,
int  h,
int  hot_x,
int  hot_y 
)
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 CursorRef.reset().

If you want to have a color cursor, or create your cursor from an SurfaceBase, you should use CursorBase.CursorBase(). 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, CursorBase.CursorBase() 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.
wthe width of the cursor.
hthe height of the cursor.
hot_xthe x-axis offset from the left of the cursor image to the mouse x position, in the range of 0 to w - 1.
hot_ythe y-axis offset from the top of the cursor image to the mouse y position, in the range of 0 to h - 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
CursorBase.CursorBase
CursorBase.CursorBase
CursorRef.reset
SetCursor

◆ CursorBase() [2/3]

SDL::CursorBase::CursorBase ( SurfaceBase surface,
int  hot_x,
int  hot_y 
)
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 SurfaceBase structure representing the cursor image.
hot_xthe x position of the cursor hot spot.
hot_ythe 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
CursorBase.CursorBase
CursorBase.CursorBase
CursorRef.reset
SetCursor

◆ CursorBase() [3/3]

SDL::CursorBase::CursorBase ( 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
CursorRef.reset

◆ reset()

void SDL::CursorRef::reset ( SDL_Cursor *  newResource = {})
inline

Use this function to free cursor resources created with CursorBase.CursorBase(), CursorBase.CursorBase() or CursorBase.CursorBase().

Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
CursorBase.CursorBase

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