Initial commit
This commit is contained in:
Executable
+69
@@ -0,0 +1,69 @@
|
||||
local gui = require("gui")
|
||||
local color = require("gui.core.color")
|
||||
local theme = require("gui.core.theme")
|
||||
local transition = require("gui.elements.transitions")
|
||||
|
||||
function gui:newMenu(title, sx, position, trans)
|
||||
if not title then multi.error("Argument 1 string('title') is required") end
|
||||
if not sx then multi.error("Argument 2 number('sx') is required") end
|
||||
|
||||
local position = position or gui.ALIGN_LEFT
|
||||
local trans = trans or transition.glide
|
||||
|
||||
local menu, to, tc, open
|
||||
if position == gui.ALIGN_LEFT then
|
||||
menu = self:newFrame(0, 0, 0, 0, -sx, 0, sx, 1)
|
||||
to = trans(-sx, 0, .25)
|
||||
tc = trans(0, -sx, .25)
|
||||
elseif position == gui.ALIGN_CENTER then
|
||||
menu = self:newFrame(0, 0, 0, 0, .5 -sx/2, 1.1, sx, 1)
|
||||
to = trans(1.1, 0, .35)
|
||||
tc = trans(0, 1.1, .35)
|
||||
elseif position == gui.ALIGN_RIGHT then
|
||||
menu = self:newFrame(0, 0, 0, 0, 1, 0, sx, 1)
|
||||
to = trans(1, 1 - sx, .25)
|
||||
tc = trans(1 - sx, 1, .25)
|
||||
end
|
||||
|
||||
function menu:isOpen()
|
||||
return open
|
||||
end
|
||||
|
||||
function menu:Open(show)
|
||||
if show then
|
||||
if not menu.lock then
|
||||
menu.lock = true
|
||||
local t = to()
|
||||
t.OnStop(function()
|
||||
open = true
|
||||
menu.lock = false
|
||||
end)
|
||||
t.OnStep(function(p)
|
||||
if position == gui.ALIGN_CENTER then
|
||||
menu:setDualDim(nil, nil, nil, nil, nil, p)
|
||||
else
|
||||
menu:setDualDim(nil, nil, nil, nil, p)
|
||||
end
|
||||
end)
|
||||
end
|
||||
else
|
||||
if not menu.lock then
|
||||
menu.lock = true
|
||||
local t = tc()
|
||||
t.OnStop(function()
|
||||
open = false
|
||||
menu.lock = false
|
||||
end)
|
||||
t.OnStep(function(p)
|
||||
if position == gui.ALIGN_CENTER then
|
||||
menu:setDualDim(nil, nil, nil, nil, nil, p)
|
||||
else
|
||||
menu:setDualDim(nil, nil, nil, nil, p)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return menu
|
||||
end
|
||||
Executable
+78
@@ -0,0 +1,78 @@
|
||||
local gui = require("gui")
|
||||
local multi, thread = require("multi"):init()
|
||||
local processor = gui:newProcessor("Transistion Processor")
|
||||
local transition = {}
|
||||
|
||||
local width, height, flags = love.window.getMode()
|
||||
local fps = 60
|
||||
|
||||
if flags.refreshrate > 0 then
|
||||
fps = flags.refreshrate
|
||||
end
|
||||
|
||||
transition.__index = transition
|
||||
transition.__call = function(t, start, stop, time, ...)
|
||||
local args = {...}
|
||||
return function(st, sp, ti) -- allow these values to be overridden
|
||||
if not (st or start) or not (sp or stop) then return multi.error("start and stop must be supplied") end
|
||||
if start == stop then
|
||||
local temp = {
|
||||
OnStep = function() end,
|
||||
OnStop = multi:newConnection()
|
||||
}
|
||||
proc:newTask(function()
|
||||
temp.OnStop:Fire()
|
||||
end)
|
||||
return temp
|
||||
end
|
||||
local handle = t.func(t, start, stop, (ti or time) or 1, unpack(args))
|
||||
return {
|
||||
OnStep = handle.OnStatus,
|
||||
OnStop = handle.OnReturn + handle.OnError,
|
||||
Kill = t.Kill
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function transition:newTransition(func)
|
||||
local c = {}
|
||||
setmetatable(c, self)
|
||||
|
||||
c.fps = fps
|
||||
c.func = processor:newFunction(func)
|
||||
c.OnStop = multi:newConnection()
|
||||
c.kill = false
|
||||
|
||||
function c:SetFPS(fps)
|
||||
self.fps = fps
|
||||
end
|
||||
|
||||
function c:GetFPS(fps)
|
||||
return self.fps
|
||||
end
|
||||
|
||||
function c:Kill()
|
||||
if c.running then
|
||||
c.kill = true
|
||||
end
|
||||
end
|
||||
|
||||
return c
|
||||
end
|
||||
|
||||
transition.glide = transition:newTransition(function(t, start, stop, time, ...)
|
||||
local steps = t.fps*time
|
||||
local piece = time/steps
|
||||
local split = stop-start
|
||||
t.running = true
|
||||
for i = 0, steps do
|
||||
if not(t.kill) then
|
||||
thread.sleep(piece)
|
||||
thread.pushStatus(start + i*(split/steps),piece*i)
|
||||
end
|
||||
end
|
||||
t.running = false
|
||||
t.kill = false
|
||||
end)
|
||||
|
||||
return transition
|
||||
Reference in New Issue
Block a user