-
Notifications
You must be signed in to change notification settings - Fork 0
/
brushscreen.lua
executable file
·219 lines (159 loc) · 4.76 KB
/
brushscreen.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
local exitQuad = {x=4*64, y=0, w=64, h=64}
local pasteQuad = {x=0, y=9*64, w=64, h=64}
local srcQuad = {x=6*64, y=1*64, w=64, h=64}
local function exitBS()
print('exit bs ')
toPaintMode()
end
local currentSel = createbrushbox(100,100,200,200)
local xFlip=false
--we stamp selection on current canvas/current frame
local stampSelection = function()
--TODO the cvs needs to be loaded with the relevant frame, then the frame needs to be saved
initCanvases(currentIdx)
--doesn t work, go and see code from paste button?
love.graphics.setCanvas(cvs)
--flip logic
local xBlitZoom=1.
local xBlitFlipOff=0
--TODO here get zoom from brush box to paste with zoom
if xFlip==true then
xBlitZoom=-1.
xBlitFlipOff=brushSelection.w
end
--lets create a quad
local toBlit=love.graphics.newQuad(
brushSelection.x,
brushSelection.y,
brushSelection.w,
brushSelection.h,
frames[copySrc].pic:getDimensions()
)
--quick fix but should be done at long time
frames[copySrc].pic:setFilter('nearest','nearest')
love.graphics.draw(
frames[copySrc].pic,
toBlit,
currentSel.x-offsetcvs.x+xBlitFlipOff,
currentSel.y-offsetcvs.y,
0.,
xBlitZoom,
1.
)
love.graphics.setCanvas()
--save result to frame
saveCanvasToFrame(currentIdx)
--we need to reset the texture in case we pasted on itself ( we changed frame referenced in brushbox )
bbsettexture(
currentSel,
frames[copySrc].pic,
love.graphics.newQuad(
brushSelection.x,
brushSelection.y,
brushSelection.w,
brushSelection.h,
frames[copySrc].pic:getDimensions()
),
xFlip
)
end
local widgets={}
toggleXFlip=function()
addMsg('toggle xflip')
xFlip=not xFlip
if xFlip then
setHoverMsg('x flip')
else
setHoverMsg('no x flip')
end
--NOT WORKING
--WIP dirty dirty, no clear sequence to communicate to widget
-- currentSel.xFLip=xFlip
end
createBSButtons=function()
local wExitBS = createpicbutton(0,0,buttonsPic,exitBS,exitQuad,buttonZoom)
local wToBSS = createpicbutton(uiw-64*buttonZoom,uih-64*buttonZoom,buttonsPic,toBrushSourceSelection,srcQuad,buttonZoom)
local wStamp = createpicbutton(uiw-64*buttonZoom,0,buttonsPic,stampSelection,pasteQuad,buttonZoom)
local wXflip = createpicbutton(uiw-64*buttonZoom,uih-128*buttonZoom,buttonsPic,toggleXFlip,exitQuad,buttonZoom)
widgets={}
table.insert(widgets,wExitBS)
table.insert(widgets,wToBSS)
table.insert(widgets,currentSel )
table.insert(widgets,wStamp)
table.insert(widgets,wXflip)
end
local function rendertouicanvas()
love.graphics.setCanvas(ui)
love.graphics.clear(1.0,1.0,1.0,0.0)
love.graphics.rectangle('fill',offsetcvs.x,offsetcvs.y,conf.cvsw*applicativezoom,conf.cvsh*applicativezoom)
-- let's render the picture we will render the paste on
--we blit optional BG
local key = 'f'..currentIdx
if mybg[key]~=nil and displayBg==true then
love.graphics.draw(frames[mybg[key]].pic,offsetcvs.x,offsetcvs.y,0,applicativezoom,applicativezoom)
end
love.graphics.draw(frames[currentIdx].pic,offsetcvs.x,offsetcvs.y)
renderWidgets(widgets)
msgToCvs()
displayHoverMsg()
--love.graphics.print()
love.graphics.setCanvas()
end
local function brushScreenDraw()
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
local function brushScreenUpdate()
if npress==true then
print('bs click')
addMsg('bs click')
consumed=consumeClick(widgets)
print('consumed '..tostring(consumed))
if consumed==true
then
return
end
npress=false
end
end
--WIP when returning from source selection, we might get an optional x and y to paste
--useful to replicate scenery parts opx,opy
--TODO seems already done log and test
function toBrushScreen()
createBSButtons()
uiResize=createBSButtons
if copySrc==nil then
print('no src frame')
return
end
--brushSelection is just a map
--current sel is the box widget
--we need to add offset, in case we work not from 0 0
currentSel.x=brushSelection.x+offsetcvs.x
print('to bs current sel x y')
print(currentSel.x )
currentSel.y=brushSelection.y+offsetcvs.y
print(currentSel.y )
currentSel.w=brushSelection.w
print(currentSel.w )
currentSel.h=brushSelection.h
print(currentSel.h )
bbsettexture(
currentSel,
frames[copySrc].pic,
love.graphics.newQuad(
brushSelection.x,
brushSelection.y,
brushSelection.w,
brushSelection.h,
frames[copySrc].pic:getDimensions()
),
xFLip
)
drawFunc=brushScreenDraw
updateFunc=brushScreenUpdate
end