64 lines
1.8 KiB
Lua
64 lines
1.8 KiB
Lua
local BezierCurve = require("BezierCurve")
|
|
local GUI = require("GUI-Framework")
|
|
local Vector2 = require("Vector2")
|
|
|
|
function addCurve(points)
|
|
local newCurve = BezierCurve:new(points)
|
|
table.insert(allCurves, newCurve)
|
|
end
|
|
|
|
function love.load(args, unfilteredArgs)
|
|
love.window.setTitle("Bezier Curves")
|
|
gui = GUI:new(love.graphics.getDimensions())
|
|
allCurves = {}
|
|
show = {true, true , false}
|
|
|
|
for _, file in pairs(love.filesystem.getDirectoryItems("GUI")) do
|
|
require("GUI."..file:sub(1, -5))
|
|
end
|
|
|
|
addCurve{200,200,300,150}
|
|
|
|
gui:addElement("Button", {pos=Vector2(10,10), size = Vector2(100,25), text = "Hide points", mouseClicked = function(self)
|
|
show[1] = not show[1]
|
|
if show[1] then
|
|
self.text = "Hide points"
|
|
else
|
|
self.text = "Show points"
|
|
end
|
|
end})
|
|
gui:addElement("Button", {pos=Vector2(10,50), size = Vector2(100,25), text = "Hide lines", mouseClicked = function(self)
|
|
show[2] = not show[2]
|
|
if show[2] then
|
|
self.text = "Hide lines"
|
|
else
|
|
self.text = "Show lines"
|
|
end
|
|
end})
|
|
gui:addElement("Button", {pos=Vector2(10,90), size = Vector2(100,25), text = "Show curves", mouseClicked = function(self)
|
|
show[3] = not show[3]
|
|
if show[3] then
|
|
self.text = "Hide curves"
|
|
else
|
|
self.text = "Show curves"
|
|
end
|
|
end})
|
|
|
|
-- Make functions
|
|
for _, name in ipairs{"mousepressed", "mousereleased", "mousemoved", "load", "resize", "keypressed", "keyreleased", "textinput"} do
|
|
love[name] = function(...)
|
|
for _, curve in ipairs(allCurves) do
|
|
if curve[name] then curve[name](curve, ...) end
|
|
if gui[name] then gui[name](gui, ...) end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function love.draw()
|
|
love.graphics.clear(0.9,0.9,0.9)
|
|
for _, curve in ipairs(allCurves) do
|
|
curve:draw(show[1], show[2], show[3])
|
|
end
|
|
gui:draw()
|
|
end |