diff --git a/Basalt/Frame.lua b/Basalt/Frame.lua index 65fdf1f..6ba3875 100644 --- a/Basalt/Frame.lua +++ b/Basalt/Frame.lua @@ -456,7 +456,6 @@ return function(name, parent, pTerm, basalt) end; setCursor = function(self, _blink, _xCursor, _yCursor, color) - --if(_blink==cursorBlink)and(xCursor==_xCursor)and(yCursor==_yCursor)and(cursorColor==color)then return self end if(self.parent~=nil)then local obx, oby = self:getAnchorPosition() self.parent:setCursor(_blink or false, (_xCursor or 0)+obx-1, (_yCursor or 0)+oby-1, color or cursorColor) @@ -601,13 +600,13 @@ return function(name, parent, pTerm, basalt) return self end, - showBar = function(self, showIt) + showBar = function(self, showIt) -- deprecated self.barActive = showIt or not self.barActive self:updateDraw() return self end; - setBar = function(self, text, bgCol, fgCol) + setBar = function(self, text, bgCol, fgCol) -- deprecated self.barText = text or "" self.barBackground = bgCol or self.barBackground self.barTextcolor = fgCol or self.barTextcolor @@ -615,7 +614,7 @@ return function(name, parent, pTerm, basalt) return self end; - setBarTextAlign = function(self, align) + setBarTextAlign = function(self, align) -- deprecated self.barTextAlign = align or "left" self:updateDraw() return self diff --git a/Basalt/Object.lua b/Basalt/Object.lua index f843950..a64d3f0 100644 --- a/Basalt/Object.lua +++ b/Basalt/Object.lua @@ -1,6 +1,5 @@ local basaltEvent = require("basaltEvent") local utils = require("utils") -local log = require("basaltLogs") local split = utils.splitString local numberFromString = utils.numberFromString local xmlValue = utils.getValueFromXML @@ -17,13 +16,14 @@ return function(name) local initialized = false local shadow = false - local borderLeft = false - local borderTop = false - local borderRight = false - local borderBottom = false + local borderColors = { + left = false, + right = false, + top = false, + bottom = false + } local shadowColor = colors.black - local borderColor = colors.black local isEnabled = true local isDragging = false local dragStartX, dragStartY, dragXOffset, dragYOffset = 0, 0, 0, 0 @@ -102,13 +102,12 @@ return function(name) if(xmlValue("enabled", data)~=nil)then if(xmlValue("enabled", data))then self:enable() else self:disable() end end if(xmlValue("zIndex", data)~=nil)then self:setZIndex(xmlValue("zIndex", data)) end if(xmlValue("anchor", data)~=nil)then self:setAnchor(xmlValue("anchor", data)) end - if(xmlValue("shadow", data)~=nil)then if(xmlValue("shadow", data))then self:showShadow(true) end end if(xmlValue("shadowColor", data)~=nil)then self:setShadow(colors[xmlValue("shadowColor", data)]) end - if(xmlValue("border", data)~=nil)then if(xmlValue("border", data))then borderLeft,borderTop,borderRight,borderBottom = true,true,true,true end end - if(xmlValue("borderLeft", data)~=nil)then if(xmlValue("borderLeft", data))then borderLeft = true else borderLeft = false end end - if(xmlValue("borderTop", data)~=nil)then if(xmlValue("borderTop", data))then borderTop = true else borderTop = false end end - if(xmlValue("borderRight", data)~=nil)then if(xmlValue("borderRight", data))then borderRight = true else borderRight = false end end - if(xmlValue("borderBottom", data)~=nil)then if(xmlValue("borderBottom", data))then borderBottom = true else borderBottom = false end end + if(xmlValue("border", data)~=nil)then self:setBorder(colors[xmlValue("border", data)]) end + if(xmlValue("borderLeft", data)~=nil)then borderColors["left"] = xmlValue("borderLeft", data) end + if(xmlValue("borderTop", data)~=nil)then borderColors["top"] = xmlValue("borderTop", data) end + if(xmlValue("borderRight", data)~=nil)then borderColors["right"] = xmlValue("borderRight", data) end + if(xmlValue("borderBottom", data)~=nil)then borderColors["bottom"] = xmlValue("borderBottom", data) end if(xmlValue("borderColor", data)~=nil)then self:setBorder(colors[xmlValue("borderColor", data)]) end if(xmlValue("ignoreOffset", data)~=nil)then if(xmlValue("ignoreOffset", data))then self:ignoreOffset(true) end end if(xmlValue("onClick", data)~=nil)then self:generateXMLEventFunction(self.onClick, xmlValue("onClick", data)) end @@ -337,14 +336,13 @@ return function(name) return self.fgColor end; - showShadow = function(self, show) - shadow = show or (not shadow) - self:updateDraw() - return self - end; - setShadow = function(self, color) - shadowColor = color + if(color==false)then + shadow = false + else + shadowColor = color + shadow = true + end self:updateDraw() return self end; @@ -353,30 +351,27 @@ return function(name) return shadow; end; - showBorder = function(self, ...) - for _,v in pairs(table.pack(...))do - if(v=="left")or(...==nil)then - borderLeft = true - end - if(v=="top")or(...==nil)then - borderTop = true - end - if(v=="right")or(...==nil)then - borderRight = true - end - if(v=="bottom")or(...==nil)then - borderBottom = true + setBorder = function(self, ...) + if(...~=nil)then + local t = {...} + for k,v in pairs(t)do + if(v=="left")or(#t==1)then + borderColors["left"] = t[1] + end + if(v=="top")or(#t==1)then + borderColors["top"] = t[1] + end + if(v=="right")or(#t==1)then + borderColors["right"] = t[1] + end + if(v=="bottom")or(#t==1)then + borderColors["bottom"] = t[1] + end end end self:updateDraw() return self end; - - setBorder = function(self, color) - borderColor = color - self:updateDraw() - return self - end; getBorder = function(self, side) if(side=="left")then @@ -418,40 +413,41 @@ return function(name) self.parent:drawForegroundBox(x+1, y+h, w, 1, shadowColor) self.parent:drawForegroundBox(x+w, y+1, 1, h, shadowColor) end - if(borderLeft)then + if(borderColors["left"]~=false)then 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 + self.parent:drawBackgroundBox(x-1, y, 1, h, borderColors["left"]) + self.parent:drawForegroundBox(x-1, y, 1, h, self.parent.bgColor) end - if(borderLeft)and(borderTop)then + if(borderColors["left"]~=false)and(borderColors["top"]~=false)then self.parent:drawTextBox(x-1, y-1, 1, 1, "\151") - self.parent:drawForegroundBox(x-1, y-1, 1, 1, borderColor) - if(self.bgColor~=false)then self.parent:drawBackgroundBox(x-1, y-1, 1, 1, self.bgColor) end + self.parent:drawBackgroundBox(x-1, y-1, 1, 1, borderColors["left"]) + self.parent:drawForegroundBox(x-1, y-1, 1, 1, self.parent.bgColor) end - if(borderTop)then + if(borderColors["top"]~=false)then + 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 + self.parent:drawBackgroundBox(x, y-1, w, 1, borderColors["top"]) + self.parent:drawForegroundBox(x, y-1, w, 1, self.parent.bgColor) end - if(borderTop)and(borderRight)then - self.parent:drawTextBox(x+w, y-1, 1, 1, "\149") - self.parent:drawForegroundBox(x+w, y-1, 1, 1, borderColor) + if(borderColors["top"]~=false)and(borderColors["right"]~=false)then + self.parent:drawTextBox(x+w, y-1, 1, 1, "\148") + self.parent:drawForegroundBox(x+w, y-1, 1, 1, borderColors["right"]) end - if(borderRight)then + if(borderColors["right"]~=false)then self.parent:drawTextBox(x+w, y, 1, h, "\149") - self.parent:drawForegroundBox(x+w, y, 1, h, borderColor) + self.parent:drawForegroundBox(x+w, y, 1, h, borderColors["right"]) end - if(borderRight)and(borderBottom)then + if(borderColors["right"]~=false)and(borderColors["bottom"]~=false)then self.parent:drawTextBox(x+w, y+h, 1, 1, "\129") - self.parent:drawForegroundBox(x+w, y+h, 1, 1, borderColor) + self.parent:drawForegroundBox(x+w, y+h, 1, 1, borderColors["right"]) end - if(borderBottom)then + if(borderColors["bottom"]~=false)then self.parent:drawTextBox(x, y+h, w, 1, "\131") - self.parent:drawForegroundBox(x, y+h, w, 1, borderColor) + self.parent:drawForegroundBox(x, y+h, w, 1, borderColors["bottom"]) end - if(borderBottom)and(borderLeft)then - self.parent:drawTextBox(x-1, y+h, 1, 1, "\131") - self.parent:drawForegroundBox(x-1, y+h, 1, 1, borderColor) + if(borderColors["bottom"]~=false)and(borderColors["left"]~=false)then + self.parent:drawTextBox(x-1, y+h, 1, 1, "\130") + self.parent:drawForegroundBox(x-1, y+h, 1, 1, borderColors["left"]) end end draw = false diff --git a/Basalt/basaltDraw.lua b/Basalt/libraries/basaltDraw.lua similarity index 100% rename from Basalt/basaltDraw.lua rename to Basalt/libraries/basaltDraw.lua diff --git a/Basalt/basaltEvent.lua b/Basalt/libraries/basaltEvent.lua similarity index 100% rename from Basalt/basaltEvent.lua rename to Basalt/libraries/basaltEvent.lua diff --git a/Basalt/tHex.lua b/Basalt/libraries/tHex.lua similarity index 100% rename from Basalt/tHex.lua rename to Basalt/libraries/tHex.lua diff --git a/Basalt/utils.lua b/Basalt/libraries/utils.lua similarity index 100% rename from Basalt/utils.lua rename to Basalt/libraries/utils.lua diff --git a/Basalt/objects/Animation.lua b/Basalt/objects/Animation.lua index 9dd6934..0ea75e4 100644 --- a/Basalt/objects/Animation.lua +++ b/Basalt/objects/Animation.lua @@ -1,4 +1,3 @@ - local xmlValue = require("utils").getValueFromXML local basaltEvent = require("basaltEvent") @@ -134,9 +133,19 @@ return function(name) end - local function predefinedLerp(v1,v2,d,t,get,set) + local function predefinedLerp(v1,v2,d,t,get,set,typ,self) local x,y + local name = "" + if(_OBJ.parent~=nil)then name = _OBJ.parent:getName() end + name = name.._OBJ:getName() addAnimationPart(t+0.05, function() + if(typ~=nil)then + if(activeAnimations[typ]==nil)then activeAnimations[typ] = {} end + if(activeAnimations[typ][name]~=nil)then + activeAnimations[typ][name]:cancel() + end + activeAnimations[typ][name] = self + end x,y = get(_OBJ) end) for n=0.05,d+0.01,0.05 do @@ -144,6 +153,13 @@ return function(name) local _x = math.floor(lerp.lerp(x, v1, lerp[mode](n / d))+0.5) local _y = math.floor(lerp.lerp(y, v2, lerp[mode](n / d))+0.5) set(_OBJ, _x,_y) + if(typ~=nil)then + if(n>=d-0.01)then + if(activeAnimations[typ][name]==self)then + activeAnimations[typ][name] = nil + end + end + end end) end end; @@ -291,19 +307,19 @@ return function(name) move = function(self, x, y, duration, timer, obj) _OBJ = obj or _OBJ - predefinedLerp(x,y,duration,timer or 0,_OBJ.getPosition,_OBJ.setPosition) + predefinedLerp(x,y,duration,timer or 0,_OBJ.getPosition,_OBJ.setPosition, "position", self) return self end, offset = function(self, x, y, duration, timer, obj) _OBJ = obj or _OBJ - predefinedLerp(x,y,duration,timer or 0,_OBJ.getOffset,_OBJ.setOffset) + predefinedLerp(x,y,duration,timer or 0,_OBJ.getOffset,_OBJ.setOffset, "offset", self) return self end, size = function(self, w, h, duration, timer, obj) _OBJ = obj or _OBJ - predefinedLerp(w,h,duration,timer or 0,_OBJ.getSize,_OBJ.setSize) + predefinedLerp(w,h,duration,timer or 0,_OBJ.getSize,_OBJ.setSize, "size", self) return self end, @@ -403,12 +419,6 @@ 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 @@ -427,13 +437,6 @@ 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/List.lua b/Basalt/objects/List.lua index 632896f..b89683b 100644 --- a/Basalt/objects/List.lua +++ b/Basalt/objects/List.lua @@ -91,7 +91,7 @@ return function(name) setSelectedItem = function(self, bgCol, fgCol, active) itemSelectedBG = bgCol or self.bgColor itemSelectedFG = fgCol or self.fgColor - selectionColorActive = active + selectionColorActive = active~=nil and active or true self:updateDraw() return self end; diff --git a/Basalt/objects/Pane.lua b/Basalt/objects/Pane.lua index 8d843ed..cfe33b7 100644 --- a/Basalt/objects/Pane.lua +++ b/Basalt/objects/Pane.lua @@ -1,4 +1,5 @@ local Object = require("Object") +local log = require("basaltLogs") return function(name) -- Pane