From 5e76932a556a3c0ee475bb5a1e3dcde66bd6fcdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sat, 4 Apr 2020 00:35:22 +0200 Subject: [PATCH] Add UiBar class --- src/ui/UiBar.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/ui/UiBar.py b/src/ui/UiBar.py index a8dac52..b9b427b 100644 --- a/src/ui/UiBar.py +++ b/src/ui/UiBar.py @@ -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)