1.6.0 Release

Release version of basalt 1.6.0
This commit is contained in:
Robert Jelic
2022-08-25 22:22:47 +02:00
parent 14643193b9
commit 8ab06dbc17
27 changed files with 1836 additions and 999 deletions

View File

@@ -1,12 +1,12 @@
local Object = require("Object")
local _OBJECTS = require("loadObjects")
local BasaltDraw = require("basaltDraw")
local utils = require("utils")
local layout = require("layout")
local uuid = utils.uuid
local rpairs = utils.rpairs
local xmlValue = utils.getValueFromXML
local tableCount = utils.tableCount
local sub,min,max = string.sub,math.min,math.max
@@ -17,6 +17,8 @@ return function(name, parent, pTerm, basalt)
local objects = {}
local objZIndex = {}
local object = {}
local events = {}
local eventZIndex = {}
local variables = {}
local theme = {}
local dynamicValues = {}
@@ -29,15 +31,20 @@ return function(name, parent, pTerm, basalt)
local dragXOffset = 0
local dragYOffset = 0
local isScrollable = false
local minScroll = 0
local maxScroll = 10
local scrollAmount = 0
local mirrorActive = false
local mirrorAttached = false
local mirrorSide = ""
local importantScroll = false
local isMovable = false
local isDragging =false
local focusedOBjectCache
local focusedObjectCache
local focusedObject
local autoSize = true
local autoScroll = true
local initialized = false
local activeEvents = {}
base:setZIndex(10)
@@ -70,17 +77,6 @@ return function(name, parent, pTerm, basalt)
end
end
if (parent ~= nil) then
base.parent = parent
base.width, base.height = parent:getSize()
base.bgColor = parent:getTheme("FrameBG")
base.fgColor = parent:getTheme("FrameText")
else
base.width, base.height = termObject.getSize()
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
@@ -135,11 +131,94 @@ return function(name, parent, pTerm, basalt)
return obj
end
local function removeEvents(self, obj)
for a, b in pairs(events) do
for c, d in pairs(b) do
for key, value in pairs(d) do
if (value == obj) then
table.remove(events[a][c], key)
if(self.parent~=nil)then
if(tableCount(events[event])<=0)then
self.parent:removeEvent(a, self)
end
end
end
end
end
end
end
local function removeObject(obj)
for a, b in pairs(objects) do
for key, value in pairs(b) do
if (value == obj) then
table.remove(objects[a], key)
removeEvents(object, obj)
return true;
end
end
end
return false
end
local function getEvent(self, event, name)
for _, value in pairs(events[event]) do
for _, b in pairs(value) do
if (b:getName() == name) then
return b
end
end
end
end
local function addEvent(self, event, obj)
local zIndex = obj:getZIndex()
if(events[event]==nil)then events[event] = {} end
if(eventZIndex[event]==nil)then eventZIndex[event] = {} end
if (getEvent(self, event, obj.name) ~= nil) then
return nil
end
if(self.parent~=nil)then
self.parent:addEvent(event, self)
end
activeEvents[event] = true
if (events[event][zIndex] == nil) then
for x = 1, #eventZIndex[event] + 1 do
if (eventZIndex[event][x] ~= nil) then
if (zIndex == eventZIndex[event][x]) then
break
end
if (zIndex > eventZIndex[event][x]) then
table.insert(eventZIndex[event], x, zIndex)
break
end
else
table.insert(eventZIndex[event], zIndex)
end
end
if (#eventZIndex[event] <= 0) then
table.insert(eventZIndex[event], zIndex)
end
events[event][zIndex] = {}
end
table.insert(events[event][zIndex], obj)
return obj
end
local function removeEvent(self, event, obj)
for a, b in pairs(events[event]) do
for key, value in pairs(b) do
if (value == obj) then
table.remove(events[event][a], key)
if(#events[event][a]<=0)then
events[event][a] = nil
if(self.parent~=nil)then
if(tableCount(events[event])<=0)then
activeEvents[event] = false
self.parent:removeEvent(event, self)
end
end
end
return true;
end
end
@@ -217,7 +296,7 @@ return function(name, parent, pTerm, basalt)
end
local function recalculateDynamicValues()
local function recalculateDynamicValues(self)
if(#dynamicValues>0)then
for n=1,dynValueId do
if(dynamicValues[n]~=nil)then
@@ -225,6 +304,18 @@ return function(name, parent, pTerm, basalt)
if(#dynamicValues[n][3]<=0)then dynamicValues[n][3] = dynValueGetObjects(dynamicValues[n][4], dynamicValues[n][2]) end
numberStr = dynValueObjectToNumber(dynamicValues[n][2], dynamicValues[n][3])
dynamicValues[n][1] = stringToNumber(numberStr)
if(dynamicValues[n][4]:getType()=="Frame")then
dynamicValues[n][4]:recalculateDynamicValues()
end
end
end
for _, index in pairs(objZIndex) do
if (objects[index] ~= nil) then
for _, value in pairs(objects[index]) do
if (value.eventHandler ~= nil) then
value:eventHandler("dynamicValueEvent", self)
end
end
end
end
end
@@ -234,6 +325,30 @@ return function(name, parent, pTerm, basalt)
return dynamicValues[id][1]
end
local function calculateMaxScroll(self)
for _, value in pairs(objects) do
for _, b in pairs(value) do
if(b.getHeight~=nil)and(b.getY~=nil)then
local h, y = b:getHeight(), b:getY()
if (h + y - self:getHeight() > scrollAmount) then
scrollAmount = max(h + y - self:getHeight(), 0)
end
end
end
end
end
local function focusSystem(self)
if(focusedObject~=focusedObjectCache)then
if(focusedObject~=nil)then
focusedObject:loseFocusHandler()
end
if(focusedObjectCache~=nil)then
focusedObjectCache:getFocusHandler()
end
focusedObject = focusedObjectCache
end
end
object = {
barActive = false,
@@ -241,7 +356,11 @@ return function(name, parent, pTerm, basalt)
barTextcolor = colors.black,
barText = "New Frame",
barTextAlign = "left",
isMoveable = false,
addEvent = addEvent,
removeEvent = removeEvent,
removeEvents = removeEvents,
getEvent = getEvent,
newDynamicValue = newDynamicValue,
recalculateDynamicValues = recalculateDynamicValues,
@@ -252,7 +371,7 @@ return function(name, parent, pTerm, basalt)
end;
setFocusedObject = function(self, obj)
focusedOBjectCache = obj
focusedObjectCache = obj
return self
end;
@@ -262,25 +381,35 @@ return function(name, parent, pTerm, basalt)
setSize = function(self, w, h, rel)
base.setSize(self, w, h, rel)
if(self.parent==nil)then
basaltDraw = BasaltDraw(termObject)
end
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_resize", value, self)
value:eventHandler("basalt_resize", value, self)
end
end
end
end
self:recalculateDynamicValues()
autoSize = false
return self
end;
setTheme = function(self, _theme)
theme = _theme
setTheme = function(self, _theme, col)
if(type(_theme)=="table")then
theme = _theme
elseif(type(_theme)=="string")then
theme[_theme] = col
end
self:updateDraw()
return self
end,
getTheme = function(self, name)
return (theme and theme[name]) or (self.parent~=nil and self.parent:getTheme(name) or basalt.getTheme(name))
return theme[name] or (self.parent~=nil and self.parent:getTheme(name) or basalt.getTheme(name))
end,
setPosition = function(self, x, y, rel)
@@ -289,11 +418,12 @@ return function(name, parent, pTerm, basalt)
if (objects[index] ~= nil) then
for _, value in pairs(objects[index]) do
if (value.eventHandler ~= nil) then
value:sendEvent("basalt_reposition", value, self)
value:eventHandler("basalt_reposition", value, self)
end
end
end
end
self:recalculateDynamicValues()
return self
end;
@@ -304,6 +434,7 @@ return function(name, parent, pTerm, basalt)
setOffset = function(self, xO, yO)
xOffset = xO ~= nil and math.floor(xO < 0 and math.abs(xO) or -xO) or xOffset
yOffset = yO ~= nil and math.floor(yO < 0 and math.abs(yO) or -yO) or yOffset
self:updateDraw()
return self
end;
@@ -311,12 +442,12 @@ return function(name, parent, pTerm, basalt)
return xOffset, yOffset
end;
getOffset = function(self) -- internal
getOffset = function(self)
return xOffset < 0 and math.abs(xOffset) or -xOffset, yOffset < 0 and math.abs(yOffset) or -yOffset
end;
removeFocusedObject = function(self)
focusedOBjectCache = nil
focusedObjectCache = nil
return self
end;
@@ -338,43 +469,48 @@ return function(name, parent, pTerm, basalt)
yCursor = oby + _yCursor - 1
end
cursorColor = color or cursorColor
self:setVisualChanged()
if (cursorBlink) then
termObject.setTextColor(cursorColor)
termObject.setCursorPos(xCursor, yCursor)
termObject.setCursorBlink(cursorBlink)
else
termObject.setCursorBlink(false)
end
end
return self
end;
setMoveable = function(self, moveable)
self.isMoveable = moveable or not self.isMoveable
self:setVisualChanged()
setMovable = function(self, movable)
if(self.parent~=nil)then
isMovable = movable or not isMovable
self.parent:addEvent("mouse_click", self)
activeEvents["mouse_click"] = true
self.parent:addEvent("mouse_up", self)
activeEvents["mouse_up"] = true
self.parent:addEvent("mouse_drag", self)
activeEvents["mouse_drag"] = true
end
return self;
end;
setScrollable = function(self, scrollable)
isScrollable = scrollable and true or false
if(self.parent~=nil)then
self.parent:addEvent("mouse_scroll", self)
end
activeEvents["mouse_scroll"] = true
return self
end,
setImportantScroll = function(self, imp)
importantScroll = imp and true or false
setScrollAmount = function(self, max)
scrollAmount = max or scrollAmount
autoScroll = 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,
getMaxScroll = function(self)
return maxScroll
end,
getMinScroll = function(self)
return minScroll
getScrollAmount = function(self)
return scrollAmount
end,
show = function(self)
@@ -434,7 +570,7 @@ return function(name, parent, pTerm, basalt)
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("movable", data)~=nil)then if(xmlValue("movable", data))then self:setMovable(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
@@ -446,9 +582,7 @@ return function(name, parent, pTerm, basalt)
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
if(xmlValue("scrollAmount", data)~=nil)then self:setScrollAmount(xmlValue("scrollAmount", data)) end
local objectList = data:children()
@@ -466,27 +600,28 @@ return function(name, parent, pTerm, basalt)
return self
end,
showBar = function(self, showIt)
showBar = function(self, showIt) -- deprecated
self.barActive = showIt or not self.barActive
self:setVisualChanged()
self:updateDraw()
return self
end;
setBar = function(self, text, bgCol, fgCol)
setBar = function(self, text, bgCol, fgCol) -- deprecated
self.barText = text or ""
self.barBackground = bgCol or self.barBackground
self.barTextcolor = fgCol or self.barTextcolor
self:setVisualChanged()
self:updateDraw()
return self
end;
setBarTextAlign = function(self, align)
setBarTextAlign = function(self, align) -- deprecated
self.barTextAlign = align or "left"
self:setVisualChanged()
self:updateDraw()
return self
end;
setMirror = function(self, side)
if(self.parent~=nil)then error("Frame has to be a base frame in order to attach a mirror.") end
mirrorSide = side
if(mirror~=nil)then
basaltDraw.setMirror(mirror)
@@ -507,11 +642,13 @@ return function(name, parent, pTerm, basalt)
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
basalt.setMonitorFrame(side, self)
else
termObject = parentTerminal
isMonitor = false
@@ -520,85 +657,73 @@ return function(name, parent, pTerm, basalt)
end
end
basaltDraw = BasaltDraw(termObject)
self:setSize(termObject.getSize())
autoSize = true
monSide = side or nil
self:updateDraw()
return self;
end;
getVisualChanged = function(self)
local changed = base.getVisualChanged(self)
for _, index in pairs(objZIndex) do
if (objects[index] ~= nil) then
for _, value in pairs(objects[index]) do
if (value.getVisualChanged ~= nil and value:getVisualChanged()) then
changed = true
end
end
end
end
return changed
end;
loseFocusHandler = function(self)
base.loseFocusHandler(self)
if(focusedOBjectCache~=nil)then
focusedOBjectCache:loseFocusHandler()
focusedOBjectCache = nil
end
if(focusedObject~=nil)then focusedObject:loseFocusHandler() focusedObject = nil end
end;
getFocusHandler = function(self)
base.getFocusHandler(self)
if (self.parent ~= nil) then
self.parent:removeObject(self)
self.parent:addObject(self)
end
end;
keyHandler = function(self, event, key)
if (focusedObject ~= nil) then
if(focusedObject~=self)then
if (focusedObject.keyHandler ~= nil) then
if (focusedObject:keyHandler(event, key)) then
return true
end
end
else
base.keyHandler(self, event, key)
end
end
return false
end;
backgroundKeyHandler = function(self, event, key)
base.backgroundKeyHandler(self, event, key)
for _, index in pairs(objZIndex) do
if (objects[index] ~= nil) then
for _, value in pairs(objects[index]) do
if (value.backgroundKeyHandler ~= nil) then
value:backgroundKeyHandler(event, key)
if(isMovable)then
self.parent:removeEvents(self)
self.parent:removeObject(self)
self.parent:addObject(self)
for k,v in pairs(activeEvents)do
if(v)then
self.parent:addEvent(k, self)
end
end
self:updateDraw()
end
end
if(focusedObject~=nil)then focusedObject:getFocusHandler() end
end;
eventHandler = function(self, event, p1, p2, p3, p4)
base.eventHandler(self, event, p1, p2, p3, p4)
for _, index in pairs(objZIndex) do
if (objects[index] ~= nil) then
for _, value in pairs(objects[index]) do
if (value.eventHandler ~= nil) then
value:eventHandler(event, p1, p2, p3, p4)
if(events["other_event"]~=nil)then
for _, index in ipairs(eventZIndex["other_event"]) do
if (events["other_event"][index] ~= nil) then
for _, value in rpairs(events["other_event"][index]) do
if (value.eventHandler ~= nil) then
if (value:eventHandler(event, p1, p2, p3, p4)) then
return true
end
end
end
end
end
end
if(autoSize)and not(isMonitor)then
if(self.parent==nil)then
if(event=="term_resize")then
self:setSize(termObject.getSize())
autoSize = true
end
end
end
if(isMonitor)then
if(autoSize)then
if(event=="monitor_resize")and(p1==monSide)then
self:setSize(termObject.getSize())
autoSize = true
self:updateDraw()
end
end
if(event == "peripheral")and(p1==monSide)then
if(peripheral.getType(monSide)=="monitor")then
monitorAttached = true
termObject = peripheral.wrap(monSide)
basaltDraw = BasaltDraw(termObject)
self:updateDraw()
end
end
if(event == "peripheral_detach")and(p1==monSide)then
@@ -613,82 +738,199 @@ return function(name, parent, pTerm, basalt)
if(event == "peripheral_detach")and(p1==mirrorSide)then
monitorAttached = false
end
if(event=="monitor_touch")then
self:mouseHandler(event, p1, p2, p3, p4)
if(event=="monitor_touch")and(mirrorSide==p1)then
self:mouseHandler(1, p2, p3, true)
end
end
if (event == "terminate") then
termObject.setCursorPos(1, 1)
termObject.clear()
if (event == "terminate")and(self.parent==nil)then
basalt.stop()
end
end;
end,
mouseHandler = function(self, event, button, x, y)
if (self.drag) then
local xO, yO = self.parent:getOffsetInternal()
xO = xO < 0 and math.abs(xO) or -xO
yO = yO < 0 and math.abs(yO) or -yO
if (event == "mouse_drag") then
local parentX = 1
local parentY = 1
if (self.parent ~= nil) then
parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition())
end
self:setPosition(x + dragXOffset - (parentX - 1) + xO, y + dragYOffset - (parentY - 1) + yO)
end
if (event == "mouse_up") then
self.drag = false
end
return true
end
local fx, fy = self:getAbsolutePosition(self:getAnchorPosition())
local yOff = false
if(fy-1 == y)and(self:getBorder("top"))then
y = y+1
yOff = true
end
if (base.mouseHandler(self, event, button, x, y)) then
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
mouseHandler = function(self, button, x, y)
if(base.mouseHandler(self, button, x, y))then
if(events["mouse_click"]~=nil)then
self:setCursor(false)
for _, index in ipairs(eventZIndex["mouse_click"]) do
if (events["mouse_click"][index] ~= nil) then
for _, value in rpairs(events["mouse_click"][index]) do
if (value.mouseHandler ~= nil) then
if (value:mouseHandler(event, button, x, y)) then
if (value:mouseHandler(button, x, y)) then
focusSystem(self)
return true
end
end
end
end
end
self:removeFocusedObject()
if (self.isMoveable) 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 (isMovable) then
local fx, fy = self:getAbsolutePosition(self:getAnchorPosition())
if (x >= fx) and (x <= fx + self:getWidth() - 1) and (y == fy)then
isDragging = true
dragXOffset = fx - x
dragYOffset = yOff and 1 or 0
end
end
self:removeFocusedObject()
focusSystem(self)
return true
end
return false
end;
end,
mouseUpHandler = function(self, button, x, y)
if (isDragging) then
isDragging = false
end
if(base.mouseUpHandler(self, button, x, y))then
if(events["mouse_up"]~=nil)then
for _, index in ipairs(eventZIndex["mouse_up"]) do
if (events["mouse_up"][index] ~= nil) then
for _, value in rpairs(events["mouse_up"][index]) do
if (value.mouseUpHandler ~= nil) then
if (value:mouseUpHandler(button, x, y)) then
focusSystem(self)
return true
end
end
end
end
end
end
focusSystem(self)
return true
end
return false
end,
scrollHandler = function(self, dir, x, y)
if(base.scrollHandler(self, dir, x, y))then
if(events["mouse_scroll"]~=nil)then
for _, index in pairs(eventZIndex["mouse_scroll"]) do
if (events["mouse_scroll"][index] ~= nil) then
for _, value in rpairs(events["mouse_scroll"][index]) do
if (value.scrollHandler ~= nil) then
if (value:scrollHandler(dir, x, y)) then
focusSystem(self)
return true
end
end
end
end
end
end
local cache = yOffset
if(isScrollable)then
calculateMaxScroll(self)
if(dir>0)or(dir<0)then
yOffset = max(min(yOffset-dir, 0),-scrollAmount)
self:updateDraw()
end
end
self:removeFocusedObject()
focusSystem(self)
if(yOffset==cache)then return false end
return true
end
return false
end,
dragHandler = function(self, button, x, y)
if (isDragging) then
local xO, yO = self.parent:getOffsetInternal()
xO = xO < 0 and math.abs(xO) or -xO
yO = yO < 0 and math.abs(yO) or -yO
local parentX = 1
local parentY = 1
if (self.parent ~= nil) then
parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition())
end
self:setPosition(x + dragXOffset - (parentX - 1) + xO, y + dragYOffset - (parentY - 1) + yO)
self:updateDraw()
return true
end
if(events["mouse_drag"]~=nil)then
for _, index in ipairs(eventZIndex["mouse_drag"]) do
if (events["mouse_drag"][index] ~= nil) then
for _, value in rpairs(events["mouse_drag"][index]) do
if (value.dragHandler ~= nil) then
if (value:dragHandler(button, x, y)) then
focusSystem(self)
return true
end
end
end
end
end
end
focusSystem(self)
base.dragHandler(self, button, x, y)
return false
end,
keyHandler = function(self, key, isHolding)
if (self:isFocused())or(self.parent==nil)then
local val = self:getEventSystem():sendEvent("key", self, "key", key)
if(val==false)then return false end
if(events["key"]~=nil)then
for _, index in pairs(eventZIndex["key"]) do
if (events["key"][index] ~= nil) then
for _, value in rpairs(events["key"][index]) do
if (value.keyHandler ~= nil) then
if (value:keyHandler(key, isHolding)) then
return true
end
end
end
end
end
end
end
return false
end,
keyUpHandler = function(self, key)
if (self:isFocused())or(self.parent==nil)then
local val = self:getEventSystem():sendEvent("key_up", self, "key_up", key)
if(val==false)then return false end
if(events["key_up"]~=nil)then
for _, index in pairs(eventZIndex["key_up"]) do
if (events["key_up"][index] ~= nil) then
for _, value in rpairs(events["key_up"][index]) do
if (value.keyUpHandler ~= nil) then
if (value:keyUpHandler(key)) then
return true
end
end
end
end
end
end
end
return false
end,
charHandler = function(self, char)
if (self:isFocused())or(self.parent==nil)then
local val = self:getEventSystem():sendEvent("char", self, "char", char)
if(val==false)then return false end
if(events["char"]~=nil)then
for _, index in pairs(eventZIndex["char"]) do
if (events["char"][index] ~= nil) then
for _, value in rpairs(events["char"][index]) do
if (value.charHandler ~= nil) then
if (value:charHandler(char)) then
return true
end
end
end
end
end
end
end
return false
end,
setText = function(self, x, y, text)
local obx, oby = self:getAnchorPosition()
@@ -768,84 +1010,54 @@ return function(name, parent, pTerm, basalt)
end
end;
draw = function(self)
draw = function(self, force)
if(isMonitor)and not(monitorAttached)then return false end;
if (self:getVisualChanged()) then
if (base.draw(self)) then
if(focusedObject~=focusedOBjectCache)then
if(focusedOBjectCache~=nil)then
focusedOBjectCache:getFocusHandler()
end
if(focusedObject~=nil)then
focusedObject:loseFocusHandler()
end
focusedObject = focusedOBjectCache
if(self.parent==nil)then if(self:getDraw()==false)then return false end end
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
basaltDraw.drawBackgroundBox(anchx, anchy, w, h, self.bgColor)
basaltDraw.drawTextBox(anchx, anchy, w, h, " ")
end
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local anchx, anchy = self:getAnchorPosition()
local w,h = self:getSize()
if(self.fgColor~=false)then basaltDraw.drawForegroundBox(anchx, anchy, w, h, self.fgColor) end
end
if (self.barActive) then
if (self.parent ~= nil) then
if(self.bgColor~=false)then
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, w, h, self.fgColor) end
self.parent:writeText(anchx, anchy, utils.getTextHorizontalAlign(self.barText, w, self.barTextAlign), self.barBackground, self.barTextcolor)
else
if(self.bgColor~=false)then
basaltDraw.drawBackgroundBox(anchx, anchy, w, h, self.bgColor)
basaltDraw.drawTextBox(anchx, anchy, w, h, " ")
end
if(self.fgColor~=false)then basaltDraw.drawForegroundBox(anchx, anchy, w, h, self.fgColor) end
basaltDraw.writeText(anchx, anchy, utils.getTextHorizontalAlign(self.barText, w, self.barTextAlign), self.barBackground, self.barTextcolor)
end
termObject.setCursorBlink(false)
if (self.barActive) then
if(self:getBorder("left"))then
if (self.parent ~= nil) then
self.parent:writeText(anchx, anchy, utils.getTextHorizontalAlign(self.barText, w, self.barTextAlign), self.barBackground, self.barTextcolor)
else
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, h-1, self.bgColor)
end
end
end
if(self:getBorder("top"))then
if (self.parent ~= nil) then
self.parent:drawBackgroundBox(anchx-1, anchy-1, w+1, 1, self.barBackground)
self.parent:drawBackgroundBox(anchx-1, anchy, 1, 1, self.barBackground)
if(self.bgColor~=false)then
self.parent:drawBackgroundBox(anchx-1, anchy+1, 1, h-1, self.bgColor)
end
end
end
for _, index in rpairs(objZIndex) do
if (objects[index] ~= nil) then
for _, value in pairs(objects[index]) do
if (value.draw ~= nil) then
value:draw()
end
end
end
end
if (cursorBlink) then
termObject.setTextColor(cursorColor)
termObject.setCursorPos(xCursor, yCursor)
if(self:getBorder("top"))then
if (self.parent ~= nil) then
termObject.setCursorBlink(self:isFocused())
else
termObject.setCursorBlink(cursorBlink)
self.parent:drawBackgroundBox(anchx-1, anchy-1, w+1, 1, self.barBackground)
end
end
end
for _, index in rpairs(objZIndex) do
if (objects[index] ~= nil) then
for _, value in pairs(objects[index]) do
if (value.draw ~= nil) then
value:draw()
end
end
end
self:setVisualChanged(false)
end
end
end;
drawUpdate = function(self)
updateTerm = function(self)
if(isMonitor)and not(monitorAttached)then return false end;
basaltDraw.update()
end;
@@ -868,7 +1080,22 @@ return function(name, parent, pTerm, basalt)
addFrame = function(self, name)
local obj = basalt.newFrame(name or uuid(), self, nil, basalt)
return addObject(obj)
end;
end,
init = function(self)
if not(initialized)then
if (parent ~= nil) then
base.width, base.height = parent:getSize()
self:setBackground(parent:getTheme("FrameBG"))
self:setForeground(parent:getTheme("FrameText"))
else
base.width, base.height = termObject.getSize()
self:setBackground(basalt.getTheme("BasaltBG"))
self:setForeground(basalt.getTheme("BasaltText"))
end
initialized = true
end
end,
}
for k,v in pairs(_OBJECTS)do
object["add"..k] = function(self, name)
@@ -877,4 +1104,4 @@ return function(name, parent, pTerm, basalt)
end
setmetatable(object, base)
return object
end
end