diff --git a/.gitignore b/.gitignore index 48a3818..52ffdca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *multi main.lua -conf.lua \ No newline at end of file +conf.lua +*.ttf \ No newline at end of file diff --git a/gui/init.lua b/gui/init.lua index 235e7f9..7a8b87f 100644 --- a/gui/init.lua +++ b/gui/init.lua @@ -1,10 +1,12 @@ local multi,thread = require("multi"):init() local GLOBAL, THREAD = require("multi.integration.loveManager"):init() +local color = require("gui.color") local gui = {} local updater = multi:newProcessor("UpdateManager",true) local drawer = multi:newProcessor("DrawManager",true) local bit = require("bit") local band, bor = bit.band, bit.bor +local floor, ceil = math.floor,math.ceil gui.__index = gui gui.MOUSE_PRIMARY = 1 gui.MOUSE_SECONDARY = 2 @@ -13,14 +15,14 @@ gui.MOUSE_MIDDLE = 3 local frame, label, image, text, button, box, video = 0, 1, 2, 4, 8, 16, 32 function gui:getChildren() - return self.Children + return self.children end function gui:getAllChildren() local Stuff = {} function Seek(Items) for i=1,#Items do - if Items[i].Visible==true then + if Items[i].visible==true then table.insert(Stuff,Items[i]) local NItems = Items[i]:getChildren() if NItems ~= nil then @@ -31,7 +33,7 @@ function gui:getAllChildren() end local Objs = self:getChildren() for i=1,#Objs do - if Objs[i].Visible==true then + if Objs[i].visible==true then table.insert(Stuff,Objs[i]) local Items = Objs[i]:getChildren() if Items ~= nil then @@ -45,18 +47,17 @@ end -- Base Library function gui:newBase(typ,x, y, w, h, sx, sy, sw, sh) local c = {} - c.Parent = self - c.Type = typ + c.parent = self + c.type = typ c.dualDim = self:newDualDim(x, y, w, h, sx, sy, sw, sh) - c.Children = {} - c.Visible = true - c.Visibility = 1 - c.Color = {.6,.6,.6} - c.BorderColor = {0,0,0} + c.children = {} + c.visible = true + c.visibility = 1 + c.color = {.6,.6,.6} + c.borderColor = color.black setmetatable(c, gui) - -- Add to the parents children table - table.insert(self.Children,c) + table.insert(self.children,c) return c end @@ -94,7 +95,84 @@ end 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) c.text = txt - + c.align = "center" + c.radians = 0 + c.textScaleX = 1 + c.textScaleY = 1 + c.textOffsetX = 0 + c.textOffsetY = 0 + c.textShearingFactorX = 0 + c.textShearingFactorY = 0 + c.textVisibility = 1 + c.font = love.graphics.newFont(12) + c.textColor = color.black + c.OnFontUpdated = multi:newConnection() + function c:calculateFontOffset() + local width, height = floor(w+w/4), floor(h+h/4) + local canvas = love.graphics.newCanvas(width, height) + local top = height + local bottom = 0 + love.graphics.setCanvas(canvas) + love.graphics.setColor(1,1,1,1) + love.graphics.setFont(self.font) + love.graphics.printf(self.text, 0, 0, self.dualDim.offset.size.x, "left", self.radians, self.textScaleX, self.textScaleY, 0, 0, self.textShearingFactorX, self.textShearingFactorY) + love.graphics.setCanvas() + local data = canvas:newImageData(nil, nil, 0, 0, width, height ) + for x = 0, width-1 do + for y = 0, height-1 do + local r,g,b,a = data:getPixel(x,y) + if r==1 and g==1 and b==1 then + if ybottom then bottom = y end + end + end + end + return top, bottom + end + function c:setFont(font,size) + if type(font)=="string" then + self.fontFile = font + self.font = love.graphics.newFont(font, size) + else + self.font = font + end + self.OnFontUpdated:Fire(self) + end + function c:fitFont(n) + local font + if self.fontFile then + if self.fontFile:match("ttf") then + font = function(n) + return love.graphics.newFont(self.fontFile, n, "normal") + end + else + font = function(n) + return love.graphics.newFont(self.fontFile, n) + end + end + else + font = function(n) + 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 s = 3 + Font = font(s) + while Font:getHeight()