-
Notifications
You must be signed in to change notification settings - Fork 0
/
pickmode.lua
183 lines (139 loc) · 4.54 KB
/
pickmode.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
local clearColor={r=0.,g=0.,b=0.,a=0.}
local function commonInit()
-- saving canvas to frame, to be sure we pick
--latest changes
saveCanvasToFrame(currentIdx)
drawFunc = pickModeDraw
updateFunc = pickModeUpdate
end
--mode flag
local fill=false
function toFloodFill()
print('init flood fill')
fill=true
commonInit()
end
function toPickMode()
fill=false
commonInit()
end
local function rendertouicanvas()
love.graphics.setCanvas(ui)
love.graphics.clear(1.0,1.0,1.0,0.0)
love.graphics.rectangle('fill',
-- 0,0,
offsetcvs.x,offsetcvs.y,
conf.cvsw*applicativezoom,conf.cvsh*applicativezoom)
-- love.graphics.draw(frames[currentIdx].pic)
--to mutualize with other screens that use canvas and offset
love.graphics.draw(cvs,offsetcvs.x,offsetcvs.y,0,applicativezoom,applicativezoom)
msgToCvs()
love.graphics.setCanvas()
end
function pickModeDraw()
rendertouicanvas()
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 pickModeUpdate()
if npress==true then
--offsetcvs.x,offsetcvs.y,0,applicativezoom
-- addMsg('pick m u, npx '..npx..' npy '..npy )
-- addMsg(' offset '+offsetcvs.x+' '+offsetcvs.y+' app zoom '+applicativezoom)
-- addMsg(' ajusted offnpx offnpy ')
addMsg('pick mode newpress npx '..npx..' npy '..npy)
local xcvs,ycvs=getTouchOnCanvas(0)
xcvs=math.floor(xcvs)
ycvs=math.floor(ycvs)
addMsg('canvas coord: '..xcvs..' '..ycvs)
if xcvs>=0 and ycvs>=0
and xcvs<=conf.cvsw and ycvs<=conf.cvsh then
addMsg('click in image canvas !!! ')
if fill==false then
addMsg('picking color')
r,g,b,a=frames[currentIdx].data:getPixel(
-- npx,npy
xcvs,ycvs
)
addMsg('color '.. math.floor( r*255) ..' '.. math.floor(g*255) ..' '.. b*255)
addMsg('quit pick')
mybrush=love.graphics.newImage(currentBrushFunc(brshradius,r,g,b))
mybrush:setFilter('nearest','nearest')
paintcolor.r=r
paintcolor.g=g
paintcolor.b=b
npress=false
toPaintMode()
return
else
addMsg('filling color WIP')
print('calling flood fill')
if eraseMode==false then
floodFill(xcvs,ycvs,paintcolor,frames[currentIdx].data,frames[currentIdx].data)
else
floodFill(xcvs,ycvs,clearColor,frames[currentIdx].data,frames[currentIdx].data)
end
--image data needs to be uploaded back to gpu mem
frames[currentIdx].pic:release()
frames[currentIdx].pic=love.graphics.newImage(frames[currentIdx].data)
frames[currentIdx].dirty=true
-- upload to work canvas
initCanvases(currentIdx)
npress=false
toPaintMode()
return
end
else
addMsg('click not in paint canvas!')
npress=false
return
end
--TODO to update for offset and zoom
-- if
-- npx<conf.cvsw
-- and npy<conf.cvsh
-- and fill==false then
-- print('pick color triggered')
-- --pick color
-- r,g,b,a=frames[currentIdx].data:getPixel(
-- npx,npy
-- )
-- addMsg('color '.. math.floor( r*255) ..' '.. math.floor(g*255) ..' '.. b*255)
-- addMsg('quit pick')
-- -- mybrush=love.graphics.newImage(roundBrushWithAlpha(brshradius,r,g,b))
-- -- mybrush=love.graphics.newImage(roundBrushWithGradient(brshradius,r,g,b))
-- mybrush=love.graphics.newImage(currentBrushFunc(brshradius,r,g,b))
-- mybrush:setFilter('nearest','nearest')
-- paintcolor.r=r
-- paintcolor.g=g
-- paintcolor.b=b
-- npress=false
-- toPaintMode()
-- return
-- elseif npx<conf.cvsw
-- and npy<conf.cvsh
-- and fill==true then
-- --local r,g,b,a = frames[currentIdx].data:getPixel(npx,npy)
-- print('calling flood fill')
-- if eraseMode==false then
-- floodFill(npx,npy,paintcolor,frames[currentIdx].data,frames[currentIdx].data)
-- else
-- floodFill(npx,npy,clearColor,frames[currentIdx].data,frames[currentIdx].data)
-- end
-- --image data needs to be uploaded back to gpu mem
-- frames[currentIdx].pic:release()
-- frames[currentIdx].pic=love.graphics.newImage(frames[currentIdx].data)
-- frames[currentIdx].dirty=true
-- -- upload to work canvas
-- initCanvases(currentIdx)
-- npress=false
-- toPaintMode()
-- return
-- else
-- npress=false
-- addMsg('out of boundaries')
-- print('out of boundaries')
-- end
end
end