-
Notifications
You must be signed in to change notification settings - Fork 2
/
messagescreens.py
169 lines (141 loc) · 6 KB
/
messagescreens.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import pygame as pg
import os
from MOT_constants import *
# == Set window ==
x, y = 0, 0
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (x,y)
win = pg.display.set_mode((win_width, win_height), pg.FULLSCREEN)
pg.display.set_caption(title)
def wait_key():
"""function to wait key press"""
while True:
for event in pg.event.get():
if event.type == pg.KEYDOWN and event.key == pg.K_f:
return
def flash_targets(dlist, tlist):
"""function to flash targets"""
# pg.time.Clock().tick(FPS)
fixation_cross()
for t in tlist:
t.flash_color()
t.draw_circle(win)
for d in dlist:
d.draw_circle(win)
pg.display.update()
def move(mlist):
for m in mlist:
m.x += m.dx
m.y += m.dy
m.draw_circle(win)
def detect_collision(mlist):
for m in mlist:
m.detect_wall(mlist)
def animate(dlist, tlist, mlist):
"""function to move or animate objects on screen"""
move(mlist)
detect_collision(mlist)
pg.display.update()
def static_draw(mlist):
"""function for static object draw"""
for obj in mlist:
obj.draw_circle(win)
def fixation_cross(color=BLACK):
"""function to draw fixation cross"""
start_x, end_x = ((win_width/2)-7, (win_height/2)) , ((win_width/2)+7, (win_height/2))
start_y, end_y = (win_width/2, (win_height/2)-7), (win_width/2, (win_height/2)+7)
pg.draw.line(win, color, start_x, end_x, 3)
pg.draw.line(win, color, start_y, end_y, 3)
def fixation_screen(mlist):
"""function to present the fixation cross and the objects"""
fixation_cross(BLACK)
for obj in mlist:
obj.draw_circle(win)
pg.display.update()
def text_objects(text, color, textsize):
"""text object defining text"""
msg = pg.font.SysFont("arial", textsize)
text_surf = msg.render(text, True, color)
return text_surf, text_surf.get_rect()
def msg_to_screen(text, textcolor, textsize, pos, display=win):
"""function to render message to screen centered"""
text_surface, text_rect = text_objects(text, textcolor, textsize)
text_rect.center = pos
display.blit(text_surface, text_rect)
def msg_to_screen_centered(text, textcolor, textsize, display=win):
"""function to render message to screen centered"""
font = pg.font.SysFont("SimHei", textsize)
text_surface = font.render(text, True, textcolor)
w, h = text_surface.get_size()
text_x, text_y = (win_width/2)-w/2, (win_height/2) -y/2
display.blit(text_surface, (text_x, text_y))
def multi_line_message(text, textsize, pos=((win_width-(win_width/10)), win_height), color=BLACK, display=win):
"""function to split text message to multiple lines and blit to display window"""
# -- Make a list of strings split by the "\n", and each list contains words of that line as elements
font = pg.font.SysFont("SimHei", textsize)
words = [word.split(" ") for word in text.splitlines()]
# -- Get the width required to render an empty space
space_w = font.size(" ")[0] # .size method returns dimension in width and height. [0] gets the width
max_w, max_h = ((win_width-(win_width/10)), win_height)
text_x, text_y = pos
for line in words:
for word in line:
word_surface = font.render(word, True, color) # get surface for each word
word_w, word_h = word_surface.get_size() # get size for each word
if text_x + word_w >= max_w: # if the a word exceeds the line length limit
text_x = (win_width/10) # reset the x
text_y += word_h # start a new row
display.blit(word_surface, (text_x, text_y)) # blit the text onto surface according to pos
text_x += word_w + space_w # force a space between each word
text_x = (win_width/10) # reset the x
text_y += word_h # start a new row
pg.display.flip()
def message_screen(message, display=win):
if message == "start":
display.fill(background_col)
multi_line_message(start_text, med_font, ((win_width - (win_width / 10)), 120))
if message == "not_selected_4":
msg_to_screen_centered(need_select_txt, BLACK, med_font)
if message == "timeup":
display.fill(background_col)
msg_to_screen_centered(exm_timeup_txt, BLACK, large_font)
pg.display.flip()
if message == "prac_finished":
display.fill(background_col)
multi_line_message(prac_finished_txt, med_font, ((win_width - (win_width / 10)), 120))
pg.display.flip()
if message == "exp_finished":
display.fill(background_col)
multi_line_message(experim_fin_txt, large_font, ((win_width - (win_width / 10)), 150))
pg.display.flip()
def guide_screen(call, mlist):
if call == "start":
win.fill(background_col)
multi_line_message(start_text, med_font, ((win_width - (win_width / 10)), 120))
pg.display.flip()
if call == "focus":
win.fill(background_col)
fixation_cross()
multi_line_message(fix_text, med_font, ((win_width - (win_width / 5)), (win_height / 2 + 30)))
pg.display.flip()
if call == "present":
win.fill(background_col)
fixation_cross()
static_draw(mlist)
multi_line_message(present_text, med_font, ((win_width - (win_width / 10)), (win_height / 2 + 30)))
pg.display.flip()
if call == "answer":
static_draw(mlist)
multi_line_message(submit_ans_txt, med_font, ((win_width - (win_width / 10)), (win_height / 2 + 30)))
pg.display.flip()
if call == "timeup":
win.fill(background_col)
multi_line_message(guide_timeup_txt, med_font, ((win_width - (win_width / 10)), (win_height / 2 + 30)))
pg.display.flip()
if call == "submitted":
win.fill(background_col)
msg_to_screen_centered(guide_submit_txt, BLACK, large_font)
pg.display.flip()
if call == "finished":
win.fill(background_col)
multi_line_message(guide_fin_txt, med_font,((win_width - (win_width / 10)), 120))
pg.display.flip()