From 5864dc5c06be2e3c93e02d644d628c3675fa016c Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Mon, 26 Feb 2024 10:01:50 -0500 Subject: [PATCH] Coarse grain mouse input with lattice --- src/painter.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/painter.py b/src/painter.py index 4abf1c0..9559d40 100644 --- a/src/painter.py +++ b/src/painter.py @@ -315,6 +315,9 @@ class Painter(Widget): # record relative position of click with respect to reference if self.undermouse!=None: self.offset=Point(touchx,touchy)-self.undermouse.elements[0].pos + # snap to lattice + if self.lattice!=None: + self.offset=self.lattice.nearest(self.offset) # no modifiers if self.modifiers==[]: @@ -361,13 +364,17 @@ class Painter(Widget): # only respond to touch in drawing area if self.collide_point(*touch.pos): # convert to logical - touchx=self.coord_topos_x(touch.x) - touchy=self.coord_topos_y(touch.y) + touchc=Point(self.coord_topos_x(touch.x),self.coord_topos_y(touch.y)) + + # snap to lattice + if self.lattice!=None: + touchc=self.lattice.nearest(touchc) # only move on left click if touch.button=="left" and self.modifiers==[] and self.undermouse!=None: # attempted move determined by the relative position to the relative position of click within self.undermouse - delta=self.adjust_move(Point(touchx,touchy)-(self.offset+self.undermouse.elements[0].pos),0) + delta=self.adjust_move(touchc-(self.offset+self.undermouse.elements[0].pos),0) + # snap to lattice if self.lattice!=None: