2017-09-21 11:38:03 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import sys, pygame
|
|
|
|
pygame.init()
|
|
|
|
|
|
|
|
infos = pygame.display.Info()
|
|
|
|
# size = infos.current_w, infos.current_h
|
|
|
|
size = 1024, 768
|
|
|
|
background = 255, 255, 255
|
|
|
|
|
|
|
|
screen = pygame.display.set_mode(size)
|
|
|
|
|
|
|
|
screen.fill(background)
|
|
|
|
|
2017-09-21 14:31:45 +02:00
|
|
|
button_size = int(screen.get_width() / 4)
|
2017-09-21 11:38:03 +02:00
|
|
|
|
2017-09-21 14:31:45 +02:00
|
|
|
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
|
2017-09-21 11:38:03 +02:00
|
|
|
|
2017-09-21 14:31:45 +02:00
|
|
|
button2 = pygame.Rect(screen.get_width() - 70, 100, 50, 50)
|
2017-09-21 11:38:03 +02:00
|
|
|
|
2017-09-21 14:31:45 +02:00
|
|
|
camera = pygame.Rect(20, 20, screen.get_width() - screen.get_width() / 4 - 60, screen.get_height() - 40)
|
2017-09-21 11:38:03 +02:00
|
|
|
|
|
|
|
font = pygame.font.Font(None, 80)
|
|
|
|
|
2017-09-21 14:31:45 +02:00
|
|
|
i = 0
|
|
|
|
pressed = False
|
2017-09-21 11:38:03 +02:00
|
|
|
while True:
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type in (pygame.QUIT, pygame.KEYDOWN):
|
|
|
|
sys.exit()
|
2017-09-21 14:31:45 +02:00
|
|
|
elif event.type == pygame.MOUSEBUTTONDOWN:
|
|
|
|
if button_up_rect.collidepoint(pygame.mouse.get_pos()):
|
|
|
|
pressed = True
|
2017-09-21 11:38:03 +02:00
|
|
|
elif event.type == pygame.MOUSEBUTTONUP:
|
2017-09-21 14:31:45 +02:00
|
|
|
if button_up_rect.collidepoint(pygame.mouse.get_pos()):
|
|
|
|
pressed = False
|
2017-09-21 11:38:03 +02:00
|
|
|
i += 1
|
|
|
|
if button2.collidepoint(pygame.mouse.get_pos()):
|
|
|
|
i -= 1
|
|
|
|
|
2017-09-21 14:31:45 +02:00
|
|
|
screen.fill(background)
|
|
|
|
|
|
|
|
screen.fill((0,0,0), rect=button2)
|
|
|
|
screen.fill((0,0,0), rect=camera)
|
|
|
|
|
2017-09-21 11:38:03 +02:00
|
|
|
text = str(i)
|
|
|
|
size = font.size(text)
|
2017-09-21 14:31:45 +02:00
|
|
|
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()
|