/
toolbox.py
36 lines (29 loc) · 1.06 KB
/
toolbox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import kivy
import math
from kivy.uix.togglebutton import ToggleButton
from kivy.graphics import *
from comicwidgets import StickMan, DraggableWidget, PacMan, Circle
class ToolButton(ToggleButton):
def on_touch_down(self,touch):
draw_space = self.parent.drawing_space
if self.state == "down" and draw_space.collide_point(touch.x,touch.y):
x = draw_space.to_widget(touch.x,touch.y)[0]
y = draw_space.to_widget(touch.x,touch.y)[1]
self.draw(draw_space,x,y)
return True
else:
return super().on_touch_down(touch)
def draw(self, draw_space,x,y):
pass
class StickManButton(ToolButton):
def draw(self,draw_space,x,y):
stickman = StickMan(width = 48, height = 48)
stickman.center_x = x
stickman.center_y = y
draw_space.add_widget(stickman)
class PacManButton(ToolButton):
def draw(self, draw_space,x,y):
pacman = PacMan(width=48,height=48)
pacman.center_x = x
pacman.center_y = y
draw_space.add_widget(pacman)