From da62ef0af87dee5e42a819424fa8195d4fd1aa07 Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Thu, 12 Jan 2023 00:29:42 -0500 Subject: [PATCH] Experimenting with themes --- gui/color.lua | 34 ++++++++++++++----------- gui/init.lua | 16 +++++++----- gui/theme.lua | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 20 deletions(-) create mode 100644 gui/theme.lua diff --git a/gui/color.lua b/gui/color.lua index e664cc3..dbad5d1 100644 --- a/gui/color.lua +++ b/gui/color.lua @@ -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 mt = { __add = function (c1,c2) @@ -49,7 +35,27 @@ local mt = { 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) + 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 if fmt then temp = {r,b,g} diff --git a/gui/init.lua b/gui/init.lua index 8fe0033..829c97a 100644 --- a/gui/init.lua +++ b/gui/init.lua @@ -124,7 +124,7 @@ updater:newThread("GUI Hotkey Manager",function() end thread.sleep(.001) end -end).OnError(print) +end) function gui:SetHotKey(keys, conn) has_hotkey = true @@ -328,7 +328,7 @@ function gui:isBeingCovered(mx,my) for i = #children, 1, -1 do if children[i] == self then 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 end end @@ -348,8 +348,10 @@ function gui:setParent(parent) break end end - table.insert(parent.children, self) - self.parent = parent + if parent then + table.insert(parent.children, self) + self.parent = parent + end end 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) 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 Font = font(s) while Font:getHeight()