add hide/show cursor methods, ishidden property
This commit is contained in:
parent
08126f4b92
commit
c55efc8c08
1 changed files with 27 additions and 8 deletions
|
|
@ -53,15 +53,19 @@ class Cursor:
|
||||||
:param displayio.Display: CircuitPython display object.
|
:param displayio.Display: CircuitPython display object.
|
||||||
:param dict cursor: Information about the cursor including its cursor_path,
|
:param dict cursor: Information about the cursor including its cursor_path,
|
||||||
cursor_scale, cursor_width, cursor_height, cursor_tile_width, and cursor_tile_height.
|
cursor_scale, cursor_width, cursor_height, cursor_tile_width, and cursor_tile_height.
|
||||||
|
:param bool is_hidden: Cursor hidden by default.
|
||||||
"""
|
"""
|
||||||
def __init__(self, display=None, display_group=None, cursor=None, cursor_speed = 1):
|
def __init__(self, display=None, display_group=None, cursor=None, cursor_speed = 1, is_hidden=False):
|
||||||
self._display = display
|
self._display = display
|
||||||
self._display_grp = display_group
|
self._display_grp = display_group
|
||||||
self._display_width = display.width
|
self._display_width = display.width
|
||||||
self._display_height = display.height
|
self._display_height = display.height
|
||||||
self._speed = cursor_speed
|
self._speed = cursor_speed
|
||||||
if cursor:
|
self._is_hidden = is_hidden
|
||||||
self.load_custom_cursor(cursor)
|
try:
|
||||||
|
self.load_cursor_image(cursor)
|
||||||
|
except:
|
||||||
|
raise TypeError('Cursor info not found!')
|
||||||
self.x = int(self._display_width/2)
|
self.x = int(self._display_width/2)
|
||||||
self.y = int(self._display_height/2)
|
self.y = int(self._display_height/2)
|
||||||
|
|
||||||
|
|
@ -111,9 +115,25 @@ class Cursor:
|
||||||
else:
|
else:
|
||||||
self._cursor_grp.y = y_val
|
self._cursor_grp.y = y_val
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_hidden(self):
|
||||||
|
"""Returns if the cursor is hidden or visible on the display."""
|
||||||
|
return self._is_hidden
|
||||||
|
|
||||||
def load_custom_cursor(self, cursor_info):
|
def hide(self):
|
||||||
""" Loads and creates a custom cursor image from a defined spritesheet.
|
"""Hides the cursor by removing the cursor subgroup from the display group.
|
||||||
|
"""
|
||||||
|
self._is_hidden = True
|
||||||
|
self._display_grp.remove(self._cursor_grp)
|
||||||
|
|
||||||
|
def show(self):
|
||||||
|
"""Shows the cursor by inserting the cursor subgroup into the display group.
|
||||||
|
"""
|
||||||
|
self._is_hidden = False
|
||||||
|
self._display_grp.insert(0, self._cursor_grp)
|
||||||
|
|
||||||
|
def load_cursor_image(self, cursor_info):
|
||||||
|
"""Loads and creates a custom cursor image from a defined spritesheet.
|
||||||
:param dict cursor: Information about the cursor including its cursor_path,
|
:param dict cursor: Information about the cursor including its cursor_path,
|
||||||
cursor_scale, cursor_width, cursor_height, cursor_tile_width, and cursor_tile_height.
|
cursor_scale, cursor_width, cursor_height, cursor_tile_width, and cursor_tile_height.
|
||||||
"""
|
"""
|
||||||
|
|
@ -126,7 +146,6 @@ class Cursor:
|
||||||
tile_width = cursor_info['cursor_tile_width'],
|
tile_width = cursor_info['cursor_tile_width'],
|
||||||
tile_height = cursor_info['cursor_tile_height'])
|
tile_height = cursor_info['cursor_tile_height'])
|
||||||
self._cursor_grp = displayio.Group(max_size = 1, scale=cursor_info['cursor_scale'])
|
self._cursor_grp = displayio.Group(max_size = 1, scale=cursor_info['cursor_scale'])
|
||||||
# add sprite to cursor subgroup
|
|
||||||
self._cursor_grp.append(self._sprite)
|
self._cursor_grp.append(self._sprite)
|
||||||
# append cursor subgroup to display group
|
if not self._is_hidden:
|
||||||
self._display_grp.append(self._cursor_grp)
|
self._display_grp.append(self._cursor_grp)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue