-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.lua
executable file
·511 lines (372 loc) · 13.5 KB
/
settings.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
-- we store range for range operations
-- set time code for range
-- copy range
rangeBeginIdx=nil
rangeEndIdx=nil
brshLineWidth=128
brshMaxRad=128
local widgets={}
local clockQuad = {x=64, y=64, w=64, h=64}
cursorQuad = {x=0, y=0, w=64, h=64}
playQuad={x=0, y=4*64, w=64, h=64}
paletteQuad={x=64, y=6*64, w=64, h=64}
pickerQuad={x=0, y=15*64, w=64, h=64}
local brushQuad={x=0, y=16*64, w=64, h=64}
local zoomQuad={x=128, y=0, w=64, h=64}
local deleteQuad={x=0, y=11*64, w=64, h=64}
local bgQuad={x=2*64, y=2*64, w=64, h=64}
local rangeBeginQuad={x=0*64, y=12*64, w=64, h=64}
local rangeEndQuad={x=0*64, y=13*64, w=64, h=64}
local pasteRangeQuad={x=0*64, y=14*64, w=64, h=64}
local exportQuad={x=2*64, y=4*64, w=64, h=64}
local pasteRangeReverseQuad={x=2*64, y=5*64, w=64, h=64}
local switchProjectQuad={x=2*64, y=6*64, w=64, h=64}
local hardBrushQuad={x=2*64, y=9*64, w=64, h=64}
local hardBrushEnabledQuad={x=3*64, y=9*64, w=64, h=64}
local softBrushQuad={x=2*64, y=10*64, w=64, h=64}
local softBrushQuadEnabled={x=3*64, y=10*64, w=64, h=64}
local underBrushQuad={x=2*64, y=11*64, w=64, h=64}
local underBrushQuadEnabled={x=2*64, y=11*64, w=64, h=64}
local toggleRepQuad={x=2*64, y=12*64, w=64, h=64}
local untoggleRepQuad={x=2*64, y=13*64, w=64, h=64}
local toggleColorFrameQuad={x=2*64, y=16*64, w=64, h=64}
local untoggleColorFrameQuad={x=6*64, y=0, w=64, h=64}
local toggleLightTableQuad = {x=3*64, y=2*64, w=64, h=64}
local copyToOtherProjectQuad = {x=3*64, y=3*64, w=64, h=64}
--check mark to say if paint modes are enabled?
--local selectedQuad = {x=4*64, y=1*64, w=64, h=64}
toggleLightTable=function ()
lightTable= not lightTable
setHoverMsg('light table '..tostring(lightTable) )
end
local enableColorFrame=function()
frames[currentIdx].cf=true
frames[currentIdx].tc=0
createSettingsButtons()
end
local disableColorFrame=function()
frames[currentIdx].cf=nil
createSettingsButtons()
end
local toggleHardBrush = function()
print('setting hard brush')
currentBrushFunc=roundBrushWithAlpha
initBasicPaintMode()
mybrush=love.graphics.newImage(currentBrushFunc( brshradius,paintcolor.r,paintcolor.g,paintcolor.b))
mybrush:setFilter('nearest','nearest')
--we maintain this for UI
-- isHardPaintEnabled=true
-- blitBrushLineRemember=basicBlitBrushLineRemember
-- backBufferRender=false
-- penUpPaintModeCb=nil
--TODO recreate
end
local toggleSoftBrush = function()
print('setting soft brush')
currentBrushFunc=roundBrushWithGradient
initBasicPaintMode()
mybrush=love.graphics.newImage(currentBrushFunc( brshradius,paintcolor.r,paintcolor.g,paintcolor.b))
mybrush:setFilter('nearest','nearest')
--we maintain this for UI
-- isHardPaintEnabled=false
end
--DISABLED IN UI, NOT WORKING ON ANDROID
--shader brush needs extra init
local toggleShaderUnderBrush = function()
print('setting under brush')
currentBrushFunc=roundBrushWithAlpha
--works only with hard brush
initPaintUnderBlitMode()
backBufferRender=false
penUpPaintModeCb=nil
end
local toggleUnderBrush = function()
--we maintain this for UI
-- isHardPaintEnabled=true
if basicPaintUnderMode==true then
initBasicPaintMode()
basicPaintUnderMode=nil
else
print('setting basic under brush')
addMsg('under brush')
--currentBrushFunc=roundBrushWithAlpha
--works only with hard brush
initBasicPaintUnderBlitMode()
end
end
function composeExport()
print('TODO export to avi start')
addMsg('start export to folder')
batch=createExportBatch()
print(batch)
local finished =false
while not finished
do
finished=batch:execute()
end
end
function disableRepeatSeq()
removeRepetition(currentIdx)
-- print('repetition unset ')
-- local r=isFrameInRepetition(idx)
-- print('current trigger '..r.trigger .. ' target ' ..r.target)
-- for i,rep in ipairs(repetitions)
-- do
-- --TODO never goes there for some reason
-- print(' cur trig '..rep.trigger)
-- if rep.trigger==r.trigger then
-- table.remove(repetitions,i)
-- break
-- end
-- end
createSettingsButtons()
end
function repeatSeq()
print('repetition set ')
addMsg('repetition set ')
setRepetition(rangeBeginIdx,rangeEndIdx,1)
createSettingsButtons()
end
function pasteRange(directOrder)
if rangeBeginIdx==nil or rangeEndIdx==nil then
print(' nil marker, not possible ')
return
end
if rangeEndIdx<=rangeBeginIdx then
print(' end marker before begin marker, not possible ')
return
end
--paste position, we paste at current +1 , current +2 .. etc
local pasteOffset=1
--paste range from current idx
for i=rangeBeginIdx,rangeEndIdx
do
--create frame
--TODO we can use add frame here
--paste source frame to created frame
--TODO we need custom code here
newid = love.image.newImageData(conf.cvsw,conf.cvsh)
newid:paste(frames[i].data,0,0,0,0,conf.cvsw,conf.cvsh)
newp=love.graphics.newImage(newid)
-- table.insert(frames,{pic=newp,data=newid})
local newFrameIdx=currentIdx+pasteOffset
--WIP we choose that cb ce frames are saved from id
table.insert(frames,newFrameIdx,{pic=newp,data=newid,tc=frames[i].tc,dirty=true})
maxframe=maxframe+1
print('number of frames '..maxframe)
maxFrameReached=maxFrameReached+1
maintainRepetitionsFrameAddition(newFrameIdx)
print('max frames reached at a given point '..maxFrameReached)
--just omitting this implements paste reverse
if directOrder==true then
pasteOffset=pasteOffset+1
end
end
flagShiftedFrames(maxFrameReached)
maintainBgRanges()
saveCanvasToUndo()
end
function pasteRangeDirect()
pasteRange(true)
end
function pasteRangeReverse()
pasteRange(false)
end
function toggleBg()
print ('toggle frame '..currentIdx..'as bg')
if frames[currentIdx].bg==true then
frames[currentIdx].bg=nil
else
frames[currentIdx].bg=true
frames[currentIdx].tc=0
end
maintainBgRanges()
end
function deleteCurrentFrame()
print('deletingFrame '..currentIdx)
if maxframe<4 then
print('not enough frames to delete')
return
end
toDel=frames[currentIdx]
toDel.data:release()
toDel.pic:release()
table.remove(frames,currentIdx)
maxframe=maxframe-1
maintainRepetitionsFrameDeletion(currentIdx)
--new current idx has been shifted due to removal
flagShiftedFrames(currentIdx-1)
if currentIdx>maxframe then
currentIdx=maxframe
end
maintainBgRanges()
initCanvases(currentIdx)
setHoverMsg('frame '..currentIdx..' deleted ')
end
function setRangeBegin()
print('setRangeBegin '..currentIdx)
rangeBeginIdx=currentIdx
end
function setRangeEnd()
print('setRangeEnd '..currentIdx)
rangeEndIdx=currentIdx
end
function switchProject()
print ('TODO got to switch screen')
print('TODO change currentproject.lua')
toSwitchProject()
-- love.event.quit( "restart" )
end
function copyFramesToOtherPrj(folder)
setHoverMsg('WIPcopy '..rangeBeginIdx ..' to '..rangeEndIdx.. ' to '..folder,600)
print('DBG APPEND '..folder)
local tgtfld="project/"..folder.."/"
appendToOtherProject(tgtfld,rangeBeginIdx,rangeEndIdx)
--is following necessary?
toSettings()
end
function copyToOtherProject()
-- setHoverMsg('WIP copy to other prj')
if rangeBeginIdx~=nil and rangeEndIdx~=nil then
setHoverMsg('WIP copy to other prj')
--TODO select other project (prj selection callback?)
--TODO do the copy and show report
toSelectProject(copyFramesToOtherPrj)
else
setHoverMsg('CB CE not set')
end
end
local settings={}
createSettingsButtons=function()
widgets = {}
local wBrushPicker = createbrushpicker(64*buttonZoom,64*buttonZoom,buttonZoom)
local wPlay=createpicbutton(uiw-64*buttonZoom,0,buttonsPic,toPlayback,playQuad,buttonZoom)
local wPalette =createpicbutton(uiw-64*buttonZoom,64*buttonZoom,buttonsPic,toPaletteMode,paletteQuad,buttonZoom)
local wPicker =createpicbutton(uiw-64*buttonZoom,128*buttonZoom,buttonsPic,toPickMode,pickerQuad,buttonZoom)
local wTC =createpicbutton(uiw-64*buttonZoom,192*buttonZoom,buttonsPic,toTimeCode,clockQuad,buttonZoom)
local wBS =createpicbutton(uiw-64*buttonZoom,256*buttonZoom,buttonsPic,toBrushScreen,brushQuad,buttonZoom)
local wZP =createpicbutton(uiw-128*buttonZoom,0*buttonZoom,buttonsPic,toZoomPos,zoomQuad,buttonZoom)
local wDF =createpicbutton(uiw-192*buttonZoom,0*buttonZoom,buttonsPic,deleteCurrentFrame,deleteQuad,buttonZoom)
local wBG =createpicbutton(uiw-256*buttonZoom,0*buttonZoom,buttonsPic,toggleBg,bgQuad,buttonZoom)
local wRB =createpicbutton(uiw-320*buttonZoom,0*buttonZoom,buttonsPic,setRangeBegin,rangeBeginQuad,buttonZoom)
local wRE =createpicbutton(uiw-384*buttonZoom,0*buttonZoom,buttonsPic,setRangeEnd,rangeEndQuad,buttonZoom)
local wPR =createpicbutton(uiw-384*buttonZoom,uih-64*buttonZoom,buttonsPic,pasteRangeDirect,pasteRangeQuad,buttonZoom)
local wEX =createpicbutton(uiw-512*buttonZoom,uih-64*buttonZoom,buttonsPic,composeExport,exportQuad,buttonZoom)
local wPRR =createpicbutton(uiw-384*buttonZoom,uih-128*buttonZoom,buttonsPic,pasteRangeReverse,pasteRangeReverseQuad,buttonZoom)
local wSP =createpicbutton(uiw-512*buttonZoom,uih-128*buttonZoom,buttonsPic,toSwitchProjectThroughSave,switchProjectQuad,buttonZoom)
--WIP
-- if isHardBrushEnabled==true then
local wTHB =createpicbutton(uiw-576*buttonZoom,uih-256*buttonZoom,buttonsPic,toggleHardBrush,hardBrushEnabledQuad,buttonZoom)
table.insert(widgets,wTHB)
-- else
-- local wTHB =createpicbutton(uiw-576*buttonZoom,uih-256*buttonZoom,buttonsPic,toggleHardBrush,hardBrushQuad, buttonZoom)
-- table.insert(widgets,wTHB)
-- end
local wTSB =createpicbutton(uiw-512*buttonZoom,uih-256*buttonZoom,buttonsPic,toggleSoftBrush,softBrushQuad,buttonZoom)
local wTUB =createpicbutton(uiw-576*buttonZoom,uih-320*buttonZoom,buttonsPic,toggleUnderBrush,underBrushQuad,buttonZoom)
--set rep or unset rep button displayed depending on state
--(TODO should be widget, note here)
local r=isFrameInRepetition(currentIdx)
if r~=nil then
local wUSR =createpicbutton(uiw-512*buttonZoom,uih-320*buttonZoom,buttonsPic,disableRepeatSeq,untoggleRepQuad,buttonZoom)
table.insert(widgets,wUSR)
else
local wSR =createpicbutton(uiw-512*buttonZoom,uih-320*buttonZoom,buttonsPic,repeatSeq,toggleRepQuad,buttonZoom)
table.insert(widgets,wSR)
end
if frames[currentIdx].cf==nil then
-- local wECF =createpicbutton(uiw-512*buttonZoom,uih-256*buttonZoom,buttonsPic,enableColorFrame,toggleColorFrameQuad,buttonZoom)
local wECF =createpicbutton(64*buttonZoom,0*buttonZoom,buttonsPic,enableColorFrame,toggleColorFrameQuad,buttonZoom)
table.insert(widgets,wECF)
else
local wDCF =createpicbutton(64*buttonZoom,0*buttonZoom,buttonsPic,disableColorFrame,untoggleColorFrameQuad,buttonZoom)
table.insert(widgets,wDCF)
end
local wTLT =createpicbutton(uiw-384*buttonZoom,uih-192*buttonZoom,buttonsPic,toggleLightTable,toggleLightTableQuad,buttonZoom)
local wCTAP =createpicbutton(uiw-384*buttonZoom,uih-256*buttonZoom,buttonsPic,copyToOtherProject,copyToOtherProjectQuad,buttonZoom)
table.insert(widgets,wPlay)
table.insert(widgets,wPalette)
table.insert(widgets,wPicker)
table.insert(widgets,wTC)
table.insert(widgets,wBS)
table.insert(widgets,wZP)
table.insert(widgets,wDF)
table.insert(widgets,wBG)
table.insert(widgets,wRB)
table.insert(widgets,wRE)
table.insert(widgets,wPR)
table.insert(widgets,wEX)
table.insert(widgets,wPRR)
table.insert(widgets,wSP)
table.insert(widgets,wTSB)
table.insert(widgets,wTUB)
table.insert(widgets,wTLT)
table.insert(widgets,wBrushPicker)
table.insert(widgets,wCTAP)
end
function toSettings()
createSettingsButtons()
uiResize=createSettingsButtons
keyFunc=nil
drawFunc=drawSettings
updateFunc=updateSettings
end
local function rendertouicanvas()
love.graphics.setCanvas(ui)
love.graphics.clear(1.0,1.0,1.0,0.0)
love.graphics.setColor(1.0,.0,.0,1.0)
love.graphics.line(brshLineWidth,0,brshLineWidth,uih)
love.graphics.print('setting',400,0)
love.graphics.setColor(1.0,1.0,1.0,1.0)
if eraseMode==false then
love.graphics.draw(mybrush)
else
--outline of eraser
love.graphics.setColor(0.0,0.0,0.0,1.0)
love.graphics.circle('line',eraserRadius,eraserRadius,eraserRadius)
love.graphics.setColor(1.0,1.0,1.0,1.0)
end
renderWidgets(widgets)
msgToCvs()
displayHoverMsg()
love.graphics.setCanvas()
end
function drawSettings()
-- love.graphics.draw(buttonsPic)
rendertouicanvas()
--this is the background image of our paint
-- love.graphics.clear(1.,1.,1.,1.0)
love.graphics.clear(.5,.5,.5,1.0)
love.graphics.setColor(1.0,1.0,1.0,1.0)
love.graphics.draw(ui,0,0,0,scrsx,scrsy)
end
function updateSettings()
if npress==true then
if npx<brshLineWidth then
potradius=math.floor(npy/uih * brshMaxRad)
if potradius>1 then
if eraseMode==true then
eraserRadius=potradius
print('eraserRadius '..potradius)
else
--TODO for test
brshradius=potradius
mybrush=love.graphics.newImage(currentBrushFunc( brshradius,paintcolor.r,paintcolor.g,paintcolor.b))
-- mybrush=love.graphics.newImage(roundBrushWithGradient( brshradius,paintcolor.r,paintcolor.g,paintcolor.b))
--normal
-- mybrush=love.graphics.newImage(roundBrushWithAlpha( brshradius,paintcolor.r,paintcolor.g,paintcolor.b))
mybrush:setFilter('nearest','nearest')
end
else
print('brsh less than 1 impossible')
end
npress=false
else
consumeClick(widgets)
--if newpress still not consumed
if npress==true then
toPaintMode()
end
end
end
end