Skip to content

Commit 1b6a0ac

Browse files
committed
Add example of using a custom cursor image
1 parent 764d27f commit 1b6a0ac

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import time
2+
import board
3+
import displayio
4+
from adafruit_cursorcontrol.cursorcontrol import Cursor
5+
from adafruit_cursorcontrol.cursorcontrol_cursormanager import CursorManager
6+
7+
# Create the display
8+
display = board.DISPLAY
9+
10+
# Create the display context
11+
splash = displayio.Group(max_size=5)
12+
13+
# initialize the mouse cursor object
14+
bmp = displayio.Bitmap(20, 20, 3)
15+
for i in range(0, bmp.height):
16+
bmp[0, i] = 1
17+
bmp[bmp.width - 1, i] = 1
18+
for i in range(0, bmp.width):
19+
bmp[i, 0] = 1
20+
bmp[i, bmp.height - 1] = 1
21+
22+
mouse_cursor = Cursor(display, display_group=splash, bmp=bmp)
23+
24+
# initialize the cursormanager
25+
cursor = CursorManager(mouse_cursor)
26+
27+
# show displayio group
28+
display.show(splash)
29+
30+
while True:
31+
cursor.update()
32+
if cursor.is_clicked:
33+
if mouse_cursor.hidden:
34+
mouse_cursor.show()
35+
else:
36+
mouse_cursor.hide()
37+
time.sleep(0.01)

0 commit comments

Comments
 (0)