-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckbox.py
More file actions
54 lines (39 loc) · 1.2 KB
/
Checkbox.py
File metadata and controls
54 lines (39 loc) · 1.2 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
#!/usr/bin/python
import pygame
from pygame.locals import *
class Checkbox():
def __init__(self, x, y, text, checked = False):
self.screen = pygame.display.get_surface()
self.checked = checked
self.text = text
self.checkboxRect = pygame.Rect(x, y, 15, 15)
self.crossRect = pygame.Rect(x + 2, y + 2, 11, 11)
if pygame.font:
font = pygame.font.Font(None, 22)
self.textDisp = font.render(self.text, 1, (75, 75, 75))
self.textRect = self.textDisp.get_rect(x = x + 25, centery = y + 9)
def update(self):
pygame.draw.rect(self.screen, (150, 150, 150), self.checkboxRect)
if self.checked:
pygame.draw.rect(self.screen, (75, 75, 75), self.crossRect)
self.screen.blit(self.textDisp, self.textRect)
def onCheckbox(self, (x, y)):
if x >= self.getX() and x <= (self.getX() + 25 + self.textRect.w) and y >= self.getY() and y <= (self.getY() + 15):
return True
else:
return False
def changeState(self):
if self.isChecked():
self.uncheck()
else:
self.check()
def isChecked(self):
return self.checked
def check(self):
self.checked = True
def uncheck(self):
self.checked = False
def getX(self):
return self.checkboxRect.x
def getY(self):
return self.checkboxRect.y