diff --git a/Basalt/Frame.lua b/Basalt/Frame.lua index b29820e..65fdf1f 100644 --- a/Basalt/Frame.lua +++ b/Basalt/Frame.lua @@ -347,7 +347,6 @@ return function(name, parent, pTerm, basalt) focusedObjectCache:getFocusHandler() end focusedObject = focusedObjectCache - focusedObjectCache = nil end end @@ -389,7 +388,7 @@ 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_resize", value, self) + value:eventHandler("basalt_resize", value, self) end end end @@ -419,7 +418,7 @@ 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 diff --git a/Basalt/Object.lua b/Basalt/Object.lua index 69d1d93..f843950 100644 --- a/Basalt/Object.lua +++ b/Basalt/Object.lua @@ -14,6 +14,7 @@ return function(name) local anchor = "topLeft" local ignOffset = false local isVisible = true + local initialized = false local shadow = false local borderLeft = false @@ -308,7 +309,7 @@ return function(name) setBackground = function(self, color, symbol, symbolCol) self.bgColor = color or false - self.bgSymbol = symbol or (color~=false and self.bgSymbol or false) + self.bgSymbol = symbol or (self.bgColor~=false and self.bgSymbol or false) self.bgSymbolColor = symbolCol or self.bgSymbolColor self:updateDraw() return self @@ -406,8 +407,10 @@ return function(name) self.parent:drawBackgroundBox(x, y, w, h, self.bgColor) end if(self.bgSymbol~=false)then - self.parent:drawForegroundBox(x, y, w, h, self.bgSymbolColor) self.parent:drawTextBox(x, y, w, h, self.bgSymbol) + if(self.bgSymbol~=" ")then + self.parent:drawForegroundBox(x, y, w, h, self.bgSymbolColor) + end end if(shadow)then self.parent:drawBackgroundBox(x+1, y+h, w, 1, shadowColor) @@ -735,9 +738,6 @@ return function(name) if(self:isCoordsInObject(x, y))then local val = eventSystem:sendEvent("mouse_up", self, "mouse_up", button, x, y) if(val==false)then return false end - if(self.parent~=nil)then - self.parent:setFocusedObject(self) - end return true end return false @@ -829,7 +829,6 @@ return function(name) getFocusHandler = function(self) local val = eventSystem:sendEvent("get_focus", self) if(val~=nil)then return val end - log("Focus "..self:getName()) return true end; @@ -837,7 +836,6 @@ return function(name) isDragging = false local val = eventSystem:sendEvent("lose_focus", self) if(val~=nil)then return val end - log("Losefocus "..self:getName()) return true end; @@ -849,6 +847,10 @@ return function(name) end end end + if not(initialized)then + initialized = true + return true + end end } diff --git a/Basalt/main.lua b/Basalt/main.lua index 0628231..baac265 100644 --- a/Basalt/main.lua +++ b/Basalt/main.lua @@ -7,7 +7,7 @@ local createText = utils.createText local baseTerm = term.current() -local version = 5 +local version = "1.6.0" local debugger = true local projectDirectory = fs.getDir(table.pack(...)[2] or "") diff --git a/Basalt/objects/Animation.lua b/Basalt/objects/Animation.lua index 8090dea..9dd6934 100644 --- a/Basalt/objects/Animation.lua +++ b/Basalt/objects/Animation.lua @@ -403,6 +403,12 @@ return function(name) play = function(self, infinite) self:cancel() + if(_OBJ~=nil)then + if(activeAnimations[_OBJ:getName()]~=nil)then + activeAnimations[_OBJ:getName()]:cancel() + end + activeAnimations[_OBJ:getName()] = self + end animationActive = true infinitePlay = infinite and true or false index = 1 @@ -421,6 +427,13 @@ return function(name) end; cancel = function(self) + if(_OBJ~=nil)then + if(activeAnimations[_OBJ:getName()]~=nil)then + if(activeAnimations[_OBJ:getName()]==self)then + activeAnimations[_OBJ:getName()] = nil + end + end + end if(timerObj~=nil)then os.cancelTimer(timerObj) infinitePlay = false diff --git a/Basalt/objects/Input.lua b/Basalt/objects/Input.lua index 73e027b..654481c 100644 --- a/Basalt/objects/Input.lua +++ b/Basalt/objects/Input.lua @@ -57,10 +57,12 @@ return function(name) setValue = function(self, val) base.setValue(self, tostring(val)) if not (internalValueChange) then - textX = tostring(val):len() + 1 - wIndex = math.max(1, textX-self:getWidth()+1) - local obx, oby = self:getAnchorPosition() - self.parent:setCursor(true, obx + textX - wIndex, oby+math.floor(self.height/2), self.fgColor) + if(self:isFocused())then + textX = tostring(val):len() + 1 + wIndex = math.max(1, textX-self:getWidth()+1) + local obx, oby = self:getAnchorPosition() + self.parent:setCursor(true, obx + textX - wIndex, oby+math.floor(self.height/2), self.fgColor) + end end self:updateDraw() return self diff --git a/Basalt/objects/Label.lua b/Basalt/objects/Label.lua index 7879b32..b4bc53e 100644 --- a/Basalt/objects/Label.lua +++ b/Basalt/objects/Label.lua @@ -79,8 +79,8 @@ return function(name) return self end, - setSize = function(self, width, height) - base.setSize(self, width, height) + setSize = function(self, width, height, rel) + base.setSize(self, width, height, rel) autoSize = false self:updateDraw() return self @@ -96,40 +96,38 @@ return function(name) if not(autoSize)then local text = createText(self:getValue(), self:getWidth()) for k,v in pairs(text)do - self.parent:setText(obx, oby+k-1, v) + self.parent:writeText(obx, oby+k-1, v, self.bgColor, self.fgColor) end else - for n = 1, h do - if (n == verticalAlign) then - self.parent:setText(obx, oby + (n - 1), utils.getTextHorizontalAlign(self:getValue(), w, textHorizontalAlign)) - end - end + self.parent:writeText(obx, oby, self:getValue(), self.bgColor, self.fgColor) end else - local tData = bigFont(fontsize, self:getValue(), self.fgColor, self.bgColor or colors.black) + local tData = bigFont(fontsize, self:getValue(), self.fgColor, self.bgColor or colors.lightGray) if(autoSize)then self:setSize(#tData[1][1], #tData[1]-1) end - for n = 1, h do - if (n == verticalAlign) then - local oX, oY = self.parent:getSize() - local cX, cY = #tData[1][1], #tData[1] - obx = obx or math.floor((oX - cX) / 2) + 1 - oby = oby or math.floor((oY - cY) / 2) + 1 - - for i = 1, cY do - self.parent:setFG(obx, oby + i + n - 2, utils.getTextHorizontalAlign(tData[2][i], w, textHorizontalAlign)) - self.parent:setText(obx, oby + i + n - 2, utils.getTextHorizontalAlign(tData[1][i], w, textHorizontalAlign)) - end + local oX, oY = self.parent:getSize() + local cX, cY = #tData[1][1], #tData[1] + obx = obx or math.floor((oX - cX) / 2) + 1 + 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]) end - end end end end end, init = function(self) - self.bgColor = self.parent:getTheme("LabelBG") - self.fgColor = self.parent:getTheme("LabelText") + if(base.init(self))then + self.bgColor = self.parent:getTheme("LabelBG") + self.fgColor = self.parent:getTheme("LabelText") + if(self.parent.bgColor==colors.black)and(self.fgColor==colors.black)then + self.fgColor = colors.lightGray + end + end end } diff --git a/Basalt/objects/Pane.lua b/Basalt/objects/Pane.lua index 7e0bf0c..8d843ed 100644 --- a/Basalt/objects/Pane.lua +++ b/Basalt/objects/Pane.lua @@ -6,15 +6,21 @@ return function(name) local objectType = "Pane" local object = { - init = function(self) - self.bgColor = self.parent:getTheme("PaneBG") - self.fgColor = self.parent:getTheme("PaneBG") - end, getType = function(self) return objectType end; + setBackground = function(self, col, sym, symC) + base.setBackground(self, col, sym, symC) + return self + end, + init = function(self) + if(base.init(self))then + self.bgColor = self.parent:getTheme("PaneBG") + self.fgColor = self.parent:getTheme("PaneBG") + end + end, } return setmetatable(object, base) diff --git a/Basalt/objects/Radio.lua b/Basalt/objects/Radio.lua index e9a23ff..82854b1 100644 --- a/Basalt/objects/Radio.lua +++ b/Basalt/objects/Radio.lua @@ -135,21 +135,20 @@ return function(name) end; draw = function(self) - if (base.draw(self)) then - if (self.parent ~= nil) then - local obx, oby = self:getAnchorPosition() - for _, value in pairs(list) do - if (value == self:getValue()) then - if (align == "left") then - self.parent:writeText(value.x + obx - 1, value.y + oby - 1, symbol, boxSelectedBG, boxSelectedFG) - self.parent:writeText(value.x + 2 + obx - 1, value.y + oby - 1, value.text, itemSelectedBG, itemSelectedFG) - end - else - self.parent:drawBackgroundBox(value.x + obx - 1, value.y + oby - 1, 1, 1, boxNotSelectedBG or self.bgColor) - self.parent:writeText(value.x + 2 + obx - 1, value.y + oby - 1, value.text, value.bgCol, value.fgCol) + if (self.parent ~= nil) then + local obx, oby = self:getAnchorPosition() + for _, value in pairs(list) do + if (value == self:getValue()) then + if (align == "left") then + self.parent:writeText(value.x + obx - 1, value.y + oby - 1, symbol, boxSelectedBG, boxSelectedFG) + self.parent:writeText(value.x + 2 + obx - 1, value.y + oby - 1, value.text, itemSelectedBG, itemSelectedFG) end + else + self.parent:drawBackgroundBox(value.x + obx - 1, value.y + oby - 1, 1, 1, boxNotSelectedBG or self.bgColor) + self.parent:writeText(value.x + 2 + obx - 1, value.y + oby - 1, value.text, value.bgCol, value.fgCol) end end + return true end end, diff --git a/Basalt/objects/Slider.lua b/Basalt/objects/Slider.lua index ded2c4b..4a71c6a 100644 --- a/Basalt/objects/Slider.lua +++ b/Basalt/objects/Slider.lua @@ -139,7 +139,9 @@ return function(name) index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1)) self:setValue(maxValue / (barType == "vertical" and h or w) * index) self:updateDraw() + return true end + return false end, draw = function(self)