Woring on features
This commit is contained in:
parent
a68966879d
commit
d1f1d79c76
0
addons/init.lua
Normal file
0
addons/init.lua
Normal file
@ -1,4 +1,5 @@
|
||||
local gui = require("gui")
|
||||
local theme = require("gui.core.theme")
|
||||
local default_theme = theme:new("64342e", "b2989e", "909b9a")
|
||||
|
||||
function gui:newWindow(x, y, w, h, text, draggable)
|
||||
|
||||
26
core/canvas.lua
Normal file
26
core/canvas.lua
Normal file
@ -0,0 +1,26 @@
|
||||
local gui = require("gui")
|
||||
|
||||
function newCanvas(domain)
|
||||
local c
|
||||
if domain == "visual" then
|
||||
c = gui:newVisualFrame()
|
||||
else
|
||||
c = gui:newVirtualFrame()
|
||||
end
|
||||
c:fullFrame()
|
||||
function c:swap(c1, c2)
|
||||
local temp = c1.children
|
||||
c1.children = c2.children
|
||||
c2.children = temp
|
||||
for i,v in pairs(c1.children) do
|
||||
v.parent = c1
|
||||
end
|
||||
for i,v in pairs(c2.children) do
|
||||
v.parent = c2
|
||||
end
|
||||
end
|
||||
|
||||
return c
|
||||
end
|
||||
|
||||
return newCanvas
|
||||
@ -47,7 +47,7 @@ function color.hsl(h, s, l)
|
||||
elseif h < 4 then r,b,g = 0,x,c
|
||||
elseif h < 5 then r,b,g = x,0,c
|
||||
else r,b,g = c,0,x
|
||||
end return (r+m)*255, (g+m)*255, (b+m)*255
|
||||
end return (r+m)*255, (g+m)*255, (b+m)*255, 255
|
||||
end
|
||||
|
||||
min = math.min
|
||||
@ -60,7 +60,7 @@ function color.hsv(h, s, v)
|
||||
local r = min (max (3*abs (((h )/180)%2-1)-1, 0), 1)
|
||||
local g = min (max (3*abs (((h -120)/180)%2-1)-1, 0), 1)
|
||||
local b = min (max (3*abs (((h +120)/180)%2-1)-1, 0), 1)
|
||||
return k1 + k2 * r, k1 + k2 * g, k1 + k2 * b
|
||||
return k1 + k2 * r, k1 + k2 * g, k1 + k2 * b, 1
|
||||
end
|
||||
|
||||
function color.isLight(r, g, b)
|
||||
@ -102,9 +102,10 @@ function color.new(r, g, b, fmt)
|
||||
end
|
||||
local temp
|
||||
if fmt then
|
||||
temp = {r,b,g}
|
||||
temp = {r, b, g, 1}
|
||||
else
|
||||
temp = {love.math.colorFromBytes(r, g, b)}
|
||||
temp[4] = 1
|
||||
end
|
||||
setmetatable(temp, mt)
|
||||
return temp
|
||||
|
||||
90
core/simulate.lua
Normal file
90
core/simulate.lua
Normal file
@ -0,0 +1,90 @@
|
||||
local gui = require("gui")
|
||||
local multi, thread = require("multi"):init()
|
||||
local transition = require("gui.elements.transitions")
|
||||
|
||||
-- Triggers press then release
|
||||
local function getPosition(obj, x, y)
|
||||
if not x or y then
|
||||
local cx, cy, w, h = obj:getAbsolutes()
|
||||
return cx + w/2, cy + h/2
|
||||
else
|
||||
return x, y
|
||||
end
|
||||
end
|
||||
|
||||
proc = gui:getProcessor()
|
||||
|
||||
local simulate = {}
|
||||
|
||||
function simulate:Press(button, x, y, istouch)
|
||||
if self then
|
||||
x, y = getPosition(self, x, y)
|
||||
elseif x == nil or y == nil then
|
||||
x, y = love.mouse.getPosition()
|
||||
end
|
||||
love.mouse.setPosition(x, y)
|
||||
gui.Events.OnMousePressed:Fire(x, y, button or gui.MOUSE_PRIMARY, istouch or false)
|
||||
end
|
||||
|
||||
function simulate:Release(button, x, y, istouch)
|
||||
if self then
|
||||
x, y = getPosition(self, x, y)
|
||||
elseif x == nil or y == nil then
|
||||
x, y = love.mouse.getPosition()
|
||||
end
|
||||
love.mouse.setPosition(x, y)
|
||||
gui.Events.OnMouseReleased:Fire(x, y, button or gui.MOUSE_PRIMARY, istouch or false)
|
||||
end
|
||||
|
||||
simulate.Click = proc:newFunction(function(self, button, x, y, istouch)
|
||||
if self then
|
||||
x, y = getPosition(self, x, y)
|
||||
elseif x == nil or y == nil then
|
||||
x, y = love.mouse.getPosition()
|
||||
end
|
||||
love.mouse.setPosition(x, y)
|
||||
gui.Events.OnMousePressed:Fire(x, y, button or gui.MOUSE_PRIMARY, istouch or false)
|
||||
thread.skip(1)
|
||||
gui.Events.OnMouseReleased:Fire(x, y, button or gui.MOUSE_PRIMARY, istouch or false)
|
||||
end, true)
|
||||
|
||||
simulate.Move = proc:newFunction(function(self, dx, dy, x, y, istouch)
|
||||
local dx, dy = dx or 0, dy or 0
|
||||
|
||||
if self then
|
||||
x, y = getPosition(self, x, y)
|
||||
elseif x == nil or y == nil then
|
||||
x, y = love.mouse.getPosition()
|
||||
end
|
||||
|
||||
if dx == 0 and dy == 0 then
|
||||
_x, _y = love.mouse.getPosition()
|
||||
if x == _x and y == _y then
|
||||
return
|
||||
end
|
||||
local dx, dy = 0, 0
|
||||
dx = x - _x
|
||||
dy = y - _y
|
||||
return simulate.Move(nil, dx, dy)
|
||||
end
|
||||
gui.Events.OnMouseMoved:Fire(x, y, 0, 0, istouch or false)
|
||||
thread.skip(1)
|
||||
local gx = transition.glide(0, dx, .25)
|
||||
local gy = transition.glide(0, dy, .25)
|
||||
local xx = gx()
|
||||
xx.OnStep(function(p)
|
||||
_x, _y = love.mouse.getPosition()
|
||||
love.mouse.setPosition(x + p, _y)
|
||||
end)
|
||||
local yy = gy()
|
||||
yy.OnStep(function(p)
|
||||
_x, _y = love.mouse.getPosition()
|
||||
love.mouse.setPosition(_x, y + p)
|
||||
end)
|
||||
if not(dx==0 and dy == 0) then
|
||||
thread.hold(xx.OnStop * yy.OnStop)
|
||||
end
|
||||
gui.Events.OnMouseMoved:Fire(x + dx, y + dy, 0, 0, istouch or false)
|
||||
end, true)
|
||||
|
||||
return simulate
|
||||
@ -47,7 +47,6 @@ function theme:random(seed, lightness, rand)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
t.seed = seed
|
||||
return t
|
||||
end
|
||||
|
||||
104
elements/init.lua
Normal file
104
elements/init.lua
Normal file
@ -0,0 +1,104 @@
|
||||
local gui = require("gui")
|
||||
local color = require("gui.core.color")
|
||||
local theme = require("gui.core.theme")
|
||||
local transition = require("gui.elements.transitions")
|
||||
local processor = gui:newProcessor("menu")
|
||||
|
||||
function gui:newMenu(title, sx, position, trans, callback, t,t2)
|
||||
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
|
||||
if callback then if not type(callback) == "function" then multi.error("Argument 5 function('callback(menu(self),align[left,center,right],transition_position)') must be a function") end end
|
||||
local t = t or .35
|
||||
local t2 = t2 or .25
|
||||
local position = position or gui.ALIGN_LEFT
|
||||
local trans = trans or transition.glide
|
||||
|
||||
local menu, to, tc, open
|
||||
if callback then
|
||||
menu = self:newFrame(0, 0, 0, 0, .5 -sx/2, 1, sx, 1)
|
||||
to = trans(1, 0, t)
|
||||
tc = trans(0, 1, t)
|
||||
else
|
||||
if position == gui.ALIGN_LEFT then
|
||||
menu = self:newFrame(0, 0, 0, 0, -sx, 0, sx, 1)
|
||||
to = trans(-sx, 0, t2)
|
||||
tc = trans(0, -sx, t2)
|
||||
elseif position == gui.ALIGN_CENTER then
|
||||
menu = self:newFrame(0, 0, 0, 0, .5 -sx/2, 1, sx, 1)
|
||||
to = trans(1, 0, t)
|
||||
tc = trans(0, 1, t)
|
||||
elseif position == gui.ALIGN_RIGHT then
|
||||
menu = self:newFrame(0, 0, 0, 0, 1, 0, sx, 1)
|
||||
to = trans(1, 1 - sx, t2)
|
||||
tc = trans(1 - sx, 1, t2)
|
||||
end
|
||||
end
|
||||
|
||||
function menu:isOpen()
|
||||
return open
|
||||
end
|
||||
|
||||
function menu:Open(show)
|
||||
if show then
|
||||
if not menu.lock then
|
||||
menu.visible = true
|
||||
menu.lock = true
|
||||
local t = to()
|
||||
t.OnStop(function()
|
||||
open = true
|
||||
menu.lock = false
|
||||
end)
|
||||
t.OnStep(function(p)
|
||||
if callback then
|
||||
callback(menu,position,p,"open")
|
||||
for i,v in pairs(menu:getAllChildren()) do
|
||||
callback(v,position,p,"open")
|
||||
end
|
||||
else
|
||||
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
|
||||
else
|
||||
if not menu.lock then
|
||||
menu.lock = true
|
||||
local t = tc()
|
||||
t.OnStop(function()
|
||||
open = false
|
||||
menu.lock = false
|
||||
menu.visible = false
|
||||
end)
|
||||
t.OnStep(function(p)
|
||||
if callback then
|
||||
callback(menu,position,p,"open")
|
||||
for i,v in pairs(menu:getAllChildren()) do
|
||||
callback(v,position,p,"open")
|
||||
end
|
||||
else
|
||||
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
|
||||
end
|
||||
|
||||
menu.OnCreate = processor:newConnection()
|
||||
local items = {}
|
||||
function menu:addItem(text)
|
||||
local item = menu:newTextButton(text,0,100*#items,0,100,0,0,1)
|
||||
items[#items+1] = item
|
||||
item:fitFont()
|
||||
item.align = gui.ALIGN_CENTER
|
||||
self.OnCreate:Fire(self,item,items)
|
||||
end
|
||||
|
||||
return menu
|
||||
end
|
||||
65
elements/transitions.lua
Normal file
65
elements/transitions.lua
Normal file
@ -0,0 +1,65 @@
|
||||
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()
|
||||
if not start or not 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, time or 1, unpack(args))
|
||||
return {
|
||||
OnStep = handle.OnStatus,
|
||||
OnStop = handle.OnReturn + handle.OnError
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function transition:newTransition(func)
|
||||
local c = {}
|
||||
setmetatable(c, self)
|
||||
|
||||
c.fps = fps
|
||||
c.func = processor:newFunction(func)
|
||||
c.OnStop = multi:newConnection()
|
||||
|
||||
function c:SetFPS(fps)
|
||||
self.fps = fps
|
||||
end
|
||||
|
||||
function c:GetFPS(fps)
|
||||
return self.fps
|
||||
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
|
||||
for i = 0, steps do
|
||||
thread.sleep(piece)
|
||||
thread.pushStatus(start + i*(split/steps))
|
||||
end
|
||||
end)
|
||||
|
||||
return transition
|
||||
Loading…
x
Reference in New Issue
Block a user