From 20ceb6b56fae49eef969772f2b3ae1b8fd927e45 Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Sun, 25 Dec 2022 16:56:13 +0100 Subject: [PATCH] Small event fix for programs --- Basalt/Frame.lua | 31 ++++------------- Basalt/libraries/utils.lua | 2 +- Basalt/objects/Button.lua | 2 +- Basalt/objects/Program.lua | 68 ++++++++++++++++++-------------------- 4 files changed, 42 insertions(+), 61 deletions(-) diff --git a/Basalt/Frame.lua b/Basalt/Frame.lua index 0bb3c0a..64953c5 100644 --- a/Basalt/Frame.lua +++ b/Basalt/Frame.lua @@ -92,6 +92,7 @@ return function(name, parent, pTerm, basalt) end end end + local function getDeepObject(name) local o = getObject(name) if(o~=nil)then return o end @@ -108,7 +109,7 @@ return function(name, parent, pTerm, basalt) local function addObject(obj) local zIndex = obj:getZIndex() if (getObject(obj.name) ~= nil) then - return + return nil end if (objects[zIndex] == nil) then for x = 1, #objZIndex + 1 do @@ -162,14 +163,14 @@ return function(name, parent, pTerm, basalt) table.remove(objects[a], key) removeEvents(object, value) self:updateDraw() - return true + return true; end else if (value == obj) then table.remove(objects[a], key) removeEvents(object, value) self:updateDraw() - return true + return true; end end end @@ -192,7 +193,7 @@ return function(name, parent, pTerm, basalt) if(events[event]==nil)then events[event] = {} end if(eventZIndex[event]==nil)then eventZIndex[event] = {} end if (getEvent(self, event, obj.name) ~= nil) then - return + return nil end if(self.parent~=nil)then self.parent:addEvent(event, self) @@ -220,7 +221,6 @@ return function(name, parent, pTerm, basalt) table.insert(events[event][zIndex], obj) return obj end - local function removeEvent(self, event, obj) if(events[event]~=nil)then @@ -412,22 +412,7 @@ return function(name, parent, pTerm, basalt) getType = function(self) return objectType - 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, + end; setZIndex = function(self, newIndex) base.setZIndex(self, newIndex) @@ -841,9 +826,7 @@ return function(name, parent, pTerm, basalt) if (events["other_event"][index] ~= nil) then for _, value in rpairs(events["other_event"][index]) do if (value.eventHandler ~= nil) then - if (value:eventHandler(event, ...)) then - return true - end + value:eventHandler(event, ...) end end end diff --git a/Basalt/libraries/utils.lua b/Basalt/libraries/utils.lua index 8138750..7c23a7d 100644 --- a/Basalt/libraries/utils.lua +++ b/Basalt/libraries/utils.lua @@ -227,4 +227,4 @@ shrink = function(image, bgCol) return results end, -} +} \ No newline at end of file diff --git a/Basalt/objects/Button.lua b/Basalt/objects/Button.lua index 76c109c..3ddf0e3 100644 --- a/Basalt/objects/Button.lua +++ b/Basalt/objects/Button.lua @@ -71,4 +71,4 @@ return function(name) } return setmetatable(object, base) -end +end \ No newline at end of file diff --git a/Basalt/objects/Program.lua b/Basalt/objects/Program.lua index 43dc916..7326e0f 100644 --- a/Basalt/objects/Program.lua +++ b/Basalt/objects/Program.lua @@ -707,48 +707,46 @@ return function(name, parent) end, eventHandler = function(self, event, p1, p2, p3, p4) - if(base.eventHandler(self, event, p1, p2, p3, p4))then - if (curProcess == nil) then - return - end - if(event=="dynamicValueEvent")then - local w, h = pWindow.getSize() - local pW, pH = self:getSize() - if(w~=pW)or(h~=pH)then - pWindow.basalt_resize(pW, pH) - if not (curProcess:isDead()) then - resumeProcess(self, "term_resize") - end + base.eventHandler(self, event, p1, p2, p3, p4) + if (curProcess == nil) then + return + end + if(event=="dynamicValueEvent")then + local w, h = pWindow.getSize() + local pW, pH = self:getSize() + if(w~=pW)or(h~=pH)then + pWindow.basalt_resize(pW, pH) + if not (curProcess:isDead()) then + resumeProcess(self, "term_resize") end - pWindow.basalt_reposition(self:getAnchorPosition()) - end - if not (curProcess:isDead()) then - if not (paused) then - if(event ~= "terminate") then - resumeProcess(self, event, p1, p2, p3, p4) - end - if (self:isFocused()) then - local obx, oby = self:getAnchorPosition() - local xCur, yCur = pWindow.getCursorPos() - 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 + pWindow.basalt_reposition(self:getAnchorPosition()) + + end + if not (curProcess:isDead()) then + if not (paused) then + if(event ~= "terminate") then + resumeProcess(self, event, p1, p2, p3, p4) + end + if (self:isFocused()) then + local obx, oby = self:getAnchorPosition() + local xCur, yCur = pWindow.getCursorPos() + 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 + end - if (event == "terminate") then - resumeProcess(self, event) - self.parent:setCursor(false) - return true - end + if (event == "terminate") then + resumeProcess(self, event) + self.parent:setCursor(false) + return true end - else - table.insert(queuedEvent, { event = event, args = { p1, p2, p3, p4 } }) end + else + table.insert(queuedEvent, { event = event, args = { p1, p2, p3, p4 } }) end - return false end end,