@@ -9,6 +9,7 @@ class Graphics(Handler):
9
9
10
10
def __init__ (self , compiler ):
11
11
Handler .__init__ (self , compiler )
12
+ self .windowCreated = False
12
13
13
14
def getName (self ):
14
15
return 'graphics'
@@ -31,12 +32,13 @@ def r_attach(self, command):
31
32
targetRecord = self .getVariable (command ['name' ])
32
33
keyword = targetRecord ['keyword' ]
33
34
id = self .getRuntimeValue (command ['id' ])
34
- element = self .ui .getElement (id )
35
- if element == None :
35
+ uiElement = self .ui .getElement (id )
36
+ if uiElement == None :
36
37
FatalError (self .program .compiler , f'There is no screen element with id \' { id } \' ' )
37
38
return - 1
38
- if element .getType () != keyword :
39
- FatalError (self .program .compiler , f'Mismatched element type: \' { element ['type' ]} \' and \' { keyword } \' ' )
39
+ if uiElement .getType () != keyword :
40
+ etype = uiElement ['type' ]
41
+ FatalError (self .program .compiler , f'Mismatched element type: "{ etype } " and "{ keyword } "' )
40
42
self .putSymbolValue (targetRecord , {'type' : 'text' , 'content' : id })
41
43
return self .nextPC ()
42
44
@@ -65,11 +67,19 @@ def k_create(self, command):
65
67
r = self .compileConstant (255 )
66
68
g = self .compileConstant (255 )
67
69
b = self .compileConstant (255 )
70
+ fullscreen = False
71
+ borderless = False
68
72
while True :
69
73
token = self .peek ()
70
74
if token == 'title' :
71
75
self .nextToken ()
72
76
t = self .nextValue ()
77
+ elif token == 'fullscreen' :
78
+ fullscreen = True
79
+ self .nextToken ()
80
+ elif token == 'borderless' :
81
+ borderless = True
82
+ self .nextToken ()
73
83
elif token == 'at' :
74
84
self .nextToken ()
75
85
left = self .nextValue ()
@@ -91,9 +101,11 @@ def k_create(self, command):
91
101
command ['pos' ] = (left , top )
92
102
command ['size' ] = (width , height )
93
103
command ['fill' ] = (r , g , b )
104
+ command ['fullscreen' ] = fullscreen
105
+ command ['borderless' ] = borderless
94
106
self .add (command )
95
107
return True
96
-
108
+
97
109
elif self .isSymbol ():
98
110
record = self .getSymbolRecord ()
99
111
command ['target' ] = record ['name' ]
@@ -113,7 +125,7 @@ def k_create(self, command):
113
125
self .add (command )
114
126
record ['elementID' ] = command ['id' ]
115
127
return False
116
-
128
+
117
129
def getElementData (self , type , command ):
118
130
width = None
119
131
height = None
@@ -170,23 +182,29 @@ def getElementData(self, type, command):
170
182
command ['source' ] = source
171
183
172
184
def r_create (self , command ):
185
+
173
186
try :
174
187
type = command ['type' ]
175
188
if type == 'window' :
189
+ if self .windowCreated == True :
190
+ RuntimeError (self .program , 'A window has already been created' )
176
191
self .windowSpec = Object ()
177
192
self .windowSpec .title = command ['title' ]['content' ]
193
+ self .windowSpec .fullscreen = command ['fullscreen' ]
194
+ self .windowSpec .borderless = command ['borderless' ]
178
195
self .windowSpec .flush = flush
179
196
self .windowSpec .kill = self .program .kill
180
197
self .windowSpec .pos = (self .getRuntimeValue (command ['pos' ][0 ]), self .getRuntimeValue (command ['pos' ][1 ]))
181
198
self .windowSpec .size = (self .getRuntimeValue (command ['size' ][0 ]), self .getRuntimeValue (command ['size' ][1 ]))
182
199
self .windowSpec .fill = (self .getRuntimeValue (command ['fill' ][0 ])/ 255 , self .getRuntimeValue (command ['fill' ][1 ])/ 255 , self .getRuntimeValue (command ['fill' ][2 ])/ 255 )
200
+ self .windowCreated = True
183
201
else :
184
202
element = self .ui .createWidget (self .getWidgetSpec (command ))
185
203
print (element )
186
204
except Exception as e :
187
205
RuntimeError (self .program , e )
188
206
return self .nextPC ()
189
-
207
+
190
208
def getWidgetSpec (self , command ):
191
209
spec = Object ()
192
210
spec .id = self .getRuntimeValue (command ['id' ])
@@ -247,6 +265,7 @@ def r_moveBy(self, command):
247
265
self .ui .moveElementBy (self .getRuntimeValue (command ['target' ]), dist )
248
266
return self .nextPC ()
249
267
268
+ # on click/tap {element} {action}
250
269
def k_on (self , command ):
251
270
token = self .nextToken ()
252
271
if token in ['click' , 'tap' ]:
@@ -280,16 +299,25 @@ def k_on(self, command):
280
299
return True
281
300
return False
282
301
302
+ # Set a handler on every element
283
303
def r_on (self , command ):
284
304
pc = command ['goto' ]
285
305
if command ['type' ] == 'tap' :
286
306
record = self .getVariable (command ['target' ])
307
+ def oncb (data ):
308
+ record ['index' ] = data .index
309
+ self .run (data .pc )
287
310
keyword = record ['keyword' ]
288
311
if self .isGraphicType (keyword ):
289
- id = record ['value' ][record ['index' ]]['content' ]
290
- self .ui .setOnClick (id , lambda : self .run (pc ))
312
+ for index in range (0 , record ['elements' ]):
313
+ id = record ['value' ][index ]['content' ]
314
+ data = Object ()
315
+ data .pc = pc
316
+ data .index = index
317
+ self .ui .setOnClick (id , data , oncb )
291
318
else :
292
- RuntimeError (self .program , f'{ record ['name' ]} is not a clickable object' )
319
+ name = record ['name' ]
320
+ RuntimeError (self .program , f'{ name } is not a clickable object' )
293
321
return self .nextPC ()
294
322
295
323
def k_rectangle (self , command ):
@@ -350,9 +378,11 @@ def k_set(self, command):
350
378
self .addCommand (command )
351
379
return True
352
380
else :
353
- FatalError (self .program .compiler , f'Invalid type: { record ['keyword' ]} ' )
381
+ rtype = record ['type' ]
382
+ FatalError (self .program .compiler , f'Invalid type: { rtype } ' )
354
383
else :
355
- FatalError (self .program .compiler , f'\' { self .getToken ()} \' is not a variable' )
384
+ token = self .getToken ()
385
+ FatalError (self .program .compiler , f'{ token } is not a variable' )
356
386
return False
357
387
358
388
def r_set (self , command ):
@@ -388,7 +418,7 @@ def compileValue(self):
388
418
value ['type' ] = 'symbol'
389
419
return value
390
420
return None
391
-
421
+
392
422
if self .tokenIs ('the' ):
393
423
self .nextToken ()
394
424
kwd = self .getToken ()
0 commit comments