forked from 26F-Studio/Zenitha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcExtend.lua
726 lines (652 loc) · 20.5 KB
/
gcExtend.lua
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
local gc=love.graphics
local getColor,setColor,prints,printf,draw,drawL=gc.getColor,gc.setColor,gc.print,gc.printf,gc.draw,gc.drawLayer
local newText=gc.newText
local line,arc,polygon=gc.line,gc.arc,gc.polygon
local rectangle,circle=gc.rectangle,gc.circle
local applyTransform=gc.applyTransform
local sin,cos=math.sin,math.cos
local pcall=pcall
local lerp,lLerp=MATH.lerp,MATH.lLerp
local NULL=NULL
local GC=setmetatable({},{
__index=gc,
__metatable=true,
})
--------------------------------------------------------------
-- Aligning Draw
---Printf a string with 'center'
---@param obj string|number
---@param x number
---@param y number
function GC.mStr(obj,x,y) printf(obj,x-1260,y,2520,'center') end
---Draw an obj with x=obj:getWidth()/2
---@param obj love.Texture|love.Drawable
---@param x? number
---@param y? number
---@param a? number
---@param k? number
function GC.mDrawX(obj,x,y,a,k) draw(obj,x,y,a,k,nil,obj:getWidth()*.5,0) end
---Draw an obj with y=obj:getWidth()/2
---@param obj love.Texture|love.Drawable
---@param x? number
---@param y? number
---@param a? number
---@param k? number
function GC.mDrawY(obj,x,y,a,k) draw(obj,x,y,a,k,nil,0,obj:getHeight()*.5) end
---Draw an obj with both middle X & Y
---@param obj love.Texture|love.Drawable
---@param x? number
---@param y? number
---@param a? number
---@param k? number
function GC.mDraw(obj,x,y,a,k) draw(obj,x,y,a,k,nil,obj:getWidth()*.5,obj:getHeight()*.5) end
---Draw an obj with both middle X & Y
---@param obj love.Texture|love.Drawable
---@param x? number
---@param y? number
---@param a? number
---@param k? number
function GC.mDrawQX(obj,quad,x,y,a,k)
local _,_,w,h=quad:getViewport()
draw(obj,quad,x,y,a,k,nil,w*.5,h*.5)
end
---Draw an obj with both middle X & Y
---@param obj love.Texture|love.Drawable
---@param x? number
---@param y? number
---@param a? number
---@param k? number
function GC.mDrawQY(obj,quad,x,y,a,k)
local _,_,w,h=quad:getViewport()
draw(obj,quad,x,y,a,k,nil,w*.5,h*.5)
end
---Draw an obj with both middle X & Y
---@param obj love.Texture|love.Drawable
---@param x? number
---@param y? number
---@param a? number
---@param k? number
function GC.mDrawQ(obj,quad,x,y,a,k)
local _,_,w,h=quad:getViewport()
draw(obj,quad,x,y,a,k,nil,w*.5,h*.5)
end
---Draw an layered obj with x=obj:getWidth()/2
---@param obj love.Texture
---@param x? number
---@param y? number
---@param a? number
---@param k? number
function GC.mDrawLX(obj,l,x,y,a,k) drawL(obj,l,x,y,a,k,nil,obj:getWidth()*.5,0) end
---Draw an layered obj with y=obj:getWidth()/2
---@param obj love.Texture
---@param x? number
---@param y? number
---@param a? number
---@param k? number
function GC.mDrawLY(obj,l,x,y,a,k) drawL(obj,l,x,y,a,k,nil,0,obj:getHeight()*.5) end
---Draw an layered obj with both middle X & Y
---@param obj love.Texture
---@param x? number
---@param y? number
---@param a? number
---@param k? number
function GC.mDrawL(obj,l,x,y,a,k) drawL(obj,l,x,y,a,k,nil,obj:getWidth()*.5,obj:getHeight()*.5) end
--------------------------------------------------------------
-- Utility
---Set current pen's alpha
---@param a number
function GC.setAlpha(a)
local r,g,b=getColor()
setColor(r,g,b,a)
end
---Multiply current pen's alpha
---@param k number
function GC.mulAlpha(k)
local r,g,b,a=getColor()
setColor(r,g,b,a*k)
end
---GC.print with protect call
function GC.safePrint(...)
return pcall(prints,...)
end
---GC.printf with protect call
function GC.safePrintf(...)
return pcall(printf,...)
end
---Draw an obj with little bias
---@param obj love.Texture|love.Drawable
---@param x number
---@param y number
---@param a? number
---@param k? number
---@param d number
---@param shadeCount 4|8
function GC.outDraw(obj,x,y,a,k,d,shadeCount)
local w,h=obj:getWidth()*.5,obj:getHeight()*.5
draw(obj,x-d,y-d,a,k,nil,w,h)
draw(obj,x-d,y+d,a,k,nil,w,h)
draw(obj,x+d,y-d,a,k,nil,w,h)
draw(obj,x+d,y+d,a,k,nil,w,h)
if shadeCount==8 then
draw(obj,x-d,y,a,k,nil,w,h)
draw(obj,x+d,y,a,k,nil,w,h)
draw(obj,x,y-d,a,k,nil,w,h)
draw(obj,x,y+d,a,k,nil,w,h)
elseif shadeCount~=4 then
errorf("GC.outDraw(...,shadeCount): Need 4 or 8, got %s",shadeCount)
end
end
---Print a string with shade around
---@param str string|number
---@param x number
---@param y number
---@param mode 'center'|'right'|'left'
---@param d number
---@param shadeCount 4|8
---@param c1? Zenitha.Color Shade color
---@param c2? Zenitha.Color Center color
function GC.shadedPrint(str,x,y,mode,d,shadeCount,c1,c2)
local w=1280
if mode=='center' then
x=x-w*.5
elseif mode=='right' then
x=x-w
end
if not d then d=1 end
setColor(c1 or COLOR.D)
if shadeCount==4 then
d=d/1.4
printf(str,x-d,y-d,w,mode)
printf(str,x-d,y+d,w,mode)
printf(str,x+d,y-d,w,mode)
printf(str,x+d,y+d,w,mode)
elseif shadeCount==8 then
printf(str,x-d,y,w,mode)
printf(str,x+d,y,w,mode)
printf(str,x,y-d,w,mode)
printf(str,x,y+d,w,mode)
d=d/1.4
printf(str,x-d,y-d,w,mode)
printf(str,x-d,y+d,w,mode)
printf(str,x+d,y-d,w,mode)
printf(str,x+d,y+d,w,mode)
else
errorf("GC.shadedPrint(...,shadeCount,...): Need 4 or 8, got %s",shadeCount)
end
setColor(c2 or COLOR.L)
printf(str,x,y,w,mode)
end
---Draw a rectangle, but with middle point
---@param mode love.DrawMode # How to draw the rectangle.
---@param x number
---@param y number
---@param w number
---@param h number
---@param rx? number
---@param ry? number
function GC.mRect(mode,x,y,w,h,rx,ry)
rectangle(mode,x-w*.5,y-h*.5,w,h,rx,ry)
end
---Draw a regular polygon
---@param mode 'fill'|'line'
---@param x? number
---@param y? number
---@param rad number Radius
---@param segments number
---@param phase? number
function GC.regPolygon(mode,x,y,rad,segments,phase)
if not x then x=0 end
if not y then y=0 end
local l={}
local ang=phase or 0
local angStep=6.283185307179586/segments
for i=1,segments do
l[2*i-1]=x+rad*cos(ang)
l[2*i]=y+rad*sin(ang)
ang=ang+angStep
end
polygon(mode,l)
end
---Draw a regular polygon with rounded corner
---@param mode 'fill'|'line'
---@param x? number
---@param y? number
---@param rad number Radius
---@param segments number
---@param rCorner number Radius of rounded corner
---@param phase? number
function GC.regRoundPolygon(mode,x,y,rad,segments,rCorner,phase)
if not x then x=0 end
if not y then y=0 end
local X,Y={},{}
local ang=phase or 0
local angStep=6.283185307179586/segments
for i=1,segments do
X[i]=x+rad*cos(ang)
Y[i]=y+rad*sin(ang)
ang=ang+angStep
end
X[segments+1]=x+rad*cos(ang)
Y[segments+1]=y+rad*sin(ang)
local halfAng=6.283185307179586/segments/2
local erasedLen=rCorner*math.tan(halfAng)
if mode=='line' then
erasedLen=erasedLen+1 -- Fix 1px cover
for i=1,segments do
-- Line
local x1,y1,x2,y2=X[i],Y[i],X[i+1],Y[i+1]
local dir=math.atan2(y2-y1,x2-x1)
line(x1+erasedLen*cos(dir),y1+erasedLen*sin(dir),x2-erasedLen*cos(dir),y2-erasedLen*sin(dir))
-- Arc
ang=ang+angStep
local R2=rad-rCorner/cos(halfAng)
local arcCX,arcCY=x+R2*cos(ang),y+R2*sin(ang)
arc('line','open',arcCX,arcCY,rCorner,ang-halfAng,ang+halfAng)
end
elseif mode=='fill' then
local L={}
for i=1,segments do
-- Line
local x1,y1,x2,y2=X[i],Y[i],X[i+1],Y[i+1]
local dir=math.atan2(y2-y1,x2-x1)
L[4*i-3]=x1+erasedLen*cos(dir)
L[4*i-2]=y1+erasedLen*sin(dir)
L[4*i-1]=x2-erasedLen*cos(dir)
L[4*i]=y2-erasedLen*sin(dir)
-- Arc
ang=ang+angStep
local R2=rad-rCorner/cos(halfAng)
local arcCX,arcCY=x+R2*cos(ang),y+R2*sin(ang)
arc('fill','open',arcCX,arcCY,rCorner,ang-halfAng,ang+halfAng)
end
polygon('fill',L)
else
error("GC.regRoundPolygon(mode,...): Draw mode should be 'line' or 'fill'")
end
end
do -- function GC.getScreenShot(table,key) -- Save screenshot as image object to a table
local _t,_k
local function _captureFunc(imageData) -- Actually triggered by engine a bit later after calling GC.getScreenShot, because love2d's capture function doesn't effect instantly
_t[_k]=gc.newImage(imageData)
end
---@param t table
---@param k any
function GC.getScreenShot(t,k)
_t,_k=t,k
gc.captureScreenshot(_captureFunc)
end
end
--------------------------------------------------------------
-- Beziers
---@class Zenitha.Curve.Bezier
---@field points Zenitha.Curve.Point[]
---@field curve number[]
---@field ctrlPos number[]
local Bezier={}
Bezier.__index=Bezier
---Render the curve to a points list with specific mode
---@param seg number Segments between each data point
---@param dist? number [Second-Processing], Distance between each data point, nil to skip this step
function Bezier:render(seg,dist)
assert(type(seg)=='number' and seg>0 and seg%1==0,"Bezier:render(seg,dist): seg need positive int")
local list=self.points
print(TABLE.dump(list))
assert(list and #list>1,"Bezier:render: points need at least 2")
local p=1 -- r goes first, Find first data point
while list[p] and list[p][3] do p=p+1 end
assert(list[p],"[Bezier]:render: Data point not found")
local curve={}
local secList={list[p]}
while true do
-- Find next data point
local _p=p
for i=p+1,#list do
if list[i][3] then
secList[#secList+1]=list[i]
else
p=i
break
end
end
if p==_p then break end -- No more data point
secList[#secList+1]=list[p]
-- Generate curve t in [0,1) for each section
for t=1,seg do
-- Normalize t
t=(t-1)/seg
-- Create list for each dimension
local xList,yList={},{}
for i=1,#secList do
xList[i]=secList[i][1]
yList[i]=secList[i][2]
end
-- Calculate curve with lerping
while #xList>1 do
for i=1,#xList-1 do
xList[i]=lerp(xList[i],xList[i+1],t)
yList[i]=lerp(yList[i],yList[i+1],t)
end
xList[#xList],yList[#yList]=nil,nil
end
curve[#curve+1]=xList[1]
curve[#curve+1]=yList[1]
end
-- Clear section list cache
TABLE.clear(secList)
secList[1]=list[p]
end
curve[#curve+1]=list[p][1]
curve[#curve+1]=list[p][2]
if dist~=nil then
assert(type(dist)=='number' and dist>0,"Bezier:render(seg,dist): dist need positive number")
-- TODO
end
self.curve=curve
return curve
end
---@class Zenitha.Curve.Point
---@field [1] number
---@field [2] number
---@field [3] boolean
---@field x? number
---@field y? number
---@field ctrl? boolean
---@param points Zenitha.Curve.Point[]
---@return Zenitha.Curve.Bezier
function GC.newBezier(points)
assert(type(points)=='table',"GC.newBezier(points): Need points[]")
local _pList={}
for i=1,#points do
local p=points[i]
local P={
p[1] or p.x,
p[2] or p.y,
not not (p[3] or p.ctrl),
}
assert(P[1] and P[2],"GC.newBezier(points): points[n] need [1]&[2]/x&y")
_pList[i]=P
end
return setmetatable({
points=_pList,
curve={},
},Bezier)
end
--------------------------------------------------------------
-- Easier Stencil
local gc_stencil,gc_setStencilTest=gc.stencil,gc.setStencilTest
local stc_action,stc_value='replace',1
---Reset stencil states, set default stencil states:
---
---draw: 'replace', 1
---
---test: 'equal', 1
function GC.stc_reset()
stc_action,stc_value='replace',1
gc_setStencilTest('equal',1)
gc_stencil(NULL)
end
---Set stencil test mode (just love.graphics.setStencilTest with default)
---@param compMode? 'equal'|'notequal'|'less'|'lequal'|'gequal'|'greater'|'never'|'always'
---@param compVal? number
function GC.stc_setComp(compMode,compVal)
gc_setStencilTest(compMode or 'equal',compVal or 1)
end
---Set stencil draw mode (just love.graphics.stencil)
---@param drawMode 'replace'|'increment'|'decrement'|'incrementwrap'|'decrementwrap'|'invert'
---@param drawVal number
function GC.stc_setPen(drawMode,drawVal)
stc_action,stc_value=drawMode,drawVal
end
---Cancel stencil comparing (just love.graphics.setStencilTest)
function GC.stc_stop()
gc_setStencilTest()
end
local rect_x,rect_y,rect_w,rect_h
local function stencil_rectangle()
rectangle('fill',rect_x,rect_y,rect_w,rect_h)
end
---Draw a rectangle as stencil
---@param x number
---@param y number
---@param w number
---@param h number
function GC.stc_rect(x,y,w,h)
rect_x,rect_y,rect_w,rect_h=x,y,w,h
gc_stencil(stencil_rectangle,stc_action,stc_value,true)
end
local circle_x,circle_y,circle_r,circle_seg
local function stencil_circle()
circle('fill',circle_x,circle_y,circle_r,circle_seg)
end
---Draw a circle as stencil
---@param x number
---@param y number
---@param r number
---@param seg? number
function GC.stc_circ(x,y,r,seg)
circle_x,circle_y,circle_r,circle_seg=x,y,r,seg
gc_stencil(stencil_circle,stc_action,stc_value,true)
end
--------------------------------------------------------------
-- Camera
---@class Zenitha.Camera
---@field x0 number
---@field y0 number
---@field k0 number
---@field a0 number
---@field x number
---@field y number
---@field k number
---@field a number
---@field moveSpeed number
---@field rotateSpeed number
---@field swing number
---@field maxDist number
---@field minK number
---@field maxK number
---@field transform love.Transform
local Camera={}
---Move camera
---@param dx number
---@param dy number
function Camera:move(dx,dy)
self.x0=self.x0+dx
self.y0=self.y0+dy
if self.maxDist then
local dist=MATH.distance(0,0,self.x0,self.y0)/self.k0
if dist>self.maxDist then
local angle=math.atan2(self.y0,self.x0)
self.x0=self.maxDist*math.cos(angle)*self.k0
self.y0=self.maxDist*math.sin(angle)*self.k0
end
end
end
---Rotate camera
---@param da number
function Camera:rotate(da)
self.a0=self.a0+da
end
---Scale camera
---@param dk number
function Camera:scale(dk)
local k0=self.k0
self.k0=MATH.clamp(self.k0*dk,self.minK or 0,self.maxK or 1e99)
dk=self.k0/k0
self.x0,self.y0=self.x0*dk,self.y0*dk
end
---Update camera
---@param dt number
function Camera:update(dt)
self.x=MATH.expApproach(self.x,self.x0,dt*self.moveSpeed)
self.y=MATH.expApproach(self.y,self.y0,dt*self.moveSpeed)
self.k=MATH.expApproach(self.k,self.k0,dt*self.moveSpeed)
self.a=MATH.expApproach(self.a,self.a0+(self.swing and self.swing*math.sin(love.timer.getTime()/1.26) or 0),dt*self.rotateSpeed)
self.transform:setTransformation(self.x,self.y,self.a,self.k)
end
---Apply camera's transform
function Camera:apply()
applyTransform(self.transform)
end
---Create a new camera
---@return Zenitha.Camera
function GC.newCamera()
local c={
x0=0,y0=0,k0=1,a0=0,
x=0,y=0,k=1,a=0,
moveSpeed=26,
rotateSpeed=6.26,
swing=false,
maxDist=false,
minK=false,maxK=false,
transform=love.math.newTransform(),
}
return setmetatable(c,{__index=Camera})
end
--------------------------------------------------------------
-- TODO: text warping
local function measureWidth(font,str)
return newText(font,str):getWidth()
end
function GC.warpText(font,str,width)
local list={}
-- TODO:
-- use 'measureWidth(font,string)' to measure the width of string
-- return a table of strings, each of which is no longer than given width
return list
end
--------------------------------------------------------------
do -- function GC.load(L), GC.execute(t)
local cmds={
push= 'push',
pop= 'pop',
repT= 'replaceTransform',
appT= 'applyTransform',
invT= 'inverseTransformPoint',
origin= 'origin',
move= 'translate',
scale= 'scale',
rotate= 'rotate',
shear= 'shear',
clear= 'clear',
setCL= 'setColor',
setCM= 'setColorMask',
setLW= 'setLineWidth',
setLS= 'setLineStyle',
setLJ= 'setLineJoin',
setBM= 'setBlendMode',
setSD= 'setShader',
print= 'print',
rawFT= function(...) FONT.rawset(...) end,
setFT= function(...) FONT.set(...) end,
mStr= 'mStr',
mDrawX= 'mDrawX',
mDrawY= 'mDrawY',
mDraw= 'mDraw',
outDraw= 'outDraw',
sdPrint= 'shadedPrint',
draw= 'draw',
line= 'line',
fRect=function(...) gc.rectangle('fill',...) end,
dRect=function(...) gc.rectangle('line',...) end,
fCirc=function(...) gc.circle('fill',...) end,
dCirc=function(...) gc.circle('line',...) end,
fElps=function(...) gc.ellipse('fill',...) end,
dElps=function(...) gc.ellipse('line',...) end,
fPoly=function(...) polygon('fill',...) end,
dPoly=function(...) polygon('line',...) end,
dPie=function(...) arc('line',...) end,
dArc=function(...) arc('line','open',...) end,
dBow=function(...) arc('line','closed',...) end,
fPie=function(...) arc('fill',...) end,
fArc=function(...) arc('fill','open',...) end,
fBow=function(...) arc('fill','closed',...) end,
fRPol=function(...) GC.regPolygon('fill',...) end,
dRPol=function(...) GC.regPolygon('line',...) end,
fRRPol=function(...) GC.regRoundPolygon('fill',...) end,
dRRPol=function(...) GC.regRoundPolygon('line',...) end,
}
for k,v in next,cmds do
if type(v)=='string' then
cmds[k]=GC[v]
end
end
local function GC_execute(t)
if type(t[1])=='string' then
cmds[t[1]](unpack(t,2))
elseif type(t[1])=='table' then
for i=1,#t do
GC_execute(t[i])
end
elseif type(t[1])=='function' then
t[1](unpack(t,2))
else
error("GC_execute(...): Wrong type of [1]")
end
end
---Run a set of graphics commands in table-format
---
---See commands list by going to declaration of this function, then scroll up.
---@param t table[]|string[]
---## Example
---```lua
---GC.execute{
--- {'setCL',1,0,0},
--- {'dRect','fill',0,0,100,100},
--- {'setCL',1,1,0},
--- {'dCirc','fill',50,50,40},
---}
---```
function GC.execute(t) GC_execute(t) end
local sizeLimit=gc.getSystemLimits().texturesize
---Similar to GC.execute, but draw on a canvas.
---@param list number[]|number[][]|table[][]|string[][]
---## Example
---```lua
---GC.load{100,100 -- size of canvas
--- {'setCL',1,0,0},
--- {'dRect','fill',0,0,100,100},
--- {'setCL',1,1,0},
--- {'dCirc','fill',50,50,40},
---} --> canvas
---```
function GC.load(list)
local w,h=tonumber(list[1]),tonumber(list[2])
assert(w and h and w>0 and h>0 and w%1==0 and h%1==0,"GC.load(L): L[1] and L[2] need int >=1")
gc.push()
local canvas
while true do
local success
success,canvas=pcall(gc.newCanvas,math.min(w,sizeLimit),math.min(h,sizeLimit))
if success then
break
else
sizeLimit=math.floor(sizeLimit*.8)
assert(sizeLimit>=1,"GC.load(L): Failed to create canvas")
end
end
gc.setCanvas(canvas)
gc.clear(1,1,1,0)
gc.origin()
gc.setColor(1,1,1)
gc.setLineWidth(1)
for i=3,#list do
---@type any
local code=list[i]
local cmd=code[1]
if type(cmd)=='string' then
cmd=assert(cmds[cmd],"GC.load(L): No gc command: "..cmd)(unpack(code,2))
elseif type(cmd)=='function' then
cmd(unpack(code,2))
else
error("GC.load: cmd need string|function")
end
end
gc.setShader()
gc.setColorMask()
gc.setBlendMode('alpha')
gc.setCanvas()
gc.pop()
return canvas
end
end
return GC