-
Notifications
You must be signed in to change notification settings - Fork 0
/
brushpicker.lua
102 lines (76 loc) · 2.4 KB
/
brushpicker.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
--TODO display save brush button
--local saveBrushQuad = {x=3*64, y=0, w=64, h=64}
local rSBQ = love.graphics.newQuad(3*64, 0, 64, 64,buttonsPic:getWidth(),buttonsPic:getHeight())
--if consumed returns true
local function click(b,mx,my)
for i=1,5
do
if mx >= b.x and mx<b.x+64*b.zoom and my >= b.y+(i-1)*64*b.zoom and my<b.y+(i)*64*b.zoom then
print("click")
-- b.cb()
if b.store==true then
--see brush preset (keycode hack)
tmpSlot=i+5
storeInSlot('f'..tmpSlot)
b.store=false
saveBrushes()
else
restoreSlot('f'..i)
end
return true
end
end
if mx >= b.x+64*b.zoom and mx<b.x+64*2*b.zoom and my >= b.y and my<b.y+64*b.zoom then
print('store mode')
b.store=true
return true
end
return false
end
local function render(b)
if renderdecos==true then
for i=1,5
do
love.graphics.setColor(0.,0.,0.,1.)
-- love.graphics.draw(b.pic,b.quad,b.x,b.y,0,b.zoom,b.zoom)
love.graphics.rectangle('line',b.x,b.y+64*b.zoom*(i-1),64*b.zoom,64*b.zoom)
love.graphics.setColor(1.,1.,1.,1.)
if brushTexes['f'..i]~=nil then
love.graphics.draw(brushTexes['f'..i],b.x,b.y+64*b.zoom*(i-1))
end
if brushPresets['f'..i]~=nil and brushPresets['f'..i].eraser==true then
local size =brushPresets['f'..i].size
--outline of eraser
love.graphics.setColor(0.0,0.0,0.0,1.0)
love.graphics.circle('line',b.x+64*b.zoom/2,b.y+64*b.zoom*(i-1)+64*b.zoom/2,size)
love.graphics.setColor(1.0,1.0,1.0,1.0)
end
love.graphics.setColor(0.,0.,0.,1.)
love.graphics.rectangle('line',b.x+64*b.zoom,b.y,64*b.zoom,64*b.zoom)
love.graphics.setColor(1.,1.,1.,1.)
end
--button to store brush
love.graphics.draw(buttonsPic,rSBQ,b.x+64*b.zoom,b.y,0,b.zoom,b.zoom)
end
end
--TODO ppass coords and create quad here
-- coords={ox oy w h } then we blit part of the pic
function createbrushpicker(x,y,zoom)
ret={}
ret.pic=pic
-- ret.coords=coords
ret.x=x
ret.y=y
-- ret.w=quad.w
-- ret.h=quad.h
ret.render=render
ret.click=click
if zoom~=nil then
ret.zoom=zoom
else
ret.zoom=1
end
--in store mode, click on a square to store the brush
ret.store=false
return ret
end