Add UiBar class

This commit is contained in:
Michał Czekański 2020-04-04 00:35:22 +02:00
parent ed1d057be2
commit 5e76932a55

View File

@ -1,5 +1,22 @@
import src.ui.UiElement as UiElement
import pygame
from src.ui.UiElement import UiElement
class UiBar(UiElement):
pass
def __init__(self, rect: pygame.Rect, initialFilledPercent=100, filledBarColor=(255, 0, 0), emptyBarColor=(0, 0, 0),
outlineColor=(75, 75, 75), outlineThickness=10):
super().__init__(rect)
self.filledPercent = initialFilledPercent / 100
self.emptyBarColor = emptyBarColor
self.barColor = filledBarColor
self.image = pygame.Surface((rect.width, rect.height))
filledPartRect = pygame.rect.Rect(outlineThickness / 2, outlineThickness / 2,
(rect.width - outlineThickness) * self.filledPercent,
rect.height - outlineThickness)
self.image.fill(filledBarColor, filledPartRect)
pygame.draw.rect(self.image, outlineColor, pygame.rect.Rect(0, 0, rect.width, rect.height),
outlineThickness)