From 32cfd341be2671c5e8f889b3f5a390a49c8a7c44 Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Wed, 20 Oct 2021 11:05:18 -0400 Subject: [PATCH] mark selected in cross object --- cross.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/cross.py b/cross.py index a0f11b5..b148536 100644 --- a/cross.py +++ b/cross.py @@ -21,8 +21,14 @@ class Cross(): self.pos.y=y def draw(self,**kwargs): - # override color - Color(*(kwargs.get("color",self.color))) + # set color + if not self.selected: + Color(*self.color) + else: + (r,g,b)=self.color + # darken selected + Color(r/2,g/2,b/2) + Rectangle(pos=((self.pos.x-1.5)*self.size,(self.pos.y-0.5)*self.size),size=(3*self.size,self.size)) Rectangle(pos=((self.pos.x-0.5)*self.size,(self.pos.y-1.5)*self.size),size=(self.size,3*self.size)) @@ -235,13 +241,7 @@ class Cross_painter(Widget): self.canvas.clear() with self.canvas: for cross in self.crosses: - if cross!=self.selected: - cross.draw() - # color selected - else: - (r,g,b)=cross.color - # darken - cross.draw(color=(r/2,g/2,b/2)) + cross.draw() # respond to mouse down @@ -259,8 +259,14 @@ class Cross_painter(Widget): # select cross if touch.button=="left": + # unselect + if self.selected!=None: + self.selected.selected=False + # select cross under touch self.selected=self.find_cross(Point(touch.x/Cross.size,touch.y/Cross.size)) + if self.selected!=None: + self.selected.selected=True self.draw()