-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmouse.py
More file actions
194 lines (150 loc) · 5.76 KB
/
mouse.py
File metadata and controls
194 lines (150 loc) · 5.76 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
from tkinter import VERTICAL
import sys, math
from direct.showbase.ShowBase import ShowBase
from pandac.PandaModules import *
from direct.gui.DirectGui import *
loadPrcFile("conf.prc")
keyMap = {
"red": False,
"green": False,
"pink": False,
"yellow": False,
"orange": False,
"blue": False,
}
keyMap2= {
"shift": True,
"darkmood": False
}
def updateKeyMap(key):
for i in keyMap:
if i == key:
if keyMap[i]:
keyMap[i] = False
continue
keyMap[i] = True
continue
else:
keyMap[i] = False
def updateKeyMap2(key):
if keyMap2[key] == True:
keyMap2[key] = False
else:
keyMap2[key] = True
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.lens = OrthographicLens()
self.lens.setFilmSize(10,10)
self.camNode.setLens(self.lens)
self.point = False
self.setBackgroundColor(0.1,0.1,0.1,1)
self.segs = LineSegs("lines")
self.x = 0
self.y = 0
self.taskMgr.add(self.update, "update")
self.accept("r", updateKeyMap, ["red"])
self.accept("g", updateKeyMap, ["green"])
self.accept("b", updateKeyMap, ["blue"])
self.accept("p", updateKeyMap, ["pink"])
self.accept("o", updateKeyMap, ["orange"])
self.accept("y", updateKeyMap, ["yellow"])
self.accept("d", updateKeyMap2, ["darkmood"])
self.accept("shift", updateKeyMap2, ["shift"])
self.colors = [[0.40,0.01,0.05,1], [1,1,1,1]]
self.point2 = True
self.font = self.loader.loadFont("Wbxkomik.ttf")
self.slider = DirectSlider(range=(1, 10), value=1, pageSize=1, command=self.showValue, orientation=VERTICAL)
self.value = int(self.slider["value"])
self.slider.setScale(0.5)
self.slider.setPos(1.6,0,0)
# def mouseClick(self):
# if not self.point:
# x = round(self.mouseWatcherNode.getMouseX(), 3)
# y = round(self.mouseWatcherNode.getMouseY(), 3)
# self.x = x
# self.y = y
# self.point = True
# return
# if base.mouseWatcherNode.hasMouse():
# x = round(self.mouseWatcherNode.getMouseX(), 3)
# y = round(self.mouseWatcherNode.getMouseY(), 3)
# self.segs = LineSegs("lines")
# self.segs.setColor(0.1,0.1,0.1 ,1)
# self.segs.drawTo(self.x,self.y, self.y)
# self.segs.drawTo(x, y, y)
# self.x = x
# self.y = y
# self.segsnode = self.segs.create(False)
# render2d.attachNewNode(self.segsnode)
# print(x, y)
# md2= self.win.getPointer(0)
# print(md2.getX(), md2.getY())
# get the mouse position
self.genLabelText("[SHIFT]: to start/stop drawing", 1)
self.genLabelText("[G]: green", 2)
self.genLabelText("[B]: blue", 3)
self.genLabelText("[P]: pink", 4)
self.genLabelText("[O]: orange", 5)
self.genLabelText("[Y]: yellow", 6)
self.genLabelText("[R]: red", 7)
self.genLabelText("[D]: dark/light mood", 8)
def showValue(self):
self.segs.setThickness(self.slider['value'])
def genLabelText(self, text, i):
if keyMap2["darkmood"]:
fgcolor = (0.1,0.1,0.1,1)
else:
fgcolor = (1,1,1,1)
return OnscreenText(text=text, parent=base.a2dTopLeft, scale=.05,
pos=(0.06, -.08 * i), fg=fgcolor,
shadow=(0, 0, 0, 1), align=TextNode.ALeft, font = self.font)
def update(self, task):
if not keyMap2["shift"]:
self.point2 = False
color = (1,1,1,1)
self.setBackgroundColor(0.1,0.1,0.1,1)
if keyMap2["darkmood"]:
self.setBackgroundColor(0.949,0.898,0.874,1)
if keyMap["red"]:
color = (0.870, 0.05, 0.07, 1)
elif keyMap["green"]:
color = (0.207,0.611,0.356,1)
elif keyMap["blue"]:
color = (0.298,0.45,0.780,1)
elif keyMap["pink"]:
color = (0.878,0.345,0.737,1)
elif keyMap["orange"]:
color = (0.760,0.345,0.168,1)
elif keyMap["yellow"]:
color = (0.760,0.686,0.219,1)
if self.mouseWatcherNode.hasMouse():
if not self.point:
x = self.mouseWatcherNode.getMouseX()
y = self.mouseWatcherNode.getMouseY()
self.x = x
self.y = y
self.point = True
return task.cont
x = self.mouseWatcherNode.getMouseX()
y = self.mouseWatcherNode.getMouseY()
self.segs.setColor(color)
self.segs.drawTo(self.x,self.y, self.y)
self.segs.drawTo(x, y, y)
self.x = x
self.y = y
self.segsnode = self.segs.create(False)
render2d.attachNewNode(self.segsnode)
# print(x,y)
return task.cont
if not self.point2:
if self.mouseWatcherNode.hasMouse():
x = self.mouseWatcherNode.getMouseX()
y = self.mouseWatcherNode.getMouseY()
self.x = x
self.y = y
self.point = True
return task.cont
return task.cont
app = MyApp()
app.run()