-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsliderClass.py
More file actions
37 lines (30 loc) · 1.39 KB
/
Copy pathsliderClass.py
File metadata and controls
37 lines (30 loc) · 1.39 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
import pygame
class Slider():
def __init__(self, left, top, width, clr, radius = 8):
self.left = left
self.top = top
self.clr = clr
self.radius = radius
self.width = width
self.mx = self.left
def draw_slider(self,screen, height, circleClr = (255,255,255), thickness = 2):
pygame.draw.rect(screen,self.clr,(self.left,self.top, self.width, height))
pygame.draw.circle(screen,circleClr, (self.mx,self.top+height/2), self.radius, thickness)
self.hitbox = pygame.Rect(self.mx-self.radius, (self.top+height/2) - self.radius, self.radius * 2, self.radius * 2)
def detect_mouse(self,mouseIsDown, mx, my):
# if clicking on slider
if mouseIsDown and self.hitbox.collidepoint(mx,my):
self.mx = mx
#move slider within boundaries
if self.mx < self.left:
self.mx = self.left
elif self.mx > self.left + self.width:
self.mx = self.left + self.width
def change_clr(self, size = 255):
#set proportion between slider width and 255(rgb max value)
self.proportion = self.width / size
increase = (self.mx - self.left) / self.proportion
return increase
def set_clr(self,RGB_value):
#set slider position based on colour (used for eyedropper)
self.mx = RGB_value * self.proportion + self.left