Set lattice on open

This commit is contained in:
Ian Jauslin 2022-09-23 14:22:44 -04:00
parent 267c5e5c5c
commit 5d40050580
2 changed files with 22 additions and 4 deletions

View File

@ -91,10 +91,6 @@ class Jam_app(App):
# command prompt # command prompt
self.command_prompt=Command_prompt(self) self.command_prompt=Command_prompt(self)
# load lattice
if self.lattice=="square":
self.painter.lattice=Square_lattice()
layout.add_widget(self.painter) layout.add_widget(self.painter)
layout.add_widget(self.status_bar) layout.add_widget(self.status_bar)
layout.add_widget(self.command_prompt) layout.add_widget(self.command_prompt)
@ -106,9 +102,14 @@ class Jam_app(App):
# set readonly mode # set readonly mode
self.readonly=not os.access(self.openfile,os.W_OK) self.readonly=not os.access(self.openfile,os.W_OK)
# load lattice
if self.lattice=="square":
self.painter.set_lattice(Square_lattice())
return layout return layout
# disable red circles on right click # disable red circles on right click
Config.set('input', 'mouse', 'mouse,disable_multitouch') Config.set('input', 'mouse', 'mouse,disable_multitouch')
# do not exit on escape # do not exit on escape

View File

@ -51,12 +51,29 @@ class Painter(Widget):
self.keyboard = Window.request_keyboard(None,self,"text") self.keyboard = Window.request_keyboard(None,self,"text")
self.keyboard.bind(on_key_down=self.on_key_down,on_key_up=self.on_key_up,on_textinput=self.on_textinput) self.keyboard.bind(on_key_down=self.on_key_down,on_key_up=self.on_key_up,on_textinput=self.on_textinput)
# redraw on resize
self.bind(size=lambda obj,value: self.draw())
def reset(self): def reset(self):
self.particles=[] self.particles=[]
self.undermouse=None self.undermouse=None
self.draw() self.draw()
# set lattice
def set_lattice(self,lattice):
self.lattice=lattice
# draw
self.draw()
# snap all existing particles to grid
for particle in self.particles:
delta=self.lattice.nearest_delta(particle.squares[0].pos)
if not self.check_interaction_any(particle,delta):
particle.move(delta)
# convert logical coordinates (normalized and centered) to the ones that are plotted # convert logical coordinates (normalized and centered) to the ones that are plotted
def pos_tocoord_x(self,x): def pos_tocoord_x(self,x):
return self.width/2+x*Square_element.size return self.width/2+x*Square_element.size