Esempio n. 1
0
    def __init__(self, parentSurface:Surface, rect:pygame.Rect,
                 fontName:str, fontColor:tuple, numLines:int,
                 borderColor:tuple, backgroundColor:tuple):
        Widget.__init__(self, parentSurface, rect, borderColor, None)
        self.backgroundColor = backgroundColor
        self.surface = self.getBackgroundSurface()

        self.fontRect = Positioning.innerRect(self.surface.get_rect(), Padding.LABEL)
        fontSize = FontSizer.bestFitSizeInPoints(fontName, self.fontRect.height / numLines)
        self._font = pygame.font.Font(fontName, fontSize)
        self._color = fontColor
        self._text = ""
        self.draw()
Esempio n. 2
0
    def createBlock(self, rect:pygame.Rect, color:tuple, fontName:str, item:Item):
        surface = pygame.Surface((rect.width, rect.height))
        colorRect = Positioning.innerRect(surface.get_rect(), Block.BORDER_SIZE)
        surface.fill(color, colorRect)

        fontRect = Positioning.innerRect(colorRect, Padding.LABEL)
        fontRect.left += Padding.BLOCK
        fontSize = FontSizer.bestFitSizeInPoints(fontName, rect.height / 4)
        font = pygame.font.Font(fontName, fontSize)
        fontSurface = font.render(item.label, True, self.fontColor)
        colorRect.left += Padding.LABEL
        colorRect.top += Padding.LABEL
        surface.blit(fontSurface, fontRect)

        return surface