diff --git a/button-down.png b/button-down.png new file mode 100644 index 0000000..01953f3 Binary files /dev/null and b/button-down.png differ diff --git a/button-up.png b/button-up.png new file mode 100644 index 0000000..12efc8a Binary files /dev/null and b/button-up.png differ diff --git a/button.svg b/button.svg new file mode 100644 index 0000000..6c0b7a1 --- /dev/null +++ b/button.svg @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/photoboite.py b/photoboite.py index 22162d4..0b19834 100755 --- a/photoboite.py +++ b/photoboite.py @@ -12,31 +12,50 @@ screen = pygame.display.set_mode(size) screen.fill(background) -button = pygame.Rect(200, 200, 50, 50) -screen.fill((0,0,0), rect=button) +button_size = int(screen.get_width() / 4) -button2 = pygame.Rect(400, 200, 50, 50) -screen.fill((0,0,0), rect=button2) +button_up = pygame.image.load('button-up.png').convert_alpha() +button_up = pygame.transform.smoothscale(button_up, (button_size, button_size)) +button_down = pygame.image.load('button-down.png').convert_alpha() +button_down = pygame.transform.smoothscale(button_down, (button_size, button_size)) +button_up_rect = button_up.get_rect() +button_up_rect.topleft = screen.get_width() - button_size - 20, screen.get_height() / 2 - button_size / 2 -pygame.display.flip() +button2 = pygame.Rect(screen.get_width() - 70, 100, 50, 50) -i = 0 +camera = pygame.Rect(20, 20, screen.get_width() - screen.get_width() / 4 - 60, screen.get_height() - 40) font = pygame.font.Font(None, 80) +i = 0 +pressed = False while True: for event in pygame.event.get(): if event.type in (pygame.QUIT, pygame.KEYDOWN): sys.exit() + elif event.type == pygame.MOUSEBUTTONDOWN: + if button_up_rect.collidepoint(pygame.mouse.get_pos()): + pressed = True elif event.type == pygame.MOUSEBUTTONUP: - if button.collidepoint(pygame.mouse.get_pos()): + if button_up_rect.collidepoint(pygame.mouse.get_pos()): + pressed = False i += 1 if button2.collidepoint(pygame.mouse.get_pos()): i -= 1 + screen.fill(background) + + screen.fill((0,0,0), rect=button2) + screen.fill((0,0,0), rect=camera) + text = str(i) size = font.size(text) - ren = font.render(text, 0, (0, 0, 0)) - screen.fill(background, rect=((10,10),size)) - screen.blit(ren, (10, 10)) - pygame.display.update(((10,10),size)) + ren = font.render(text, 0, (255, 255, 0)) + screen.blit(ren, (40, 40)) + + + if pressed: + screen.blit(button_down, button_up_rect) + else: + screen.blit(button_up, button_up_rect) + pygame.display.flip()