@@ -66,14 +66,16 @@ class Cursor:
66
66
mouse_cursor = Cursor(display, display_group=splash)
67
67
"""
68
68
# pylint: disable=too-many-arguments
69
- def __init__ (self , display = None , display_group = None , is_hidden = False , cursor_speed = 5 , scale = 1 ):
69
+ def __init__ (self , display = None , display_group = None , bmp = None , is_hidden = False , cursor_speed = 5 , scale = 1 ):
70
70
self ._display = display
71
71
self ._scale = scale
72
72
self ._speed = cursor_speed
73
73
self ._is_hidden = is_hidden
74
74
self ._display_grp = display_group
75
75
self ._disp_sz = display .height - 1 , display .width - 1
76
- self .generate_cursor ()
76
+ if bmp is None :
77
+ bmp = self ._default_cursor_bitmap ()
78
+ self .generate_cursor (bmp )
77
79
78
80
def __enter__ (self ):
79
81
return self
@@ -173,34 +175,37 @@ def hide(self, is_hidden):
173
175
self ._is_hidden = False
174
176
self ._display_grp .append (self ._cursor_grp )
175
177
176
- def generate_cursor (self ):
177
- """Generates a cursor icon"""
178
- self ._is_deinited ()
179
- self ._cursor_grp = displayio .Group (max_size = 1 , scale = self ._scale )
180
- self ._cur_bmp = displayio .Bitmap (20 , 20 , 3 )
181
- self ._cur_palette = displayio .Palette (3 )
182
- self ._cur_palette .make_transparent (0 )
183
- self ._cur_palette [1 ] = 0xFFFFFF
184
- self ._cur_palette [2 ] = 0x0000
178
+ def _default_cursor_bitmap (self ):
179
+ bmp = displayio .Bitmap (20 , 20 , 3 )
185
180
# left edge, outline
186
- for i in range (0 , self . _cur_bmp .height ):
187
- self . _cur_bmp [0 , i ] = 2
181
+ for i in range (0 , bmp .height ):
182
+ bmp [0 , i ] = 2
188
183
# right diag outline, inside fill
189
184
for j in range (1 , 15 ):
190
- self . _cur_bmp [j , j ] = 2
191
- for i in range (j + 1 , self . _cur_bmp .height - j ):
192
- self . _cur_bmp [j , i ] = 1
185
+ bmp [j , j ] = 2
186
+ for i in range (j + 1 , bmp .height - j ):
187
+ bmp [j , i ] = 1
193
188
# bottom diag., outline
194
189
for i in range (1 , 5 ):
195
- self . _cur_bmp [i , self . _cur_bmp .height - i ] = 2
190
+ bmp [i , bmp .height - i ] = 2
196
191
# bottom flat line, right side fill
197
192
for i in range (5 , 15 ):
198
- self ._cur_bmp [i , 15 ] = 2
199
- self ._cur_bmp [i - 1 , 14 ] = 1
200
- self ._cur_bmp [i - 2 , 13 ] = 1
201
- self ._cur_bmp [i - 3 , 12 ] = 1
202
- self ._cur_bmp [i - 4 , 11 ] = 1
203
- self ._cur_sprite = displayio .TileGrid (self ._cur_bmp ,
193
+ bmp [i , 15 ] = 2
194
+ bmp [i - 1 , 14 ] = 1
195
+ bmp [i - 2 , 13 ] = 1
196
+ bmp [i - 3 , 12 ] = 1
197
+ bmp [i - 4 , 11 ] = 1
198
+ return bmp
199
+
200
+ def generate_cursor (self , bmp ):
201
+ """Generates a cursor icon"""
202
+ self ._is_deinited ()
203
+ self ._cursor_grp = displayio .Group (max_size = 1 , scale = self ._scale )
204
+ self ._cur_palette = displayio .Palette (3 )
205
+ self ._cur_palette .make_transparent (0 )
206
+ self ._cur_palette [1 ] = 0xFFFFFF
207
+ self ._cur_palette [2 ] = 0x0000
208
+ self ._cur_sprite = displayio .TileGrid (bmp ,
204
209
pixel_shader = self ._cur_palette )
205
210
self ._cursor_grp .append (self ._cur_sprite )
206
211
self ._display_grp .append (self ._cursor_grp )
0 commit comments