-
Notifications
You must be signed in to change notification settings - Fork 0
/
anpicbutton.lua
executable file
·60 lines (47 loc) · 1.29 KB
/
anpicbutton.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
--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.clickZoom=1.5
b.cb()
return true
end
return false
end
local function render(b)
if renderdecos==true then
if b.clickZoom>1. then
b.clickZoom=b.clickZoom-0.1
elseif b.clickZoom<1. then
b.clickZoom=1.
end
xCorrection=(1.-b.clickZoom)*b.zoom*64
love.graphics.draw(b.pic,b.quad,b.x+xCorrection,b.y,0,b.zoom*b.clickZoom,b.zoom*b.clickZoom)
--for debug
love.graphics.setColor(0.,0.,0.)
love.graphics.rectangle('line',b.x+xCorrection,b.y,b.zoom*64*b.clickZoom,b.zoom*64*b.clickZoom)
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 createanpicbutton(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
ret.clickZoom=1.
return ret
end