41 lines
992 B
Lua
41 lines
992 B
Lua
function makeButton(options)
|
|
local state = 0 -- 0 = normal, 1 = hovered, 2 = pressed
|
|
return {
|
|
x = options.x,
|
|
y = options.y,
|
|
w = options.w,
|
|
h = options.h or 6,
|
|
data = options.data,
|
|
text = options.text,
|
|
onClick = options.onClick,
|
|
onHover = options.onHover,
|
|
onDraw = options.onDraw,
|
|
ogColor = options.color or 5,
|
|
color = options.color or 5,
|
|
|
|
draw=function(self, selected)
|
|
standardFont()
|
|
-- rect2(self.x, self.y, self.w, self.h, 8)
|
|
if self.onDraw then self.onDraw(self) end
|
|
print(self.text, self.x+1, self.y+1, self.color)
|
|
end,
|
|
|
|
update=function(self)
|
|
self.color = self.ogColor
|
|
if mouse_x >= self.x and mouse_x <= self.x + self.w and
|
|
mouse_y >= self.y and mouse_y <= self.y + self.h then
|
|
if stat(34)&1 == 0 and state == 2 and self.onClick then
|
|
self.onClick(self)
|
|
end
|
|
if stat(34)&1 == 1 then
|
|
state = 2
|
|
else
|
|
if self.onHover then self.onHover(self) end
|
|
state = 1
|
|
end
|
|
else
|
|
state = 0
|
|
end
|
|
end
|
|
}
|
|
end |