forked from MyreMylar/pygame_gui_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_controlled_image_loading_example.py
More file actions
70 lines (55 loc) · 2.01 KB
/
user_controlled_image_loading_example.py
File metadata and controls
70 lines (55 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pygame
import pygame_gui
from pygame_gui.elements import UIButton
from pygame_gui.core import IncrementalThreadedResourceLoader
# 20 * image buttons
# Sequential Image loading time taken: 27.362 seconds.
pygame.init()
pygame.display.set_caption('Image Loading Test')
window_surface = pygame.display.set_mode((800, 600))
background = pygame.Surface((800, 600))
background.fill(pygame.Color('#000000'))
clock = pygame.time.Clock()
load_time_1 = clock.tick()
loader = IncrementalThreadedResourceLoader()
manager = pygame_gui.UIManager((800, 600),
pygame_gui.PackageResource('data.themes', 'image_loading_test.json'),
resource_loader=loader)
loader.start()
finished = False
last_progress = 0
print("Progress: ", end='')
while not finished:
finished, progress = loader.update()
int_progress = int(10 * progress)
if last_progress != int_progress:
last_progress = int_progress
print('■', end='')
print('',)
load_time_2 = clock.tick()
print('Image loading time taken:', load_time_2 / 1000.0, 'seconds.')
button_row_width = 200
button_row_height = 150
spacing = 0
num_buttons = 1
for j in range(1, 5):
for i in range(1, 5):
position = (i * spacing + ((i - 1) * button_row_width),
(j * spacing + ((j - 1) * button_row_height)))
button = UIButton(relative_rect=pygame.Rect(position, (button_row_width,
button_row_height)),
text=str(num_buttons),
manager=manager,
object_id='#'+str(num_buttons))
num_buttons += 1
is_running = True
while is_running:
time_delta = clock.tick(60)/1000.0
for event in pygame.event.get():
if event.type == pygame.QUIT:
is_running = False
manager.process_events(event)
manager.update(time_delta)
window_surface.blit(background, (0, 0))
manager.draw_ui(window_surface)
pygame.display.update()