-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCheckBox.lua
More file actions
99 lines (88 loc) · 2.4 KB
/
Copy pathCheckBox.lua
File metadata and controls
99 lines (88 loc) · 2.4 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
87
88
89
90
91
92
93
94
95
96
97
98
99
--The Hankinator's UI library
import "Addons/THUI/THUI.lua"
if THUI.CheckBox ~= nil then
return
end
THUI.CheckBox = {}
function THUI.CheckBox:Create(x, y, width, height, justify_x, justify_y)
local checkbox = THUI:CreateWidget(x, y, width, height, justify_x, justify_y)
checkbox.active = true;
checkbox.interactive = true
checkbox.hover_color = THUI.default_hover_color
checkbox.mouse_down_color = THUI.default_mouse_down_color
checkbox.checked = false
checkbox.click = THUI:Callback(self.Clicked, checkbox)
checkbox.draw = self.Draw
return checkbox;
end
function THUI.CheckBox:Clicked()
self.checked = not self.checked
end
function THUI.CheckBox:Draw(ctx)
local img
local fg
if self.checked then
if not self.active then
if self.img_checked_inactive ~= nil then
img = self.img_checked_inactive
end
fg = self.inactive_color
elseif self.mouse_down then
if self.img_checked_mouse_down ~= nil then
img = self.img_checked_mouse_down
end
fg = self.mouse_down_color
self.mouse_down = false
elseif self.hover == true then
if self.img_checked_hover ~= nil then
img = self.img_checked_hover
end
fg = self.hover_color
self.hover = false
else
if self.img_checked_mouseup ~= nil then
img = self.img_checked_mouseup
end
fg = self.fg_color
end
else
if not self.active then
if self.img_inactive ~= nil then
img = self.img_inactive
end
fg = self.inactive_color
elseif self.mouse_down then
if self.img_mouse_down ~= nil then
img = self.img_mouse_down
end
fg = self.mouse_down_color
self.mouse_down = false
elseif self.hover == true then
if self.img_hover ~= nil then
img = self.img_hover
end
fg = self.hover_color
self.hover = false
else
if self.img_mouseup ~= nil then
img = self.img_mouseup
end
fg = self.fg_color
end
end
if img ~= nil then
ctx:SetColor(1.0, 1.0, 1.0, 1.0)
ctx:DrawImage(img, self.x, self.y, self.width, self.height)
else
--bg
ctx:SetColor(self.bg_color)
ctx:DrawRect(self.x, self.y, self.width, self.height, 0)
--fg
ctx:SetColor(fg)
ctx:DrawRect(self.x, self.y, self.width, self.height, 1)
if self.checked then
ctx:DrawLine(self.x, self.y, self.x + self.width, self.y + self.height)
ctx:DrawLine(self.x, self.y + self.height, self.x + self.width, self.y)
end
end
end