This commit is contained in:
2022-09-23 12:58:48 -04:00
parent 88959cb233
commit 9cb25730eb
3 changed files with 69 additions and 6 deletions

View File

@ -7,6 +7,7 @@ from kivy.graphics import Color,Line
from point import Point
from polyomino import Cross
from polyomino import Square_element
from lattice import Square_lattice
from tools import remove_fromlist
@ -20,6 +21,10 @@ class Painter(Widget):
# list of particles
self.particles=[]
# underlying lattice
#self.lattice=None
self.lattice=Square_lattice()
# particle under mouse
self.undermouse=None
@ -74,6 +79,10 @@ class Painter(Widget):
for particle in self.particles:
particle.draw(self)
# draw lattice
if self.lattice!=None:
self.lattice.draw(self)
# draw grids
for particle in self.particles:
if particle.grid>0:
@ -175,6 +184,10 @@ class Painter(Widget):
# create new cross
if touch.button=="right":
new=Cross(touchx,touchy)
# snap to lattice
if self.lattice!=None:
new.move(self.lattice.nearest_delta(new.squares[0].pos))
if not self.check_interaction_any(new,Point(0,0)):
# add to list
self.particles.append(new)
@ -237,18 +250,30 @@ class Painter(Widget):
# respond to drag
def on_touch_move(self,touch):
# convert to logical
touchx=self.coord_topos_x(touch.x)
touchy=self.coord_topos_y(touch.y)
# 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)
# 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.squares[0].pos),0)
for particle in self.selected:
particle.move(delta)
# snap to lattice
if self.lattice!=None:
delta=self.lattice.nearest(delta)
# check that the move is possible (which is not guaranteed after snapping to lattice)
if not self.check_interaction_unselected_list(self.selected,delta):
for particle in self.selected:
particle.move(delta)
# no lattice, move is guaranteed to be acceptable
else:
for particle in self.selected:
particle.move(delta)
# redraw
self.draw()