fullscreen implementation
This commit is contained in:
@@ -71,6 +71,7 @@ function lib.create(name, w, h, x, y, do_not_add)
|
|||||||
y = y or 2,
|
y = y or 2,
|
||||||
|
|
||||||
-- column-major buffer: buffer[x][y] = {char, tc, bc}
|
-- column-major buffer: buffer[x][y] = {char, tc, bc}
|
||||||
|
isFullscreen = false,
|
||||||
buffer = {},
|
buffer = {},
|
||||||
cursorX = 1,
|
cursorX = 1,
|
||||||
cursorY = 1,
|
cursorY = 1,
|
||||||
@@ -329,7 +330,9 @@ function lib.create(name, w, h, x, y, do_not_add)
|
|||||||
t.buffer, t.w, t.h = newbuf, nw, nh
|
t.buffer, t.w, t.h = newbuf, nw, nh
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
function t.fullscreen(fullscreen)
|
||||||
|
t.isFullscreen = fullscreen or not t.isFullscreen
|
||||||
|
end
|
||||||
function t.redraw() end -- renderer handles this elsewhere
|
function t.redraw() end -- renderer handles this elsewhere
|
||||||
|
|
||||||
function t.setVisible(_) end
|
function t.setVisible(_) end
|
||||||
|
|||||||
@@ -33,24 +33,39 @@ while true do
|
|||||||
if data[1] == "mouse_click" then
|
if data[1] == "mouse_click" then
|
||||||
for indx = #_G.windows, 1, -1 do
|
for indx = #_G.windows, 1, -1 do
|
||||||
local win = _G.windows[indx]
|
local win = _G.windows[indx]
|
||||||
|
local h= win.h
|
||||||
|
local w = win.w
|
||||||
|
local x = win.x
|
||||||
|
local y = win.y
|
||||||
|
if win.isFullscreen then
|
||||||
|
local sw,sh = term.getSize()
|
||||||
|
w = sw
|
||||||
|
h = sh-2
|
||||||
|
x=1
|
||||||
|
y=3
|
||||||
|
end
|
||||||
if data[4] == 1 then
|
if data[4] == 1 then
|
||||||
break
|
break
|
||||||
elseif win.x+win.w-1 == data[3] and win.y+win.h-1 == data[4] and win.decorations and win.resizable then
|
elseif x+w-1 == data[3] and y+h-1 == data[4] and win.decorations and win.resizable and not win.isFullscreen then
|
||||||
dragging = win
|
dragging = win
|
||||||
resizing = true
|
resizing = true
|
||||||
bringtofront(indx)
|
bringtofront(indx)
|
||||||
elseif ((win.y - 1 == data[4] and win.x + 1 <= data[3] and win.x + win.w >= data[3] and data[2] == 1 and win.decorations) or (win.y <= data[4] and win.x <= data[3] and win.y + win.h > data[4] and win.x + win.w > data[3] and key[keys["leftAlt"]] and win.draggable)) then
|
elseif ((y - 1 == data[4] and x + 2 <= data[3] and x + w >= data[3] and data[2] == 1 and win.decorations) or (y <= data[4] and x <= data[3] and y + h > data[4] and x + w > data[3] and key[keys["leftAlt"]] and win.draggable)) and not win.isFullscreen then
|
||||||
dragging = win
|
dragging = win
|
||||||
offsetX = win.x - data[3]
|
offsetX = x - data[3]
|
||||||
offsetY = win.y - data[4]
|
offsetY = y - data[4]
|
||||||
bringtofront(indx)
|
bringtofront(indx)
|
||||||
break
|
break
|
||||||
elseif win.y - 1 == data[4] and win.x == data[3] and win.decorations then
|
elseif y - 1 == data[4] and x == data[3] and win.decorations then
|
||||||
threading.addThread(function() win.closeRequested() end)
|
threading.addThread(function() win.closeRequested() end)
|
||||||
bringtofront(indx)
|
bringtofront(indx)
|
||||||
break
|
break
|
||||||
elseif win.y <= data[4] and win.x <= data[3] and win.y + win.h > data[4] and win.x + win.w > data[3] then
|
elseif y - 1 == data[4] and x+1 == data[3] and win.decorations then
|
||||||
threading.addThread(function() win.clicked(data[3] - win.x + 1, data[4] - win.y + 1, data[2]) end)
|
threading.addThread(function() win.fullscreen() end)
|
||||||
|
bringtofront(indx)
|
||||||
|
break
|
||||||
|
elseif y <= data[4] and x <= data[3] and y + h > data[4] and x + w > data[3] then
|
||||||
|
threading.addThread(function() win.clicked(data[3] - x + 1, data[4] - y + 1, data[2]) end)
|
||||||
bringtofront(indx)
|
bringtofront(indx)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@@ -69,8 +84,19 @@ while true do
|
|||||||
else
|
else
|
||||||
for indx = #_G.windows, 1, -1 do
|
for indx = #_G.windows, 1, -1 do
|
||||||
local win = _G.windows[indx]
|
local win = _G.windows[indx]
|
||||||
if win.y <= data[4] and win.x <= data[3] and win.y + win.h > data[4] and win.x + win.w > data[3] then
|
local h= win.h
|
||||||
threading.addThread(function() win.dragged(data[3] - win.x + 1, data[4] - win.y + 1, data[2]) end)
|
local w = win.w
|
||||||
|
local x = win.x
|
||||||
|
local y = win.y
|
||||||
|
if win.isFullscreen then
|
||||||
|
local sw,sh = term.getSize()
|
||||||
|
w = sw
|
||||||
|
h = sh-2
|
||||||
|
x=1
|
||||||
|
y=3
|
||||||
|
end
|
||||||
|
if y <= data[4] and x <= data[3] and y + h > data[4] and x + w > data[3] then
|
||||||
|
threading.addThread(function() win.dragged(data[3] - x + 1, data[4] - y + 1, data[2]) end)
|
||||||
bringtofront(indx)
|
bringtofront(indx)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@@ -83,8 +109,19 @@ while true do
|
|||||||
else
|
else
|
||||||
for indx = #_G.windows, 1, -1 do
|
for indx = #_G.windows, 1, -1 do
|
||||||
local win = _G.windows[indx]
|
local win = _G.windows[indx]
|
||||||
if win.y <= data[4] and win.x <= data[3] and win.y + win.h > data[4] and win.x + win.w > data[3] then
|
local h= win.h
|
||||||
threading.addThread(function() win.released(data[3] - win.x + 1, data[4] - win.y + 1, data[2]) end)
|
local w = win.w
|
||||||
|
local x = win.x
|
||||||
|
local y = win.y
|
||||||
|
if win.isFullscreen then
|
||||||
|
local sw,sh = term.getSize()
|
||||||
|
w = sw
|
||||||
|
h = sh-2
|
||||||
|
x=1
|
||||||
|
y=3
|
||||||
|
end
|
||||||
|
if y <= data[4] and x <= data[3] and y + h > data[4] and x + w > data[3] then
|
||||||
|
threading.addThread(function() win.released(data[3] - x + 1, data[4] - y + 1, data[2]) end)
|
||||||
bringtofront(indx)
|
bringtofront(indx)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@@ -93,8 +130,19 @@ while true do
|
|||||||
elseif data[1] == "mouse_scroll" then
|
elseif data[1] == "mouse_scroll" then
|
||||||
for indx = #_G.windows, 1, -1 do
|
for indx = #_G.windows, 1, -1 do
|
||||||
local win = _G.windows[indx]
|
local win = _G.windows[indx]
|
||||||
if win.y <= data[4] and win.x <= data[3] and win.y + win.h > data[4] and win.x + win.w > data[3] then
|
local h= win.h
|
||||||
threading.addThread(function() win.scrolled(data[2], data[3] - win.x + 1, data[4] - win.y + 1) end)
|
local w = win.w
|
||||||
|
local x = win.x
|
||||||
|
local y = win.y
|
||||||
|
if win.isFullscreen then
|
||||||
|
local sw,sh = term.getSize()
|
||||||
|
w = sw
|
||||||
|
h = sh-2
|
||||||
|
x=1
|
||||||
|
y=3
|
||||||
|
end
|
||||||
|
if y <= data[4] and x <= data[3] and y + h > data[4] and x + w > data[3] then
|
||||||
|
threading.addThread(function() win.scrolled(data[2], data[3] - x + 1, data[4] - y + 1) end)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
27
startup.lua
27
startup.lua
@@ -61,10 +61,21 @@ end
|
|||||||
local function windows()
|
local function windows()
|
||||||
term.setCursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
for id, win in ipairs(_G.windows) do
|
for id, win in ipairs(_G.windows) do
|
||||||
for cy = 1, win.h do
|
local h= win.h
|
||||||
term.setCursorPos(win.x, win.y + cy - 1)
|
local w = win.w
|
||||||
|
local x = win.x
|
||||||
|
local y = win.y
|
||||||
|
if win.isFullscreen then
|
||||||
|
local sw,sh = term.getSize()
|
||||||
|
w = sw
|
||||||
|
h = sh-2
|
||||||
|
x=1
|
||||||
|
y=3
|
||||||
|
end
|
||||||
|
for cy = 1, h do
|
||||||
|
term.setCursorPos(x, y + cy - 1)
|
||||||
local line, fg, bg = "", "", ""
|
local line, fg, bg = "", "", ""
|
||||||
for cx = 1, win.w do
|
for cx = 1, w do
|
||||||
if win.buffer[cx] then
|
if win.buffer[cx] then
|
||||||
local cell = win.buffer[cx][cy]
|
local cell = win.buffer[cx][cy]
|
||||||
if cell then
|
if cell then
|
||||||
@@ -85,16 +96,16 @@ local function windows()
|
|||||||
term.blit(line, fg, bg)
|
term.blit(line, fg, bg)
|
||||||
end
|
end
|
||||||
if win.decorations then
|
if win.decorations then
|
||||||
term.setCursorPos(win.x, win.y - 1)
|
term.setCursorPos(x, y - 1)
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
term.setBackgroundColor(colors.blue)
|
term.setBackgroundColor(colors.blue)
|
||||||
term.write(string.sub("X " .. win.name .. string.rep(" ", win.w - #win.name - 2),1,win.w))
|
term.write(string.sub("XO " .. win.name .. string.rep(" ", w - #win.name - 3),1,w))
|
||||||
if win.resizable then
|
if win.resizable and not win.isFullscreen then
|
||||||
term.setCursorPos(win.x+win.w-1,win.y+win.h-1)
|
term.setCursorPos(x+w-1,y+h-1)
|
||||||
term.write("\127")
|
term.write("\127")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
term.setCursorPos(win.x + win.cursorX - 1, win.y + win.cursorY - 1)
|
term.setCursorPos(x + win.cursorX - 1, y + win.cursorY - 1)
|
||||||
nterm.setCursorBlink(win.cursorBlink)
|
nterm.setCursorBlink(win.cursorBlink)
|
||||||
if win.closing then
|
if win.closing then
|
||||||
_G.windows[id] = nil
|
_G.windows[id] = nil
|
||||||
|
|||||||
Reference in New Issue
Block a user