diff --git a/Basalt/libraries/basaltMon.lua b/Basalt/libraries/basaltMon.lua index 820e997..bda683b 100644 --- a/Basalt/libraries/basaltMon.lua +++ b/Basalt/libraries/basaltMon.lua @@ -1,180 +1,143 @@ --- Right now this doesn't support scroll(n) --- Because this lbirary is mainly made for basalt - it doesn't need scroll support, maybe i will add it in the future -local tHex = { - [colors.white] = "0", - [colors.orange] = "1", - [colors.magenta] = "2", - [colors.lightBlue] = "3", - [colors.yellow] = "4", - [colors.lime] = "5", - [colors.pink] = "6", - [colors.gray] = "7", - [colors.lightGray] = "8", - [colors.cyan] = "9", - [colors.purple] = "a", - [colors.blue] = "b", - [colors.brown] = "c", - [colors.green] = "d", - [colors.red] = "e", - [colors.black] = "f", -} +local max, sub = math.max,string.sub -local type,len,rep,sub = type,string.len,string.rep,string.sub - - -return function (monitorNames) +return function(monitorNames) local monitors = {} - for k,v in pairs(monitorNames)do - monitors[k] = {} + local multiMonWidth, multiMonHeight = 0,0 + local multiMonX, multiMonY = 1, 1 + local bgColor, txtColor = colors.black, colors.white + for k,v in pairs(monitorNames) do + monitors[k] = {} for a,b in pairs(v)do - local mon = peripheral.wrap(b) - if(mon==nil)then - error("Unable to find monitor "..b) - end - monitors[k][a] = mon - monitors[k][a].name = b + monitors[k][a] = {name=b, monitor=peripheral.wrap(b)} end end - - local x,y,monX,monY,monW,monH,w,h = 1,1,1,1,0,0,0,0 - local blink,scale = false,1 - local fg,bg = colors.white,colors.black - - - local function calcSize() - local maxW,maxH = 0,0 - for k,v in pairs(monitors)do - local _maxW,_maxH = 0,0 - for a,b in pairs(v)do - local nw,nh = b.getSize() - _maxW = _maxW + nw - _maxH = nh > _maxH and nh or _maxH + local function calculateSize() + local absWidth, absHeight = 0,0 + local height = 0 + for _,v in pairs(monitors)do + local width = 0 + for _,b in pairs(v)do + local w, h = b.monitor.getSize() + width = width + w + height = max(height, h) end - maxW = maxW > _maxW and maxW or _maxW - maxH = maxH + _maxH + absWidth = max(absWidth, width) + absHeight = absHeight + height + height = 0 end - w,h = maxW,maxH + multiMonWidth, multiMonHeight = absWidth, absHeight end - calcSize() + calculateSize() - local function calcPosition() - local relY = 0 - local mX,mY = 0,0 + local function getMonitorFromPosition(x, y) + local absWidth, absHeight = 0,0 + local height = 0 for k,v in pairs(monitors)do - local relX = 0 - local _mh = 0 + local width = 0 for a,b in pairs(v)do - local mw,mh = b.getSize() - if(x-relX>=1)and(x-relX<=mw)then - mX = a + local w, h = b.monitor.getSize() + width = width + w + height = max(height, h) + if(x >= absWidth and x <= absWidth + w and y >= absHeight and y <= absHeight + h)then + return b.monitor, a, k end - b.setCursorPos(x-relX, y-relY) - relX = relX + mw - if(_mh=1)and(y-relY<=_mh)then - mY = k - end - relY = relY + _mh + absWidth = 0 + absHeight = absHeight + height + height = 0 end - monX,monY = mX,mY end - calcPosition() - local function call(f, ...) - local t = {...} - return function() - for k,v in pairs(monitors)do - for a,b in pairs(v)do - b[f](table.unpack(t)) + local function getRelativeCursorPos(mon, x, y) + local absWidth, absHeight = 0,0 + local height = 0 + for k,v in pairs(monitors)do + local width = 0 + for a,b in pairs(v)do + local w, h = b.monitor.getSize() + width = width + w + height = max(height, h) + if(b.monitor == mon)then + return x - absWidth, y - absHeight + end + absWidth = absWidth + w + end + absWidth = 0 + absHeight = absHeight + height + height = 0 + end + end + + local function blit(text, fgColor, bgColor) + local mon, x, y = getMonitorFromPosition(multiMonX, multiMonY) + + for k, v in pairs(monitors[y])do + if(k >= x)then + local xCursor, yCursor = getRelativeCursorPos(v.monitor, multiMonX, multiMonY) + local w, h = v.monitor.getSize() + local textToScreen = sub(text, 1, w) + text = sub(text, w+1) + local fgColorToScreen = sub(fgColor, 1, w) + fgColor = sub(fgColor, w+1) + local bgColorToScreen = sub(bgColor, 1, w) + bgColor = sub(bgColor, w+1) + v.monitor.setCursorPos(xCursor, yCursor) + v.monitor.blit(textToScreen, fgColorToScreen, bgColorToScreen) + multiMonX = multiMonX + w + end + end + end + + return { + getSize = function() + return multiMonWidth, multiMonHeight + end, + + blit = blit, + getCursorPos = function() + return multiMonX, multiMonY + end, + + setCursorPos = function(x, y) + multiMonX, multiMonY = x, y + for _,v in pairs(monitors)do + for _,b in pairs(v)do + local xCursor, yCursor = getRelativeCursorPos(b.monitor, multiMonX, multiMonY) + b.monitor.setCursorPos(xCursor, yCursor) end end - end - end - - local function cursorBlink() - call("setCursorBlink", false)() - if not(blink)then return end - if(monitors[monY]==nil)then return end - local mon = monitors[monY][monX] - if(mon==nil)then return end - mon.setCursorBlink(blink) - end - - local function blit(text, tCol, bCol) - if(monitors[monY]==nil)then return end - local mon = monitors[monY][monX] - if(mon==nil)then return end - mon.blit(text, tCol, bCol) - local mW, mH = mon.getSize() - if(len(text)+x>mW)then - local monRight = monitors[monY][monX+1] - if(monRight~=nil)then - monRight.blit(text, tCol, bCol) - monX = monX + 1 - x = x + len(text) - end - end - calcPosition() - end - - return { - clear = call("clear"), - - setCursorBlink = function(_blink) - blink = _blink - cursorBlink() end, getCursorBlink = function() - return blink + local mon = getMonitorFromPosition(multiMonX, multiMonY) + return mon.getCursorBlink() end, - getCursorPos = function() - return x, y - end, - - setCursorPos = function(newX,newY) - x, y = newX, newY - calcPosition() - cursorBlink() + setCursorBlink = function(blink) + for _,v in pairs(monitors)do + for _,b in pairs(v)do + b.monitor.setCursorBlink(blink) + end + end end, - setTextScale = function(_scale) - call("setTextScale", _scale)() - calcSize() - calcPosition() - scale = _scale + setBackgroundColor = function(color) + bgColor = color end, - getTextScale = function() - return scale + getBackgroundColor = function() + return bgColor end, - blit = function(text,fgCol,bgCol) - blit(text,fgCol,bgCol) + setTextColor = function(color) + txtColor = color end, - write = function(text) - text = tostring(text) - local l = len(text) - blit(text, rep(tHex[fg], l), rep(tHex[bg], l)) - end, - - getSize = function() - return w,h - end, - - setBackgroundColor = function(col) - call("setBackgroundColor", col)() - bg = col - end, - - setTextColor = function(col) - call("setTextColor", col)() - fg = col + getTextColor = function() + return txtColor end, calculateClick = function(name, xClick, yClick) @@ -183,7 +146,7 @@ return function (monitorNames) local relX = 0 local maxY = 0 for a,b in pairs(v)do - local wM,hM = b.getSize() + local wM,hM = b.monitor.getSize() if(b.name==name)then return xClick + relX, yClick + relY end @@ -194,6 +157,5 @@ return function (monitorNames) end return xClick, yClick end, - - } + } end \ No newline at end of file diff --git a/Basalt/objects/Graph.lua b/Basalt/objects/Graph.lua index 37a4263..8d13728 100644 --- a/Basalt/objects/Graph.lua +++ b/Basalt/objects/Graph.lua @@ -23,7 +23,7 @@ return function(name, basalt) table.insert(graphData, value) self:updateDraw() end - if(#graphData>100)then -- 100 is hard capped to prevent memory leaks + while #graphData>self:getMaxEntries() do table.remove(graphData,1) end return self @@ -105,4 +105,4 @@ return function(name, basalt) object.__index = object return setmetatable(object, base) -end \ No newline at end of file +end diff --git a/Basalt/objects/Label.lua b/Basalt/objects/Label.lua index 130d434..0441340 100644 --- a/Basalt/objects/Label.lua +++ b/Basalt/objects/Label.lua @@ -12,6 +12,7 @@ return function(name, basalt) base:addProperty("text", "string", "Label", nil, function(self, value) local autoSize = self:getAutoSize() + value = tostring(value) if(autoSize)then local t = wrapText(value, #value) local newW, newH = 1,0 diff --git a/Basalt/objects/Object.lua b/Basalt/objects/Object.lua index 2907483..5b3a6fa 100644 --- a/Basalt/objects/Object.lua +++ b/Basalt/objects/Object.lua @@ -61,6 +61,10 @@ return function(name, basalt) if(typ=="any")or(value==nil)or(type(value)=="function")then isValid = true end + if(typ=="string")and(type(value)~="function")then + value = tostring(value) + isValid = true + end if(not isValid)then local t = type(value) diff --git a/Basalt/plugins/bigfonts.lua b/Basalt/plugins/bigfonts.lua index 3d68c04..c277121 100644 --- a/Basalt/plugins/bigfonts.lua +++ b/Basalt/plugins/bigfonts.lua @@ -166,6 +166,7 @@ return { setText = function(self, text) base.setText(self, text) if(fontsize>1)then + bigfont = makeText(fontsize-1, self:getText(), self:getForeground(), self:getBackground() or colors.lightGray) if(self:getAutoSize())then self:getBase():setSize(#bigfont[1][1], #bigfont[1]-1) end diff --git a/Basalt/plugins/templates.lua b/Basalt/plugins/templates.lua index 919789c..5f43734 100644 --- a/Basalt/plugins/templates.lua +++ b/Basalt/plugins/templates.lua @@ -74,9 +74,6 @@ local plugin = { Input = { Background = "{self.focused ? gray : black}", Foreground = "{self.focused ? black : lightGray}", - defaultBackground = "{self.focused ? gray : black}", - defaultForeground = "{self.focused ? black : lightGray}", - defaultText = "..." }, }, }