bugfixes
-fixed bug where dynamicvalue table increases which makes the program very laggy - improved focuslose/focusget events
This commit is contained in:
@@ -20,9 +20,7 @@ return function(name, parent, pTerm, basalt)
|
|||||||
local variables = {}
|
local variables = {}
|
||||||
local theme = {}
|
local theme = {}
|
||||||
local dynamicValues = {}
|
local dynamicValues = {}
|
||||||
local focusedObjectCache
|
|
||||||
local dynValueId = 0
|
local dynValueId = 0
|
||||||
local calculateDynValues = false
|
|
||||||
local termObject = pTerm or term.current()
|
local termObject = pTerm or term.current()
|
||||||
|
|
||||||
local monSide = ""
|
local monSide = ""
|
||||||
@@ -38,6 +36,9 @@ return function(name, parent, pTerm, basalt)
|
|||||||
local mirrorSide = ""
|
local mirrorSide = ""
|
||||||
local importantScroll = false
|
local importantScroll = false
|
||||||
|
|
||||||
|
local focusedOBjectCache
|
||||||
|
local focusedObject
|
||||||
|
|
||||||
base:setZIndex(10)
|
base:setZIndex(10)
|
||||||
|
|
||||||
local basaltDraw = BasaltDraw(termObject)
|
local basaltDraw = BasaltDraw(termObject)
|
||||||
@@ -146,11 +147,6 @@ return function(name, parent, pTerm, basalt)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local function removeAllObjects()
|
|
||||||
objects = {}
|
|
||||||
objZIndex = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
local function stringToNumber(str)
|
local function stringToNumber(str)
|
||||||
local ok, err = pcall(load("return " .. str))
|
local ok, err = pcall(load("return " .. str))
|
||||||
if not(ok)then error(str.." is not a valid dynamic code") end
|
if not(ok)then error(str.." is not a valid dynamic code") end
|
||||||
@@ -158,6 +154,11 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function newDynamicValue(_, obj, str)
|
local function newDynamicValue(_, obj, str)
|
||||||
|
for k,v in pairs(dynamicValues)do
|
||||||
|
if(v[2]==str)and(v[4]==obj)then
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
end
|
||||||
dynValueId = dynValueId + 1
|
dynValueId = dynValueId + 1
|
||||||
dynamicValues[dynValueId] = {0, str, {}, obj, dynValueId}
|
dynamicValues[dynValueId] = {0, str, {}, obj, dynValueId}
|
||||||
return dynamicValues[dynValueId]
|
return dynamicValues[dynValueId]
|
||||||
@@ -216,8 +217,7 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function _recalculateDynamicValues(force)
|
local function recalculateDynamicValues()
|
||||||
if(calculateDynValues)or(force)then
|
|
||||||
if(#dynamicValues>0)then
|
if(#dynamicValues>0)then
|
||||||
for n=1,dynValueId do
|
for n=1,dynValueId do
|
||||||
if(dynamicValues[n]~=nil)then
|
if(dynamicValues[n]~=nil)then
|
||||||
@@ -228,8 +228,6 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
calculateDynValues = false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getDynamicValue(id)
|
local function getDynamicValue(id)
|
||||||
@@ -246,10 +244,7 @@ return function(name, parent, pTerm, basalt)
|
|||||||
isMoveable = false,
|
isMoveable = false,
|
||||||
|
|
||||||
newDynamicValue = newDynamicValue,
|
newDynamicValue = newDynamicValue,
|
||||||
recalculateDynamicValues = function(self)
|
recalculateDynamicValues = recalculateDynamicValues,
|
||||||
calculateDynValues = true
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getDynamicValue = getDynamicValue,
|
getDynamicValue = getDynamicValue,
|
||||||
|
|
||||||
getType = function(self)
|
getType = function(self)
|
||||||
@@ -257,11 +252,7 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
setFocusedObject = function(self, obj)
|
setFocusedObject = function(self, obj)
|
||||||
if(self.parent~=nil)then
|
focusedOBjectCache = obj
|
||||||
self.getBaseFrame():setFocusedObject(obj)
|
|
||||||
else
|
|
||||||
focusedObjectCache = obj
|
|
||||||
end
|
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -316,25 +307,21 @@ return function(name, parent, pTerm, basalt)
|
|||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
getOffset = function(self)
|
getOffsetInternal = function(self)
|
||||||
return xOffset, yOffset
|
return xOffset, yOffset
|
||||||
end;
|
end;
|
||||||
|
|
||||||
getOffsetInternal = function(self) -- internal
|
getOffset = function(self) -- internal
|
||||||
return xOffset < 0 and math.abs(xOffset) or -xOffset, yOffset < 0 and math.abs(yOffset) or -yOffset
|
return xOffset < 0 and math.abs(xOffset) or -xOffset, yOffset < 0 and math.abs(yOffset) or -yOffset
|
||||||
end;
|
end;
|
||||||
|
|
||||||
removeFocusedObject = function(self)
|
removeFocusedObject = function(self)
|
||||||
if(self.parent~=nil)then
|
focusedOBjectCache = nil
|
||||||
self.parent:removeFocusedObject()
|
|
||||||
else
|
|
||||||
focusedObjectCache = nil
|
|
||||||
end
|
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
getFocusedObject = function(self)
|
getFocusedObject = function(self)
|
||||||
return basalt.getFocusedObject()
|
return focusedObject
|
||||||
end;
|
end;
|
||||||
|
|
||||||
setCursor = function(self, _blink, _xCursor, _yCursor, color)
|
setCursor = function(self, _blink, _xCursor, _yCursor, color)
|
||||||
@@ -458,7 +445,7 @@ return function(name, parent, pTerm, basalt)
|
|||||||
local objectList = data:children()
|
local objectList = data:children()
|
||||||
|
|
||||||
for k,v in pairs(objectList)do
|
for k,v in pairs(objectList)do
|
||||||
if(v.___name~="animation")and(v.___name~="frame")then
|
if(v.___name~="animation")then
|
||||||
local name = v.___name:gsub("^%l", string.upper)
|
local name = v.___name:gsub("^%l", string.upper)
|
||||||
if(_OBJECTS[name]~=nil)then
|
if(_OBJECTS[name]~=nil)then
|
||||||
addXMLObjectType(v, self["add"..name], self)
|
addXMLObjectType(v, self["add"..name], self)
|
||||||
@@ -545,6 +532,10 @@ return function(name, parent, pTerm, basalt)
|
|||||||
|
|
||||||
loseFocusHandler = function(self)
|
loseFocusHandler = function(self)
|
||||||
base.loseFocusHandler(self)
|
base.loseFocusHandler(self)
|
||||||
|
if(focusedOBjectCache~=nil)then
|
||||||
|
focusedOBjectCache:loseFocusHandler()
|
||||||
|
focusedOBjectCache = nil
|
||||||
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
getFocusHandler = function(self)
|
getFocusHandler = function(self)
|
||||||
@@ -556,7 +547,6 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
keyHandler = function(self, event, key)
|
keyHandler = function(self, event, key)
|
||||||
local focusedObject = basalt.getFocusedObject()
|
|
||||||
if (focusedObject ~= nil) then
|
if (focusedObject ~= nil) then
|
||||||
if(focusedObject~=self)then
|
if(focusedObject~=self)then
|
||||||
if (focusedObject.keyHandler ~= nil) then
|
if (focusedObject.keyHandler ~= nil) then
|
||||||
@@ -628,7 +618,7 @@ return function(name, parent, pTerm, basalt)
|
|||||||
|
|
||||||
mouseHandler = function(self, event, button, x, y)
|
mouseHandler = function(self, event, button, x, y)
|
||||||
if (self.drag) then
|
if (self.drag) then
|
||||||
local xO, yO = self.parent:getOffset()
|
local xO, yO = self.parent:getOffsetInternal()
|
||||||
xO = xO < 0 and math.abs(xO) or -xO
|
xO = xO < 0 and math.abs(xO) or -xO
|
||||||
yO = yO < 0 and math.abs(yO) or -yO
|
yO = yO < 0 and math.abs(yO) or -yO
|
||||||
if (event == "mouse_drag") then
|
if (event == "mouse_drag") then
|
||||||
@@ -645,15 +635,14 @@ return function(name, parent, pTerm, basalt)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
|
local fx, fy = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
local yOff = false
|
local yOff = false
|
||||||
if(objY-1 == y)and(self:getBorder("top"))then
|
if(fy-1 == y)and(self:getBorder("top"))then
|
||||||
y = y+1
|
y = y+1
|
||||||
yOff = true
|
yOff = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if (base.mouseHandler(self, event, button, x, y)) then
|
if (base.mouseHandler(self, event, button, x, y)) then
|
||||||
local fx, fy = self:getAbsolutePosition(self:getAnchorPosition())
|
|
||||||
fx = fx + xOffset;fy = fy + yOffset;
|
fx = fx + xOffset;fy = fy + yOffset;
|
||||||
if(isScrollable)and(importantScroll)then
|
if(isScrollable)and(importantScroll)then
|
||||||
if(event=="mouse_scroll")then
|
if(event=="mouse_scroll")then
|
||||||
@@ -673,8 +662,8 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
self:removeFocusedObject()
|
||||||
if (self.isMoveable) then
|
if (self.isMoveable) then
|
||||||
local fx, fy = self:getAbsolutePosition(self:getAnchorPosition())
|
|
||||||
if (x >= fx) and (x <= fx + self:getWidth() - 1) and (y == fy) and (event == "mouse_click") then
|
if (x >= fx) and (x <= fx + self:getWidth() - 1) and (y == fy) and (event == "mouse_click") then
|
||||||
self.drag = true
|
self.drag = true
|
||||||
dragXOffset = fx - x
|
dragXOffset = fx - x
|
||||||
@@ -775,21 +764,17 @@ return function(name, parent, pTerm, basalt)
|
|||||||
if(isMonitor)and not(monitorAttached)then return false end;
|
if(isMonitor)and not(monitorAttached)then return false end;
|
||||||
if (self:getVisualChanged()) then
|
if (self:getVisualChanged()) then
|
||||||
if (base.draw(self)) then
|
if (base.draw(self)) then
|
||||||
if(self.parent==nil)then
|
|
||||||
local curObj = basalt.getFocusedObject()
|
if(focusedObject~=focusedOBjectCache)then
|
||||||
basalt.setFocusedObject(focusedObjectCache)
|
if(focusedOBjectCache~=nil)then
|
||||||
if(focusedObjectCache~=nil)then
|
focusedOBjectCache:getFocusHandler()
|
||||||
focusedObjectCache:getFocusHandler()
|
|
||||||
end
|
end
|
||||||
if(curObj~=focusedObjectCache)then
|
if(focusedObject~=nil)then
|
||||||
if(curObj~=nil)then
|
focusedObject:loseFocusHandler()
|
||||||
curObj:loseFocusHandler()
|
|
||||||
end
|
end
|
||||||
|
focusedObject = focusedOBjectCache
|
||||||
end
|
end
|
||||||
end
|
|
||||||
if(calculateDynValues)then
|
|
||||||
_recalculateDynamicValues()
|
|
||||||
end
|
|
||||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
local anchx, anchy = self:getAnchorPosition()
|
local anchx, anchy = self:getAnchorPosition()
|
||||||
local w,h = self:getSize()
|
local w,h = self:getSize()
|
||||||
@@ -860,9 +845,7 @@ return function(name, parent, pTerm, basalt)
|
|||||||
addObject = function(self, obj)
|
addObject = function(self, obj)
|
||||||
return addObject(obj)
|
return addObject(obj)
|
||||||
end;
|
end;
|
||||||
removeAllObjects = function(self)
|
|
||||||
return removeAllObjects()
|
|
||||||
end;
|
|
||||||
removeObject = function(self, obj)
|
removeObject = function(self, obj)
|
||||||
return removeObject(obj)
|
return removeObject(obj)
|
||||||
end;
|
end;
|
||||||
|
|||||||
@@ -464,7 +464,7 @@ return function(name)
|
|||||||
y = math.floor(ph/2) + y - 1
|
y = math.floor(ph/2) + y - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local xO, yO = self.parent:getOffset()
|
local xO, yO = self.parent:getOffsetInternal()
|
||||||
if not(ignOffset or ignOff) then
|
if not(ignOffset or ignOff) then
|
||||||
return x+xO, y+yO
|
return x+xO, y+yO
|
||||||
end
|
end
|
||||||
@@ -663,7 +663,7 @@ return function(name)
|
|||||||
if(isDragging)and(event=="mouse_drag")then
|
if(isDragging)and(event=="mouse_drag")then
|
||||||
local xO, yO, parentX, parentY = 0, 0, 1, 1
|
local xO, yO, parentX, parentY = 0, 0, 1, 1
|
||||||
if (self.parent ~= nil) then
|
if (self.parent ~= nil) then
|
||||||
xO, yO = self.parent:getOffset()
|
xO, yO = self.parent:getOffsetInternal()
|
||||||
xO = xO < 0 and math.abs(xO) or -xO
|
xO = xO < 0 and math.abs(xO) or -xO
|
||||||
yO = yO < 0 and math.abs(yO) or -yO
|
yO = yO < 0 and math.abs(yO) or -yO
|
||||||
parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition())
|
parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition())
|
||||||
@@ -680,12 +680,11 @@ return function(name)
|
|||||||
dragXOffset, dragYOffset = objX - x, objY - y
|
dragXOffset, dragYOffset = objX - x, objY - y
|
||||||
end
|
end
|
||||||
if(event~="mouse_drag")then
|
if(event~="mouse_drag")then
|
||||||
if (self.parent ~= nil)and(event~="mouse_up")then
|
if(event~="mouse_up")then
|
||||||
--self.parent:setFocusedObject(self)
|
if (self.parent ~= nil) then
|
||||||
elseif(self.parent == nil)and(event~="mouse_up")and(self:getType()=="Frame")then
|
self.parent:setFocusedObject(self)
|
||||||
--self:setFocusedObject(self)
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local val = eventSystem:sendEvent(event, self, event, button, x, y)
|
local val = eventSystem:sendEvent(event, self, event, button, x, y)
|
||||||
if(val~=nil)then return val end
|
if(val~=nil)then return val end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ return function(name)
|
|||||||
|
|
||||||
local animations = {}
|
local animations = {}
|
||||||
local animationTime = 0
|
local animationTime = 0
|
||||||
|
local animationActive = false
|
||||||
local index = 1
|
local index = 1
|
||||||
local infinitePlay = false
|
local infinitePlay = false
|
||||||
|
|
||||||
@@ -279,7 +280,7 @@ return function(name)
|
|||||||
|
|
||||||
offset = function(self, x, y, duration, timer, obj)
|
offset = function(self, x, y, duration, timer, obj)
|
||||||
_OBJ = obj or _OBJ
|
_OBJ = obj or _OBJ
|
||||||
predefinedLerp(x,y,duration,timer or 0,_OBJ.getOffsetInternal,_OBJ.setOffset)
|
predefinedLerp(x,y,duration,timer or 0,_OBJ.getOffset,_OBJ.setOffset)
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@@ -384,6 +385,7 @@ return function(name)
|
|||||||
|
|
||||||
play = function(self, infinite)
|
play = function(self, infinite)
|
||||||
self:cancel()
|
self:cancel()
|
||||||
|
animationActive = true
|
||||||
infinitePlay = infinite and true or false
|
infinitePlay = infinite and true or false
|
||||||
index = 1
|
index = 1
|
||||||
animationTime = 0
|
animationTime = 0
|
||||||
@@ -404,6 +406,7 @@ return function(name)
|
|||||||
os.cancelTimer(timerObj)
|
os.cancelTimer(timerObj)
|
||||||
infinitePlay = false
|
infinitePlay = false
|
||||||
end
|
end
|
||||||
|
animationActive = false
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -412,6 +415,7 @@ return function(name)
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
eventHandler = function(self, event, tObj)
|
eventHandler = function(self, event, tObj)
|
||||||
|
if(animationActive)then
|
||||||
if (event == "timer") and (tObj == timerObj) then
|
if (event == "timer") and (tObj == timerObj) then
|
||||||
if (animations[index] ~= nil) then
|
if (animations[index] ~= nil) then
|
||||||
onPlay(self)
|
onPlay(self)
|
||||||
@@ -419,6 +423,7 @@ return function(name)
|
|||||||
self:animationDoneHandler()
|
self:animationDoneHandler()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end;
|
end;
|
||||||
}
|
}
|
||||||
object.__index = object
|
object.__index = object
|
||||||
|
|||||||
Reference in New Issue
Block a user