Initial commit
This commit is contained in:
Executable
+26
@@ -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
|
||||
Executable
+1660
File diff suppressed because it is too large
Load Diff
Executable
+91
@@ -0,0 +1,91 @@
|
||||
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)
|
||||
local event = xx.OnStop * yy.OnStop
|
||||
if not(dx==0 and dy == 0) then
|
||||
thread.hold(event)
|
||||
end
|
||||
gui.Events.OnMouseMoved:Fire(x + dx, y + dy, 0, 0, istouch or false)
|
||||
end, true)
|
||||
|
||||
return simulate
|
||||
Executable
+135
@@ -0,0 +1,135 @@
|
||||
local color = require("gui.core.color")
|
||||
local theme = {}
|
||||
local defaultFont = love.graphics.getFont()
|
||||
theme.__index = theme
|
||||
|
||||
local function generate_harmonious_colors(num_colors, lightness)
|
||||
local base_hue = math.random(0, 360) -- random starting hue
|
||||
local colors = {}
|
||||
for i = 1, num_colors do
|
||||
local new_hue = (base_hue + (360 / num_colors) * i) % 360 -- offset hue by 1/n of the color wheel
|
||||
if lightness == "dark" then
|
||||
table.insert(colors, color.new(color.hsl(new_hue, math.random(45, 55), math.random(30, 40))))
|
||||
elseif lightness == "light" then
|
||||
table.insert(colors, color.new(color.hsl(new_hue, math.random(45, 55), math.random(60, 80))))
|
||||
else
|
||||
table.insert(colors, color.new(color.hsl(new_hue, math.random(45, 55), math.random(30, 80))))
|
||||
end
|
||||
|
||||
end
|
||||
return colors
|
||||
end
|
||||
|
||||
function theme:random(seed, lightness, rand)
|
||||
local seed = seed or math.random(0,9999999999)
|
||||
math.randomseed(seed)
|
||||
local harmonious_colors = generate_harmonious_colors(3, lightness)
|
||||
local t = theme:new(unpack(harmonious_colors))
|
||||
|
||||
if lightness == "dark" then
|
||||
t.colorPrimaryText = color.lighten(t.colorPrimaryText, .8)
|
||||
t.colorButtonText = color.lighten(t.colorButtonText, .7)
|
||||
elseif lightness == "light" then
|
||||
t.colorPrimaryText = color.darken(t.colorPrimaryText, .8)
|
||||
t.colorButtonText = color.darken(t.colorButtonText, .7)
|
||||
else
|
||||
if color.getAverageLightness(t.colorPrimary)<.5 then
|
||||
t.colorPrimaryText = color.lighten(t.colorPrimaryText, .5)
|
||||
t.colorButtonNormal = color.lighten(t.colorButtonNormal, .2)
|
||||
else
|
||||
t.colorPrimaryText = color.darken(t.colorPrimaryText, .3)
|
||||
end
|
||||
|
||||
if color.getAverageLightness(t.colorPrimary)<.5 then
|
||||
t.colorButtonText = color.lighten(t.colorButtonText, .5)
|
||||
else
|
||||
t.colorButtonText = color.darken(t.colorButtonText, .3)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
t.seed = seed
|
||||
return t
|
||||
end
|
||||
|
||||
function theme:dump()
|
||||
return '"' .. table.concat({color.rgbToHex(self.colorPrimary), color.rgbToHex(self.colorPrimaryText), color.rgbToHex(self.colorButtonText)},"\",\"") .. '"'
|
||||
end
|
||||
|
||||
local function newColor(c,default)
|
||||
if not c then
|
||||
return default
|
||||
end
|
||||
return color.new(c)
|
||||
end
|
||||
|
||||
function theme:new(colorPrimary, primaryText, buttonText, buttonNormal, primaryTextFont, buttonTextFont)
|
||||
local c = {}
|
||||
setmetatable(c, theme)
|
||||
|
||||
if type(colorPrimary) == "table" then
|
||||
local opts = colorPrimary
|
||||
c.colorPrimary = newColor(opts.primary)
|
||||
c.colorPrimaryDark = newColor(opts.primaryDark, color.darken(c.colorPrimary,.4))
|
||||
c.colorPrimaryText = newColor(opts.primaryText)
|
||||
c.colorButtonNormal = newColor(opts.buttonNormal, color.darken(c.colorPrimary,.2))
|
||||
c.colorButtonHighlight = newColor(opts.buttonHighlight, color.lighten(c.colorPrimary,.2))
|
||||
c.colorButtonText = newColor(opts.buttonText, c.colorPrimaryText)
|
||||
c.fontPrimary = opts.textFont or defaultFont
|
||||
c.fontButton = opts.buttonTextFont or defaultFont
|
||||
for i,v in pairs(colorPrimary) do
|
||||
if not c[i] then
|
||||
c[i] = v -- only overwrite non managed fields
|
||||
end
|
||||
end
|
||||
return c
|
||||
end
|
||||
|
||||
c.colorPrimary = color.new(colorPrimary)
|
||||
c.colorPrimaryDark = color.darken(c.colorPrimary,.4)
|
||||
c.colorPrimaryText = color.new(primaryText)
|
||||
c.colorButtonNormal = newColor(buttonNormal) or color.darken(c.colorPrimary,.2)
|
||||
c.colorButtonHighlight = color.lighten(c.colorButtonNormal,.2)
|
||||
c.colorButtonText = color.new(buttonText)
|
||||
c.fontPrimary = primaryTextFont or defaultFont
|
||||
c.fontButton = buttonTextFont or defaultFont
|
||||
return c
|
||||
end
|
||||
|
||||
function theme:setColorPrimary(c)
|
||||
self.colorPrimary = color.new(c)
|
||||
end
|
||||
|
||||
function theme:setColorPrimaryDark(c)
|
||||
self.colorPrimaryDark = color.new(c)
|
||||
end
|
||||
|
||||
function theme:setColorPrimaryText(c)
|
||||
self.colorPrimaryText = color.new(c)
|
||||
end
|
||||
|
||||
function theme:setColorButtonNormal(c)
|
||||
self.colorButtonNormal = color.new(c)
|
||||
end
|
||||
|
||||
function theme:setColorButtonHighlight(c)
|
||||
self.colorButtonHighlight = color.new(c)
|
||||
end
|
||||
|
||||
function theme:setColorButtonText(c)
|
||||
self.colorButtonText = color.new(c)
|
||||
end
|
||||
|
||||
function theme:setFontPrimary(c)
|
||||
self.fontPrimary = c
|
||||
end
|
||||
|
||||
function theme:setFontButton(c)
|
||||
self.fontButton = c
|
||||
end
|
||||
|
||||
function theme:getSeed()
|
||||
return self.seed
|
||||
end
|
||||
|
||||
return theme
|
||||
Reference in New Issue
Block a user