Skip to content

Commit 2fcfe4a

Browse files
committed
add mouse sensitivity parameter
1 parent 900e93f commit 2fcfe4a

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Fruit_Jam/Fruit_Jam_PyPaint/code.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def set_cursor_bitmap(self, bmp):
167167
class MousePoller():
168168
"""Get 'pressed' and location updates from a USB mouse."""
169169

170-
def __init__(self, splash, cursor_bmp, screen_width, screen_height):
170+
def __init__(self, splash, cursor_bmp, screen_width, screen_height, sensitivity=3):
171171
print("Creating a MousePoller")
172172
self._display_grp = splash
173173
self._cursor_grp = displayio.Group()
@@ -197,6 +197,9 @@ def __init__(self, splash, cursor_bmp, screen_width, screen_height):
197197
self.mouse_x = screen_width // 2
198198
self.mouse_y = screen_height // 2
199199

200+
# Mouse resolution/sensitivity
201+
self.sensitivity = sensitivity
202+
200203
if not self.find_mouse():
201204
print("WARNING: Mouse not found after multiple attempts.")
202205
print("The application will run, but mouse control may not work.")
@@ -208,6 +211,10 @@ def find_mouse(self): # pylint: disable=too-many-statements, too-many-locals
208211
if self.mouse is None:
209212
print("No mouse found.")
210213
return False
214+
215+
# Change the mouse resolution so it's not too sensitive
216+
self.mouse.display_size = (supervisor.runtime.display.width*self.sensitivity,
217+
supervisor.runtime.display.height*self.sensitivity)
211218
return True
212219

213220
def poll(self):
@@ -269,8 +276,8 @@ def _process_mouse_input(self):
269276
self.last_right_button_state = current_right_button_state
270277

271278
# Update position
272-
self.mouse_x = self.mouse.x
273-
self.mouse_y = self.mouse.y
279+
self.mouse_x = self.mouse.x // self.sensitivity
280+
self.mouse_y = self.mouse.y // self.sensitivity
274281

275282
# Ensure position stays within bounds
276283
self.mouse_x = max(0, min(self.SCREEN_WIDTH - 1, self.mouse_x))

0 commit comments

Comments
 (0)