Experimenting with themes
This commit is contained in:
parent
d1b3ffb39a
commit
da62ef0af8
@ -1,17 +1,3 @@
|
|||||||
local function HSL(h, s, l, a)
|
|
||||||
if s<=0 then return l,l,l,a end
|
|
||||||
h, s, l = h/256*6, s/255, l/255
|
|
||||||
local c = (1-math.abs(2*l-1))*s
|
|
||||||
local x = (1-math.abs(h%2-1))*c
|
|
||||||
local m,r,b,g = (l-.5*c), 0,0,0
|
|
||||||
if h < 1 then r,b,g = c,x,0
|
|
||||||
elseif h < 2 then r,b,g = x,c,0
|
|
||||||
elseif h < 3 then r,b,g = 0,c,x
|
|
||||||
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,a
|
|
||||||
end
|
|
||||||
local color={}
|
local color={}
|
||||||
local mt = {
|
local mt = {
|
||||||
__add = function (c1,c2)
|
__add = function (c1,c2)
|
||||||
@ -49,7 +35,27 @@ local mt = {
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function color.hsl(h, s, l)
|
||||||
|
if s<=0 then return l,l,l end
|
||||||
|
h, s, l = h/256*6, s/255, l/255
|
||||||
|
local c = (1-math.abs(2*l-1))*s
|
||||||
|
local x = (1-math.abs(h%2-1))*c
|
||||||
|
local m,r,b,g = (l-.5*c), 0,0,0
|
||||||
|
if h < 1 then r,b,g = c,x,0
|
||||||
|
elseif h < 2 then r,b,g = x,c,0
|
||||||
|
elseif h < 3 then r,b,g = 0,c,x
|
||||||
|
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
|
||||||
|
|
||||||
function color.new(r, b, g, fmt)
|
function color.new(r, b, g, fmt)
|
||||||
|
if type(r) == "string" then
|
||||||
|
r, b, g = tonumber(string.sub(r,1,2),16),tonumber(string.sub(r,3,4),16),tonumber(string.sub(r,5,6),16)
|
||||||
|
elseif type(r) == "table" then
|
||||||
|
return r
|
||||||
|
end
|
||||||
local temp
|
local temp
|
||||||
if fmt then
|
if fmt then
|
||||||
temp = {r,b,g}
|
temp = {r,b,g}
|
||||||
|
|||||||
16
gui/init.lua
16
gui/init.lua
@ -124,7 +124,7 @@ updater:newThread("GUI Hotkey Manager",function()
|
|||||||
end
|
end
|
||||||
thread.sleep(.001)
|
thread.sleep(.001)
|
||||||
end
|
end
|
||||||
end).OnError(print)
|
end)
|
||||||
|
|
||||||
function gui:SetHotKey(keys, conn)
|
function gui:SetHotKey(keys, conn)
|
||||||
has_hotkey = true
|
has_hotkey = true
|
||||||
@ -328,7 +328,7 @@ function gui:isBeingCovered(mx,my)
|
|||||||
for i = #children, 1, -1 do
|
for i = #children, 1, -1 do
|
||||||
if children[i] == self then
|
if children[i] == self then
|
||||||
return false
|
return false
|
||||||
elseif children[i]:canPress(mx,my) and not(children[i] == self) then
|
elseif children[i]:canPress(mx,my) and not(children[i] == self) and not(children[i].ignore) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -348,8 +348,10 @@ function gui:setParent(parent)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.insert(parent.children, self)
|
if parent then
|
||||||
self.parent = parent
|
table.insert(parent.children, self)
|
||||||
|
self.parent = parent
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function processDo(ref)
|
local function processDo(ref)
|
||||||
@ -710,7 +712,8 @@ function gui:newTextBase(typ, txt, x, y, w, h, sx, sy, sw, sh)
|
|||||||
return love.graphics.newFont(n)
|
return love.graphics.newFont(n)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local Font,width,height,text=self.Font,self.dualDim.offset.size.x,self.dualDim.offset.size.y,self.text
|
local x, y, width, height = self:getAbsolutes()
|
||||||
|
local Font, text = self.Font, self.text
|
||||||
local s = 3
|
local s = 3
|
||||||
Font = font(s)
|
Font = font(s)
|
||||||
while Font:getHeight()<height and Font:getWidth(text)<width do
|
while Font:getHeight()<height and Font:getWidth(text)<width do
|
||||||
@ -1005,7 +1008,7 @@ function gui:newImageBase(typ,x, y, w, h, sx, sy, sw, sh)
|
|||||||
self.imageHeigth = img:getHeight()
|
self.imageHeigth = img:getHeight()
|
||||||
self.imageWidth = img:getWidth()
|
self.imageWidth = img:getWidth()
|
||||||
self.quad = love.graphics.newQuad(0, 0, w, h, self.imageWidth, self.imageHeigth)
|
self.quad = love.graphics.newQuad(0, 0, w, h, self.imageWidth, self.imageHeigth)
|
||||||
end).OnError(print)
|
end)
|
||||||
end
|
end
|
||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
@ -1251,6 +1254,7 @@ gui.virtual.children = {}
|
|||||||
gui.virtual.dualDim = gui:newDualDim()
|
gui.virtual.dualDim = gui:newDualDim()
|
||||||
gui.virtual.x = 0
|
gui.virtual.x = 0
|
||||||
gui.virtual.y = 0
|
gui.virtual.y = 0
|
||||||
|
setmetatable(gui.virtual, gui)
|
||||||
|
|
||||||
local w, h = love.graphics.getDimensions()
|
local w, h = love.graphics.getDimensions()
|
||||||
gui.virtual.dualDim.offset.size.x = w
|
gui.virtual.dualDim.offset.size.x = w
|
||||||
|
|||||||
70
gui/theme.lua
Normal file
70
gui/theme.lua
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
local color = require("gui.color")
|
||||||
|
local theme = {}
|
||||||
|
local defaultFont = love.graphics.getFont()
|
||||||
|
theme.__index = theme
|
||||||
|
|
||||||
|
local function generate_harmonious_colors(num_colors)
|
||||||
|
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
|
||||||
|
table.insert(colors, color.new(color.hsl(new_hue, math.random(50, 100), math.random(20, 70))))
|
||||||
|
end
|
||||||
|
return colors
|
||||||
|
end
|
||||||
|
|
||||||
|
function theme:random()
|
||||||
|
local harmonious_colors = generate_harmonious_colors(5)
|
||||||
|
return theme:new(unpack(harmonious_colors))
|
||||||
|
end
|
||||||
|
|
||||||
|
function theme:new(colorPrimary, primaryText, buttonNormal, buttonHighlight,
|
||||||
|
buttonText, primaryTextFont, buttonTextFont)
|
||||||
|
local c = {}
|
||||||
|
setmetatable(c, theme)
|
||||||
|
c.colorPrimary = color.new(colorPrimary)
|
||||||
|
c.colorPrimaryDark = color.darken(c.colorPrimary,.4)
|
||||||
|
c.colorPrimaryText = color.new(primaryText)
|
||||||
|
c.colorButtonNormal = color.new(buttonNormal)
|
||||||
|
c.colorButtonHighlight = color.new(buttonHighlight)
|
||||||
|
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 = color.new(c)
|
||||||
|
end
|
||||||
|
|
||||||
|
function theme:setFontButton(c)
|
||||||
|
self.fontButton = color.new(c)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return theme
|
||||||
Loading…
x
Reference in New Issue
Block a user