From 1f299153d06c21cec4249caf65382656cff3fd05 Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Fri, 23 Sep 2022 19:22:10 +0200 Subject: [PATCH] Bugfix - Focus fix for programs - package.path for Program object fix --- Basalt/Frame.lua | 38 ++++++++++++++---------------------- Basalt/libraries/process.lua | 5 ++++- Basalt/objects/Program.lua | 14 +++++++------ 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/Basalt/Frame.lua b/Basalt/Frame.lua index af49f20..49198aa 100644 --- a/Basalt/Frame.lua +++ b/Basalt/Frame.lua @@ -352,19 +352,6 @@ return function(name, parent, pTerm, basalt) end end - - local function focusSystem(self) - if(focusedObject~=focusedObjectCache)then - if(focusedObject~=nil)then - focusedObject:loseFocusHandler() - end - if(focusedObjectCache~=nil)then - focusedObjectCache:getFocusHandler() - end - focusedObject = focusedObjectCache - end - end - object = { barActive = false, barBackground = colors.gray, @@ -386,8 +373,15 @@ return function(name, parent, pTerm, basalt) end; setFocusedObject = function(self, obj) - focusedObjectCache = obj - focusSystem(self) + if(focusedObject~=obj)then + if(focusedObject~=nil)then + focusedObject:loseFocusHandler() + end + if(obj~=nil)then + obj:getFocusHandler() + end + focusedObject = obj + end return self end; @@ -463,8 +457,10 @@ return function(name, parent, pTerm, basalt) end; removeFocusedObject = function(self) - focusedObjectCache = nil - focusSystem(self) + if(focusedObject~=nil)then + focusedObject:loseFocusHandler() + end + focusedObject = nil return self end; @@ -816,7 +812,7 @@ return function(name, parent, pTerm, basalt) for _, value in rpairs(events["mouse_click"][index]) do if (value.mouseHandler ~= nil) then if (value:mouseHandler(button, x, y)) then - focusSystem(self) + return true end end @@ -849,7 +845,6 @@ return function(name, parent, pTerm, basalt) for _, value in rpairs(events["mouse_up"][index]) do if (value.mouseUpHandler ~= nil) then if (value:mouseUpHandler(button, x, y)) then - focusSystem(self) return true end end @@ -857,7 +852,6 @@ return function(name, parent, pTerm, basalt) end end end - focusSystem(self) return true end return false @@ -871,7 +865,6 @@ return function(name, parent, pTerm, basalt) for _, value in rpairs(events["mouse_scroll"][index]) do if (value.scrollHandler ~= nil) then if (value:scrollHandler(dir, x, y)) then - focusSystem(self) return true end end @@ -934,7 +927,6 @@ return function(name, parent, pTerm, basalt) for _, value in rpairs(events["mouse_drag"][index]) do if (value.dragHandler ~= nil) then if (value:dragHandler(button, x, y)) then - focusSystem(self) return true end end @@ -943,7 +935,7 @@ return function(name, parent, pTerm, basalt) end end end - focusSystem(self) + base.dragHandler(self, button, x, y) return false end, diff --git a/Basalt/libraries/process.lua b/Basalt/libraries/process.lua index 2b410a3..cf712b0 100644 --- a/Basalt/libraries/process.lua +++ b/Basalt/libraries/process.lua @@ -2,6 +2,8 @@ local processes = {} local process = {} local processId = 0 +local newPackage = dofile("rom/modules/main/cc/require.lua").make + function process:new(path, window, newEnv, ...) local args = {...} local newP = setmetatable({ path = path }, { __index = self }) @@ -11,11 +13,12 @@ function process:new(path, window, newEnv, ...) newP.processId = processId if(type(path)=="string")then newP.coroutine = coroutine.create(function() + local pPath = shell.resolveProgram(path) local env = setmetatable(newEnv, {__index=_ENV}) env.shell = shell env.basaltProgram=true env.arg = {[0]=path, table.unpack(args)} - local pPath = shell.resolveProgram(path) + env.require, env.package = newPackage(env, fs.getDir(pPath)) if(fs.exists(pPath))then local file = fs.open(pPath, "r") local content = file.readAll() diff --git a/Basalt/objects/Program.lua b/Basalt/objects/Program.lua index f9b97ab..dd28298 100644 --- a/Basalt/objects/Program.lua +++ b/Basalt/objects/Program.lua @@ -428,7 +428,7 @@ return function(name, parent) local obx, oby = self:getAnchorPosition() 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()) + self.parent:setCursor(self:isFocused() and pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor()) end end @@ -684,11 +684,9 @@ return function(name, parent) if (self.parent ~= nil) then local xCur, yCur = pWindow.getCursorPos() local obx, oby = self:getAnchorPosition() - 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 + 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 @@ -757,9 +755,13 @@ return function(name, parent) if (base.draw(self)) then if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() + local xCur, yCur = pWindow.getCursorPos() local w,h = self:getSize() pWindow.basalt_reposition(obx, oby) pWindow.basalt_update() + 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(self:isFocused() and pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor()) + end end end end,