- Focus fix for programs
- package.path for Program object fix
This commit is contained in:
Robert Jelic
2022-09-23 19:22:10 +02:00
parent 39a238c3c0
commit 1f299153d0
3 changed files with 27 additions and 30 deletions

View File

@@ -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,

View File

@@ -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()

View File

@@ -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,