import draw_util

import mouse
import sound


class Button:
    def __init__(self,
                 name, left, top, right, bottom,
                 func=None,
                 func_args=None,
                 label=None):
        self.name=name
        self.left=left
        self.top=top
        self.right=right
        self.bottom=bottom
        self.func=func
        self.func_args=func_args
        self.label=label

    def draw(self):
        draw_util.draw_quad(self.name,
                            self.left,
                            self.top,
                            self.right,
                            self.bottom)

        if self.label:
            draw_util.draw_quad(self.label,
                                self.left,
                                self.top,
                                self.right,
                                self.bottom)

    def handleMouseButton(self, bDown, button):
        mx,my=mouse.get_pos()

        if bDown and (button==1) and self.func:
            if (mx >= self.left and
                mx <= self.right and
                my >= self.bottom and
                my <= self.top):

                sound.play("twist")
                self.func(self.func_args)
            
        
                 
