mark selected in cross object

This commit is contained in:
Ian Jauslin 2021-10-20 11:05:18 -04:00
parent 8f1d841f14
commit 32cfd341be

View File

@ -21,8 +21,14 @@ class Cross():
self.pos.y=y self.pos.y=y
def draw(self,**kwargs): def draw(self,**kwargs):
# override color # set color
Color(*(kwargs.get("color",self.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-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)) 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() self.canvas.clear()
with self.canvas: with self.canvas:
for cross in self.crosses: for cross in self.crosses:
if cross!=self.selected:
cross.draw() cross.draw()
# color selected
else:
(r,g,b)=cross.color
# darken
cross.draw(color=(r/2,g/2,b/2))
# respond to mouse down # respond to mouse down
@ -259,8 +259,14 @@ class Cross_painter(Widget):
# select cross # select cross
if touch.button=="left": if touch.button=="left":
# unselect
if self.selected!=None:
self.selected.selected=False
# select cross under touch # select cross under touch
self.selected=self.find_cross(Point(touch.x/Cross.size,touch.y/Cross.size)) self.selected=self.find_cross(Point(touch.x/Cross.size,touch.y/Cross.size))
if self.selected!=None:
self.selected.selected=True
self.draw() self.draw()