gale.ui.cursor module

This file contains the implementation of the class Cursor: a custom cursor image, usable as the OS mouse pointer or as a ListView’s keyboard-navigation indicator sprite.

Author: Alejandro Mujica (aledrums@gmail.com)

class gale.ui.cursor.Cursor(image, hotspot=(0, 0))[source]

Bases: object

A custom cursor image, usable two ways:

  • As the OS mouse pointer: call set_as_system_cursor() once (a state’s enter() is a good place) to swap pygame’s own cursor for this image.

  • As a keyboard-navigation indicator: pass it to ListView(cursor=…) so it is rendered next to the currently selected item.

A game configures the cursors it needs through its own settings.py, the same way it already does for TEXTURES/FONTS/SOUNDS:

CURSORS = {

“pointer”: Cursor(pygame.image.load(BASE_DIR / “assets” / “graphics” / “cursor_pointer.png”), hotspot=(2, 2)),

}

Parameters:
  • image (Surface)

  • hotspot (Tuple[int, int])

set_as_system_cursor()[source]

Replace the OS mouse pointer with this cursor’s image.

Return type:

None

show()[source]
Return type:

None

hide()[source]
Return type:

None

render(surface, position)[source]

Draw this cursor’s image at position, used for the keyboard-navigation indicator use case (the OS pointer use case never calls this: pygame already draws the real cursor).

Parameters:
  • surface (Surface) – The surface to draw on.

  • position (Tuple[float, float]) – Where the hotspot should land.

Return type:

None