added new features
-remade animation -added xml support -finished dynamic values -added new object: graphic -added themes for frames -textfield got some basic improvements to create coding editors
This commit is contained in:
340
Basalt/Frame.lua
340
Basalt/Frame.lua
@@ -2,11 +2,13 @@ local Object = require("Object")
|
||||
local _OBJECTS = require("loadObjects")
|
||||
|
||||
local BasaltDraw = require("basaltDraw")
|
||||
local theme = require("theme")
|
||||
local utils = require("utils")
|
||||
local layout = require("layout")
|
||||
local uuid = utils.uuid
|
||||
local rpairs = utils.rpairs
|
||||
local xmlValue = utils.getValueFromXML
|
||||
|
||||
local sub = string.sub
|
||||
local sub,min,max = string.sub,math.min,math.max
|
||||
|
||||
return function(name, parent, pTerm, basalt)
|
||||
-- Frame
|
||||
@@ -15,6 +17,8 @@ return function(name, parent, pTerm, basalt)
|
||||
local objects = {}
|
||||
local objZIndex = {}
|
||||
local object = {}
|
||||
local variables = {}
|
||||
local theme = {}
|
||||
local termObject = pTerm or term.current()
|
||||
|
||||
local monSide = ""
|
||||
@@ -22,6 +26,13 @@ return function(name, parent, pTerm, basalt)
|
||||
local monitorAttached = false
|
||||
local dragXOffset = 0
|
||||
local dragYOffset = 0
|
||||
local isScrollable = false
|
||||
local minScroll = 0
|
||||
local maxScroll = 10
|
||||
local mirrorActive = false
|
||||
local mirrorAttached = false
|
||||
local mirrorSide = ""
|
||||
local importantScroll = false
|
||||
|
||||
base:setZIndex(10)
|
||||
|
||||
@@ -34,22 +45,80 @@ return function(name, parent, pTerm, basalt)
|
||||
|
||||
local xOffset, yOffset = 0, 0
|
||||
|
||||
local lastXMLReferences = {}
|
||||
|
||||
local function xmlDefaultValues(data, obj)
|
||||
if(obj~=nil)then
|
||||
obj:setValuesByXMLData(data)
|
||||
end
|
||||
end
|
||||
|
||||
local function addXMLObjectType(tab, f, self)
|
||||
if(tab~=nil)then
|
||||
if(tab.properties~=nil)then tab = {tab} end
|
||||
|
||||
for k,v in pairs(tab)do
|
||||
local obj = f(self, v["@id"] or uuid())
|
||||
table.insert(lastXMLReferences, obj)
|
||||
xmlDefaultValues(v, obj)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function duplicateTerm(term1, term2)
|
||||
local both = {}
|
||||
setmetatable(both, {
|
||||
__index = function(_, k)
|
||||
if (type(term1[k]) == "function") then
|
||||
return function(...)
|
||||
pcall(term1[k], ...)
|
||||
return term2[k](...)
|
||||
end
|
||||
else
|
||||
return term1[k]
|
||||
end
|
||||
end,
|
||||
__call = function(_, f, ...)
|
||||
pcall(term2[f], ...)
|
||||
return term1[f](...)
|
||||
end,
|
||||
__newindex = function(_, k, v)
|
||||
term1[k] = v
|
||||
term2[k] = v
|
||||
end
|
||||
})
|
||||
return both
|
||||
end
|
||||
|
||||
if (parent ~= nil) then
|
||||
base.parent = parent
|
||||
base.width, base.height = parent:getSize()
|
||||
base.bgColor = theme.FrameBG
|
||||
base.fgColor = theme.FrameFG
|
||||
base.bgColor = parent:getTheme("FrameBG")
|
||||
base.fgColor = parent:getTheme("FrameText")
|
||||
print(parent:getTheme("FrameBG"))
|
||||
else
|
||||
base.width, base.height = termObject.getSize()
|
||||
base.bgColor = theme.basaltBG
|
||||
base.fgColor = theme.basaltFG
|
||||
base.bgColor = basalt.getTheme("BasaltBG")
|
||||
base.fgColor = basalt.getTheme("BasaltText")
|
||||
end
|
||||
|
||||
local function getObject(name)
|
||||
for _, value in pairs(objects) do
|
||||
for _, b in pairs(value) do
|
||||
if (b.name == name) then
|
||||
return value
|
||||
if (b:getName() == name) then
|
||||
return b
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local function getDeepObject(name)
|
||||
local o = getObject(name)
|
||||
if(o~=nil)then return o end
|
||||
for _, value in pairs(objects) do
|
||||
for _, b in pairs(value) do
|
||||
if (b:getType() == "Frame") then
|
||||
local oF = b:getDeepObject(name)
|
||||
if(oF~=nil)then return oF end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -80,6 +149,9 @@ return function(name, parent, pTerm, basalt)
|
||||
objects[zIndex] = {}
|
||||
end
|
||||
obj.parent = object
|
||||
if(obj.init~=nil)then
|
||||
obj:init()
|
||||
end
|
||||
table.insert(objects[zIndex], obj)
|
||||
return obj
|
||||
end
|
||||
@@ -120,8 +192,12 @@ return function(name, parent, pTerm, basalt)
|
||||
return self
|
||||
end;
|
||||
|
||||
setSize = function(self, w, h)
|
||||
base.setSize(self, w, h)
|
||||
getVariable = function(self, name)
|
||||
return basalt.getVariable(name)
|
||||
end,
|
||||
|
||||
setSize = function(self, w, h, rel)
|
||||
base.setSize(self, w, h, rel)
|
||||
for _, index in pairs(objZIndex) do
|
||||
if (objects[index] ~= nil) then
|
||||
for _, value in pairs(objects[index]) do
|
||||
@@ -134,6 +210,29 @@ return function(name, parent, pTerm, basalt)
|
||||
return self
|
||||
end;
|
||||
|
||||
setTheme = function(self, _theme)
|
||||
theme = _theme
|
||||
return self
|
||||
end,
|
||||
|
||||
getTheme = function(self, name)
|
||||
return theme[name] or (self.parent~=nil and self.parent:getTheme(name) or basalt.getTheme(name))
|
||||
end,
|
||||
|
||||
setPosition = function(self, x, y, rel)
|
||||
base.setPosition(self, x, y, rel)
|
||||
for _, index in pairs(objZIndex) do
|
||||
if (objects[index] ~= nil) then
|
||||
for _, value in pairs(objects[index]) do
|
||||
if (value.eventHandler ~= nil) then
|
||||
value:sendEvent("basalt_reposition", value, self)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
getBasaltInstance = function(self)
|
||||
return basalt
|
||||
end,
|
||||
@@ -185,6 +284,26 @@ return function(name, parent, pTerm, basalt)
|
||||
return self;
|
||||
end;
|
||||
|
||||
setScrollable = function(self, scrollable)
|
||||
isScrollable = scrollable and true or false
|
||||
return self
|
||||
end,
|
||||
|
||||
setImportantScroll = function(self, imp)
|
||||
importantScroll = imp and true or false
|
||||
return self
|
||||
end,
|
||||
|
||||
setMaxScroll = function(self, max)
|
||||
maxScroll = max or maxScroll
|
||||
return self
|
||||
end,
|
||||
|
||||
setMinScroll = function(self, min)
|
||||
minScroll = min or minScroll
|
||||
return self
|
||||
end,
|
||||
|
||||
show = function(self)
|
||||
base.show(self)
|
||||
if(self.parent==nil)then
|
||||
@@ -214,7 +333,61 @@ return function(name, parent, pTerm, basalt)
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
addLayout = function(self, file)
|
||||
if(file~=nil)then
|
||||
if(fs.exists(file))then
|
||||
local f = fs.open(file, "r")
|
||||
local data = layout:ParseXmlText(f.readAll())
|
||||
f.close()
|
||||
lastXMLReferences = {}
|
||||
self:setValuesByXMLData(data)
|
||||
end
|
||||
end
|
||||
return self
|
||||
end,
|
||||
|
||||
getLastLayout = function(self)
|
||||
return lastXMLReferences
|
||||
end,
|
||||
|
||||
addLayoutFromString = function(self, str)
|
||||
if(str~=nil)then
|
||||
local data = layout:ParseXmlText(str)
|
||||
self:setValuesByXMLData(data)
|
||||
end
|
||||
return self
|
||||
end,
|
||||
|
||||
setValuesByXMLData = function(self, data)
|
||||
base.setValuesByXMLData(self, data)
|
||||
|
||||
if(xmlValue("moveable", data)~=nil)then if(xmlValue("moveable", data))then self:setMoveable(true) end end
|
||||
if(xmlValue("scrollable", data)~=nil)then if(xmlValue("scrollable", data))then self:setScrollable(true) end end
|
||||
if(xmlValue("monitor", data)~=nil)then self:setMonitor(xmlValue("monitor", data)):show() end
|
||||
if(xmlValue("mirror", data)~=nil)then self:setMirror(xmlValue("mirror", data)) end
|
||||
if(xmlValue("bar", data)~=nil)then if(xmlValue("bar", data))then self:showBar(true) else self:showBar(false) end end
|
||||
if(xmlValue("barText", data)~=nil)then self.barText = xmlValue("barText", data) end
|
||||
if(xmlValue("barBG", data)~=nil)then self.barBackground = colors[xmlValue("barBG", data)] end
|
||||
if(xmlValue("barFG", data)~=nil)then self.barTextcolor = colors[xmlValue("barFG", data)] end
|
||||
if(xmlValue("barAlign", data)~=nil)then self.barTextAlign = xmlValue("barAlign", data) end
|
||||
if(xmlValue("layout", data)~=nil)then self:addLayout(xmlValue("layout", data)) end
|
||||
if(xmlValue("xOffset", data)~=nil)then self:setOffset(xmlValue("xOffset", data), yOffset) end
|
||||
if(xmlValue("yOffset", data)~=nil)then self:setOffset(yOffset, xmlValue("yOffset", data)) end
|
||||
if(xmlValue("maxScroll", data)~=nil)then self:setMaxScroll(xmlValue("maxScroll", data)) end
|
||||
if(xmlValue("minScroll", data)~=nil)then self:setMaxScroll(xmlValue("minScroll", data)) end
|
||||
if(xmlValue("importantScroll", data)~=nil)then self:setImportantScroll(xmlValue("importantScroll", data)) end
|
||||
|
||||
|
||||
for k,v in pairs(_OBJECTS)do
|
||||
if(k~="Animation")then
|
||||
addXMLObjectType(data[string.lower(k)], self["add"..k], self)
|
||||
end
|
||||
end
|
||||
addXMLObjectType(data["animation"], self.addAnimation, self)
|
||||
addXMLObjectType(data["frame"], self.addFrame, self)
|
||||
return self
|
||||
end,
|
||||
|
||||
showBar = function(self, showIt)
|
||||
self.barActive = showIt or not self.barActive
|
||||
@@ -236,12 +409,31 @@ return function(name, parent, pTerm, basalt)
|
||||
return self
|
||||
end;
|
||||
|
||||
setMirror = function(self, side)
|
||||
mirrorSide = side
|
||||
if(mirror~=nil)then
|
||||
basaltDraw.setMirror(mirror)
|
||||
end
|
||||
mirrorActive = true
|
||||
return self
|
||||
end,
|
||||
|
||||
removeMirror = function(self)
|
||||
mirror = nil
|
||||
mirrorActive = false
|
||||
basaltDraw.setMirror(nil)
|
||||
return self
|
||||
end,
|
||||
|
||||
setMonitor = function(self, side)
|
||||
if(side~=nil)and(side~=false)then
|
||||
if(peripheral.getType(side)=="monitor")then
|
||||
termObject = peripheral.wrap(side)
|
||||
monitorAttached = true
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:removeObject(self)
|
||||
end
|
||||
isMonitor = true
|
||||
else
|
||||
termObject = parentTerminal
|
||||
@@ -326,16 +518,28 @@ return function(name, parent, pTerm, basalt)
|
||||
if(peripheral.getType(monSide)=="monitor")then
|
||||
monitorAttached = true
|
||||
termObject = peripheral.wrap(monSide)
|
||||
basaltDraw = basaltDraw(termObject)
|
||||
basaltDraw = BasaltDraw(termObject)
|
||||
end
|
||||
end
|
||||
if(event == "peripheral_detach")and(p1==monSide)then
|
||||
monitorAttached = false
|
||||
end
|
||||
end
|
||||
if(mirrorActive)then
|
||||
if(peripheral.getType(mirrorSide)=="monitor")then
|
||||
mirrorAttached = true
|
||||
basaltDraw.setMirror(peripheral.wrap(mirrorSide))
|
||||
end
|
||||
if(event == "peripheral_detach")and(p1==mirrorSide)then
|
||||
monitorAttached = false
|
||||
end
|
||||
if(event=="monitor_touch")then
|
||||
self:mouseHandler(event, p1, p2, p3, p4)
|
||||
end
|
||||
end
|
||||
if (event == "terminate") then
|
||||
termObject.clear()
|
||||
termObject.setCursorPos(1, 1)
|
||||
termObject.clear()
|
||||
basalt.stop()
|
||||
end
|
||||
end;
|
||||
@@ -369,6 +573,13 @@ return function(name, parent, pTerm, basalt)
|
||||
if (base.mouseHandler(self, event, button, x, y)) then
|
||||
local fx, fy = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
fx = fx + xOffset;fy = fy + yOffset;
|
||||
if(isScrollable)and(importantScroll)then
|
||||
if(event=="mouse_scroll")then
|
||||
if(button>0)or(button<0)then
|
||||
yOffset = max(min(yOffset-button, -minScroll),-maxScroll)
|
||||
end
|
||||
end
|
||||
end
|
||||
for _, index in pairs(objZIndex) do
|
||||
if (objects[index] ~= nil) then
|
||||
for _, value in rpairs(objects[index]) do
|
||||
@@ -382,12 +593,19 @@ return function(name, parent, pTerm, basalt)
|
||||
end
|
||||
if (self.isMoveable) then
|
||||
local fx, fy = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
if (x >= fx) and (x <= fx + self.width - 1) and (y == fy) and (event == "mouse_click") then
|
||||
if (x >= fx) and (x <= fx + self:getWidth() - 1) and (y == fy) and (event == "mouse_click") then
|
||||
self.drag = true
|
||||
dragXOffset = fx - x
|
||||
dragYOffset = yOff and 1 or 0
|
||||
end
|
||||
end
|
||||
if(isScrollable)and(not importantScroll)then
|
||||
if(event=="mouse_scroll")then
|
||||
if(button>0)or(button<0)then
|
||||
yOffset = max(min(yOffset-button, -minScroll),-maxScroll)
|
||||
end
|
||||
end
|
||||
end
|
||||
if (basalt.getFocusedObject() ~= nil) then
|
||||
basalt.getFocusedObject():loseFocusHandler()
|
||||
basalt.setFocusedObject(nil)
|
||||
@@ -398,86 +616,80 @@ return function(name, parent, pTerm, basalt)
|
||||
end;
|
||||
|
||||
setText = function(self, x, y, text)
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
if (y >= 1) and (y <= self.height) then
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
if (y >= 1) and (y <= self:getHeight()) then
|
||||
if (self.parent ~= nil) then
|
||||
local parentX, parentY = self.parent:getAnchorPosition()
|
||||
self.parent:setText(math.max(x + (obx - 1), obx) - (parentX - 1), oby + y - 1 - (parentY - 1), sub(text, math.max(1 - x + 1, 1), math.max(self.width - x + 1,1)))
|
||||
self.parent:setText(max(x + (obx - 1), obx), oby + y - 1, sub(text, max(1 - x + 1, 1), max(self:getWidth() - x + 1,1)))
|
||||
else
|
||||
basaltDraw.setText(math.max(x + (obx - 1), obx), oby + y - 1, sub(text, math.max(1 - x + 1, 1), math.max(self.width - x + 1,1))) -- math.max(self.width - x + 1,1) now, before: self.width - x + 1
|
||||
basaltDraw.setText(max(x + (obx - 1), obx), oby + y - 1, sub(text, max(1 - x + 1, 1), max(self:getWidth() - x + 1,1)))
|
||||
end
|
||||
end
|
||||
end;
|
||||
|
||||
setBG = function(self, x, y, bgCol)
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
if (y >= 1) and (y <= self.height) then
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
if (y >= 1) and (y <= self:getHeight()) then
|
||||
if (self.parent ~= nil) then
|
||||
local parentX, parentY = self.parent:getAnchorPosition()
|
||||
self.parent:setBG(math.max(x + (obx - 1), obx) - (parentX - 1), oby + y - 1 - (parentY - 1), sub(bgCol, math.max(1 - x + 1, 1), math.max(self.width - x + 1,1)))
|
||||
self.parent:setBG(max(x + (obx - 1), obx), oby + y - 1, sub(bgCol, max(1 - x + 1, 1), max(self:getWidth() - x + 1,1)))
|
||||
else
|
||||
basaltDraw.setBG(math.max(x + (obx - 1), obx), oby + y - 1, sub(bgCol, math.max(1 - x + 1, 1), math.max(self.width - x + 1,1)))
|
||||
basaltDraw.setBG(max(x + (obx - 1), obx), oby + y - 1, sub(bgCol, max(1 - x + 1, 1), max(self:getWidth() - x + 1,1)))
|
||||
end
|
||||
end
|
||||
end;
|
||||
|
||||
setFG = function(self, x, y, fgCol)
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
if (y >= 1) and (y <= self.height) then
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
if (y >= 1) and (y <= self:getHeight()) then
|
||||
if (self.parent ~= nil) then
|
||||
local parentX, parentY = self.parent:getAnchorPosition()
|
||||
self.parent:setFG(math.max(x + (obx - 1), obx) - (parentX - 1), oby + y - 1 - (parentY - 1), sub(fgCol, math.max(1 - x + 1, 1), math.max(self.width - x + 1,1)))
|
||||
self.parent:setFG(max(x + (obx - 1), obx), oby + y - 1, sub(fgCol, max(1 - x + 1, 1), max(self:getWidth() - x + 1,1)))
|
||||
else
|
||||
basaltDraw.setFG(math.max(x + (obx - 1), obx), oby + y - 1, sub(fgCol, math.max(1 - x + 1, 1), math.max(self.width - x + 1,1)))
|
||||
basaltDraw.setFG(max(x + (obx - 1), obx), oby + y - 1, sub(fgCol, max(1 - x + 1, 1), max(self:getWidth() - x + 1,1)))
|
||||
end
|
||||
end
|
||||
end;
|
||||
|
||||
writeText = function(self, x, y, text, bgCol, fgCol)
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
if (y >= 1) and (y <= self.height) then
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
if (y >= 1) and (y <= self:getHeight()) then
|
||||
if (self.parent ~= nil) then
|
||||
local parentX, parentY = self.parent:getAnchorPosition()
|
||||
self.parent:writeText(math.max(x + (obx - 1), obx) - (parentX - 1), oby + y - 1 - (parentY - 1), sub(text, math.max(1 - x + 1, 1), self.width - x + 1), bgCol, fgCol)
|
||||
self.parent:writeText(max(x + (obx - 1), obx), oby + y - 1, sub(text, max(1 - x + 1, 1), self:getWidth() - x + 1), bgCol, fgCol)
|
||||
else
|
||||
basaltDraw.writeText(math.max(x + (obx - 1), obx), oby + y - 1, sub(text, math.max(1 - x + 1, 1), math.max(self.width - x + 1,1)), bgCol, fgCol)
|
||||
basaltDraw.writeText(max(x + (obx - 1), obx), oby + y - 1, sub(text, max(1 - x + 1, 1), max(self:getWidth() - x + 1,1)), bgCol, fgCol)
|
||||
end
|
||||
end
|
||||
end;
|
||||
|
||||
drawBackgroundBox = function(self, x, y, width, height, bgCol)
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
height = (y < 1 and (height + y > self.height and self.height or height + y - 1) or (height + y > self.height and self.height - y + 1 or height))
|
||||
width = (x < 1 and (width + x > self.width and self.width or width + x - 1) or (width + x > self.width and self.width - x + 1 or width))
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
|
||||
height = (y < 1 and (height + y > self:getHeight() and self:getHeight() or height + y - 1) or (height + y > self:getHeight() and self:getHeight() - y + 1 or height))
|
||||
width = (x < 1 and (width + x > self:getWidth() and self:getWidth() or width + x - 1) or (width + x > self:getWidth() and self:getWidth() - x + 1 or width))
|
||||
if (self.parent ~= nil) then
|
||||
local parentX, parentY = self.parent:getAnchorPosition()
|
||||
self.parent:drawBackgroundBox(math.max(x + (obx - 1), obx) - (parentX - 1), math.max(y + (oby - 1), oby) - (parentY - 1), width, height, bgCol)
|
||||
self.parent:drawBackgroundBox(max(x + (obx - 1), obx), max(y + (oby - 1), oby), width, height, bgCol)
|
||||
else
|
||||
basaltDraw.drawBackgroundBox(math.max(x + (obx - 1), obx), math.max(y + (oby - 1), oby), width, height, bgCol)
|
||||
basaltDraw.drawBackgroundBox(max(x + (obx - 1), obx), max(y + (oby - 1), oby), width, height, bgCol)
|
||||
end
|
||||
end;
|
||||
|
||||
drawTextBox = function(self, x, y, width, height, symbol)
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
height = (y < 1 and (height + y > self.height and self.height or height + y - 1) or (height + y > self.height and self.height - y + 1 or height))
|
||||
width = (x < 1 and (width + x > self.width and self.width or width + x - 1) or (width + x > self.width and self.width - x + 1 or width))
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
height = (y < 1 and (height + y > self:getHeight() and self:getHeight() or height + y - 1) or (height + y > self:getHeight() and self:getHeight() - y + 1 or height))
|
||||
width = (x < 1 and (width + x > self:getWidth() and self:getWidth() or width + x - 1) or (width + x > self:getWidth() and self:getWidth() - x + 1 or width))
|
||||
if (self.parent ~= nil) then
|
||||
local parentX, parentY = self.parent:getAnchorPosition()
|
||||
self.parent:drawTextBox(math.max(x + (obx - 1), obx) - (parentX - 1), math.max(y + (oby - 1), oby) - (parentY - 1), width, height, symbol:sub(1, 1))
|
||||
self.parent:drawTextBox(max(x + (obx - 1), obx), max(y + (oby - 1), oby), width, height, sub(symbol,1,1))
|
||||
else
|
||||
basaltDraw.drawTextBox(math.max(x + (obx - 1), obx), math.max(y + (oby - 1), oby), width, height, symbol:sub(1, 1))
|
||||
basaltDraw.drawTextBox(max(x + (obx - 1), obx), max(y + (oby - 1), oby), width, height, sub(symbol,1,1))
|
||||
end
|
||||
end;
|
||||
|
||||
drawForegroundBox = function(self, x, y, width, height, fgCol)
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
height = (y < 1 and (height + y > self.height and self.height or height + y - 1) or (height + y > self.height and self.height - y + 1 or height))
|
||||
width = (x < 1 and (width + x > self.width and self.width or width + x - 1) or (width + x > self.width and self.width - x + 1 or width))
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
height = (y < 1 and (height + y > self:getHeight() and self:getHeight() or height + y - 1) or (height + y > self:getHeight() and self:getHeight() - y + 1 or height))
|
||||
width = (x < 1 and (width + x > self:getWidth() and self:getWidth() or width + x - 1) or (width + x > self:getWidth() and self:getWidth() - x + 1 or width))
|
||||
if (self.parent ~= nil) then
|
||||
local parentX, parentY = self.parent:getAnchorPosition()
|
||||
self.parent:drawForegroundBox(math.max(x + (obx - 1), obx) - (parentX - 1), math.max(y + (oby - 1), oby) - (parentY - 1), width, height, fgCol)
|
||||
self.parent:drawForegroundBox(max(x + (obx - 1), obx), max(y + (oby - 1), oby), width, height, fgCol)
|
||||
else
|
||||
basaltDraw.drawForegroundBox(math.max(x + (obx - 1), obx), math.max(y + (oby - 1), oby), width, height, fgCol)
|
||||
basaltDraw.drawForegroundBox(max(x + (obx - 1), obx), max(y + (oby - 1), oby), width, height, fgCol)
|
||||
end
|
||||
end;
|
||||
|
||||
@@ -487,37 +699,38 @@ return function(name, parent, pTerm, basalt)
|
||||
if (base.draw(self)) then
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
local anchx, anchy = self:getAnchorPosition()
|
||||
local w,h = self:getSize()
|
||||
if (self.parent ~= nil) then
|
||||
if(self.bgColor~=false)then
|
||||
self.parent:drawBackgroundBox(anchx, anchy, self.width, self.height, self.bgColor)
|
||||
self.parent:drawTextBox(anchx, anchy, self.width, self.height, " ")
|
||||
self.parent:drawBackgroundBox(anchx, anchy, w, h, self.bgColor)
|
||||
self.parent:drawTextBox(anchx, anchy, w, h, " ")
|
||||
end
|
||||
if(self.bgColor~=false)then self.parent:drawForegroundBox(anchx, anchy, self.width, self.height, self.fgColor) end
|
||||
if(self.bgColor~=false)then self.parent:drawForegroundBox(anchx, anchy, w, h, self.fgColor) end
|
||||
else
|
||||
if(self.bgColor~=false)then
|
||||
basaltDraw.drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
|
||||
basaltDraw.drawTextBox(obx, oby, self.width, self.height, " ")
|
||||
basaltDraw.drawBackgroundBox(anchx, anchy, w, h, self.bgColor)
|
||||
basaltDraw.drawTextBox(anchx, anchy, w, h, " ")
|
||||
end
|
||||
if(self.fgColor~=false)then basaltDraw.drawForegroundBox(obx, oby, self.width, self.height, self.fgColor) end
|
||||
if(self.fgColor~=false)then basaltDraw.drawForegroundBox(anchx, anchy, w, h, self.fgColor) end
|
||||
end
|
||||
termObject.setCursorBlink(false)
|
||||
if (self.barActive) then
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:writeText(anchx, anchy, utils.getTextHorizontalAlign(self.barText, self.width, self.barTextAlign), self.barBackground, self.barTextcolor)
|
||||
self.parent:writeText(anchx, anchy, utils.getTextHorizontalAlign(self.barText, w, self.barTextAlign), self.barBackground, self.barTextcolor)
|
||||
else
|
||||
basaltDraw.writeText(obx, oby, utils.getTextHorizontalAlign(self.barText, self.width, self.barTextAlign), self.barBackground, self.barTextcolor)
|
||||
basaltDraw.writeText(anchx, anchy, utils.getTextHorizontalAlign(self.barText, w, self.barTextAlign), self.barBackground, self.barTextcolor)
|
||||
end
|
||||
if(self:getBorder("left"))then
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:drawBackgroundBox(anchx-1, anchy, 1, 1, self.barBackground)
|
||||
if(self.bgColor~=false)then
|
||||
self.parent:drawBackgroundBox(anchx-1, anchy+1, 1, self.height-1, self.bgColor)
|
||||
self.parent:drawBackgroundBox(anchx-1, anchy+1, 1, h-1, self.bgColor)
|
||||
end
|
||||
end
|
||||
end
|
||||
if(self:getBorder("top"))then
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:drawBackgroundBox(anchx-1, anchy-1, self.width+1, 1, self.barBackground)
|
||||
self.parent:drawBackgroundBox(anchx-1, anchy-1, w+1, 1, self.barBackground)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -562,6 +775,9 @@ return function(name, parent, pTerm, basalt)
|
||||
getObject = function(self, obj)
|
||||
return getObject(obj)
|
||||
end;
|
||||
getDeepObject = function(self, name)
|
||||
return getDeepObject(name)
|
||||
end,
|
||||
|
||||
addFrame = function(self, name)
|
||||
local obj = basalt.newFrame(name, self, nil, basalt)
|
||||
@@ -570,7 +786,7 @@ return function(name, parent, pTerm, basalt)
|
||||
}
|
||||
for k,v in pairs(_OBJECTS)do
|
||||
object["add"..k] = function(self, name)
|
||||
return addObject(v(name, self))
|
||||
return addObject(v(name or uuid(), self))
|
||||
end
|
||||
end
|
||||
setmetatable(object, base)
|
||||
|
||||
Reference in New Issue
Block a user