Reworking fitfont
This commit is contained in:
parent
6b0a2d074e
commit
3111907efc
0
gui/addons/functions.lua
Normal file
0
gui/addons/functions.lua
Normal file
0
gui/addons/system.lua
Normal file
0
gui/addons/system.lua
Normal file
@ -1,4 +1,4 @@
|
|||||||
local color = require("gui.color")
|
local color = require("gui.core.color")
|
||||||
local theme = {}
|
local theme = {}
|
||||||
local defaultFont = love.graphics.getFont()
|
local defaultFont = love.graphics.getFont()
|
||||||
theme.__index = theme
|
theme.__index = theme
|
||||||
@ -8,7 +8,7 @@ local function generate_harmonious_colors(num_colors)
|
|||||||
local colors = {}
|
local colors = {}
|
||||||
for i = 1, num_colors do
|
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
|
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(30, 80))))
|
table.insert(colors, color.new(color.hsl(new_hue, math.random(45, 110), math.random(30, 80))))
|
||||||
end
|
end
|
||||||
return colors
|
return colors
|
||||||
end
|
end
|
||||||
@ -33,8 +33,6 @@ function theme:random(seed)
|
|||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function theme:dump()
|
function theme:dump()
|
||||||
return '"' .. table.concat({color.rgbToHex(self.colorPrimary), color.rgbToHex(self.colorPrimaryText), color.rgbToHex(self.colorButtonText)},"\",\"") .. '"'
|
return '"' .. table.concat({color.rgbToHex(self.colorPrimary), color.rgbToHex(self.colorPrimaryText), color.rgbToHex(self.colorButtonText)},"\",\"") .. '"'
|
||||||
end
|
end
|
||||||
@ -45,7 +43,7 @@ function theme:new(colorPrimary, primaryText, buttonText, primaryTextFont, butto
|
|||||||
c.colorPrimary = color.new(colorPrimary)
|
c.colorPrimary = color.new(colorPrimary)
|
||||||
c.colorPrimaryDark = color.darken(c.colorPrimary,.4)
|
c.colorPrimaryDark = color.darken(c.colorPrimary,.4)
|
||||||
c.colorPrimaryText = color.new(primaryText)
|
c.colorPrimaryText = color.new(primaryText)
|
||||||
c.colorButtonNormal = color.darken(c.colorPrimary,.6)
|
c.colorButtonNormal = color.darken(c.colorPrimary,.2)
|
||||||
c.colorButtonHighlight = color.darken(c.colorButtonNormal,.2)
|
c.colorButtonHighlight = color.darken(c.colorButtonNormal,.2)
|
||||||
c.colorButtonText = color.new(buttonText)
|
c.colorButtonText = color.new(buttonText)
|
||||||
c.fontPrimary = primaryTextFont or defaultFont
|
c.fontPrimary = primaryTextFont or defaultFont
|
||||||
@ -78,11 +76,11 @@ function theme:setColorButtonText(c)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function theme:setFontPrimary(c)
|
function theme:setFontPrimary(c)
|
||||||
self.fontPrimary = color.new(c)
|
self.fontPrimary = c
|
||||||
end
|
end
|
||||||
|
|
||||||
function theme:setFontButton(c)
|
function theme:setFontButton(c)
|
||||||
self.fontButton = color.new(c)
|
self.fontButton = c
|
||||||
end
|
end
|
||||||
|
|
||||||
function theme:getSeed()
|
function theme:getSeed()
|
||||||
117
gui/init.lua
117
gui/init.lua
@ -1,7 +1,7 @@
|
|||||||
local utf8 = require("utf8")
|
local utf8 = require("utf8")
|
||||||
local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
local GLOBAL, THREAD = require("multi.integration.loveManager"):init()
|
local GLOBAL, THREAD = require("multi.integration.loveManager"):init()
|
||||||
local color = require("gui.color")
|
local color = require("gui.core.color")
|
||||||
local gui = {}
|
local gui = {}
|
||||||
local updater = multi:newProcessor("UpdateManager",true)
|
local updater = multi:newProcessor("UpdateManager",true)
|
||||||
local drawer = multi:newProcessor("DrawManager",true)
|
local drawer = multi:newProcessor("DrawManager",true)
|
||||||
@ -13,6 +13,7 @@ local max, min, abs, rad, floor, ceil = math.max, math.min, math.abs, math.rad,
|
|||||||
local frame, image, text, box, video, button, anim = 0, 1, 2, 4, 8, 16, 32
|
local frame, image, text, box, video, button, anim = 0, 1, 2, 4, 8, 16, 32
|
||||||
local global_drag
|
local global_drag
|
||||||
local object_focus = gui
|
local object_focus = gui
|
||||||
|
local first_loop = false
|
||||||
|
|
||||||
-- Types
|
-- Types
|
||||||
gui.TYPE_FRAME = frame
|
gui.TYPE_FRAME = frame
|
||||||
@ -656,7 +657,7 @@ end
|
|||||||
function gui:newVirtualFrame(x, y, w, h, sx, sy, sw, sh)
|
function gui:newVirtualFrame(x, y, w, h, sx, sy, sw, sh)
|
||||||
return self:newBase(frame, x, y, w, h, sx, sy, sw, sh, true)
|
return self:newBase(frame, x, y, w, h, sx, sy, sw, sh, true)
|
||||||
end
|
end
|
||||||
|
local testIMG
|
||||||
-- Texts
|
-- Texts
|
||||||
function gui:newTextBase(typ, txt, x, y, w, h, sx, sy, sw, sh)
|
function gui:newTextBase(typ, txt, x, y, w, h, sx, sy, sw, sh)
|
||||||
local c = self:newBase(text + typ, x, y, w, h, sx, sy, sw, sh)
|
local c = self:newBase(text + typ, x, y, w, h, sx, sy, sw, sh)
|
||||||
@ -674,27 +675,38 @@ function gui:newTextBase(typ, txt, x, y, w, h, sx, sy, sw, sh)
|
|||||||
c.textColor = color.black
|
c.textColor = color.black
|
||||||
c.OnFontUpdated = multi:newConnection()
|
c.OnFontUpdated = multi:newConnection()
|
||||||
|
|
||||||
function c:calculateFontOffset()
|
function c:calculateFontOffset(font)
|
||||||
local width, height = floor(w+w/4), floor(h+h/4)
|
local x, y, width, height = self:getAbsolutes()
|
||||||
local canvas = love.graphics.newCanvas(width, height)
|
local top = height+10
|
||||||
local top = height
|
|
||||||
local bottom = 0
|
local bottom = 0
|
||||||
|
local canvas = love.graphics.newCanvas(width, height+10)
|
||||||
love.graphics.setCanvas(canvas)
|
love.graphics.setCanvas(canvas)
|
||||||
|
love.graphics.clear( 0, 0, 0, .5, false, false)
|
||||||
love.graphics.setColor(1,1,1,1)
|
love.graphics.setColor(1,1,1,1)
|
||||||
love.graphics.setFont(self.font)
|
love.graphics.setFont(font)
|
||||||
love.graphics.printf(self.text, 0, h/8, self.dualDim.offset.size.x, "left", self.radians, self.textScaleX, self.textScaleY, 0, 0, self.textShearingFactorX, self.textShearingFactorY)
|
love.graphics.printf(self.text, 0, 5, width, "left", self.rotation, self.textScaleX, self.textScaleY, 0, 0, self.textShearingFactorX, self.textShearingFactorY)
|
||||||
love.graphics.setCanvas()
|
love.graphics.setCanvas()
|
||||||
local data = canvas:newImageData(nil, nil, 0, 0, width, height )
|
local data = canvas:newImageData()
|
||||||
for x = 0, width-1 do
|
testIMG:setDualDim(0, 0, width, height)
|
||||||
for y = 0, height-1 do
|
testIMG:setImage(data)
|
||||||
local r,g,b,a = data:getPixel(x,y)
|
local f_top, f_bot = false, false
|
||||||
if r==1 and g==1 and b==1 then
|
for yy = 0, height-1 do
|
||||||
if y<top then top = y end
|
for xx = 0, width-1 do
|
||||||
if y>bottom then bottom = y end
|
local r,g,b,a = data:getPixel(xx,yy)
|
||||||
|
if r~=0 or g~=0 or b~=0 then
|
||||||
|
if yy<top and not f_top then top = yy f_top = true end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return top-h/8, bottom-h/8
|
for yy = height-1, 0, -1 do
|
||||||
|
for xx = 0, width-1 do
|
||||||
|
local r,g,b,a = data:getPixel(xx,yy)
|
||||||
|
if r~=0 or g~=0 or b~=0 then
|
||||||
|
if yy>bottom and not f_bot then bottom = yy f_bot = false end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return top-10, bottom-10
|
||||||
end
|
end
|
||||||
|
|
||||||
function c:setFont(font,size)
|
function c:setFont(font,size)
|
||||||
@ -721,7 +733,7 @@ function gui:newTextBase(typ, txt, x, y, w, h, sx, sy, sw, sh)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
font = function(n)
|
font = function(n)
|
||||||
return love.graphics.newFont(n)
|
return love.graphics.setNewFont(n)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local x, y, width, height = self:getAbsolutes()
|
local x, y, width, height = self:getAbsolutes()
|
||||||
@ -735,9 +747,16 @@ function gui:newTextBase(typ, txt, x, y, w, h, sx, sy, sw, sh)
|
|||||||
Font = font(s - (2+(n or 0)))
|
Font = font(s - (2+(n or 0)))
|
||||||
Font:setFilter("linear","nearest",4)
|
Font:setFilter("linear","nearest",4)
|
||||||
self.font = Font
|
self.font = Font
|
||||||
local h = (self.parent.dualDim.offset.size.y*self.dualDim.scale.size.y)+self.dualDim.offset.size.y
|
local top, bottom = self:calculateFontOffset(Font)
|
||||||
local top, bottom = self:calculateFontOffset()
|
local fh = Font:getHeight()
|
||||||
self.textOffsetY = (h-bottom-top/2)/2
|
local ch = floor((height - fh)/2)
|
||||||
|
local cch = height - (bottom + top)
|
||||||
|
--if cch < ch then
|
||||||
|
self.textOffsetY = cch/2
|
||||||
|
--else
|
||||||
|
-- self.textOffsetY = ch
|
||||||
|
--end
|
||||||
|
print(self.text, top, bottom, self.textOffsetY, height - (bottom + top))
|
||||||
self.OnFontUpdated:Fire(self)
|
self.OnFontUpdated:Fire(self)
|
||||||
return s - (2+(n or 0))
|
return s - (2+(n or 0))
|
||||||
end
|
end
|
||||||
@ -994,7 +1013,7 @@ end)
|
|||||||
function gui:newImageBase(typ,x, y, w, h, sx, sy, sw, sh)
|
function gui:newImageBase(typ,x, y, w, h, sx, sy, sw, sh)
|
||||||
local c = self:newBase(image + typ,x, y, w, h, sx, sy, sw, sh)
|
local c = self:newBase(image + typ,x, y, w, h, sx, sy, sw, sh)
|
||||||
c.color = color.white
|
c.color = color.white
|
||||||
c.visibility = 0
|
--c.visibility = 0
|
||||||
local IMAGE
|
local IMAGE
|
||||||
function c:getUniques()
|
function c:getUniques()
|
||||||
return gui.getUniques(c, {
|
return gui.getUniques(c, {
|
||||||
@ -1003,23 +1022,43 @@ function gui:newImageBase(typ,x, y, w, h, sx, sy, sw, sh)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
function c:setImage(i)
|
function c:setImage(i)
|
||||||
|
if i == nil then return end
|
||||||
IMAGE = i
|
IMAGE = i
|
||||||
drawer:newThread(function()
|
if not first_loop then
|
||||||
thread.yield()
|
-- Wait one cycle for things to load up
|
||||||
local img
|
drawer:newThread(function()
|
||||||
if type(i) == "userdata" and i:type() == "Image" then
|
thread.yield()
|
||||||
img = i
|
local img
|
||||||
elseif type(i) == "string" then
|
if type(i) == "userdata" and i:type() == "Image" then
|
||||||
img = love.graphics.newImage(i)
|
img = i
|
||||||
end
|
elseif type(i) == "userdata" and i:type() == "ImageData" then
|
||||||
local x, y, w, h = self:getAbsolutes()
|
img = love.graphics.newImage(i)
|
||||||
self.imageColor = color.white
|
else
|
||||||
self.imageVisibility = 1
|
img = love.graphics.newImage(i)
|
||||||
self.image = img
|
end
|
||||||
self.imageHeigth = img:getHeight()
|
local x, y, w, h = self:getAbsolutes()
|
||||||
self.imageWidth = img:getWidth()
|
self.imageColor = color.white
|
||||||
self.quad = love.graphics.newQuad(0, 0, w, h, self.imageWidth, self.imageHeigth)
|
self.imageVisibility = 1
|
||||||
end)
|
self.image = img
|
||||||
|
self.imageHeigth = img:getHeight()
|
||||||
|
self.imageWidth = img:getWidth()
|
||||||
|
self.quad = love.graphics.newQuad(0, 0, w, h, self.imageWidth, self.imageHeigth)
|
||||||
|
end)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local img
|
||||||
|
if type(i) == "userdata" and i:type() == "Image" then
|
||||||
|
img = i
|
||||||
|
else
|
||||||
|
img = love.graphics.newImage(i)
|
||||||
|
end
|
||||||
|
local x, y, w, h = self:getAbsolutes()
|
||||||
|
self.imageColor = color.white
|
||||||
|
self.imageVisibility = 1
|
||||||
|
self.image = img
|
||||||
|
self.imageHeigth = img:getHeight()
|
||||||
|
self.imageWidth = img:getWidth()
|
||||||
|
self.quad = love.graphics.newQuad(0, 0, w, h, self.imageWidth, self.imageHeigth)
|
||||||
end
|
end
|
||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
@ -1253,6 +1292,7 @@ drawer:newLoop(function()
|
|||||||
draw_handler(child)
|
draw_handler(child)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
first_loop = true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Drawing and Updating
|
-- Drawing and Updating
|
||||||
@ -1293,4 +1333,7 @@ gui.Events.OnResized(function(w,h)
|
|||||||
gui.h = h
|
gui.h = h
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
testIMG = gui:newImageLabel(nil,0,0,100,30)
|
||||||
|
testIMG.color = color.Red
|
||||||
|
|
||||||
return gui
|
return gui
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user