예제 #1
0
 def redraw(self):
     paddingL, paddingT = self.padding
     self.rawRect.width += paddingL
     self.rawRect.height = paddingT + len(
         self.dropDownItems) * self.dropDownItems[0].rawRect.height
     self.rawRect.topleft = self.triggerRect.top + self.triggerRect.height + 5, self.triggerRect.left + 5
     self.rect = RoundedButtonHelper(self.rawRect, self.colour, self.radius)
예제 #2
0
 def redraw(self):
     paddingL, paddingT = self.padding
     self.rawRect = self.textRect
     self.rawRect.width += paddingL
     self.rawRect.height += paddingT
     self.rawRect.topleft = (self.textRect.left - paddingL / 2,
                             self.textRect.top - paddingT / 2)
     self.rect = RoundedButtonHelper(self.rawRect, self.colour, self.radius)
예제 #3
0
class Button:
    rect = None
    rawRect = None
    radius = None

    textContent = None
    text = None
    textRect = None

    padding = None
    colour = None

    radius = 0

    def __init__(self, text, colour, padding, textColour=Colours.WHITE):
        self.colour = colour
        self.textContent = text
        self.padding = padding
        self.text = Fonts.productSansRegular(18).render(text, True, textColour)
        self.textRect = self.text.get_rect()

        paddingL, paddingT = padding
        self.rawRect = self.textRect
        self.rawRect.width += paddingL
        self.rawRect.height += paddingT
        self.rawRect.topleft = self.textRect.left - paddingL / 2, self.textRect.top - paddingT / 2
        self.rect = RoundedButtonHelper(self.rawRect, colour, self.radius)

    def isMouseOver(self, point):
        return self.rawRect.collidepoint(point)

    def onClick(self):
        pass

    def onHover(self):
        pass

    def noHover(self):
        pass

    def draw(self, surface):
        self.rect.draw(surface)
        textRect = self.text.get_rect()
        textRect.center = self.rawRect.center
        surface.blit(self.text, textRect)

    def setColour(self, colour):
        self.colour = colour
        self.rect = RoundedButtonHelper(self.rawRect, colour, self.radius)

    def redraw(self):
        paddingL, paddingT = self.padding
        self.rawRect = self.textRect
        self.rawRect.width += paddingL
        self.rawRect.height += paddingT
        self.rawRect.topleft = (self.textRect.left - paddingL / 2,
                                self.textRect.top - paddingT / 2)
        self.rect = RoundedButtonHelper(self.rawRect, self.colour, self.radius)
예제 #4
0
    def __init__(self, text, colour, padding, textColour=Colours.WHITE):
        self.colour = colour
        self.textContent = text
        self.padding = padding
        self.text = Fonts.productSansRegular(18).render(text, True, textColour)
        self.textRect = self.text.get_rect()

        paddingL, paddingT = padding
        self.rawRect = self.textRect
        self.rawRect.width += paddingL
        self.rawRect.height += paddingT
        self.rawRect.topleft = self.textRect.left - paddingL / 2, self.textRect.top - paddingT / 2
        self.rect = RoundedButtonHelper(self.rawRect, colour, self.radius)
예제 #5
0
    def __init__(self, colour, radius, padding, dropDownItems, triggerRect):
        self.colour = colour
        self.padding = padding

        paddingL, paddingT = padding
        self.rawRect = dropDownItems[0].rawRect
        self.rawRect.width = paddingL + 70
        self.rawRect.height = paddingT + len(
            dropDownItems) * dropDownItems[0].rawRect.height
        self.rawRect.topleft = (triggerRect.top + triggerRect.height + 5,
                                triggerRect.left + 5)
        self.radius = radius
        self.rect = RoundedButtonHelper(self.rawRect, colour, radius)
        self.dropDownItems = dropDownItems
        self.isShowing = False
        self.triggerRect = triggerRect
예제 #6
0
 def setRadius(self, radius):
     self.radius = radius
     self.rect = RoundedButtonHelper(self.rawRect, self.colour, radius)
예제 #7
0
class DropDownPanel:
    rect = None
    rawRect = None
    radius = None

    padding = None
    colour = None

    dropDownItems = None

    def __init__(self, colour, radius, padding, dropDownItems, triggerRect):
        self.colour = colour
        self.padding = padding

        paddingL, paddingT = padding
        self.rawRect = dropDownItems[0].rawRect
        self.rawRect.width = paddingL + 70
        self.rawRect.height = paddingT + len(
            dropDownItems) * dropDownItems[0].rawRect.height
        self.rawRect.topleft = (triggerRect.top + triggerRect.height + 5,
                                triggerRect.left + 5)
        self.radius = radius
        self.rect = RoundedButtonHelper(self.rawRect, colour, radius)
        self.dropDownItems = dropDownItems
        self.isShowing = False
        self.triggerRect = triggerRect

    def isMouseOver(self, point):
        return self.rawRect.collidepoint(
            point) or self.triggerRect.collidepoint(point)

    def onClick(self):
        pass

    def onHover(self):
        pass

    def noHover(self):
        self.hide()

    def draw(self, surface):
        if self.isShowing:
            self.rect.draw(surface)
            paddingL, paddingT = self.padding
            top = self.rawRect.top + paddingT / 2
            left = self.rawRect.left + paddingL / 2
            for item in self.dropDownItems:
                item.topleft = top, left
                item.draw(surface)
                top += item.rawRect.height

    def show(self):
        self.isShowing = True

    def hide(self):
        self.isShowing = False

    def addDropDownItem(self, item):
        self.dropDownItems.append(item)
        self.redraw()

    def removeDropDownItem(self, item):
        if len(self.dropDownItems) > 0:
            self.dropDownItems.remove(item)
            self.redraw()

    def setTrigger(self, triggerRect):
        self.triggerRect = triggerRect

    def redraw(self):
        paddingL, paddingT = self.padding
        self.rawRect.width += paddingL
        self.rawRect.height = paddingT + len(
            self.dropDownItems) * self.dropDownItems[0].rawRect.height
        self.rawRect.topleft = self.triggerRect.top + self.triggerRect.height + 5, self.triggerRect.left + 5
        self.rect = RoundedButtonHelper(self.rawRect, self.colour, self.radius)
예제 #8
0
 def setColour(self, colour):
     self.colour = colour
     self.rect = RoundedButtonHelper(self.rawRect, colour, self.radius)