adjust zoom level

This commit is contained in:
Ian Jauslin 2021-12-06 13:19:39 -05:00
parent 6d7cfbf2be
commit b0d6178271
2 changed files with 34 additions and 0 deletions

View File

@ -323,6 +323,8 @@ class Command_prompt(Label):
elif argv[1]=="grid": elif argv[1]=="grid":
self.run_set_grid(argv) self.run_set_grid(argv)
return return
elif argv[1]=="zoom":
self.run_set_zoom(argv)
else: else:
self.message="error: unrecognized command '"+argv[1]+"'" self.message="error: unrecognized command '"+argv[1]+"'"
return return
@ -383,6 +385,22 @@ class Command_prompt(Label):
return return
self.app.painter.set_grid(mesh) self.app.painter.set_grid(mesh)
# set zoom level (changes size of elements)
def run_set_zoom(self,argv):
if len(argv)==2:
self.message="error: missing argument in 'set zoom'"
return
else:
try:
zoom_level=float(argv[2])
except:
self.message="error: unrecognized argument '"+argv[2]+"' -- usage 'set zoom <zoom_level>'"
return
if zoom_level<0:
self.message="error: zoom level cannot be negative: '"+argv[2]+"'"
return
self.app.painter.set_zoom(zoom_level)
# write to file # write to file

View File

@ -110,6 +110,17 @@ class Painter(Widget):
particle.grid=-particle.grid particle.grid=-particle.grid
self.draw() self.draw()
# zoom
elif keycode[1]=="+":
# increment by 10%
self.set_zoom(Square_element.size/50*1.1)
elif keycode[1]=="-":
# decrease by 10%
self.set_zoom(Square_element.size/50*0.9)
elif keycode[1]=="=":
# reset
self.set_zoom(1)
def on_key_up(self, keyboard, keycode): def on_key_up(self, keyboard, keycode):
if keycode[1]=="shift": if keycode[1]=="shift":
if 's' in self.modifiers: if 's' in self.modifiers:
@ -414,6 +425,11 @@ class Painter(Widget):
ff.close() ff.close()
self.draw() self.draw()
# set zoom level
def set_zoom(self,level):
Square_element.size=level*50
self.draw()
# global variables (used like precompiler variables) # global variables (used like precompiler variables)
CROSS_INDEX=1 CROSS_INDEX=1