diff --git a/Basalt/Frame.lua b/Basalt/Frame.lua index 817c2ca..a47eeae 100644 --- a/Basalt/Frame.lua +++ b/Basalt/Frame.lua @@ -144,7 +144,7 @@ return function(name, parent, pTerm, basalt) return self end; - getFrameOffset = function(self) -- internal + getOffset = function(self) -- internal return xOffset, yOffset end; @@ -250,7 +250,7 @@ return function(name, parent, pTerm, basalt) basalt.setMonitorFrame(monSide, nil) end end - basaltDraw = basaltDraw(termObject) + basaltDraw = BasaltDraw(termObject) monSide = side or nil return self; end; diff --git a/Basalt/Object.lua b/Basalt/Object.lua index 598db0f..7e0d9b5 100644 --- a/Basalt/Object.lua +++ b/Basalt/Object.lua @@ -1,8 +1,11 @@ local basaltEvent = require("basaltEvent") +local split = require("utils").splitString +local numberFromString = require("utils").numberFromString return function(name) -- Base object local objectType = "Object" -- not changeable + local object = {} local value local zIndex = 1 local anchor = "topLeft" @@ -22,7 +25,46 @@ return function(name) local eventSystem = basaltEvent() - local object = { + local dynamicValue = {} + local dynamicValueResult = {} + + local function replacePercentage(str, parentValue) + local _fullStr = str + for v in _fullStr:gmatch("%d+%%") do + local pValue = v:gsub("%%", "") + print(str) + str = str:gsub(v.."%", parentValue / 100 * math.max(math.min(tonumber(pValue),100),0)) + end + return str + end + + local function fToNumber(str, fTable) + for k,v in pairs(fTable)do + if(type(v)=="function")then + local nmb = v() + for _ in str:gmatch("f"..k)do + str = string.gsub(str, "f"..k, nmb) + end + end + end + str = str:gsub("f%d+", "") + return str + end + + local calcDynamicValue = function(newDValue) + local val = dynamicValue[newDValue][1] + if(val~=nil)then + if(type(val)=="string")then + if(dynamicValue[newDValue][3]~=nil)then + dynamicValueResult[newDValue] = numberFromString(replacePercentage(fToNumber(val, dynamicValue[newDValue][3]), dynamicValue[newDValue][2]() or 1)) + else + dynamicValueResult[newDValue] = numberFromString(replacePercentage(val, dynamicValue[newDValue][2]() or 1)) + end + end + end + end + + object = { x = 1, y = 1, width = 1, @@ -133,12 +175,36 @@ return function(name) else self.x, self.y = math.floor(xPos), math.floor(yPos) end + + + if(type(xPos)=="number")then + self.x = rel and self.x+xPos or xPos + end + if(type(yPos)=="number")then + self.y = rel and self.y+yPos or yPos + end + if(type(xPos)=="string")or(type(xPos)=="table")then + dynamicValue.x = {xPos, function() return self:getParent():getX() end} + end + if(type(yPos)=="string")or(type(yPos)=="table")then + dynamicValue.y = {yPos, function() return self:getParent():getY() end} + end + self:recalculateDynamicValue() + eventSystem:sendEvent("basalt_reposition", self) visualsChanged = true return self end; + getX = function(self) + return dynamicValue.x or self.x + end, + + getY = function(self) + return dynamicValue.y or self.y + end, + getPosition = function(self) - return self.x, self.y + return self:getX(), self:getY() end; getVisibility = function(self) @@ -151,23 +217,45 @@ return function(name) return self end; - setSize = function(self, width, height) - self.width, self.height = width, height + setSize = function(self, width, height, rel) + if(type(width)=="number")then + self.width = rel and self.width+width or width + end + if(type(height)=="number")then + self.height = rel and self.height+height or height + end + if(type(width)=="string")then + dynamicValue.width = {width, function() return self:getParent():getWidth() end} + end + if(type(width)=="table")then + dynamicValue.width = {width[1], function() return self:getParent():getWidth() end} + table.remove(width, 1) + dynamicValue.width[3] = width + end + if(type(height)=="string")then + dynamicValue.height = {height, function() return self:getParent():getHeight() end} + end + if(type(height)=="table")then + dynamicValue.height = {height[1], function() return self:getParent():getHeight() end} + table.remove(height, 1) + dynamicValue.height[3] = height + end + self:recalculateDynamicValue() eventSystem:sendEvent("basalt_resize", self) visualsChanged = true return self end; getHeight = function(self) - return self.height + return dynamicValueResult["height"] or self.height end; getWidth = function(self) - return self.width + return dynamicValueResult["width"] or self.width end; getSize = function(self) - return self.width, self.height + return self:getWidth(), self:getHeight() end; setBackground = function(self, color) @@ -246,16 +334,17 @@ return function(name) if (isVisible) then if(self.parent~=nil)then local x, y = self:getAnchorPosition() + local w,h = self:getSize() if(shadow)then - self.parent:drawBackgroundBox(x+1, y+self.height, self.width, 1, shadowColor) - self.parent:drawBackgroundBox(x+self.width, y+1, 1, self.height, shadowColor) - self.parent:drawForegroundBox(x+1, y+self.height, self.width, 1, shadowColor) - self.parent:drawForegroundBox(x+self.width, y+1, 1, self.height, shadowColor) + self.parent:drawBackgroundBox(x+1, y+h, w, 1, shadowColor) + self.parent:drawBackgroundBox(x+w, y+1, 1, h, shadowColor) + self.parent:drawForegroundBox(x+1, y+h, w, 1, shadowColor) + self.parent:drawForegroundBox(x+w, y+1, 1, h, shadowColor) end if(borderLeft)then - self.parent:drawTextBox(x-1, y, 1, self.height, "\149") - self.parent:drawForegroundBox(x-1, y, 1, self.height, borderColor) - if(self.bgColor~=false)then self.parent:drawBackgroundBox(x-1, y, 1, self.height, self.bgColor) end + self.parent:drawTextBox(x-1, y, 1, h, "\149") + self.parent:drawForegroundBox(x-1, y, 1, h, borderColor) + if(self.bgColor~=false)then self.parent:drawBackgroundBox(x-1, y, 1, h, self.bgColor) end end if(borderLeft)and(borderTop)then self.parent:drawTextBox(x-1, y-1, 1, 1, "\151") @@ -263,29 +352,29 @@ return function(name) if(self.bgColor~=false)then self.parent:drawBackgroundBox(x-1, y-1, 1, 1, self.bgColor) end end if(borderTop)then - self.parent:drawTextBox(x, y-1, self.width, 1, "\131") - self.parent:drawForegroundBox(x, y-1, self.width, 1, borderColor) - if(self.bgColor~=false)then self.parent:drawBackgroundBox(x, y-1, self.width, 1, self.bgColor) end + self.parent:drawTextBox(x, y-1, w, 1, "\131") + self.parent:drawForegroundBox(x, y-1, w, 1, borderColor) + if(self.bgColor~=false)then self.parent:drawBackgroundBox(x, y-1, w, 1, self.bgColor) end end if(borderTop)and(borderRight)then - self.parent:drawTextBox(x+self.width, y-1, 1, 1, "\149") - self.parent:drawForegroundBox(x+self.width, y-1, 1, 1, borderColor) + self.parent:drawTextBox(x+w, y-1, 1, 1, "\149") + self.parent:drawForegroundBox(x+w, y-1, 1, 1, borderColor) end if(borderRight)then - self.parent:drawTextBox(x+self.width, y, 1, self.height, "\149") - self.parent:drawForegroundBox(x+self.width, y, 1, self.height, borderColor) + self.parent:drawTextBox(x+w, y, 1, h, "\149") + self.parent:drawForegroundBox(x+w, y, 1, h, borderColor) end if(borderRight)and(borderBottom)then - self.parent:drawTextBox(x+self.width, y+self.height, 1, 1, "\129") - self.parent:drawForegroundBox(x+self.width, y+self.height, 1, 1, borderColor) + self.parent:drawTextBox(x+w, y+h, 1, 1, "\129") + self.parent:drawForegroundBox(x+w, y+h, 1, 1, borderColor) end if(borderBottom)then - self.parent:drawTextBox(x, y+self.height, self.width, 1, "\131") - self.parent:drawForegroundBox(x, y+self.height, self.width, 1, borderColor) + self.parent:drawTextBox(x, y+h, w, 1, "\131") + self.parent:drawForegroundBox(x, y+h, w, 1, borderColor) end if(borderBottom)and(borderLeft)then - self.parent:drawTextBox(x-1, y+self.height, 1, 1, "\131") - self.parent:drawForegroundBox(x-1, y+self.height, 1, 1, borderColor) + self.parent:drawTextBox(x-1, y+h, 1, 1, "\131") + self.parent:drawForegroundBox(x-1, y+h, 1, 1, borderColor) end end return true @@ -336,20 +425,15 @@ return function(name) x = math.floor(self.parent.width/2) + x - 1 y = math.floor(self.parent.height/2) + y - 1 end - local xO, yO = self:getOffset() - if not(ignOffset or ignOff) then - return x+xO, y+yO + if(self.parent~=nil)then + local xO, yO = self.parent:getOffset() + if not(ignOffset or ignOff) then + return x+xO, y+yO + end end return x, y end; - getOffset = function(self) - if (self.parent ~= nil) then - return self.parent:getFrameOffset() - end - return 0, 0 - end; - ignoreOffset = function(self, ignore) ignOffset = ignore if(ignore==nil)then ignOffset = true end @@ -439,7 +523,19 @@ return function(name) return self end; + recalculateDynamicValue = function(self, special) + if(special==nil)then + for k in pairs(dynamicValue)do + calcDynamicValue(k) + end + else + calcDynamicValue(special) + end + return self + end, + onResize = function(self, ...) + self:recalculateValues() for _,v in pairs(table.pack(...))do if(type(v)=="function")then self:registerEvent("basalt_resize", v) @@ -515,13 +611,14 @@ return function(name) mouseHandler = function(self, event, button, x, y) local objX, objY = self:getAbsolutePosition(self:getAnchorPosition()) + local w, h = self:getSize() local yOff = false if(objY-1 == y)and(self:getBorder("top"))then y = y+1 yOff = true end - if (objX <= x) and (objX + self.width > x) and (objY <= y) and (objY + self.height > y) and (isVisible) then + if (objX <= x) and (objX + w > x) and (objY <= y) and (objY + h > y) and (isVisible) then if (self.parent ~= nil) then self.parent:setFocusedObject(self) end diff --git a/Basalt/init.lua b/Basalt/init.lua index 8ba625f..bb8e6b0 100644 --- a/Basalt/init.lua +++ b/Basalt/init.lua @@ -2,9 +2,9 @@ local curDir = fs.getDir(table.pack(...)[2]) or "" local defaultPath = package.path local format = "%s;/%s/?.lua;/%s/?/init.lua" -package.path = string.format(format, package.path, curDir,curDir)..string.format(format, package.path, curDir.."/libraries",curDir.."/libraries") +package.path = string.format(format, package.path, curDir,curDir)..string.format(format, package.path, curDir.."/libraries",curDir.."/libraries")..string.format(format, package.path, curDir.."/objects",curDir.."/objects") local Basalt = require("main") package.path = defaultPath -return Basalt +return Basalt \ No newline at end of file diff --git a/Basalt/libraries/Lerp.lua b/Basalt/libraries/Lerp.lua new file mode 100644 index 0000000..2f58315 --- /dev/null +++ b/Basalt/libraries/Lerp.lua @@ -0,0 +1,14 @@ +return { + lerp = function(s, e, pct) + return s + (e - s) * pct + end, + + flip = function (x) + return 1 - x + end, + + easeIn = function (t) + return t * t + end, + +} \ No newline at end of file diff --git a/Basalt/libraries/basaltDraw.lua b/Basalt/libraries/basaltDraw.lua index b3835bf..554dbf9 100644 --- a/Basalt/libraries/basaltDraw.lua +++ b/Basalt/libraries/basaltDraw.lua @@ -181,4 +181,4 @@ return function(drawTerm) end; } return drawHelper -end +end \ No newline at end of file diff --git a/Basalt/libraries/bigfont.lua b/Basalt/libraries/bigfont.lua index 2373dab..9d8d14c 100644 --- a/Basalt/libraries/bigfont.lua +++ b/Basalt/libraries/bigfont.lua @@ -10,6 +10,8 @@ -- 5. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. -- NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. YOU ACKNOWLEDGE THAT THIS SOFTWARE IS NOT DESIGNED, LICENSED OR INTENDED FOR USE IN THE DESIGN, CONSTRUCTION, OPERATION OR MAINTENANCE OF ANY NUCLEAR FACILITY. +local tHex = require("tHex") + local rawFont = {{"\32\32\32\137\156\148\158\159\148\135\135\144\159\139\32\136\157\32\159\139\32\32\143\32\32\143\32\32\32\32\32\32\32\32\147\148\150\131\148\32\32\32\151\140\148\151\140\147", "\32\32\32\149\132\149\136\156\149\144\32\133\139\159\129\143\159\133\143\159\133\138\32\133\138\32\133\32\32\32\32\32\32\150\150\129\137\156\129\32\32\32\133\131\129\133\131\132", "\32\32\32\130\131\32\130\131\32\32\129\32\32\32\32\130\131\32\130\131\32\32\32\32\143\143\143\32\32\32\32\32\32\130\129\32\130\135\32\32\32\32\131\32\32\131\32\131", "\139\144\32\32\143\148\135\130\144\149\32\149\150\151\149\158\140\129\32\32\32\135\130\144\135\130\144\32\149\32\32\139\32\159\148\32\32\32\32\159\32\144\32\148\32\147\131\132", "\159\135\129\131\143\149\143\138\144\138\32\133\130\149\149\137\155\149\159\143\144\147\130\132\32\149\32\147\130\132\131\159\129\139\151\129\148\32\32\139\131\135\133\32\144\130\151\32", "\32\32\32\32\32\32\130\135\32\130\32\129\32\129\129\131\131\32\130\131\129\140\141\132\32\129\32\32\129\32\32\32\32\32\32\32\131\131\129\32\32\32\32\32\32\32\32\32", "\32\32\32\32\149\32\159\154\133\133\133\144\152\141\132\133\151\129\136\153\32\32\154\32\159\134\129\130\137\144\159\32\144\32\148\32\32\32\32\32\32\32\32\32\32\32\151\129", "\32\32\32\32\133\32\32\32\32\145\145\132\141\140\132\151\129\144\150\146\129\32\32\32\138\144\32\32\159\133\136\131\132\131\151\129\32\144\32\131\131\129\32\144\32\151\129\32", "\32\32\32\32\129\32\32\32\32\130\130\32\32\129\32\129\32\129\130\129\129\32\32\32\32\130\129\130\129\32\32\32\32\32\32\32\32\133\32\32\32\32\32\129\32\129\32\32", "\150\156\148\136\149\32\134\131\148\134\131\148\159\134\149\136\140\129\152\131\32\135\131\149\150\131\148\150\131\148\32\148\32\32\148\32\32\152\129\143\143\144\130\155\32\134\131\148", "\157\129\149\32\149\32\152\131\144\144\131\148\141\140\149\144\32\149\151\131\148\32\150\32\150\131\148\130\156\133\32\144\32\32\144\32\130\155\32\143\143\144\32\152\129\32\134\32", "\130\131\32\131\131\129\131\131\129\130\131\32\32\32\129\130\131\32\130\131\32\32\129\32\130\131\32\130\129\32\32\129\32\32\133\32\32\32\129\32\32\32\130\32\32\32\129\32", "\150\140\150\137\140\148\136\140\132\150\131\132\151\131\148\136\147\129\136\147\129\150\156\145\138\143\149\130\151\32\32\32\149\138\152\129\149\32\32\157\152\149\157\144\149\150\131\148", "\149\143\142\149\32\149\149\32\149\149\32\144\149\32\149\149\32\32\149\32\32\149\32\149\149\32\149\32\149\32\144\32\149\149\130\148\149\32\32\149\32\149\149\130\149\149\32\149", "\130\131\129\129\32\129\131\131\32\130\131\32\131\131\32\131\131\129\129\32\32\130\131\32\129\32\129\130\131\32\130\131\32\129\32\129\131\131\129\129\32\129\129\32\129\130\131\32", "\136\140\132\150\131\148\136\140\132\153\140\129\131\151\129\149\32\149\149\32\149\149\32\149\137\152\129\137\152\129\131\156\133\149\131\32\150\32\32\130\148\32\152\137\144\32\32\32", "\149\32\32\149\159\133\149\32\149\144\32\149\32\149\32\149\32\149\150\151\129\138\155\149\150\130\148\32\149\32\152\129\32\149\32\32\32\150\32\32\149\32\32\32\32\32\32\32", "\129\32\32\130\129\129\129\32\129\130\131\32\32\129\32\130\131\32\32\129\32\129\32\129\129\32\129\32\129\32\131\131\129\130\131\32\32\32\129\130\131\32\32\32\32\140\140\132", "\32\154\32\159\143\32\149\143\32\159\143\32\159\144\149\159\143\32\159\137\145\159\143\144\149\143\32\32\145\32\32\32\145\149\32\144\32\149\32\143\159\32\143\143\32\159\143\32", "\32\32\32\152\140\149\151\32\149\149\32\145\149\130\149\157\140\133\32\149\32\154\143\149\151\32\149\32\149\32\144\32\149\149\153\32\32\149\32\149\133\149\149\32\149\149\32\149", "\32\32\32\130\131\129\131\131\32\130\131\32\130\131\129\130\131\129\32\129\32\140\140\129\129\32\129\32\129\32\137\140\129\130\32\129\32\130\32\129\32\129\129\32\129\130\131\32", "\144\143\32\159\144\144\144\143\32\159\143\144\159\138\32\144\32\144\144\32\144\144\32\144\144\32\144\144\32\144\143\143\144\32\150\129\32\149\32\130\150\32\134\137\134\134\131\148", "\136\143\133\154\141\149\151\32\129\137\140\144\32\149\32\149\32\149\154\159\133\149\148\149\157\153\32\154\143\149\159\134\32\130\148\32\32\149\32\32\151\129\32\32\32\32\134\32", "\133\32\32\32\32\133\129\32\32\131\131\32\32\130\32\130\131\129\32\129\32\130\131\129\129\32\129\140\140\129\131\131\129\32\130\129\32\129\32\130\129\32\32\32\32\32\129\32", "\32\32\32\32\149\32\32\149\32\32\32\32\32\32\32\32\149\32\32\149\32\32\32\32\32\32\32\32\149\32\32\149\32\32\32\32\32\32\32\32\149\32\32\149\32\32\32\32", "\32\32\32\32\32\32\32\32\32\32\32\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\32\32\32\32\32\32\32\32\32\32\32", "\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32", "\32\32\32\32\149\32\32\149\32\32\32\32\32\32\32\32\149\32\32\149\32\32\32\32\32\32\32\32\149\32\32\149\32\32\32\32\32\32\32\32\149\32\32\149\32\32\32\32", "\32\32\32\32\32\32\32\32\32\32\32\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\32\32\32\32\32\32\32\32\32\32\32", "\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32", "\32\32\32\32\145\32\159\139\32\151\131\132\155\143\132\134\135\145\32\149\32\158\140\129\130\130\32\152\147\155\157\134\32\32\144\144\32\32\32\32\32\32\152\131\155\131\131\129", "\32\32\32\32\149\32\149\32\145\148\131\32\149\32\149\140\157\132\32\148\32\137\155\149\32\32\32\149\154\149\137\142\32\153\153\32\131\131\149\131\131\129\149\135\145\32\32\32", "\32\32\32\32\129\32\130\135\32\131\131\129\134\131\132\32\129\32\32\129\32\131\131\32\32\32\32\130\131\129\32\32\32\32\129\129\32\32\32\32\32\32\130\131\129\32\32\32", "\150\150\32\32\148\32\134\32\32\132\32\32\134\32\32\144\32\144\150\151\149\32\32\32\32\32\32\145\32\32\152\140\144\144\144\32\133\151\129\133\151\129\132\151\129\32\145\32", "\130\129\32\131\151\129\141\32\32\142\32\32\32\32\32\149\32\149\130\149\149\32\143\32\32\32\32\142\132\32\154\143\133\157\153\132\151\150\148\151\158\132\151\150\148\144\130\148", "\32\32\32\140\140\132\32\32\32\32\32\32\32\32\32\151\131\32\32\129\129\32\32\32\32\134\32\32\32\32\32\32\32\129\129\32\129\32\129\129\130\129\129\32\129\130\131\32", "\156\143\32\159\141\129\153\140\132\153\137\32\157\141\32\159\142\32\150\151\129\150\131\132\140\143\144\143\141\145\137\140\148\141\141\144\157\142\32\159\140\32\151\134\32\157\141\32", "\157\140\149\157\140\149\157\140\149\157\140\149\157\140\149\157\140\149\151\151\32\154\143\132\157\140\32\157\140\32\157\140\32\157\140\32\32\149\32\32\149\32\32\149\32\32\149\32", "\129\32\129\129\32\129\129\32\129\129\32\129\129\32\129\129\32\129\129\131\129\32\134\32\131\131\129\131\131\129\131\131\129\131\131\129\130\131\32\130\131\32\130\131\32\130\131\32", "\151\131\148\152\137\145\155\140\144\152\142\145\153\140\132\153\137\32\154\142\144\155\159\132\150\156\148\147\32\144\144\130\145\136\137\32\146\130\144\144\130\145\130\136\32\151\140\132", "\151\32\149\151\155\149\149\32\149\149\32\149\149\32\149\149\32\149\149\32\149\152\137\144\157\129\149\149\32\149\149\32\149\149\32\149\149\32\149\130\150\32\32\157\129\149\32\149", "\131\131\32\129\32\129\130\131\32\130\131\32\130\131\32\130\131\32\130\131\32\32\32\32\130\131\32\130\131\32\130\131\32\130\131\32\130\131\32\32\129\32\130\131\32\133\131\32", "\156\143\32\159\141\129\153\140\132\153\137\32\157\141\32\159\142\32\159\159\144\152\140\144\156\143\32\159\141\129\153\140\132\157\141\32\130\145\32\32\147\32\136\153\32\130\146\32", "\152\140\149\152\140\149\152\140\149\152\140\149\152\140\149\152\140\149\149\157\134\154\143\132\157\140\133\157\140\133\157\140\133\157\140\133\32\149\32\32\149\32\32\149\32\32\149\32", "\130\131\129\130\131\129\130\131\129\130\131\129\130\131\129\130\131\129\130\130\131\32\134\32\130\131\129\130\131\129\130\131\129\130\131\129\32\129\32\32\129\32\32\129\32\32\129\32", "\159\134\144\137\137\32\156\143\32\159\141\129\153\140\132\153\137\32\157\141\32\32\132\32\159\143\32\147\32\144\144\130\145\136\137\32\146\130\144\144\130\145\130\138\32\146\130\144", "\149\32\149\149\32\149\149\32\149\149\32\149\149\32\149\149\32\149\149\32\149\131\147\129\138\134\149\149\32\149\149\32\149\149\32\149\149\32\149\154\143\149\32\157\129\154\143\149", "\130\131\32\129\32\129\130\131\32\130\131\32\130\131\32\130\131\32\130\131\32\32\32\32\130\131\32\130\131\129\130\131\129\130\131\129\130\131\129\140\140\129\130\131\32\140\140\129" }, {"000110000110110000110010101000000010000000100101", "000000110110000000000010101000000010000000100101", "000000000000000000000000000000000000000000000000", "100010110100000010000110110000010100000100000110", "000000110000000010110110000110000000000000110000", "000000000000000000000000000000000000000000000000", "000000110110000010000000100000100000000000000010", "000000000110110100010000000010000000000000000100", "000000000000000000000000000000000000000000000000", "010000000000100110000000000000000000000110010000", "000000000000000000000000000010000000010110000000", "000000000000000000000000000000000000000000000000", "011110110000000100100010110000000100000000000000", "000000000000000000000000000000000000000000000000", "000000000000000000000000000000000000000000000000", "110000110110000000000000000000010100100010000000", "000010000000000000110110000000000100010010000000", "000000000000000000000000000000000000000000000000", "010110010110100110110110010000000100000110110110", "000000000000000000000110000000000110000000000000", "000000000000000000000000000000000000000000000000", "010100010110110000000000000000110000000010000000", "110110000000000000110000110110100000000010000000", "000000000000000000000000000000000000000000000000", "000100011111000100011111000100011111000100011111", "000000000000100100100100011011011011111111111111", "000000000000000000000000000000000000000000000000", "000100011111000100011111000100011111000100011111", "000000000000100100100100011011011011111111111111", "100100100100100100100100100100100100100100100100", "000000110100110110000010000011110000000000011000", "000000000100000000000010000011000110000000001000", "000000000000000000000000000000000000000000000000", "010000100100000000000000000100000000010010110000", "000000000000000000000000000000110110110110110000", "000000000000000000000000000000000000000000000000", "110110110110110110000000110110110110110110110110", "000000000000000000000110000000000000000000000000", "000000000000000000000000000000000000000000000000", "000000000000110110000110010000000000000000010010", "000010000000000000000000000000000000000000000000", "000000000000000000000000000000000000000000000000", "110110110110110110110000110110110110000000000000", "000000000000000000000110000000000000000000000000", "000000000000000000000000000000000000000000000000", "110110110110110110110000110000000000000000010000", "000000000000000000000000100000000000000110000110", "000000000000000000000000000000000000000000000000" }} --### Genarate fonts using 3x3 chars per a character. (1 character is 6x9 pixels) diff --git a/Basalt/libraries/geometric.lua b/Basalt/libraries/geometric.lua new file mode 100644 index 0000000..88facc2 --- /dev/null +++ b/Basalt/libraries/geometric.lua @@ -0,0 +1,88 @@ +local function filledRectangle(x1,y1,x2,y2) + +end + +local function filledCircle(xC, yC, r) + local points = {} + for x=-r, r+1 do + local dy = math.floor(math.sqrt(r*r - x*x)) + for y=-dy, dy+1 do + table.insert(points, {x=xC+x, y=yC+y}) + end + end + return points +end + +local function elipse(xC, yC, r1, r2, filled) + local rx,ry = math.ceil(math.floor(r1-0.5)/2),math.ceil(math.floor(r2-0.5)/2) + local x,y=0,ry + local d1 = ((ry * ry) - (rx * rx * ry) + (0.25 * rx * rx)) + local dx = 2*ry^2*x + local dy = 2*rx^2*y + local points = {} + while dx < dy do + table.insert(points,{x=x+xC,y=y+yC}) + table.insert(points,{x=-x+xC,y=y+yC}) + table.insert(points,{x=x+xC,y=-y+yC}) + table.insert(points,{x=-x+xC,y=-y+yC}) + if filled then + for y=-y+yC+1,y+yC-1 do + table.insert(points,{x=x+xC,y=y}) + table.insert(points,{x=-x+xC,y=y}) + end + end + if d1 < 0 then + x = x + 1 + dx = dx + 2*ry^2 + d1 = d1 + dx + ry^2 + else + x,y = x+1,y-1 + dx = dx + 2*ry^2 + dy = dy - 2*rx^2 + d1 = d1 + dx - dy + ry^2 + end + end + local d2 = (((ry * ry) * ((x + 0.5) * (x + 0.5))) + ((rx * rx) * ((y - 1) * (y - 1))) - (rx * rx * ry * ry)) + while y >= 0 do + table.insert(points,{x=x+xC,y=y+yC}) + table.insert(points,{x=-x+xC,y=y+yC}) + table.insert(points,{x=x+xC,y=-y+yC}) + table.insert(points,{x=-x+xC,y=-y+yC}) + if filled then + for y=-y+yC,y+yC do + table.insert(points,{x=x+xC,y=y}) + table.insert(points,{x=-x+xC,y=y}) + end + end + if d2 > 0 then + y = y - 1 + dy = dy - 2*rx^2 + d2 = d2 + rx^2 - dy + else + y = y - 1 + x = x + 1 + dy = dy - 2*rx^2 + dx = dx + 2*ry^2 + d2 = d2 + dx - dy + rx^2 + end + end + return points +end + +local function circle(xC, yC, r, filled) + return elipse(xC, yC, r, r, filled) +end + +return { +circle = function(x, y, radius, filled) + return circle(x, y, radius, filled) +end, + +rectangle = function(x1,y1,x2, y2, filled) + local positions = {} +end, + +elipse = function(xCenter, yCenter, radius1, radius2, filled) + return elipse(xCenter, yCenter, radius1, radius2, filled) +end +} \ No newline at end of file diff --git a/Basalt/libraries/imageConverter.lua b/Basalt/libraries/imageConverter.lua new file mode 100644 index 0000000..cc548a5 --- /dev/null +++ b/Basalt/libraries/imageConverter.lua @@ -0,0 +1,16 @@ +local function PPMToBasalt() + +end + + + +local function loadPPM(path) +local image = {} + + + return image +end + +return { + loadPPM = loadPPM +} \ No newline at end of file diff --git a/Basalt/libraries/layout.lua b/Basalt/libraries/layout.lua new file mode 100644 index 0000000..e69de29 diff --git a/Basalt/libraries/utils.lua b/Basalt/libraries/utils.lua index 82d118c..195b254 100644 --- a/Basalt/libraries/utils.lua +++ b/Basalt/libraries/utils.lua @@ -37,6 +37,22 @@ rpairs = function(t) end, t, #t + 1 end, +splitString = function(str, sep) + if sep == nil then + sep = "%s" + end + local t={} + for v in string.gmatch(str, "([^"..sep.."]+)") do + table.insert(t, v) + end + return t +end, + +numberFromString = function(str) + print(str) + return load("return " .. str)() +end, + -- shrink system is copy pasted (and slightly changed) from blittle by Bomb Bloke: http://www.computercraft.info/forums2/index.php?/topic/25354-cc-176-blittle-api/ shrink = function(bLittleData, bgColor) local relations = { [0] = { 8, 4, 3, 6, 5 }, { 4, 14, 8, 7 }, { 6, 10, 8, 7 }, { 9, 11, 8, 0 }, { 1, 14, 8, 0 }, { 13, 12, 8, 0 }, { 2, 10, 8, 0 }, { 15, 8, 10, 11, 12, 14 }, diff --git a/Basalt/main.lua b/Basalt/main.lua index be237f1..e5e7ce4 100644 --- a/Basalt/main.lua +++ b/Basalt/main.lua @@ -2,7 +2,7 @@ local basaltEvent = require("basaltEvent")() local Frame = require("Frame") local baseTerm = term.current() -local version = 2 +local version = 3 local debugger = true local projectDirectory = fs.getDir(table.pack(...)[2] or "") @@ -10,6 +10,10 @@ local projectDirectory = fs.getDir(table.pack(...)[2] or "") local activeKey, frames, monFrames = {}, {}, {} local mainFrame, activeFrame, focusedObject, updaterActive +if not term.isColor or not term.isColor() then + error('Basalt requires an advanced (golden) comptuer to run.', 0) +end + local function stop() updaterActive = false end @@ -112,6 +116,9 @@ end local basalt = {} basalt = { + getVersion = function() + return version + end, setBaseTerm = function(_baseTerm) baseTerm = _baseTerm diff --git a/Basalt/objects/Animation.lua b/Basalt/objects/Animation.lua index 902def5..0006ef0 100644 --- a/Basalt/objects/Animation.lua +++ b/Basalt/objects/Animation.lua @@ -1,3 +1,5 @@ +local lerp = require("Lerp") + return function(name) local object = {} local objectType = "Animation" @@ -232,4 +234,4 @@ return function(name) object.__index = object return object -end +end \ No newline at end of file diff --git a/Basalt/objects/Button.lua b/Basalt/objects/Button.lua index aa5a9b7..c2fd581 100644 --- a/Basalt/objects/Button.lua +++ b/Basalt/objects/Button.lua @@ -37,16 +37,17 @@ return function(name) if (base.draw(self)) then if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() - local verticalAlign = utils.getTextVerticalAlign(self.height, textVerticalAlign) + local w,h = self:getSize() + local verticalAlign = utils.getTextVerticalAlign(h, textVerticalAlign) if(self.bgColor~=false)then - self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) - self.parent:drawTextBox(obx, oby, self.width, self.height, " ") + self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor) + self.parent:drawTextBox(obx, oby, w, h, " ") end - if(self.fgColor~=false)then self.parent:drawForegroundBox(obx, oby, self.width, self.height, self.fgColor) end - for n = 1, self.height do + if(self.fgColor~=false)then self.parent:drawForegroundBox(obx, oby, w, h, self.fgColor) end + for n = 1, h do if (n == verticalAlign) then - self.parent:setText(obx, oby + (n - 1), utils.getTextHorizontalAlign(self:getValue(), self.width, textHorizontalAlign)) + self.parent:setText(obx, oby + (n - 1), utils.getTextHorizontalAlign(self:getValue(), w, textHorizontalAlign)) end end end diff --git a/Basalt/objects/Graphic.lua b/Basalt/objects/Graphic.lua new file mode 100644 index 0000000..4395297 --- /dev/null +++ b/Basalt/objects/Graphic.lua @@ -0,0 +1,53 @@ +local Object = require("Object") +local geometric = require("geometric") +local tHex = require("tHex") + +return function(name) + -- Graphic + local base = Object(name) + local objectType = "Graphic" + base:setZIndex(2) + + local graphic = {} + local graphicCache = {} + + local object = { + getType = function(self) + return objectType + end; + + addCircle = function(self, rad, color, x, y, filled) + table.insert(graphic, {area=geometric.circle(x or 1, y or 1, rad, filled), color=color}) + return self + end; + + addElipse = function(self, rad,rad2, color, x, y, filled) + table.insert(graphic, {area=geometric.elipse(x or 1, y or 1, rad, rad2, filled), color=color}) + return self + end; + + draw = function(self) + if (base.draw(self)) then + if (self.parent ~= nil) then + if(#graphic>0)then + local obx, oby = self:getAnchorPosition() + if(self.bgColor~=false)then + self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) + end + for _,v in pairs(graphic)do + local col = tHex[v.color] + for _,b in pairs(v.area)do + if(b.x>=1)and(b.x<=self.width)and(b.y>=1)and(b.y<=self.height)then + self.parent:setBG(obx+b.x-1, oby+b.y-1, col) + end + end + end + end + end + self:setVisualChanged(false) + end + end; + } + + return setmetatable(object, base) +end \ No newline at end of file diff --git a/Basalt/objects/Image.lua b/Basalt/objects/Image.lua index a646d00..4949b04 100644 --- a/Basalt/objects/Image.lua +++ b/Basalt/objects/Image.lua @@ -1,5 +1,5 @@ return function(name) - -- Pane + -- Image local base = Object(name) local objectType = "Image" base:setZIndex(2) diff --git a/Basalt/objects/Label.lua b/Basalt/objects/Label.lua index f8d87a6..289dfac 100644 --- a/Basalt/objects/Label.lua +++ b/Basalt/objects/Label.lua @@ -82,9 +82,26 @@ return function(name) self.parent:drawTextBox(obx, oby, self.width, self.height, " ") end if(self.fgColor~=false)then self.parent:drawForegroundBox(obx, oby, self.width, self.height, self.fgColor) end if(fontsize==0)then - for n = 1, self.height do - if (n == verticalAlign) then - self.parent:setText(obx, oby + (n - 1), utils.getTextHorizontalAlign(self:getValue(), self.width, textHorizontalAlign)) + if not(autoSize)then + local splittedText = utils.splitString(self:getValue(), " ") + local text = {} + local line = "" + for _,v in pairs(splittedText)do + if(line:len()+v:len()<=self.width)then + line = line=="" and v or line.." "..v + else + table.insert(text, line) + line = v:sub(1,self.width) + end + end + for k,v in pairs(text)do + self.parent:setText(obx, oby+k-1, v) + end + else + for n = 1, self.height do + if (n == verticalAlign) then + self.parent:setText(obx, oby + (n - 1), utils.getTextHorizontalAlign(self:getValue(), self.width, textHorizontalAlign)) + end end end else diff --git a/Basalt/objects/Scrollbar.lua b/Basalt/objects/Scrollbar.lua index 6992864..b8058f6 100644 --- a/Basalt/objects/Scrollbar.lua +++ b/Basalt/objects/Scrollbar.lua @@ -31,6 +31,20 @@ return function(name) return self end; + setIndex = function(self, _index) + index = _index + if (index < 1) then + index = 1 + end + index = math.min(index, (barType == "vertical" and self.height or self.width) - (symbolSize - 1)) + self:setValue(maxValue / (barType == "vertical" and self.height or self.width) * index) + return self + end, + + getIndex = function(self) + return index + end, + setSymbolSize = function(self, size) symbolSize = tonumber(size) or 1 if (barType == "vertical") then