-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGui.py
85 lines (65 loc) · 2.16 KB
/
Gui.py
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""
"""
import time
import numpy as np
class GUI:
def __init__(self, renderer):
self.renderer = renderer
self.texture = renderer.guiRenderer.texture
self.gui_data = self.texture.img_data
(x, y) = renderer.guiRenderer.texture.image.size
self.width = x
self.height = y
self.history = np.zeros(30, 'b')
self.last_frame = 0
self.last_time = -1
def update_fps(self):
t = time.time()
if self.last_time > 0 and t < self.last_time + 1:
return False
self.last_time = t
fps = self.renderer.info.render.frame - self.last_frame
if fps > 30:
fps = 30
self.last_frame = self.renderer.info.render.frame
for i in range(29):
self.history[i] = self.history[i+1]
self.history[29] = fps
for x in range(30):
fps = self.history[x]
for y in range(self.height - 30, self.height - 30 + fps):
p = 4*(x + y*self.width)
self.gui_data[p] = 255
self.gui_data[p+3] = 255
for y in range(self.height - 30 + fps, self.height):
p = 4*(x + y*self.width)
self.gui_data[p+3] = 0
self.texture.needsUpdate = True
return True
def load_bar(self, pct):
t = time.time()
if self.last_time > 0 and t < self.last_time + 1:
return
self.last_time = t
h = int(self.height / 2)
pct = int(pct * 200 / 100)
for y in range(h - 20, h + 20):
p = 4*y*self.width
for x in range(0, pct):
self.gui_data[p] = 255
self.gui_data[p+3] = 255
p += 4
self.texture.needsUpdate = True
def loaded_tiles(self, nb):
h = 5
pct = int(nb * 200 / 100)
for y in range(h, 0, -1):
p = 4*y*self.width
for x in range(0, pct):
self.gui_data[p] = 255
self.gui_data[p+3] = 255
p += 4
self.texture.needsUpdate = True
def reset(self):
self.gui_data.fill(0)
self.texture.needsUpdate = True