-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTextButton.lua
More file actions
65 lines (52 loc) · 1.61 KB
/
TextButton.lua
File metadata and controls
65 lines (52 loc) · 1.61 KB
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
-- TextButton.lua
-- by Vega from the codea forums
-- a button with rounded corners and nice color mgmt. Looks really good!
TextButton = class(Button)
function TextButton:init(text,x,y,w,h,args)
Button.init(self,x,y,w,h)
self.pressed = false
self.banner = TextBanner(text,x,y,w,h,args)
args = args or {}
self.topColor = args.topColor or color(255, 255, 255, 255)
self.bottomColor = args.bottomColor or color(255,255,255,255)
self.pressedTopColor = args.pressedTopColor or color(127,127,127,255)
self.pressedBottomColor = args.pressedBottomColor or color(127,127,127,255)
--print(self.pressed)
end
function TextButton:setColors(top,bot)
self.topColor = top
self.bottomColor = bot
self.banner.topColor = top
self.banner.bottomColor = bot
self.banner:recolor()
end
function TextButton:translate(dx,dy)
Button.translate(self,dx,dy)
self.banner:translate(dx,dy)
end
function TextButton:setUnpressed()
self.pressed = false
self.banner.topColor = self.topColor
self.banner.bottomColor = self.bottomColor
self.banner:recolor()
end
function TextButton:setPressed()
self.pressed = true
self.banner.topColor = self.pressedTopColor
self.banner.bottomColor = self.pressedBottomColor
self.banner:recolor()
end
function TextButton:onBegan(t)
self:setPressed()
end
function TextButton:onEnded(t)
self:setUnpressed()
end
function TextButton:touched(t)
local didTouch = Button.touched(self,t)
if not didTouch and self.pressed then self:setUnpressed() end
return didTouch
end
function TextButton:draw()
self.banner:draw()
end