From b0d617827175bd56625c9fc43b5c4f71ec2c1610 Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Mon, 6 Dec 2021 13:19:39 -0500 Subject: [PATCH] adjust zoom level --- command_prompt.py | 18 ++++++++++++++++++ painter.py | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/command_prompt.py b/command_prompt.py index e3856c5..9960d69 100644 --- a/command_prompt.py +++ b/command_prompt.py @@ -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 '" + return + if zoom_level<0: + self.message="error: zoom level cannot be negative: '"+argv[2]+"'" + return + self.app.painter.set_zoom(zoom_level) diff --git a/painter.py b/painter.py index 9a121aa..95e4b06 100644 --- a/painter.py +++ b/painter.py @@ -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