Skip to content

Commit 336525f

Browse files
set range for mouse_x and mouse_y variables
Fixes #16 . Pyglet returns cursor values which my not be in the range of scren size. Hence I have constraint the cursor values to the size of sketch
1 parent e78c4a8 commit 336525f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

p5/sketch/events.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ class MouseEvent(Event):
177177
"""
178178
def __init__(self, action, x, y, change=(0, 0), scroll=(0, 0),
179179
buttons=None, modifiers=0, handler_name=None):
180-
self.x = x
181-
self.y = builtins.height - y
180+
self.x = max(min(builtins.width, x), 0)
181+
self.y = max(min(builtins.height, builtins.height - y), 0)
182182

183183
self.position = Position(self.x, self.y)
184184
self.change = Position(*change)

0 commit comments

Comments
 (0)