-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTextBox
More file actions
46 lines (40 loc) · 1.28 KB
/
TextBox
File metadata and controls
46 lines (40 loc) · 1.28 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
class TextBox:
selected = False
data = ""
x = 0
y = 0
l = 0
w = 0
ts = 5
timer = 0
def __init__ (self,xc,yc,le,wi,tsz):
self.x = xc
self.y = yc
self.l = le
self.w = wi
self.ts = tsz
def update(self):
if(mouseX > self.x and mouseX < (self.x+self.l) and mouseY > self.y and mouseY < (self.y+self.w) and mousePressed):
self.selected = True
elif((mouseX < self.x or mouseX > (self.x+self.l) or mouseY < self.y or mouseY > (self.y+self.w)) and mousePressed):
self.selected = False
if(self.selected == True and keyPressed and self.timer >= 8):
self.timer = 0
if(str(key) == "65535"):
self.data += str(key).upper().replace("65535","")
else:
self.data += str(key)
if(key == BACKSPACE):
self.data = ""
if self.timer < 8:
self.timer+=1
if(self.selected == True):
fill(119,136,153);
else:
fill(255,255,255);
rect(self.x,self.y,self.l,self.w)
fill(0,0,0)
textSize(self.ts)
text(self.data,self.x+5,self.y+self.w-5)
def getData(self):
return self.data