From b4fbc7c7e2face0110cfcf14310d05f26f0cec2a Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Mon, 20 Dec 2021 23:23:11 +0100 Subject: [PATCH] Set reference for relative position --- painter.py | 11 +++++++++++ status_bar.py | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/painter.py b/painter.py index c841cbd..cf71c6b 100644 --- a/painter.py +++ b/painter.py @@ -29,6 +29,9 @@ class Painter(Widget): # relative position of mouse when moving self.offset=Point(0,0) + # reference particle from which positions should be computed + self.reference=None + # app is used to share information between widgets self.app=app @@ -130,6 +133,14 @@ class Painter(Widget): # reset self.set_zoom(1) + # set reference + elif text=="r": + if len(self.selected)>0: + self.reference=self.selected[0] + else: + self.reference=None + self.app.status_bar.draw() + def on_key_up(self, keyboard, keycode): if keycode[1]=="shift": if 's' in self.modifiers: diff --git a/status_bar.py b/status_bar.py index 111ac76..455f73f 100644 --- a/status_bar.py +++ b/status_bar.py @@ -44,7 +44,10 @@ class Status_bar(Label): # number of spaces to align right (use 13 characters to print position) spaces=int(self.width/self.char_width)-len(self.raw_text)-13 if spaces>0: - self.raw_text+=" "*spaces+"({:05.2f},{:05.2f})\n".format(self.app.painter.selected[0].squares[0].pos.x,self.app.painter.selected[0].squares[0].pos.y) + if self.app.painter.reference==None: + self.raw_text+=" "*spaces+"({:05.2f},{:05.2f})\n".format(self.app.painter.selected[0].squares[0].pos.x,self.app.painter.selected[0].squares[0].pos.y) + else: + self.raw_text+=" "*spaces+"({:05.2f},{:05.2f})\n".format(self.app.painter.selected[0].squares[0].pos.x-self.app.painter.reference.squares[0].pos.x,self.app.painter.selected[0].squares[0].pos.y-self.app.painter.reference.squares[0].pos.y) # do not wrap self.text=self.raw_text[:min(len(self.raw_text),int(self.width/self.char_width))]