23
23
`adafruit_cursor`
24
24
================================================================================
25
25
26
- Simulated mouse cursor for display interaction
26
+ Simulated mouse cursor for interaction using displayio Groups.
27
27
28
28
* Author(s): Brent Rubell
29
29
@@ -51,15 +51,14 @@ class Cursor:
51
51
;param int scale: Scale amount for the cursor in both directions.
52
52
:param bool is_hidden: Cursor is hidden on init.
53
53
"""
54
+ # pylint: disable=too-many-arguments
54
55
def __init__ (self , display = None , display_group = None , is_hidden = False , cursor_speed = 5 , scale = 1 ):
55
56
self ._display = display
56
57
self ._scale = scale
57
- self ._display_grp = display_group
58
- self ._disp_x = display .height
59
- self ._disp_y = display .width
60
- self ._disp_sz = self ._disp_x - 1 , self ._disp_y - 1
61
58
self ._speed = cursor_speed
62
59
self ._is_hidden = is_hidden
60
+ self ._display_grp = display_group
61
+ self ._disp_sz = display .height - 1 , display .width - 1
63
62
self .generate_cursor ()
64
63
65
64
@property
@@ -96,7 +95,7 @@ def x(self):
96
95
@x .setter
97
96
def x (self , x_val ):
98
97
"""Sets the x-value of the cursor.
99
- :param int x_val: x position, in pixels.
98
+ :param int x_val: cursor x- position, in pixels.
100
99
"""
101
100
if x_val < 0 and not self ._is_hidden :
102
101
self ._cursor_grp .x = self ._cursor_grp .x
@@ -113,7 +112,7 @@ def y(self):
113
112
@y .setter
114
113
def y (self , y_val ):
115
114
"""Sets the y-value of the cursor.
116
- :param int y_val: y position, in pixels.
115
+ :param int y_val: cursor y- position, in pixels.
117
116
"""
118
117
if y_val < 0 and not self ._is_hidden :
119
118
self ._cursor_grp .y = self ._cursor_grp .y
@@ -122,16 +121,11 @@ def y(self, y_val):
122
121
elif not self ._is_hidden :
123
122
self ._cursor_grp .y = y_val
124
123
125
- @property
126
- def is_hidden (self ):
127
- """Returns if the cursor is hidden or visible on the display."""
128
- return self ._is_hidden
129
-
130
124
@property
131
125
def hide (self ):
132
- """Returns if the cursor is hidden or visible on the display."""
126
+ """Returns True if the cursor is hidden or visible on the display."""
133
127
return self ._is_hidden
134
-
128
+
135
129
@hide .setter
136
130
def hide (self , is_hidden ):
137
131
if is_hidden :
@@ -142,36 +136,32 @@ def hide(self, is_hidden):
142
136
self ._display_grp .append (self ._cursor_grp )
143
137
144
138
def generate_cursor (self ):
145
- """Generates a cursor icon bitmap """
139
+ """Generates a cursor icon"""
146
140
self ._cursor_grp = displayio .Group (max_size = 1 , scale = self ._scale )
147
- self ._pointer_bitmap = displayio .Bitmap (20 , 20 , 3 )
148
- self ._pointer_palette = displayio .Palette (3 )
149
- self ._pointer_palette .make_transparent (0 )
150
- self ._pointer_palette [1 ] = 0xFFFFFF
151
- self ._pointer_palette [2 ] = 0x0000
141
+ self ._cur_bmp = displayio .Bitmap (20 , 20 , 3 )
142
+ self ._cur_palette = displayio .Palette (3 )
143
+ self ._cur_palette .make_transparent (0 )
144
+ self ._cur_palette [1 ] = 0xFFFFFF
145
+ self ._cur_palette [2 ] = 0x0000
152
146
# left edge, outline
153
- for i in range (0 , self ._pointer_bitmap .height ):
154
- self ._pointer_bitmap [0 , i ] = 2
155
- # inside fill
147
+ for i in range (0 , self ._cur_bmp .height ):
148
+ self ._cur_bmp [0 , i ] = 2
149
+ # right diag outline, inside fill
156
150
for j in range (1 , 15 ):
157
- for i in range (j + 1 , self ._pointer_bitmap .height - j ):
158
- self ._pointer_bitmap [j , i ] = 1
159
- # right diag., outline
160
- for i in range (1 , 15 ):
161
- self ._pointer_bitmap [i , i ] = 2
151
+ self ._cur_bmp [j , j ] = 2
152
+ for i in range (j + 1 , self ._cur_bmp .height - j ):
153
+ self ._cur_bmp [j , i ] = 1
162
154
# bottom diag., outline
163
155
for i in range (1 , 5 ):
164
- self ._pointer_bitmap [i , self ._pointer_bitmap .height - i ] = 2
165
- # bottom flat line, outline
166
- for i in range (5 , 15 ):
167
- self ._pointer_bitmap [i , 15 ] = 2
168
- # right side fill
156
+ self ._cur_bmp [i , self ._cur_bmp .height - i ] = 2
157
+ # bottom flat line, right side fill
169
158
for i in range (5 , 15 ):
170
- self ._pointer_bitmap [i - 1 , 14 ] = 1
171
- self ._pointer_bitmap [i - 2 , 13 ] = 1
172
- self ._pointer_bitmap [i - 3 , 12 ] = 1
173
- self ._pointer_bitmap [i - 4 , 11 ] = 1
174
- # create a tilegrid out of the bitmap and palette
175
- self ._pointer_sprite = displayio .TileGrid (self ._pointer_bitmap , pixel_shader = self ._pointer_palette )
176
- self ._cursor_grp .append (self ._pointer_sprite )
159
+ self ._cur_bmp [i , 15 ] = 2
160
+ self ._cur_bmp [i - 1 , 14 ] = 1
161
+ self ._cur_bmp [i - 2 , 13 ] = 1
162
+ self ._cur_bmp [i - 3 , 12 ] = 1
163
+ self ._cur_bmp [i - 4 , 11 ] = 1
164
+ self ._cur_sprite = displayio .TileGrid (self ._cur_bmp ,
165
+ pixel_shader = self ._cur_palette )
166
+ self ._cursor_grp .append (self ._cur_sprite )
177
167
self ._display_grp .append (self ._cursor_grp )
0 commit comments