-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathButton.lua
More file actions
71 lines (59 loc) · 1.59 KB
/
Copy pathButton.lua
File metadata and controls
71 lines (59 loc) · 1.59 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
--The Hankinator's UI library
import "Addons/THUI/THUI.lua"
if THUI.Button ~= nil then
return
end
THUI.Button = {}
function THUI.Button:Create(x, y, width, height, text, justify_x, justify_y)
local button = THUI:CreateWidget(x, y, width, height, justify_x, justify_y)
button.text = text
button.active = true;
button.interactive = true
button.hover_color = THUI.default_hover_color
button.mouse_down_color = THUI.default_mouse_down_color
button.draw = self.Draw;
return button
end
function THUI.Button:Draw(ctx)
local img
local fg
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
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)
end
if self.text ~= nil then
ctx:SetFont(self.font)
ctx:SetColor(fg)
THUI:DrawText(ctx, self.text, self.x + self.width/2, self.y + self.height/2, THUI.CENTER, THUI.MIDDLE)
end
end