-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflickmode.lua
executable file
·245 lines (173 loc) · 5.08 KB
/
flickmode.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
nb_flick=10
-- it is the displayed frame, and will become the new currentIdx when you releaseBon
local tgt=nil
local dragx=nil
local leftmode=nil
local flickFrames={
-- 1,2,4,6 nb_flick numbers
}
--ui scaled
function dragFlick(me,x,y,dx,dy)
-- addMsg('drag flick called')
dragx=x
end
--WIP
--TODO add logs for range calculated
function calculateFlickRange()
--when starting a flick, we should ignore frames that have a tc=0, such as bg or color
--to do that we need to precalculate the indexes of the flick frames
-- WIP TO FINISH
if leftmode==true then
--if to the left we count towards 0
print('towards left mode')
-- lpot=currentIdx+1
lpot=currentIdx
--lets skip if current frame is color
if frames[lpot].tc==0 then
lpot=lpot-1
print('skipping current frame because tc=0')
end
for i=1,nb_flick
do
--slot 0 is current slot (before moving flick)
local slot=i-1
if lpot<1 then
flickFrames[slot]=1
print(' slot '..slot..' frame '..lpot)
--TODO all slots still need to be filled with last picked up number, otherwise it will
--crash if you flick to empty slot
-- break
end
--TODO if first one is a color or tc=0 frame, skip until first suitable
--(otherwise instant crash)
if lpot>0 and frames[lpot].tc>0 then
flickFrames[slot]=lpot
print(' slot '..slot..' frame '..lpot)
end
lpot=lpot-1
-- tgtflick=nb
-- print('valid flick '.. )
end
--end of loop
else
print('right mode')
--TODO copy do loop above
--if to the right we count towards maxframe
-- lpot=currentIdx-1
lpot=currentIdx
--lets skip if current frame is color
if frames[lpot].tc==0 then
lpot=lpot+1
print('skipping current frame because tc=0')
end
for i=1,nb_flick
do
local slot=i-1
if lpot>maxframe then
flickFrames[slot]=maxframe
print(' slot '..slot..' frame '..lpot)
--break
end
if lpot<=maxframe and frames[lpot].tc>0 then
flickFrames[slot]=lpot
print(' slot '..slot..' frame '..lpot)
end
lpot=lpot+1
end
end
end
function flickRelease()
-- for some reason this corrupts frame !!
-- seems to copy initial on target
--id setting and preparing cvs go together,
--should be func
if tgt~=nil then
currentIdx=tgt
end
print('new idx '..currentIdx)
initCanvases(currentIdx)
leftmode=nil
toPaintMode()
end
-- function tst()
-- addMsg('tst')
-- end
function toFlick(bleft)
-- let s make sure we save our lates drawing
saveCanvasToFrame(currentIdx)
leftmode=bleft
drawFunc=drawFlick
updateFunc=updateFlick
if bleft==true then
dragx=uiw
else
dragx=0
end
flickNb=currentIdx
tgt=currentIdx
calculateFlickRange()
registerdrag={drag=dragFlick,dragrelease=flickRelease}
-- registerdrag={drag=tst}
end
function toLeftFlick()
toFlick(true)
end
function toRightFlick()
toFlick(false)
end
local function rendertouicanvas()
love.graphics.setCanvas(ui)
love.graphics.clear(1.0,1.0,1.0,0.0)
--we blit optional BG
local key = 'f'..tgt
if mybg[key]~=nil then
love.graphics.draw(frames[mybg[key]].pic,offsetcvs.x,offsetcvs.y)
end
if tgt~=nil then
love.graphics.draw(frames[tgt].pic,offsetcvs.x,offsetcvs.y)
end
--WIP rdr frame num not current idx changed when flicking, look in model
love.graphics.setColor(1.0,0.0,0.0,1.0)
love.graphics.print(tgt,0,0,0,4,4)
love.graphics.setColor(1.0,1.0,1.0,1.0)
msgToCvs()
love.graphics.setCanvas()
end
function drawFlick()
rendertouicanvas()
--this is the background image of our paint
love.graphics.clear(1.,1.,1.,1.0)
love.graphics.setColor(1.0,1.0,1.0,1.0)
love.graphics.draw(ui,0,0,0,scrsx,scrsy)
end
function updateFlick()
-- mouse drag is redefinted, it gives us a coordinate
if leftmode == false then
offset=dragx
else
offset=uiw-dragx
end
-- addMsg('dragx '..dragx)
slotwidth=uiw/nb_flick
nbslot=math.floor(offset/slotwidth)
addMsg('nbslot '..nbslot)
print('nbslot '..nbslot)
-- if leftmode ==true then
--TODO use lookup table ( to skip tc 0s )
potTgt=flickFrames[nbslot]
if potTgt~=nil then
tgt=potTgt
else
--to display nothing
tgt=nil
end
--tgt= flickNb+nbslot
-- else
-- tgt= flickNb-nbslot
-- end
-- if tgt<1 then tgt=1 end
-- if tgt>maxframe then
-- tgt=maxframe
-- addMsg('tgt = maxframe')
-- end
end