-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslider.py
50 lines (45 loc) · 1.71 KB
/
slider.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#slider class
class Slider(object):
def __init__(self, sX, sY, sLen, sHeight, sName):
self.sX = sX
self.sY = sY
self.sLen = sLen
self.sHeight = sHeight
self.val = 5
self.mouseOver_left = False
self.mouseOver_right = False
self.sName = sName
def display(self):
stroke(0)
strokeWeight(3)
fill(255)
rect(self.sX, self.sY, self.sLen, self.sHeight)
if (self.sX-25 < mouseX < self.sX-10) and (self.sY < mouseY < self.sY+self.sHeight):
fill(200)
self.mouseOver_left = True
else:
fill(255)
self.mouseOver_left = False
triangle(self.sX-10, self.sY, self.sX-10, self.sY+self.sHeight, self.sX-25, self.sY+self.sHeight/2)
if (self.sX+self.sLen+10 < mouseX < self.sX+self.sLen+25) and (self.sY < mouseY < self.sY+self.sHeight):
fill(200)
self.mouseOver_right = True
else:
fill(255)
self.mouseOver_right = False
triangle(self.sX+self.sLen+10, self.sY, self.sX+self.sLen+10, self.sY+self.sHeight, self.sX+self.sLen+25, self.sY+self.sHeight/2)
fill(180)
rect(self.sX, self.sY, self.sLen*(self.val/10.0), self.sHeight)
fill(0)
textSize(18)
textAlign(LEFT)
value = '['+str(self.val)+']'
fill(0)
text(self.sName+' '+value, self.sX, self.sY-10)
def onClick(self):
if self.mouseOver_left == True:
if self.val > 0:
self.val -= 1
elif self.mouseOver_right == True:
if self.val < 10:
self.val += 1