42
42
__version__ = "0.0.0-auto.0"
43
43
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Cursor.git"
44
44
45
- class Cursor :
45
+ class Cursor ( object ) :
46
46
"""Mouse cursor interaction for CircuitPython.
47
47
48
48
:param ~displayio.Display display: CircuitPython display object.
@@ -65,15 +65,18 @@ class Cursor:
65
65
# initialize the mouse cursor object
66
66
mouse_cursor = Cursor(display, display_group=splash)
67
67
"""
68
- # pylint: disable=too-many-arguments
69
- def __init__ (self , display = None , display_group = None , is_hidden = False , cursor_speed = 5 , scale = 1 ):
68
+ # pylint: disable=too-many-arguments,line-too-long
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 )
79
+ # pylint: enable=too-many-arguments,line-too-long
77
80
78
81
def __enter__ (self ):
79
82
return self
@@ -159,12 +162,12 @@ def y(self, y_val):
159
162
self ._cursor_grp .y = y_val
160
163
161
164
@property
162
- def hide (self ):
165
+ def hidden (self ):
163
166
"""Returns True if the cursor is hidden or visible on the display."""
164
167
return self ._is_hidden
165
168
166
- @hide .setter
167
- def hide (self , is_hidden ):
169
+ @hidden .setter
170
+ def hidden (self , is_hidden ):
168
171
self ._is_deinited ()
169
172
if is_hidden :
170
173
self ._is_hidden = True
@@ -173,34 +176,47 @@ def hide(self, is_hidden):
173
176
self ._is_hidden = False
174
177
self ._display_grp .append (self ._cursor_grp )
175
178
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
179
+ def hide (self ):
180
+ """Hide the cursor."""
181
+ self .hidden = True
182
+
183
+ def show (self ):
184
+ """Show the cursor."""
185
+ self .hidden = False
186
+
187
+ #pylint:disable=no-self-use
188
+ def _default_cursor_bitmap (self ):
189
+ bmp = displayio .Bitmap (20 , 20 , 3 )
185
190
# left edge, outline
186
- for i in range (0 , self . _cur_bmp .height ):
187
- self . _cur_bmp [0 , i ] = 2
191
+ for i in range (0 , bmp .height ):
192
+ bmp [0 , i ] = 2
188
193
# right diag outline, inside fill
189
194
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
195
+ bmp [j , j ] = 2
196
+ for i in range (j + 1 , bmp .height - j ):
197
+ bmp [j , i ] = 1
193
198
# bottom diag., outline
194
199
for i in range (1 , 5 ):
195
- self . _cur_bmp [i , self . _cur_bmp .height - i ] = 2
200
+ bmp [i , bmp .height - i ] = 2
196
201
# bottom flat line, right side fill
197
202
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 ,
203
+ bmp [i , 15 ] = 2
204
+ bmp [i - 1 , 14 ] = 1
205
+ bmp [i - 2 , 13 ] = 1
206
+ bmp [i - 3 , 12 ] = 1
207
+ bmp [i - 4 , 11 ] = 1
208
+ return bmp
209
+ #pylint:enable=no-self-use
210
+
211
+ def generate_cursor (self , bmp ):
212
+ """Generates a cursor icon"""
213
+ self ._is_deinited ()
214
+ self ._cursor_grp = displayio .Group (max_size = 1 , scale = self ._scale )
215
+ self ._cur_palette = displayio .Palette (3 )
216
+ self ._cur_palette .make_transparent (0 )
217
+ self ._cur_palette [1 ] = 0xFFFFFF
218
+ self ._cur_palette [2 ] = 0x0000
219
+ self ._cur_sprite = displayio .TileGrid (bmp ,
204
220
pixel_shader = self ._cur_palette )
205
221
self ._cursor_grp .append (self ._cur_sprite )
206
222
self ._display_grp .append (self ._cursor_grp )
0 commit comments