-
Notifications
You must be signed in to change notification settings - Fork 0
/
picbutton.lua
executable file
·50 lines (39 loc) · 1 KB
/
picbutton.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
--if consumed returns true
local function click(b,mx,my)
if mx >= b.x and mx<b.x+b.coords.w*b.zoom and my >= b.y and my<b.y+b.coords.h*b.zoom then
print("click")
b.cb()
return true
end
return false
end
local function render(b)
if renderdecos==true then
love.graphics.draw(b.pic,b.quad,b.x,b.y,0,b.zoom,b.zoom)
--for debug
love.graphics.setColor(0.,0.,0.)
love.graphics.rectangle('line',b.x,b.y,b.zoom*64,b.zoom*64)
love.graphics.setColor(1.,1.,1.)
end
end
--TODO ppass coords and create quad here
-- coords={ox oy w h } then we blit part of the pic
function createpicbutton(x,y,pic,callback,coords,zoom)
ret={}
ret.pic=pic
ret.coords=coords
ret.quad=love.graphics.newQuad(coords.x,coords.y,coords.w,coords.h,pic:getWidth(),pic:getHeight())
ret.x=x
ret.y=y
-- ret.w=quad.w
-- ret.h=quad.h
ret.cb=callback
ret.render=render
ret.click=click
if zoom~=nil then
ret.zoom=zoom
else
ret.zoom=1
end
return ret
end