added bigfonts api for labels

Added bigfonts to labels
just use :setFontSize(number) (1,2, 3 or 4)
This commit is contained in:
Robert Jelic
2022-05-29 16:22:28 +02:00
parent 1f97eeacd1
commit 7871d7205c
7 changed files with 4837 additions and 13 deletions

View File

@@ -4,12 +4,15 @@ local function Label(name)
local objectType = "Label"
base:setZIndex(3)
base.fgColor = colors.white
base.bgcolor = colors.black
local autoWidth = true
base:setValue("")
local textHorizontalAlign = "left"
local textVerticalAlign = "top"
local fontsize = 0
local object = {
getType = function(self)
@@ -31,6 +34,17 @@ local function Label(name)
return self
end;
setFontSize = function(self, size)
if(size>0)and(size<=4)then
fontsize = size-1 or 0
end
return self
end;
getFontSize = function(self)
return fontsize+1
end;
setSize = function(self, width, height)
base.setSize(self, width, height)
autoWidth = false
@@ -46,9 +60,27 @@ local function Label(name)
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
self.parent:drawForegroundBox(obx, oby, self.width, self.height, self.fgColor)
self.parent:drawTextBox(obx, oby, self.width, self.height, " ")
for n = 1, self.height do
if (n == verticalAlign) then
self.parent:writeText(obx, oby + (n - 1), getTextHorizontalAlign(self:getValue(), self.width, textHorizontalAlign), self.bgColor, self.fgColor)
if(fontsize==0)then
for n = 1, self.height do
if (n == verticalAlign) then
self.parent:writeText(obx, oby + (n - 1), getTextHorizontalAlign(self:getValue(), self.width, textHorizontalAlign), self.bgColor, self.fgColor)
end
end
else
local tData = makeText(fontsize, self:getValue(), self.fgColor, self.bgColor)
for n = 1, self.height do
if (n == verticalAlign) then
local oX, oY = self.parent:getSize()
local cX, cY = #tData[1][1], #tData[1]
obx = obx or math.floor((oX - cX) / 2) + 1
oby = oby or math.floor((oY - cY) / 2) + 1
for i = 1, cY do
self.parent:setFG(obx, oby + i + n - 2, getTextHorizontalAlign(tData[2][i], self.width, textHorizontalAlign))
self.parent:setBG(obx, oby + i + n - 2, getTextHorizontalAlign(tData[3][i], self.width, textHorizontalAlign, tHex[self.bgColor]))
self.parent:setText(obx, oby + i + n - 2, getTextHorizontalAlign(tData[1][i], self.width, textHorizontalAlign))
end
end
end
end
end