-
Notifications
You must be signed in to change notification settings - Fork 0
/
textbutton.lua
50 lines (36 loc) · 987 Bytes
/
textbutton.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
local txtBtnBaseW=64
--if consumed returns true
local function click(b,mx,my)
if mx >= b.x and mx<b.x+txtBtnBaseW*b.zoom and my >= b.y and my<b.y+txtBtnBaseW*b.zoom then
print("click")
b.cb(b.textAndKey.key)
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)
love.graphics.setColor(0.,0.,0.,1.)
love.graphics.rectangle('line',b.x,b.y,txtBtnBaseW*b.zoom,txtBtnBaseW*b.zoom)
love.graphics.print(b.textAndKey.text,b.x+txtBtnBaseW,b.y+txtBtnBaseW/2,0,b.zoom,b.zoom)
love.graphics.setColor(1.,1.,1.,1.)
end
end
-- the text passed will be passed to the callback
function createTextButton(x,y,callback,textAndKey,zoom)
--textAndKey = {text='display',key=for_callback}
ret={}
ret.textAndKey=textAndKey
ret.x=x
ret.y=y
ret.cb=callback
ret.render=render
ret.click=click
if zoom~=nil then
ret.zoom=zoom
else
ret.zoom=1
end
return ret
end