Small event fix for programs

This commit is contained in:
Robert Jelic
2022-12-25 16:56:13 +01:00
parent 6d2956f3bf
commit 20ceb6b56f
4 changed files with 42 additions and 61 deletions

View File

@@ -92,6 +92,7 @@ return function(name, parent, pTerm, basalt)
end end
end end
end end
local function getDeepObject(name) local function getDeepObject(name)
local o = getObject(name) local o = getObject(name)
if(o~=nil)then return o end if(o~=nil)then return o end
@@ -108,7 +109,7 @@ return function(name, parent, pTerm, basalt)
local function addObject(obj) local function addObject(obj)
local zIndex = obj:getZIndex() local zIndex = obj:getZIndex()
if (getObject(obj.name) ~= nil) then if (getObject(obj.name) ~= nil) then
return return nil
end end
if (objects[zIndex] == nil) then if (objects[zIndex] == nil) then
for x = 1, #objZIndex + 1 do for x = 1, #objZIndex + 1 do
@@ -162,14 +163,14 @@ return function(name, parent, pTerm, basalt)
table.remove(objects[a], key) table.remove(objects[a], key)
removeEvents(object, value) removeEvents(object, value)
self:updateDraw() self:updateDraw()
return true return true;
end end
else else
if (value == obj) then if (value == obj) then
table.remove(objects[a], key) table.remove(objects[a], key)
removeEvents(object, value) removeEvents(object, value)
self:updateDraw() self:updateDraw()
return true return true;
end end
end end
end end
@@ -192,7 +193,7 @@ return function(name, parent, pTerm, basalt)
if(events[event]==nil)then events[event] = {} end if(events[event]==nil)then events[event] = {} end
if(eventZIndex[event]==nil)then eventZIndex[event] = {} end if(eventZIndex[event]==nil)then eventZIndex[event] = {} end
if (getEvent(self, event, obj.name) ~= nil) then if (getEvent(self, event, obj.name) ~= nil) then
return return nil
end end
if(self.parent~=nil)then if(self.parent~=nil)then
self.parent:addEvent(event, self) self.parent:addEvent(event, self)
@@ -220,7 +221,6 @@ return function(name, parent, pTerm, basalt)
table.insert(events[event][zIndex], obj) table.insert(events[event][zIndex], obj)
return obj return obj
end end
local function removeEvent(self, event, obj) local function removeEvent(self, event, obj)
if(events[event]~=nil)then if(events[event]~=nil)then
@@ -412,22 +412,7 @@ return function(name, parent, pTerm, basalt)
getType = function(self) getType = function(self)
return objectType return objectType
end, end;
getObjectCount = function(self)
local count = 0
for _, value in pairs(objects) do
count = count+#value
end
return count
end,
getEventCount = function(self, ev)
local count = 0
for _, value in pairs(events[ev]) do
count = count+#value
end
return count
end,
setZIndex = function(self, newIndex) setZIndex = function(self, newIndex)
base.setZIndex(self, newIndex) base.setZIndex(self, newIndex)
@@ -841,9 +826,7 @@ return function(name, parent, pTerm, basalt)
if (events["other_event"][index] ~= nil) then if (events["other_event"][index] ~= nil) then
for _, value in rpairs(events["other_event"][index]) do for _, value in rpairs(events["other_event"][index]) do
if (value.eventHandler ~= nil) then if (value.eventHandler ~= nil) then
if (value:eventHandler(event, ...)) then value:eventHandler(event, ...)
return true
end
end end
end end
end end

View File

@@ -227,4 +227,4 @@ shrink = function(image, bgCol)
return results return results
end, end,
} }

View File

@@ -71,4 +71,4 @@ return function(name)
} }
return setmetatable(object, base) return setmetatable(object, base)
end end

View File

@@ -707,48 +707,46 @@ return function(name, parent)
end, end,
eventHandler = function(self, event, p1, p2, p3, p4) eventHandler = function(self, event, p1, p2, p3, p4)
if(base.eventHandler(self, event, p1, p2, p3, p4))then base.eventHandler(self, event, p1, p2, p3, p4)
if (curProcess == nil) then if (curProcess == nil) then
return return
end end
if(event=="dynamicValueEvent")then if(event=="dynamicValueEvent")then
local w, h = pWindow.getSize() local w, h = pWindow.getSize()
local pW, pH = self:getSize() local pW, pH = self:getSize()
if(w~=pW)or(h~=pH)then if(w~=pW)or(h~=pH)then
pWindow.basalt_resize(pW, pH) pWindow.basalt_resize(pW, pH)
if not (curProcess:isDead()) then if not (curProcess:isDead()) then
resumeProcess(self, "term_resize") resumeProcess(self, "term_resize")
end
end end
pWindow.basalt_reposition(self:getAnchorPosition())
end end
if not (curProcess:isDead()) then pWindow.basalt_reposition(self:getAnchorPosition())
if not (paused) then
if(event ~= "terminate") then end
resumeProcess(self, event, p1, p2, p3, p4) if not (curProcess:isDead()) then
end if not (paused) then
if (self:isFocused()) then if(event ~= "terminate") then
local obx, oby = self:getAnchorPosition() resumeProcess(self, event, p1, p2, p3, p4)
local xCur, yCur = pWindow.getCursorPos() end
if (self.parent ~= nil) then if (self:isFocused()) then
local w,h = self:getSize() local obx, oby = self:getAnchorPosition()
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 local xCur, yCur = pWindow.getCursorPos()
self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor()) if (self.parent ~= nil) then
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
if (event == "terminate") then if (event == "terminate") then
resumeProcess(self, event) resumeProcess(self, event)
self.parent:setCursor(false) self.parent:setCursor(false)
return true return true
end
end end
else
table.insert(queuedEvent, { event = event, args = { p1, p2, p3, p4 } })
end end
else
table.insert(queuedEvent, { event = event, args = { p1, p2, p3, p4 } })
end end
return false
end end
end, end,