Gamedev Framework (gf)  0.10.0
A C++14 framework for 2D games
Public Types | Public Member Functions | List of all members
gf::Cursor Class Reference

A mouse cursor. More...

#include <gf/Cursor.h>

Public Types

enum  Type {
  Arrow,
  ArrowWait,
  Wait,
  Text,
  Hand,
  SizeHorizontal,
  SizeVertical,
  SizeTopLeftBottomRight,
  SizeBottomLeftTopRight,
  SizeAll,
  Cross,
  NotAllowed
}
 Enumeration of the native system cursor types. More...
 

Public Member Functions

 Cursor ()
 Default constructor. More...
 
 Cursor (const Cursor &)=delete
 Deleted copy constructor. More...
 
Cursoroperator= (const Cursor &)=delete
 Deleted copy assignment. More...
 
 Cursor (Cursor &&other) noexcept
 Move constructor. More...
 
Cursoroperator= (Cursor &&other) noexcept
 Move assignment. More...
 
 ~Cursor ()
 Destructor. More...
 
bool loadFromPixels (const uint8_t *pixels, Vector2u size, Vector2u hotspot)
 Create a cursor with the provided pixels. More...
 
bool loadFromImage (const Image &image, Vector2u hotspot)
 Create a cursor from the provided image. More...
 
bool loadFromSystem (Type type)
 Create a native system cursor. More...
 

Detailed Description

A mouse cursor.

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 loadFromPixels() or loadFromSystem(), the cursor can be changed with gf::Window::setMouseCursor().

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

Usage example:

gf::Window window;
// ... create window as usual ...
gf::Cursor cursor;
window.setMouseCursor(cursor);
}
See also
gf::Window::setMouseCursor()

Member Enumeration Documentation

◆ Type

Enumeration of the native system cursor types.

Enumerator
Arrow 

Arrow cursor (default)

ArrowWait 

Busy arrow cursor.

Wait 

Busy cursor.

Text 

I-beam, cursor when hovering over a field allowing text entry.

Hand 

Pointing hand cursor.

SizeHorizontal 

Horizontal double arrow cursor.

SizeVertical 

Vertical double arrow cursor.

SizeTopLeftBottomRight 

Double arrow cursor going from top-left to bottom-right.

SizeBottomLeftTopRight 

Double arrow cursor going from bottom-left to top-right.

SizeAll 

Combination of SizeHorizontal and SizeVertical.

Cross 

Crosshair cursor.

NotAllowed 

Action not allowed cursor.

Constructor & Destructor Documentation

◆ Cursor() [1/3]

gf::Cursor::Cursor ( )

Default constructor.

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

◆ Cursor() [2/3]

gf::Cursor::Cursor ( const Cursor )
delete

Deleted copy constructor.

◆ Cursor() [3/3]

gf::Cursor::Cursor ( Cursor &&  other)
noexcept

Move constructor.

◆ ~Cursor()

gf::Cursor::~Cursor ( )

Destructor.

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

Member Function Documentation

◆ loadFromImage()

bool gf::Cursor::loadFromImage ( const Image image,
Vector2u  hotspot 
)

Create a cursor from the provided image.

Parameters
imageThe image
hotspotTHe location of the hotspot
Returns
True if the cursor was successfully loaded; false otherwise
See also
loadFromPixels()

◆ loadFromPixels()

bool gf::Cursor::loadFromPixels ( const uint8_t *  pixels,
Vector2u  size,
Vector2u  hotspot 
)

Create a cursor with the provided pixels.

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.

Parameters
pixelsAn array of pixels of the image
sizeThe width and height of the image
hotspotThe location of the hotspot
Returns
True if the cursor was successfully loaded; false otherwise
See also
loadFromImage()

◆ loadFromSystem()

bool gf::Cursor::loadFromSystem ( Type  type)

Create a native system cursor.

Parameters
typeThe native system cursor type
Returns
True if the cursor was successfully loaded; false otherwise

◆ operator=() [1/2]

Cursor& gf::Cursor::operator= ( const Cursor )
delete

Deleted copy assignment.

◆ operator=() [2/2]

Cursor& gf::Cursor::operator= ( Cursor &&  other)
noexcept

Move assignment.