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":
self.run_set_grid(argv)
return
elif argv[1]=="zoom":
self.run_set_zoom(argv)
else:
self.message="error: unrecognized command '"+argv[1]+"'"
return
@ -382,6 +384,22 @@ class Command_prompt(Label):
self.message="error: grid size cannot be negative: '"+argv[2]+"'"
return
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)

View File

@ -110,6 +110,17 @@ class Painter(Widget):
particle.grid=-particle.grid
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):
if keycode[1]=="shift":
if 's' in self.modifiers:
@ -414,6 +425,11 @@ class Painter(Widget):
ff.close()
self.draw()
# set zoom level
def set_zoom(self,level):
Square_element.size=level*50
self.draw()
# global variables (used like precompiler variables)
CROSS_INDEX=1