-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.lua
More file actions
86 lines (68 loc) · 2.01 KB
/
Copy pathwidget.lua
File metadata and controls
86 lines (68 loc) · 2.01 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
local widget = {}
widget.__index = widget
widget.colors = {
released = {text={0,0,0,1}, fill={0.9,0.9,0.9,1}, stroke={0.5,0.5,0.5,1}},
pressed = {text={0,0,0,1}, fill={0.7,0.7,0.7,1}, stroke={1,1,1,1}},
hovered = {text={0,0,0,1}, fill={0.8,0.8,1,1}, stroke={1,1,1,1}},
focused = {text={0,0,0,1}, fill={0.9,0.9,0.9,1}, stroke={0.5,0.5,0.5,1}},
}
widget.padding = {x=8, y=8}
widget.radius = {x=5, y=5}
widget.focused = false
widget.pressed = false
widget.clock = 0
function widget.init(self, app)
self.application = app
if app and app.addWidget then
app:addWidget(self)
end
end
function widget.update(self,dt)
self.clock = self.clock + dt
end
function widget.hit(self, x, y)
return x >= self.x and x < self.x + self.width and y >= self.y and y < self.y + self.height
end
function widget.getClientSize(self)
return {x = self.width - self.padding.x * 2, y = self.height - self.padding.y * 2}
end
function widget.getColor(self)
local currentColor = self.colors.released
if self.pressed then
currentColor = self.colors.pressed
elseif self.focused then
currentColor = self.colors.focused
end
return currentColor
end
function widget.onClick(self)
-- empty click handler
end
function widget.mousePressed(self, handled, x, y, button, isTouch)
if self:hit(x,y) and not handled then
self.pressed = true
return true
end
end
function widget.mouseReleased(self, handled, x, y, button, isTouch)
if self:hit(x,y) and self.pressed then
if not handled then
self.focused = true
handled = true
end
else
self.focused = false
end
self.pressed = false
return handled
end
function widget.wheelMoved(self, x, y)
-- empty function for widgets that do not respond to wheel movement.
end
function widget.textInput(self, handled, text)
-- empty function for widgets that do not receive text.
end
function widget.drawAfter(self)
-- empty function for widgets that do not have foreground graphics
end
return widget