blob: 65fa13330e753608a56e107d1864f90c4d3d66db (
plain)
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
|
import pygame
import api.Label
from api.Label import CLabel
class CButton(CLabel):
""" a button based on the label
same properties as label +
active: True if user is clicking on sprite
False if user is not currently clicking
clicked: True when user releases mouse over a
currently active button
"""
def __init__(self):
CLabel.__init__(self)
self.active = False
self.clicked = False
self.bgColor = (0xCC, 0xCC, 0xCC)
def update(self):
CLabel.update(self)
self.clicked = False
#TODO: Make a CMouse class and check for isPressed() and click().
#check for mouse input
if pygame.mouse.get_pressed() == (1, 0, 0):
if self.rect.collidepoint(pygame.mouse.get_pos()):
self.active = True
#check for mouse release
if self.active == True:
if pygame.mouse.get_pressed() == (0, 0, 0):
self.active = False
if self.rect.collidepoint(pygame.mouse.get_pos()):
self.clicked = True
|