-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.lua
More file actions
47 lines (39 loc) · 1.44 KB
/
Copy pathbutton.lua
File metadata and controls
47 lines (39 loc) · 1.44 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
function NewButton(DrawFunction, ClickFunction, x, y, width, height, gamestate)
return
{
x = x,
y = y,
width = width,
height = height,
DrawFunction = DrawFunction,
ClickFunction = ClickFunction,
gamestate = gamestate,
GetHitbox = function (self)
return self.x, self.y, self.x + self.width, self.y + self.height
end,
Draw = function (self)
local transform = love.math.newTransform(self.x, self.y, self.angle)
local mask = function ()
love.graphics.rectangle("fill", self.x, self.y, self.width, self.height, 20, 20)
end
love.graphics.stencil(mask, "replace", 1)
love.graphics.setStencilTest("gequal", 1)
love.graphics.applyTransform(transform)
self.DrawFunction()
love.graphics.applyTransform(transform:inverse())
love.graphics.setStencilTest()
love.graphics.setColor(1, 1, 1)
love.graphics.setLineWidth(5)
if IsHoveredByMouse(self:GetHitbox()) then
love.graphics.setColor(1, 1, 0.6)
love.graphics.setLineWidth(8)
end
love.graphics.rectangle("line", self.x, self.y, self.width, self.height, 20, 20)
end,
Click = function (self)
-- print(GameState.state["menu"])
if not (IsHoveredByMouse(self:GetHitbox())) or not GameState.state[self.gamestate] then return end
self.ClickFunction()
end
}
end