From f67ec8b0372c2d136f4f87445fd9b10ece73e7bf Mon Sep 17 00:00:00 2001 From: Guillaume Dott Date: Mon, 2 Oct 2017 10:10:26 +0200 Subject: [PATCH] Display countdown at bottom of the screen --- photoboite.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/photoboite.py b/photoboite.py index 15c64ad..80758e8 100755 --- a/photoboite.py +++ b/photoboite.py @@ -47,18 +47,28 @@ class CaptureButton(Button): self.capture_mode = False self.count = 0 + self.background_rect = pygame.Rect(0, self.photoboite.screen.get_height() - 80, self.photoboite.screen.get_width(), 80) + self.background = pygame.Surface((self.background_rect.width, self.background_rect.height)) + self.background.fill((0, 0, 0)) + self.background.set_alpha(150) + + self.font = pygame.font.Font(None, 80) + def draw_on(self, screen): if self.enabled: super(CaptureButton, self).draw_on(screen) - if self.capture_mode: - if self.elapsed >= CaptureButton.countdown: - text = "CLIC!" - else: - text = str(CaptureButton.countdown - self.elapsed) - size = self.photoboite.font.size(text) - ren = self.photoboite.font.render(text, True, (0, 0, 0)) + if self.capture_mode and self.elapsed < CaptureButton.countdown: + screen.blit(self.background, self.background_rect.topleft) + + text = str(CaptureButton.countdown - self.elapsed) + size = self.font.size(text) + ren = self.font.render(text, True, (255, 255, 255)) + ren.set_alpha(150) + topleft = (self.rect.topleft[0] + self.rect.width / 2 - size[0] / 2, self.rect.topleft[1] + self.rect.height / 2 - size[1] / 2) - screen.blit(ren, topleft) + top = self.background_rect.top + self.background_rect.height / 2 - size[1] / 2 + left = self.background_rect.left + self.background_rect.width / 2 - size[0] / 2 + screen.blit(ren, (left, top)) def run(self): pygame.event.set_blocked((pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP)) @@ -155,8 +165,6 @@ class Photoboite: camera_rect = pygame.Rect(0, 0, 800, 480) self.camera = Camera(camera_rect) - self.font = pygame.font.Font(pygame.font.match_font('calibri'), 180) - self.clock = pygame.time.Clock()