From 44402b1d261b880b718288b40118ad5746212232 Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Sun, 9 Oct 2022 10:50:02 +0200 Subject: [PATCH] Basalt 1.6.3 - some improvements - added new animations (:setMode("animname") - added :addMode("animname", f) to create custom easings - Fixed a bug in input when using - or . nothing happens (inputmode number) - Added a event for labels when using multiple line text and the window/frame gets resized) - Changed some backend stuff for programs - added a setEnviroment method for programs - Added a program_done event and a program_error event for programs (:onError() and :onDone()) - Fixed a bug in textfields (when using editLine it doesn't update colors) - seperated the char event from the key event (before both events executed :onKey events, now there is a :onChar() and :onKey() event --- Basalt/libraries/geometricPoints.lua | 197 ----------- Basalt/objects/Animation.lua | 186 ++++++++++- Basalt/objects/Button.lua | 6 +- Basalt/objects/Checkbox.lua | 8 +- Basalt/objects/Dropdown.lua | 16 +- Basalt/objects/Graphic.lua | 471 --------------------------- Basalt/objects/Input.lua | 10 +- Basalt/objects/Label.lua | 45 ++- Basalt/objects/List.lua | 10 +- Basalt/objects/Menubar.lua | 12 +- Basalt/objects/Program.lua | 85 +++-- Basalt/objects/Progressbar.lua | 8 +- Basalt/objects/Radio.lua | 14 +- Basalt/objects/Scrollbar.lua | 8 +- Basalt/objects/Slider.lua | 8 +- Basalt/objects/Switch.lua | 12 +- Basalt/objects/Textfield.lua | 11 +- 17 files changed, 358 insertions(+), 749 deletions(-) delete mode 100644 Basalt/libraries/geometricPoints.lua delete mode 100644 Basalt/objects/Graphic.lua diff --git a/Basalt/libraries/geometricPoints.lua b/Basalt/libraries/geometricPoints.lua deleted file mode 100644 index 01800a2..0000000 --- a/Basalt/libraries/geometricPoints.lua +++ /dev/null @@ -1,197 +0,0 @@ -local function line(x1,y1,x2,y2) - local points = {} - if x1 == x2 and y1 == y2 then return {x=x1,y=x2} end - local minX = math.min(x1, x2) - local maxX, minY, maxY - if minX == x1 then minY,maxX,maxY = y1,x2,y2 - else minY,maxX,maxY = y2,x1,y1 end - local xDiff,yDiff = maxX - minX,maxY - minY - if xDiff > math.abs(yDiff) then - local y = minY - local dy = yDiff / xDiff - for x = minX, maxX do - table.insert(points,{x=x,y=math.floor(y + 0.5)}) - y = y + dy - end - else - local x,dx = minX,xDiff / yDiff - if maxY >= minY then - for y = minY, maxY do - table.insert(points,{x=math.floor(x + 0.5),y=y}) - x = x + dx - end - else - for y = minY, maxY, -1 do - table.insert(points,{x=math.floor(x + 0.5),y=y}) - x = x - dx - end - end - end - return points -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 ellipse(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 ellipse(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 points = {} - if(filled)then - for y=y1,y2 do - for x=x1,x2 do - table.insert(points, {x=x,y=y}) - end - end - else - for y=y1,y2 do - for x=x1,x2 do - if(x==x1)or(x==x2)or(y==y1)or(y==y2)then - table.insert(points, {x=x,y=y}) - end - end - end - end - return points -end, - -triangle = function(x1, y1, x2, y2, x3, y3, filled) - local function drawFlatTopTriangle(points,x1,y1,x2,y2,x3,y3) - local m1 = (x3 - x1) / (y3 - y1) - local m2 = (x3 - x2) / (y3 - y2) - local yStart = math.ceil(y1 - 0.5) - local yEnd = math.ceil(y3 - 0.5)-1 - for y = yStart, yEnd do - local px1 = m1 * (y + 0.5 - y1) + x1 - local px2 = m2 * (y + 0.5 - y2) + x2 - local xStart = math.ceil(px1 - 0.5) - local xEnd = math.ceil(px2 - 0.5) - for x=xStart,xEnd do - table.insert(points,{x=x,y=y}) - end - end - end - - local function drawFlatBottomTriangle(points,x1,y1,x2,y2,x3,y3) - local m1 = (x2 - x1) / (y2 - y1) - local m2 = (x3 - x1) / (y3 - y1) - local yStart = math.ceil(y1-0.5) - local yEnd = math.ceil(y3-0.5)-1 - for y = yStart, yEnd do - local px1 = m1 * (y + 0.5 - y1) + x1 - local px2 = m2 * (y + 0.5 - y1) + x1 - local xStart = math.ceil(px1 - 0.5) - local xEnd = math.ceil(px2 - 0.5) - for x=xStart,xEnd do - table.insert(points,{x=x,y=y}) - end - end - end - local points = {} - if(filled)then - if y2 < y1 then x1,y1,x2,y2 = x2,y2,x1,y1 end - if y3 < y2 then x2,y2,x3,y3 = x3,y3,x2,y2 end - if y2 < y2 then x1,y1,x2,y2 = x2,y2,x1,y1 end - if y1 == y2 then - if x2 < x1 then x1,y1,x2,y2 = x2,y2,x1,y1 end - drawFlatTopTriangle(points,x1,y1,x2,y2,x3,y3) - elseif y2 == y3 then - if x3 < x2 then x3,y3,x2,y2 = x2,y2,x3,y3 end - drawFlatBottomTriangle(points,x1,y1,x2,y2,x3,y3) - else - local alphaSplit = (y2-y1)/(y3-y1) - local x = x1 + ((x3 - x1) * alphaSplit) - local y = y1 + ((y3 - y1) * alphaSplit) - if x2 < x then - drawFlatBottomTriangle(points,x1,y1,x2,y2,x, y) - drawFlatTopTriangle(points,x2,y2,x,y,x3,y3) - else - drawFlatBottomTriangle(points,x1,y1,x,y,x1,y1) - drawFlatTopTriangle(points,x,y,x2,y2,x3,y3) - end - end - else - points = line(x1,y1,x2,y2) - for k,v in pairs(line(x2,y2,x3,y3))do table.insert(points, v) end - for k,v in pairs(line(x3,y3,x1,y1))do table.insert(points, v) end - end - return points -end, - -line = line, - -ellipse = function(xCenter, yCenter, radius1, radius2, filled) - return ellipse(xCenter, yCenter, radius1, radius2, filled) -end -} \ No newline at end of file diff --git a/Basalt/objects/Animation.lua b/Basalt/objects/Animation.lua index 48d9d97..45800b6 100644 --- a/Basalt/objects/Animation.lua +++ b/Basalt/objects/Animation.lua @@ -1,7 +1,9 @@ local xmlValue = require("utils").getValueFromXML local basaltEvent = require("basaltEvent") -local floor,sin,cos,pi = math.floor,math.sin,math.cos,math.pi +local floor,sin,cos,pi,sqrt,pow = math.floor,math.sin,math.cos,math.pi,math.sqrt,math.pow + +-- You can find the easing curves here https://easings.net local lerp = function(s, e, pct) return s + (e - s) * pct @@ -39,16 +41,183 @@ local easeInOutSine = function(t) return -(cos(pi * x) - 1) / 2 end +local easeInBack = function(t) + local c1 = 1.70158; + local c3 = c1 + 1 + return c3*t^3-c1*t^2 +end + +local easeInCubic = function(t) + return t^3 +end + +local easeInElastic = function(t) + local c4 = (2*pi)/3; + return t == 0 and 0 or (t == 1 and 1 or ( + -2^(10*t-10)*sin((t*10-10.75)*c4) + )) +end + +local function easeInExpo(t) + return t == 0 and 0 or 2^(10*t-10) +end + +local function easeInExpo(t) + return t == 0 and 0 or 2^(10*t-10) +end + +local function easeInOutBack(t) + local c1 = 1.70158; + local c2 = c1 * 1.525; + return t < 0.5 and ((2*t)^2*((c2+1)*2*t-c2))/2 or ((2*t-2)^2*((c2+1)*(t*2-2)+c2)+2)/2 +end + +local function easeInOutCubic(t) + return t < 0.5 and 4 * t^3 or 1-(-2*t+2)^3 / 2 +end + +local function easeInOutElastic(t) + local c5 = (2*pi) / 4.5 + return t==0 and 0 or (t == 1 and 1 or (t < 0.5 and -(2^(20*t-10) * sin((20*t - 11.125) * c5))/2 or (2^(-20*t+10) * sin((20*t - 11.125) * c5))/2 + 1)) +end + +local function easeInOutExpo(t) + return t == 0 and 0 or (t == 1 and 1 or (t < 0.5 and 2^(20*t-10)/2 or (2-2^(-20*t+10)) /2)) +end + +local function easeInOutQuad(t) + return t < 0.5 and 2*t^2 or 1-(-2*t+2)^2/2 +end + +local function easeInOutQuart(t) + return t < 0.5 and 8*t^4 or 1 - (-2*t+2)^4 / 2 +end + +local function easeInOutQuint(t) + return t < 0.5 and 16*t^5 or 1-(-2*t+2)^5 / 2 +end + +local function easeInQuad(t) + return t^2 +end + +local function easeInQuart(t) + return t^4 +end + +local function easeInQuint(t) + return t^5 +end + +local function easeOutBack(t) + local c1 = 1.70158; + local c3 = c1 + 1 + return 1+c3*(t-1)^3+c1*(t-1)^2 +end + +local function easeOutCubic(t) + return 1 - (1-t)^3 +end + +local function easeOutElastic(t) + local c4 = (2*pi)/3; + + return t == 0 and 0 or (t == 1 and 1 or (2^(-10*t)*sin((t*10-0.75)*c4)+1)) +end + +local function easeOutExpo(t) + return t == 1 and 1 or 1-2^(-10*t) +end + +local function easeOutQuad(t) + return 1 - (1 - t) * (1 - t) +end + +local function easeOutQuart(t) + return 1 - (1-t)^4 +end + +local function easeOutQuint(t) + return 1 - (1 - t)^5 +end + +local function easeInCirc(t) + return 1 - sqrt(1 - pow(t, 2)) +end + +local function easeOutCirc(t) + return sqrt(1 - pow(t - 1, 2)) +end + +local function easeInOutCirc(t) + return t < 0.5 and (1 - sqrt(1 - pow(2 * t, 2))) / 2 or (sqrt(1 - pow(-2 * t + 2, 2)) + 1) / 2; +end + +local function easeOutBounce(t) + local n1 = 7.5625; + local d1 = 2.75; + + if (t < 1 / d1)then + return n1 * t * t + elseif (t < 2 / d1)then + local a = t - 1.5 / d1 + return n1 * a * a + 0.75; + elseif (t < 2.5 / d1)then + local a = t - 2.25 / d1 + return n1 * a * a + 0.9375; + else + local a = t - 2.625 / d1 + return n1 * a * a + 0.984375; + end +end + +local function easeInBounce(t) + return 1 - easeOutBounce(1 - t) +end + +local function easeInOutBounce(t) + return x < 0.5 and (1 - easeOutBounce(1 - 2 * t)) / 2 or (1 + easeOutBounce(2 * t - 1)) / 2; +end + + + local lerp = { linear = linear, lerp = lerp, flip=flip, easeIn=easeIn, - easeOut=easeOut, - easeInOut=easeInOut, - easeOutSine = easeOutSine, easeInSine = easeInSine, + easeInBack=easeInBack, + easeInCubic=easeInCubic, + easeInElastic=easeInElastic, + easeInExpo=easeInExpo, + easeInQuad=easeInQuad, + easeInQuart=easeInQuart, + easeInQuint=easeInQuint, + easeInCirc=easeInCirc, + easeInBounce=easeInBounce, + easeOut=easeOut, + easeOutSine = easeOutSine, + easeOutBack=easeOutBack, + easeOutCubic=easeOutCubic, + easeOutElastic=easeOutElastic, + easeOutExpo=easeOutExpo, + easeOutQuad=easeOutQuad, + easeOutQuart=easeOutQuart, + easeOutQuint=easeOutQuint, + easeOutCirc=easeOutCirc, + easeOutBounce=easeOutBounce, + easeInOut=easeInOut, easeInOutSine = easeInOutSine, + easeInOutBack=easeInOutBack, + easeInOutCubic=easeInOutCubic, + easeInOutElastic=easeInOutElastic, + easeInOutExpo=easeInOutExpo, + easeInOutQuad=easeInOutQuad, + easeInOutQuart=easeInOutQuart, + easeInOutQuint=easeInOutQuint, + easeInOutCirc=easeInOutCirc, + easeInOutBounce=easeInOutBounce, } local activeAnimations = {} @@ -185,6 +354,11 @@ return function(name) return self end, + addMode = function(self, modeId, modeF) + lerp[modeId] = modeF + return self + end, + generateXMLEventFunction = function(self, func, val) local createF = function(str) if(str:sub(1,1)=="#")then @@ -362,9 +536,9 @@ return function(name) return self end, - add = function(self, func, wait) + add = function(self, func, timer) lastFunc = func - addAnimationPart((wait or nextWaitTimer) + (animations[#animations]~=nil and animations[#animations].t or 0), func) + addAnimationPart((timer or nextWaitTimer) + (animations[#animations]~=nil and animations[#animations].t or 0), func) return self end; diff --git a/Basalt/objects/Button.lua b/Basalt/objects/Button.lua index 577f593..6ae68b1 100644 --- a/Basalt/objects/Button.lua +++ b/Basalt/objects/Button.lua @@ -17,8 +17,10 @@ return function(name) local object = { init = function(self) - self.bgColor = self.parent:getTheme("ButtonBG") - self.fgColor = self.parent:getTheme("ButtonText") + if(base.init(self))then + self.bgColor = self.parent:getTheme("ButtonBG") + self.fgColor = self.parent:getTheme("ButtonText") + end end, getType = function(self) return objectType diff --git a/Basalt/objects/Checkbox.lua b/Basalt/objects/Checkbox.lua index 5ef5834..fc4ef39 100644 --- a/Basalt/objects/Checkbox.lua +++ b/Basalt/objects/Checkbox.lua @@ -72,10 +72,12 @@ return function(name) end, init = function(self) - base.init(self) - self.bgColor = self.parent:getTheme("CheckboxBG") - self.fgColor = self.parent:getTheme("CheckboxText") self.parent:addEvent("mouse_click", self) + self.parent:addEvent("mouse_up", self) + if(base.init(self))then + self.bgColor = self.parent:getTheme("CheckboxBG") + self.fgColor = self.parent:getTheme("CheckboxText") + end end, } diff --git a/Basalt/objects/Dropdown.lua b/Basalt/objects/Dropdown.lua index 29706fd..6f90715 100644 --- a/Basalt/objects/Dropdown.lua +++ b/Basalt/objects/Dropdown.lua @@ -225,14 +225,14 @@ return function(name) end, init = function(self) - self.bgColor = self.parent:getTheme("DropdownBG") - self.fgColor = self.parent:getTheme("DropdownText") - itemSelectedBG = self.parent:getTheme("SelectionBG") - itemSelectedFG = self.parent:getTheme("SelectionText") - if(self.parent~=nil)then - self.parent:addEvent("mouse_click", self) - self.parent:addEvent("mouse_up", self) - self.parent:addEvent("mouse_scroll", self) + self.parent:addEvent("mouse_click", self) + self.parent:addEvent("mouse_up", self) + self.parent:addEvent("mouse_scroll", self) + if(base.init(self))then + self.bgColor = self.parent:getTheme("DropdownBG") + self.fgColor = self.parent:getTheme("DropdownText") + itemSelectedBG = self.parent:getTheme("SelectionBG") + itemSelectedFG = self.parent:getTheme("SelectionText") end end, } diff --git a/Basalt/objects/Graphic.lua b/Basalt/objects/Graphic.lua deleted file mode 100644 index 52be81d..0000000 --- a/Basalt/objects/Graphic.lua +++ /dev/null @@ -1,471 +0,0 @@ -local Object = require("Object") -local geometric = require("geometricPoints") -local tHex = require("tHex") -local xmlValue = require("utils").getValueFromXML - -local sub,len,max,min = string.sub,string.len,math.max,math.min - -return function(name) - -- Graphic - local base = Object(name) - local objectType = "Graphic" - base:setZIndex(2) - - local graphicObjects = {} - local graphic = {} - local shrinkedGraphic = {} - local isGraphicShrinked = false - local xOffset, yOffset = 0, 0 - local dragable = false - local xMouse,yMouse - local w, h = 40, 15 - local canvasSizeChanged = false - - local tColourLookup = {} - for n=1,16 do - tColourLookup[ string.byte( "0123456789abcdef",n,n ) ] = 2^(n-1) - end - - local function stringToTable(str) - local t = {} - for i = 1, #str do - t[i] = str:sub(i, i) - end - return t - end - - local function setBG(x, y, width, height, colorStr) - if (y >= 1) and (y <= height) then - if (x + len(colorStr) > 0) and (x <= width) then - local oldCache = graphic[y] - local newCache - local nEnd = x + #colorStr - 1 - - if (x < 1) then - colorStr = sub(colorStr, 1 - x + 1, width - x + 1) - elseif (nEnd > width) then - colorStr = sub(colorStr, 1, width - x + 1) - end - - if (x > 1) then - newCache = sub(oldCache, 1, x - 1) .. colorStr - else - newCache = colorStr - end - if nEnd < width then - newCache = newCache .. sub(oldCache, nEnd + 1, width) - end - graphic[y] = newCache - end - end - end - - local function redrawCanvasSize() - local w,h = w,h - if(isGraphicShrinked)then w = w*2 h = h*3 end - for y=1,h do - if(graphic[y]~=nil)then - if(w>graphic[y]:len())then - graphic[y] = graphic[y]..(tHex[base.bgColor]):rep(w-graphic[y]:len()) - else - graphic[y] = graphic[y]:sub(1,w) - end - else - graphic[y] = (tHex[base.bgColor]):rep(w) - end - end - end - redrawCanvasSize() - - - local function shrink() - local function parseLine( tImageArg, sLine ) - local tLine = {} - for x=1,sLine:len() do - tLine[x] = tColourLookup[ string.byte(sLine,x,x) ] or 0 - end - table.insert( tImageArg, tLine ) - end - function parseImage( sRawData ) - if type( sRawData ) ~= "string" then - error( "bad argument #1 (expected string, got " .. type( sRawData ) .. ")" ) - end - local tImage = {} - for sLine in ( sRawData .. "\n" ):gmatch( "(.-)\n" ) do - parseLine( tImage, sLine ) - end - return tImage - end - - local rawImg = "" - for y=1,#graphic do - if(y==#graphic)then - rawImg = rawImg..graphic[y] - else - rawImg = rawImg..graphic[y].."\n" - end - end - local img = parseImage(rawImg) - -- shrinkSystem is copy pasted (and slightly changed) from blittle by Bomb Bloke: http://www.computercraft.info/forums2/index.php?/topic/25354-cc-176-blittle-api/ - 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 }, - { 0, 7, 1, 9, 2, 13 }, { 3, 11, 8, 7 }, { 2, 6, 7, 15 }, { 9, 3, 7, 15 }, { 13, 5, 7, 15 }, { 5, 12, 8, 7 }, { 1, 4, 7, 15 }, { 7, 10, 11, 12, 14 } } - - local colourNum, exponents, colourChar = {}, {}, {} - for i = 0, 15 do - exponents[2 ^ i] = i - end - do - local hex = "0123456789abcdef" - for i = 1, 16 do - colourNum[hex:sub(i, i)] = i - 1 - colourNum[i - 1] = hex:sub(i, i) - colourChar[hex:sub(i, i)] = 2 ^ (i - 1) - colourChar[2 ^ (i - 1)] = hex:sub(i, i) - - local thisRel = relations[i - 1] - for i = 1, #thisRel do - thisRel[i] = 2 ^ thisRel[i] - end - end - end - - local function getBestColourMatch(usage) - local lastCol = relations[exponents[usage[#usage][1]]] - - for j = 1, #lastCol do - local thisRelation = lastCol[j] - for i = 1, #usage - 1 do - if usage[i][1] == thisRelation then - return i - end - end - end - - return 1 - end - - local function colsToChar(pattern, totals) - if not totals then - local newPattern = {} - totals = {} - for i = 1, 6 do - local thisVal = pattern[i] - local thisTot = totals[thisVal] - totals[thisVal], newPattern[i] = thisTot and (thisTot + 1) or 1, thisVal - end - pattern = newPattern - end - - local usage = {} - for key, value in pairs(totals) do - usage[#usage + 1] = { key, value } - end - - if #usage > 1 then - -- Reduce the chunk to two colours: - while #usage > 2 do - table.sort(usage, function(a, b) - return a[2] > b[2] - end) - local matchToInd, usageLen = getBestColourMatch(usage), #usage - local matchFrom, matchTo = usage[usageLen][1], usage[matchToInd][1] - for i = 1, 6 do - if pattern[i] == matchFrom then - pattern[i] = matchTo - usage[matchToInd][2] = usage[matchToInd][2] + 1 - end - end - usage[usageLen] = nil - end - - -- Convert to character. Adapted from oli414's function: - -- http://www.computercraft.info/forums2/index.php?/topic/25340-cc-176-easy-drawing-characters/ - local data = 128 - for i = 1, #pattern - 1 do - if pattern[i] ~= pattern[6] then - data = data + 2 ^ (i - 1) - end - end - return string.char(data), colourChar[usage[1][1] == pattern[6] and usage[2][1] or usage[1][1]], colourChar[pattern[6]] - else - -- Solid colour character: - return "\128", colourChar[pattern[1]], colourChar[pattern[1]] - end - end - - local results, width, height, bgCol = { {}, {}, {} }, 0, #img + #img % 3, base.bgColor or colors.black - for i = 1, #img do - if #img[i] > width then - width = #img[i] - end - end - - for y = 0, height - 1, 3 do - local cRow, tRow, bRow, counter = {}, {}, {}, 1 - - for x = 0, width - 1, 2 do - -- Grab a 2x3 chunk: - local pattern, totals = {}, {} - - for yy = 1, 3 do - for xx = 1, 2 do - pattern[#pattern + 1] = (img[y + yy] and img[y + yy][x + xx]) and (img[y + yy][x + xx] == 0 and bgCol or img[y + yy][x + xx]) or bgCol - totals[pattern[#pattern]] = totals[pattern[#pattern]] and (totals[pattern[#pattern]] + 1) or 1 - end - end - - cRow[counter], tRow[counter], bRow[counter] = colsToChar(pattern, totals) - counter = counter + 1 - end - - results[1][#results[1] + 1], results[2][#results[2] + 1], results[3][#results[3] + 1] = table.concat(cRow), table.concat(tRow), table.concat(bRow) - end - - results.width, results.height = #results[1][1], #results[1] - - shrinkedGraphic = results - end - - local function redraw() - local w,h = w,h - if(isGraphicShrinked)then w = w*2 h = h*3 end - for k,v in pairs(graphicObjects)do - for a,b in pairs(v[1])do - setBG(b.x, b.y, w, h, v[2]) - end - end - if(isGraphicShrinked)then - shrink() - end - end - - local object = { - init = function(self) - self.bgColor = self.parent:getTheme("GraphicBG") - end, - - getType = function(self) - return objectType - end; - - setSize = function(self, width, height, rel) - base.setSize(self, width, height, rel) - if not(canvasSizeChanged)then - w = width - h = height - redrawCanvasSize() - end - redraw() - return self - end, - - setOffset = function(self, x, y) - xOffset = x or xOffset - yOffset = y or yOffset - return self - end, - - setCanvasSize = function(self, width, height) - w,h = width,height - canvasSizeChanged = true - redrawCanvasSize() - return self - end, - - clearCanvas = function(self) - graphicObjects = {} - graphic = {} - redrawCanvasSize() - end, - - getOffset = function(self) - return xOffset,yOffset - end, - - setValuesByXMLData = function(self, data) - base.setValuesByXMLData(self, data) - if(xmlValue("text", data)~=nil)then self:setText(xmlValue("text", data)) end - if(xmlValue("xOffset", data)~=nil)then self:setOffset(xmlValue("xOffset", data), yOffset) end - if(xmlValue("yOffset", data)~=nil)then self:setOffset(xOffset, xmlValue("yOffset", data)) end - if(xmlValue("wCanvas", data)~=nil)then w = xmlValue("wCanvas", data) end - if(xmlValue("hCanvas", data)~=nil)then h = xmlValue("hCanvas", data) end - if(xmlValue("shrink", data)~=nil)then if(xmlValue("shrink", data))then self:shrink() end end - if(xmlValue("dragable", data)~=nil)then if(xmlValue("dragable", data))then dragable = true end end - if(data["ellipse"]~=nil)then - local tab = data["ellipse"] - if(tab.properties~=nil)then tab = {tab} end - for k,v in pairs(tab)do - local col = colors[xmlValue("color", v)] - local rad1 = xmlValue("radius", v) - local rad2 = xmlValue("radius2", v) - local x = xmlValue("x", v) - local y = xmlValue("y", v) - local filled = xmlValue("filled", v) - self:addEllipse(col, rad1, rad2, x, y, filled) - end - end - if(data["circle"]~=nil)then - local tab = data["circle"] - if(tab.properties~=nil)then tab = {tab} end - for k,v in pairs(tab)do - local col = colors[xmlValue("color", v)] - local rad = tonumber(xmlValue("radius", v)) - local x = tonumber(xmlValue("x", v)) - local y = tonumber(xmlValue("y", v)) - local filled = xmlValue("filled", v) - self:addCircle(col, rad, x, y, filled) - end - end - if(data["line"]~=nil)then - local tab = data["line"] - if(tab.properties~=nil)then tab = {tab} end - for k,v in pairs(tab)do - local col = colors[xmlValue("color", v)] - local x = tonumber(xmlValue("x", v)) - local x2 = tonumber(xmlValue("x2", v)) - local y = tonumber(xmlValue("y", v)) - local y2 = tonumber(xmlValue("y2", v)) - self:addLine(col, x, y, x2, y2) - end - end - - if(data["rectangle"]~=nil)then - local tab = data["rectangle"] - if(tab.properties~=nil)then tab = {tab} end - for k,v in pairs(tab)do - local col = colors[xmlValue("color", v)] - local x = tonumber(xmlValue("x", v)) - local x2 = tonumber(xmlValue("x2", v)) - local y = tonumber(xmlValue("y", v)) - local y2 = tonumber(xmlValue("y2", v)) - local filled = xmlValue("filled", v)=="true" and true or false - self:addRectangle(col, x, y, x2, y2, filled) - end - end - if(data["triangle"]~=nil)then - local tab = data["triangle"] - if(tab.properties~=nil)then tab = {tab} end - for k,v in pairs(tab)do - local col = colors[xmlValue("color", v)] - local x = tonumber(xmlValue("x", v)) - local x2 = tonumber(xmlValue("x2", v)) - local x3 = tonumber(xmlValue("x2", v)) - local y = tonumber(xmlValue("y", v)) - local y2 = tonumber(xmlValue("y2", v)) - local y3 = tonumber(xmlValue("y3", v)) - local filled = xmlValue("filled", v) - self:addTriangle(col, x, y, x2, y2, x3, y3, filled) - end - end - - return self - end, - - addCircle = function(self, color, rad, x, y, filled) - local col = tHex[color] - table.insert(graphicObjects, {geometric.circle(x or 1, y or 1, rad, filled), tHex[color]}) - redraw() - return self - end; - - addEllipse = function(self, color, rad, rad2, x, y, filled) - table.insert(graphicObjects, {geometric.ellipse(x or 1, y or 1, rad, rad2, filled), tHex[color]}) - redraw() - return self - end; - - addLine = function(self, color, x1, y1, x2, y2) - table.insert(graphicObjects, {geometric.line(x1 or 1, y1 or 1, x2 or 1, y2 or 1), tHex[color]}) - redraw() - return self - end; - - addTriangle = function(self, color, x1, y1, x2, y2, x3, y3, filled) - table.insert(graphicObjects, {geometric.triangle(x1 or 1, y1 or 1, x2 or 1, y2 or 1, x3 or 1, y3 or 1, filled), tHex[color]}) - redraw() - return self - end; - - addRectangle = function(self, color, x1, y1, x2, y2, filled) - table.insert(graphicObjects, {geometric.rectangle(x1 or 1, y1 or 1, x2 or 1, y2 or 1, filled), tHex[color]}) - redraw() - return self - end; - - shrink = function(self) - isGraphicShrinked = true - redrawCanvasSize() - shrink() - return self - end, - - setDragable = function(self, drag) - dragable = drag == true and true or false - return self - end, - - mouseHandler = function(self, event, button, x, y) - if(base.mouseHandler(self, event, button, x, y))then - if(dragable)then - if(event=="mouse_click")then - xMouse,yMouse = x,y - end - - if(event=="mouse_drag")then - if(xMouse~=nil)and(yMouse~=nil)then - xOffset = max(min(xOffset+xMouse-x, w-self:getWidth()),0) - xMouse = x - yOffset = max(min(yOffset+yMouse-y, h-self:getHeight()),0) - yMouse = y - end - end - end - return true - end - return false - end, - - draw = function(self) - if (base.draw(self)) then - if (self.parent ~= nil) then - local obx, oby = self:getAnchorPosition() - local w,h = self:getSize() - if(self.bgColor~=false)then - self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor) - end - if (isGraphicShrinked) then - -- this is copy pasted (and slightly changed) from blittle by Bomb Bloke: http://www.computercraft.info/forums2/index.php?/topic/25354-cc-176-blittle-api/ - local t, tC, bC = shrinkedGraphic[1], shrinkedGraphic[2], shrinkedGraphic[3] - for i = 1, shrinkedGraphic.height do - local x, y = obx+xOffset, oby + i - 1 + yOffset - if(y>oby-1)and(y<=oby+h-1)and(x<=w+obx)then - local tI = t[i] - local xpos,substart,subend = max(x, obx), max(1 - x + 1, 1), min(w - (x-obx), w) - if type(tI) == "string" then - self.parent:setText(xpos, y, sub(tI, substart, subend)) - self.parent:setFG(xpos, y, sub(tC[i], substart, subend)) - self.parent:setBG(xpos, y, sub(bC[i], substart, subend)) - elseif type(tI) == "table" then - self.parent:setText(xpos, y, sub(tI[2], substart, subend)) - self.parent:setFG(xpos, y, sub(tC[i], substart, subend)) - self.parent:setBG(xpos, y, sub(bC[i], substart, subend)) - end - end - end - else - for i = 1, #graphic do - local x, y = obx+xOffset, oby + i - 1 + yOffset - if(y>oby-1)and(y<=oby+h-1)and(x<=w+obx)then - local xpos,substart,subend = max(x, obx), max(1 - x + 1, 1), min(w - (x-obx), w) - self.parent:setBG(xpos, y, sub(graphic[i],substart,subend)) - 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/Input.lua b/Basalt/objects/Input.lua index a54fb9c..06c68f6 100644 --- a/Basalt/objects/Input.lua +++ b/Basalt/objects/Input.lua @@ -202,12 +202,12 @@ return function(name) if (text:len() < inputLimit or inputLimit <= 0) then if (inputType == "number") then local cache = text - if (char == ".") or (tonumber(char) ~= nil) then + if (#text==0 and char == "-") or (char == ".") or (tonumber(char) ~= nil) then self:setValue(text:sub(1, textX - 1) .. char .. text:sub(textX, text:len())) textX = textX + 1 end if (tonumber(base.getValue()) == nil) then - self:setValue(cache) + --self:setValue(cache) end else self:setValue(text:sub(1, textX - 1) .. char .. text:sub(textX, text:len())) @@ -353,8 +353,6 @@ return function(name) end, init = function(self) - self.bgColor = self.parent:getTheme("InputBG") - self.fgColor = self.parent:getTheme("InputText") if(self.parent~=nil)then self.parent:addEvent("mouse_click", self) self.parent:addEvent("key", self) @@ -362,6 +360,10 @@ return function(name) self.parent:addEvent("other_event", self) self.parent:addEvent("mouse_drag", self) end + if(base.init(self))then + self.bgColor = self.parent:getTheme("InputBG") + self.fgColor = self.parent:getTheme("InputText") + end end, } diff --git a/Basalt/objects/Label.lua b/Basalt/objects/Label.lua index b4bc53e..7c586d1 100644 --- a/Basalt/objects/Label.lua +++ b/Basalt/objects/Label.lua @@ -31,7 +31,12 @@ return function(name) text = tostring(text) base:setValue(text) if (autoSize) then - self.width = text:len() + if(text:len()+self:getX()>self.parent:getWidth())then + local newW = self.parent:getWidth() - self:getX() + base.setSize(self, newW, #createText(text, newW)) + else + base.setSize(self, text:len(), 1) + end end self:updateDraw() return self @@ -86,6 +91,22 @@ return function(name) return self end; + eventHandler = function(self, event) + if(event=="basalt_resize")then + if (autoSize) then + local text = self:getValue() + if(text:len()+self:getX()>self.parent:getWidth())then + local newW = self.parent:getWidth() - self:getX() + base.setSize(self, newW, #createText(text, newW)) + else + base.setSize(self, text:len(), 1) + end + else + --self.parent:removeEvent("other_event", self) + end + end + end, + draw = function(self) if (base.draw(self)) then if (self.parent ~= nil) then @@ -96,10 +117,21 @@ return function(name) if not(autoSize)then local text = createText(self:getValue(), self:getWidth()) for k,v in pairs(text)do - self.parent:writeText(obx, oby+k-1, v, self.bgColor, self.fgColor) + if(k<=h)then + self.parent:writeText(obx, oby+k-1, v, self.bgColor, self.fgColor) + end end else - self.parent:writeText(obx, oby, self:getValue(), self.bgColor, self.fgColor) + if(#self:getValue()+obx>self.parent:getWidth())then + local text = createText(self:getValue(), self:getWidth()) + for k,v in pairs(text)do + if(k<=h)then + self.parent:writeText(obx, oby+k-1, v, self.bgColor, self.fgColor) + end + end + else + self.parent:writeText(obx, oby, self:getValue(), self.bgColor, self.fgColor) + end end else local tData = bigFont(fontsize, self:getValue(), self.fgColor, self.bgColor or colors.lightGray) @@ -112,15 +144,16 @@ return function(name) oby = oby or math.floor((oY - cY) / 2) + 1 for i = 1, cY do - self.parent:setFG(obx, oby + i - 2, tData[2][i]) - self.parent:setBG(obx, oby + i - 2, tData[3][i]) - self.parent:setText(obx, oby + i - 2, tData[1][i]) + self.parent:setFG(obx, oby + i - 1, tData[2][i]) + self.parent:setBG(obx, oby + i - 1, tData[3][i]) + self.parent:setText(obx, oby + i - 1, tData[1][i]) end end end end end, init = function(self) + self.parent:addEvent("other_event", self) if(base.init(self))then self.bgColor = self.parent:getTheme("LabelBG") self.fgColor = self.parent:getTheme("LabelText") diff --git a/Basalt/objects/List.lua b/Basalt/objects/List.lua index b89683b..97bdae4 100644 --- a/Basalt/objects/List.lua +++ b/Basalt/objects/List.lua @@ -199,13 +199,15 @@ return function(name) end, init = function(self) - self.bgColor = self.parent:getTheme("ListBG") - self.fgColor = self.parent:getTheme("ListText") - itemSelectedBG = self.parent:getTheme("SelectionBG") - itemSelectedFG = self.parent:getTheme("SelectionText") self.parent:addEvent("mouse_click", self) self.parent:addEvent("mouse_drag", self) self.parent:addEvent("mouse_scroll", self) + if(base.init(self))then + self.bgColor = self.parent:getTheme("ListBG") + self.fgColor = self.parent:getTheme("ListText") + itemSelectedBG = self.parent:getTheme("SelectionBG") + itemSelectedFG = self.parent:getTheme("SelectionText") + end end, } diff --git a/Basalt/objects/Menubar.lua b/Basalt/objects/Menubar.lua index 0e28f5a..2745783 100644 --- a/Basalt/objects/Menubar.lua +++ b/Basalt/objects/Menubar.lua @@ -226,14 +226,14 @@ return function(name) end, init = function(self) - self.bgColor = self.parent:getTheme("MenubarBG") - self.fgColor = self.parent:getTheme("MenubarText") - itemSelectedBG = self.parent:getTheme("SelectionBG") - itemSelectedFG = self.parent:getTheme("SelectionText") - self.parent:addEvent("mouse_click", self) self.parent:addEvent("mouse_scroll", self) - + if(base.init(self))then + self.bgColor = self.parent:getTheme("MenubarBG") + self.fgColor = self.parent:getTheme("MenubarText") + itemSelectedBG = self.parent:getTheme("SelectionBG") + itemSelectedFG = self.parent:getTheme("SelectionText") + end end, } diff --git a/Basalt/objects/Program.lua b/Basalt/objects/Program.lua index 6a5df05..adbda79 100644 --- a/Basalt/objects/Program.lua +++ b/Basalt/objects/Program.lua @@ -2,7 +2,6 @@ local Object = require("Object") local tHex = require("tHex") local process = require("process") local xmlValue = require("utils").getValueFromXML -local log = require("basaltLogs") local sub = string.sub @@ -12,6 +11,7 @@ return function(name, parent) base:setZIndex(5) local object local cachedPath + local enviroment = {} local function createBasaltWindow(x, y, width, height, self) local xCursor, yCursor = 1, 1 @@ -428,7 +428,21 @@ return function(name, parent) local obx, oby = self:getAnchorPosition() local w,h = self:getSize() if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then - self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor()) + self.parent:setCursor(self:isFocused() and pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor()) + end + end + + local function resumeProcess(self, event, ...) + local ok, result = curProcess:resume(event, ...) + if (ok==false)and(result~=nil)and(result~="Terminated")then + local val = self:sendEvent("program_error", result) + if(val~=false)then + error("Basalt Program - "..result) + end + end + + if(curProcess:getStatus()=="dead")then + self:sendEvent("program_done") end end @@ -439,7 +453,7 @@ return function(name, parent) if not (curProcess:isDead()) then if not (paused) then local absX, absY = self:getAbsolutePosition(self:getAnchorPosition(nil, nil, true)) - curProcess:resume(event, p1, x-absX+1, y-absY+1) + resumeProcess(self, event, p1, x-absX+1, y-absY+1) updateCursor(self) end end @@ -452,7 +466,7 @@ return function(name, parent) if not (curProcess:isDead()) then if not (paused) then if (self.draw) then - curProcess:resume(event, key, isHolding) + resumeProcess(self, event, key, isHolding) updateCursor(self) end end @@ -511,9 +525,14 @@ return function(name, parent) return "inactive" end; + setEnviroment = function(self, env) + enviroment = env or {} + return self + end, + execute = function(self, path, ...) cachedPath = path or cachedPath - curProcess = process:new(cachedPath, pWindow, ...) + curProcess = process:new(cachedPath, pWindow, enviroment, ...) pWindow.setBackgroundColor(colors.black) pWindow.setTextColor(colors.white) pWindow.clear() @@ -521,7 +540,8 @@ return function(name, parent) pWindow.setBackgroundColor(self.bgColor) pWindow.setTextColor(self.fgColor) pWindow.basalt_setVisible(true) - curProcess:resume() + + resumeProcess(self) paused = false if(self.parent~=nil)then self.parent:addEvent("mouse_click", self) @@ -539,7 +559,7 @@ return function(name, parent) stop = function(self) if (curProcess ~= nil) then if not (curProcess:isDead()) then - curProcess:resume("terminate") + resumeProcess(self, "terminate") if (curProcess:isDead()) then if (self.parent ~= nil) then self.parent:setCursor(false) @@ -572,7 +592,7 @@ return function(name, parent) if (curProcess ~= nil) then if not (curProcess:isDead()) then if (paused == false) or (ign) then - curProcess:resume(event, p1, p2, p3, p4) + resumeProcess(self, event, p1, p2, p3, p4) else table.insert(queuedEvent, { event = event, args = { p1, p2, p3, p4 } }) end @@ -594,7 +614,7 @@ return function(name, parent) if (curProcess ~= nil) then if not (curProcess:isDead()) then for _, value in pairs(events) do - curProcess:resume(value.event, table.unpack(value.args)) + resumeProcess(self, value.event, table.unpack(value.args)) end end end @@ -665,11 +685,9 @@ return function(name, parent) if (self.parent ~= nil) then local xCur, yCur = pWindow.getCursorPos() local obx, oby = self:getAnchorPosition() - if (self.parent ~= nil) then - local w,h = self:getSize() - if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then - self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor()) - end + local w,h = self:getSize() + if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then + self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor()) end end end @@ -699,7 +717,7 @@ return function(name, parent) if(w~=pW)or(h~=pH)then pWindow.basalt_resize(pW, pH) if not (curProcess:isDead()) then - curProcess:resume("term_resize") + resumeProcess(self, "term_resize") end end pWindow.basalt_reposition(self:getAnchorPosition()) @@ -708,7 +726,7 @@ return function(name, parent) if not (curProcess:isDead()) then if not (paused) then if(event ~= "terminate") then - curProcess:resume(event, p1, p2, p3, p4) + resumeProcess(self, event, p1, p2, p3, p4) end if (self:isFocused()) then local obx, oby = self:getAnchorPosition() @@ -721,8 +739,7 @@ return function(name, parent) end if (event == "terminate") then - log(self:isFocused()) - curProcess:resume(event) + resumeProcess(self, event) self.parent:setCursor(false) return true end @@ -739,15 +756,45 @@ return function(name, parent) if (base.draw(self)) then if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() + local xCur, yCur = pWindow.getCursorPos() local w,h = self:getSize() pWindow.basalt_reposition(obx, oby) pWindow.basalt_update() + if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then + self.parent:setCursor(self:isFocused() and pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor()) + end end end end, + onError = function(self, ...) + for _,v in pairs(table.pack(...))do + if(type(v)=="function")then + self:registerEvent("program_error", v) + end + end + if(self.parent~=nil)then + self.parent:addEvent("other_event", self) + end + return self + end, + + onDone = function(self, ...) + for _,v in pairs(table.pack(...))do + if(type(v)=="function")then + self:registerEvent("program_done", v) + end + end + if(self.parent~=nil)then + self.parent:addEvent("other_event", self) + end + return self + end, + init = function(self) - self.bgColor = self.parent:getTheme("ProgramBG") + if(base.init(self))then + elf.bgColor = self.parent:getTheme("ProgramBG") + end end, } diff --git a/Basalt/objects/Progressbar.lua b/Basalt/objects/Progressbar.lua index ab5974c..8b17151 100644 --- a/Basalt/objects/Progressbar.lua +++ b/Basalt/objects/Progressbar.lua @@ -21,9 +21,11 @@ return function(name) local object = { init = function(self) - self.bgColor = self.parent:getTheme("ProgressbarBG") - self.fgColor = self.parent:getTheme("ProgressbarText") - activeBarColor = self.parent:getTheme("ProgressbarActiveBG") + if(base.init(self))then + self.bgColor = self.parent:getTheme("ProgressbarBG") + self.fgColor = self.parent:getTheme("ProgressbarText") + activeBarColor = self.parent:getTheme("ProgressbarActiveBG") + end end, getType = function(self) return objectType diff --git a/Basalt/objects/Radio.lua b/Basalt/objects/Radio.lua index 82854b1..b870c2e 100644 --- a/Basalt/objects/Radio.lua +++ b/Basalt/objects/Radio.lua @@ -153,13 +153,15 @@ return function(name) end, init = function(self) - self.bgColor = self.parent:getTheme("MenubarBG") - self.fgColor = self.parent:getTheme("MenubarFG") - itemSelectedBG = self.parent:getTheme("SelectionBG") - itemSelectedFG = self.parent:getTheme("SelectionText") - boxSelectedBG = self.parent:getTheme("MenubarBG") - boxSelectedFG = self.parent:getTheme("MenubarText") self.parent:addEvent("mouse_click", self) + if(base.init(self))then + self.bgColor = self.parent:getTheme("MenubarBG") + self.fgColor = self.parent:getTheme("MenubarFG") + itemSelectedBG = self.parent:getTheme("SelectionBG") + itemSelectedFG = self.parent:getTheme("SelectionText") + boxSelectedBG = self.parent:getTheme("MenubarBG") + boxSelectedFG = self.parent:getTheme("MenubarText") + end end, } diff --git a/Basalt/objects/Scrollbar.lua b/Basalt/objects/Scrollbar.lua index dbe46ed..e73310b 100644 --- a/Basalt/objects/Scrollbar.lua +++ b/Basalt/objects/Scrollbar.lua @@ -173,12 +173,14 @@ return function(name) end, init = function(self) - self.bgColor = self.parent:getTheme("ScrollbarBG") - self.fgColor = self.parent:getTheme("ScrollbarText") - symbolColor = self.parent:getTheme("ScrollbarSymbolColor") self.parent:addEvent("mouse_click", self) self.parent:addEvent("mouse_drag", self) self.parent:addEvent("mouse_scroll", self) + if(base.init(self))then + self.bgColor = self.parent:getTheme("ScrollbarBG") + self.fgColor = self.parent:getTheme("ScrollbarText") + symbolColor = self.parent:getTheme("ScrollbarSymbolColor") + end end, } diff --git a/Basalt/objects/Slider.lua b/Basalt/objects/Slider.lua index 4a71c6a..dc72884 100644 --- a/Basalt/objects/Slider.lua +++ b/Basalt/objects/Slider.lua @@ -173,12 +173,14 @@ return function(name) end, init = function(self) - self.bgColor = self.parent:getTheme("SliderBG") - self.fgColor = self.parent:getTheme("SliderText") - symbolColor = self.parent:getTheme("SliderSymbolColor") self.parent:addEvent("mouse_click", self) self.parent:addEvent("mouse_drag", self) self.parent:addEvent("mouse_scroll", self) + if(base.init(self))then + self.bgColor = self.parent:getTheme("SliderBG") + self.fgColor = self.parent:getTheme("SliderText") + symbolColor = self.parent:getTheme("SliderSymbolColor") + end end, } diff --git a/Basalt/objects/Switch.lua b/Basalt/objects/Switch.lua index 8eb4603..717773d 100644 --- a/Basalt/objects/Switch.lua +++ b/Basalt/objects/Switch.lua @@ -74,12 +74,14 @@ return function(name) end, init = function(self) - self.bgColor = self.parent:getTheme("SwitchBG") - self.fgColor = self.parent:getTheme("SwitchText") - bgSymbol = self.parent:getTheme("SwitchBGSymbol") - inactiveBG = self.parent:getTheme("SwitchInactive") - activeBG = self.parent:getTheme("SwitchActive") self.parent:addEvent("mouse_click", self) + if(base.init(self))then + self.bgColor = self.parent:getTheme("SwitchBG") + self.fgColor = self.parent:getTheme("SwitchText") + bgSymbol = self.parent:getTheme("SwitchBGSymbol") + inactiveBG = self.parent:getTheme("SwitchInactive") + activeBG = self.parent:getTheme("SwitchActive") + end end, } diff --git a/Basalt/objects/Textfield.lua b/Basalt/objects/Textfield.lua index 2516e01..29730a7 100644 --- a/Basalt/objects/Textfield.lua +++ b/Basalt/objects/Textfield.lua @@ -144,6 +144,7 @@ return function(name) editLine = function(self, index, text) lines[index] = text or lines[index] + updateColors(self, index) self:updateDraw() return self end; @@ -163,18 +164,20 @@ return function(name) lines[1] = text bgLines[1] = tHex[self.bgColor]:rep(text:len()) fgLines[1] = tHex[self.fgColor]:rep(text:len()) + updateColors(self, 1) return self end if (index ~= nil) then table.insert(lines, index, text) table.insert(bgLines, index, tHex[self.bgColor]:rep(text:len())) - table.insert(fgLines, tHex[self.fgColor]:rep(text:len())) + table.insert(fgLines, index, tHex[self.fgColor]:rep(text:len())) else table.insert(lines, text) table.insert(bgLines, tHex[self.bgColor]:rep(text:len())) table.insert(fgLines, tHex[self.fgColor]:rep(text:len())) end end + updateColors(self, index or #lines) self:updateDraw() return self end; @@ -605,14 +608,16 @@ return function(name) end, init = function(self) - self.bgColor = self.parent:getTheme("TextfieldBG") - self.fgColor = self.parent:getTheme("TextfieldText") self.parent:addEvent("mouse_click", self) self.parent:addEvent("mouse_scroll", self) self.parent:addEvent("mouse_drag", self) self.parent:addEvent("key", self) self.parent:addEvent("char", self) self.parent:addEvent("other_event", self) + if(base.init(self))then + self.bgColor = self.parent:getTheme("TextfieldBG") + self.fgColor = self.parent:getTheme("TextfieldText") + end end, }