Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/api/Button.py
blob: abe5863c5b692560366f52a11e9e1b542d22091c (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import pygame
import api.Label
from api.Label import CLabel

import Mouse


class CButton(CLabel):
    """ a button based on the label 
        same properties as label +
        mactive: True if user is clicking on sprite
                False if user is not currently clicking
        mclicked: True when user releases mouse over a 
                 currently active button
    """

    def __init__(self):
        CLabel.__init__(self)
        self.mactive = False
        self.mclicked = False
        self.bgColor = (0xCC, 0xCC, 0xCC)
        self.set_text('Button')
        
    def setCenter(self, aCenter):
        self.set_center(aCenter)
    
    def clicked(self):
        return self.mclicked
    
    def active(self):
        return self.mactive
    
    def update(self):
        CLabel.update(self)
        
        self.mclicked = False

        #TODO: Make a CMouse class and check for isPressed() and click().

        #check for mouse input
        
        if Mouse.get_pressed() == (1, 0, 0):
            if self.rect.collidepoint(Mouse.get_position()):
                self.mactive = True

        #check for mouse release
        if self.mactive == True:
            if Mouse.get_pressed() == (0, 0, 0):
                self.mactive = False
                if self.rect.collidepoint(Mouse.get_position()):
                    self.mclicked = True