Compare commits

...

6 Commits

Author SHA1 Message Date
6068162d6a Update startup.lua 2025-11-21 04:21:05 +00:00
b464270e60 toggleable fullscreen button 2025-10-25 16:10:49 -07:00
06bc628ecf fixed fullscreen support 2025-10-25 15:03:32 -07:00
4194765119 fullscreen implementation 2025-10-25 13:25:03 -07:00
85e19133a3 resizing fixes 2025-10-25 10:59:55 -07:00
b1da7a3337 migrate to new git repo 2025-10-25 08:28:57 +00:00
5 changed files with 184 additions and 60 deletions

View File

@@ -3,6 +3,7 @@ local window = require("libs.window")
local x, y = term.getSize()
local win = window.create("Worm", x / 1.4, y / 1.4, x / 2 - ((x / 1.4) / 2), y / 2 - ((y / 1.5) / 2))
win.resizable = false
win.fullscreenButton = false
sleep()
compat.runFile("/rom/programs/fun/worm.lua", win)
win.close()

View File

@@ -27,24 +27,24 @@ if netmount then
settings.save()
end
download_to("https://github.com/cadenthecreator/ccde/raw/refs/heads/main/startup.lua","startup.lua")
download_to("https://github.com/cadenthecreator/ccde/raw/refs/heads/main/modules/interactions.lua","modules/interactions.lua")
download_to("https://github.com/cadenthecreator/ccde/raw/refs/heads/main/modules/keybinds.lua","modules/keybinds.lua")
download_to("https://github.com/cadenthecreator/ccde/raw/refs/heads/main/modules/launcher.lua","modules/launcher.lua")
download_to("https://github.com/cadenthecreator/ccde/raw/refs/heads/main/modules/entrypointclient.lua","modules/entrypointclient.lua")
download_to("https://github.com/cadenthecreator/ccde/raw/refs/heads/main/libs/keybinds.lua","libs/keybinds.lua")
download_to("https://github.com/cadenthecreator/ccde/raw/refs/heads/main/libs/compat.lua","libs/compat.lua")
download_to("https://github.com/cadenthecreator/ccde/raw/refs/heads/main/libs/threading.lua","libs/threading.lua")
download_to("https://github.com/cadenthecreator/ccde/raw/refs/heads/main/libs/window.lua","libs/window.lua")
download_to("https://github.com/cadenthecreator/ccde/raw/refs/heads/main/apps/adventure.lua","apps/adventure.lua")
download_to("https://github.com/cadenthecreator/ccde/raw/refs/heads/main/apps/shell.lua","apps/shell.lua")
download_to("https://github.com/cadenthecreator/ccde/raw/refs/heads/main/apps/worm.lua","apps/worm.lua")
download_to("https://github.com/cadenthecreator/ccde/raw/refs/heads/main/apps/launcher.lua","apps/launcher.lua")
download_to("https://github.com/cadenthecreator/ccde/raw/refs/heads/main/.apps/adventure.app",".apps/adventure.app")
download_to("https://github.com/cadenthecreator/ccde/raw/refs/heads/main/.apps/shell.app",".apps/shell.app")
download_to("https://github.com/cadenthecreator/ccde/raw/refs/heads/main/.apps/worm.app",".apps/worm.app")
download_to("https://github.com/cadenthecreator/ccde/raw/refs/heads/main/.wallpaper.nfp",".wallpaper.nfp")
download_to("https://git.cadencoaster.com/Rivulet/ccde/raw/branch/main/startup.lua","startup.lua")
download_to("https://git.cadencoaster.com/Rivulet/ccde/raw/branch/main/modules/interactions.lua","modules/interactions.lua")
download_to("https://git.cadencoaster.com/Rivulet/ccde/raw/branch/main/modules/keybinds.lua","modules/keybinds.lua")
download_to("https://git.cadencoaster.com/Rivulet/ccde/raw/branch/main/modules/launcher.lua","modules/launcher.lua")
download_to("https://git.cadencoaster.com/Rivulet/ccde/raw/branch/main/modules/entrypointclient.lua","modules/entrypointclient.lua")
download_to("https://git.cadencoaster.com/Rivulet/ccde/raw/branch/main/libs/keybinds.lua","libs/keybinds.lua")
download_to("https://git.cadencoaster.com/Rivulet/ccde/raw/branch/main/libs/compat.lua","libs/compat.lua")
download_to("https://git.cadencoaster.com/Rivulet/ccde/raw/branch/main/libs/threading.lua","libs/threading.lua")
download_to("https://git.cadencoaster.com/Rivulet/ccde/raw/branch/main/libs/window.lua","libs/window.lua")
download_to("https://git.cadencoaster.com/Rivulet/ccde/raw/branch/main/apps/adventure.lua","apps/adventure.lua")
download_to("https://git.cadencoaster.com/Rivulet/ccde/raw/branch/main/apps/shell.lua","apps/shell.lua")
download_to("https://git.cadencoaster.com/Rivulet/ccde/raw/branch/main/apps/worm.lua","apps/worm.lua")
download_to("https://git.cadencoaster.com/Rivulet/ccde/raw/branch/main/apps/launcher.lua","apps/launcher.lua")
download_to("https://git.cadencoaster.com/Rivulet/ccde/raw/branch/main/.apps/adventure.app",".apps/adventure.app")
download_to("https://git.cadencoaster.com/Rivulet/ccde/raw/branch/main/.apps/shell.app",".apps/shell.app")
download_to("https://git.cadencoaster.com/Rivulet/ccde/raw/branch/main/.apps/worm.app",".apps/worm.app")
download_to("https://git.cadencoaster.com/Rivulet/ccde/raw/branch/main/.wallpaper.nfp",".wallpaper.nfp")
if netmount then
download_to("https://github.com/cadenthecreator/ccde/raw/refs/heads/main/modules/netmount.lua","modules/netmount.lua")
download_to("https://git.cadencoaster.com/Rivulet/ccde/raw/branch/main/modules/netmount.lua","modules/netmount.lua")
end

View File

@@ -1,5 +1,5 @@
local lib = {}
local threading = require("libs.threading")
local function add(t, v)
for i = 1, #t + 1 do
if t[i] == nil then
@@ -71,6 +71,7 @@ function lib.create(name, w, h, x, y, do_not_add)
y = y or 2,
-- column-major buffer: buffer[x][y] = {char, tc, bc}
isFullscreen = false,
buffer = {},
cursorX = 1,
cursorY = 1,
@@ -82,23 +83,38 @@ function lib.create(name, w, h, x, y, do_not_add)
decorations = true,
alwaysOnTop = false,
alwaysBelow = false,
fullscreenButton = true,
closing = false,
_palette = {}, -- optional local palette store
}
local function init_col(xi)
local w = t.w
local h = t.h
if t.isFullscreen then
local sw,sh = term.getSize()
w = sw
h = sh-2
end
if not t.buffer[xi] then
t.buffer[xi] = {}
for yy = 1, t.h do
for yy = 1, h do
t.buffer[xi][yy] = { char = " ", tc = t.textColor, bc = t.bgColor }
end
end
end
function t.clear()
for xi = 1, t.w do
local w = t.w
local h = t.h
if t.isFullscreen then
local sw,sh = term.getSize()
w = sw
h = sh-2
end
for xi = 1, w do
init_col(xi)
for yy = 1, t.h do
for yy = 1, h do
local cell = t.buffer[xi][yy]
if not cell then cell = { char = " ", tc = t.textColor, bc = t.bgColor } end
cell.char, cell.tc, cell.bc = " ", t.textColor, t.bgColor
@@ -113,8 +129,15 @@ function lib.create(name, w, h, x, y, do_not_add)
function t.clearLine()
local y0 = t.cursorY
if y0 < 1 or y0 > t.h then return end
for xi = 1, t.w do
local w = t.w
local h = t.h
if t.isFullscreen then
local sw,sh = term.getSize()
w = sw
h = sh-2
end
if y0 < 1 or y0 > h then return end
for xi = 1, w do
init_col(xi)
if not t.buffer[xi][y0] then t.buffer[xi][y0] = { char = " ", tc = t.textColor, bc = t.bgColor } end
local cell = t.buffer[xi][y0]
@@ -123,7 +146,13 @@ function lib.create(name, w, h, x, y, do_not_add)
-- base keeps cursorX unchanged
end
function t.getSize() return t.w, t.h end
function t.getSize()
if t.isFullscreen then
local sw,sh = term.getSize()
return sw,sh-2
end
return t.w, t.h
end
function t.setCursorPos(x0, y0)
-- do NOT clamp; let writers clip like base window
@@ -186,11 +215,18 @@ function lib.create(name, w, h, x, y, do_not_add)
-- write/blit: mutate buffer with clipping; let cursor run past width
function t.write(str)
local w = t.w
local h = t.h
if t.isFullscreen then
local sw,sh = term.getSize()
w = sw
h = sh-2
end
str = tostring(str)
local y0 = t.cursorY
for i = 1, #str do
local x = t.cursorX + i - 1
if x >= 1 and x <= t.w and y0 >= 1 and y0 <= t.h then
if x >= 1 and x <= w and y0 >= 1 and y0 <= h then
init_col(x)
if not t.buffer[x][y0] then t.buffer[x][y0] = { char = " ", tc = t.textColor, bc = t.bgColor } end
local cell = t.buffer[x][y0]
@@ -207,7 +243,13 @@ function lib.create(name, w, h, x, y, do_not_add)
if bgColors and type(bgColors) ~= "string" then error("bad argument #3 (expected string)", 2) end
if textColors and #textColors ~= #text then error("Arguments must be the same length", 2) end
if bgColors and #bgColors ~= #text then error("Arguments must be the same length", 2) end
local w = t.w
local h = t.h
if t.isFullscreen then
local sw,sh = term.getSize()
w = sw
h = sh-2
end
textColors = textColors and textColors:lower() or nil
bgColors = bgColors and bgColors:lower() or nil
@@ -215,7 +257,7 @@ function lib.create(name, w, h, x, y, do_not_add)
local n = #text
for i = 1, n do
local x = t.cursorX + i - 1
if x >= 1 and x <= t.w and y0 >= 1 and y0 <= t.h then
if x >= 1 and x <= w and y0 >= 1 and y0 <= h then
init_col(x)
local ch = text:sub(i, i)
local tch = textColors and textColors:sub(i, i) or nil
@@ -232,15 +274,22 @@ function lib.create(name, w, h, x, y, do_not_add)
-- scroll: supports positive (up) and negative (down)
function t.scroll(n)
local w = t.w
local h = t.h
if t.isFullscreen then
local sw,sh = term.getSize()
w = sw
h = sh-2
end
n = math.floor(n or 1)
if n == 0 then return end
local absn = math.abs(n)
if absn >= t.h then
if absn >= h then
-- clear all rows to new empty lines with current colors
for xi = 1, t.w do
for xi = 1, w do
init_col(xi)
for yy = 1, t.h do
for yy = 1, h do
local cell = t.buffer[xi][yy] or { char = " ", tc = t.textColor, bc = t.bgColor }
cell.char, cell.tc, cell.bc = " ", t.textColor, t.bgColor
end
@@ -250,13 +299,14 @@ function lib.create(name, w, h, x, y, do_not_add)
if n > 0 then
-- move content up
for xi = 1, t.w do
for xi = 1, w do
init_col(xi)
for yy = 1, t.h - n do
local dst, src = t.buffer[xi][yy], t.buffer[xi][yy + n]
for yy = 1, h - n do
if not t.buffer[xi][yy] then t.buffer[xi][yy] = { char = " ", tc = t.textColor, bc = t.bgColor } end
local dst, src = t.buffer[xi][yy], (t.buffer[xi][yy + n] or { char = " ", tc = t.textColor, bc = t.bgColor })
dst.char, dst.tc, dst.bc = src.char, src.tc, src.bc
end
for yy = t.h - n + 1, t.h do
for yy = h - n + 1, h do
local cell = t.buffer[xi][yy] or { char = " ", tc = t.textColor, bc = t.bgColor }
cell.char, cell.tc, cell.bc = " ", t.textColor, t.bgColor
end
@@ -264,9 +314,9 @@ function lib.create(name, w, h, x, y, do_not_add)
else
-- n < 0 : move content down
local k = -n
for xi = 1, t.w do
for xi = 1, w do
init_col(xi)
for yy = t.h, k + 1, -1 do
for yy = h, k + 1, -1 do
local dst, src = t.buffer[xi][yy], t.buffer[xi][yy - k]
dst.char, dst.tc, dst.bc = src.char, src.tc, src.bc
end
@@ -328,7 +378,19 @@ function lib.create(name, w, h, x, y, do_not_add)
t.buffer, t.w, t.h = newbuf, nw, nh
end
end
function t.fullscreen(fullscreen)
if fullscreen == nil or fullscreen ~= t.isFullscreen then
local w = t.w
local h = t.h
if t.isFullscreen then
local sw,sh = term.getSize()
w = sw
h = sh-2
end
threading.addThread(function () t.resized(w,h) end)
end
t.isFullscreen = fullscreen or not t.isFullscreen
end
function t.redraw() end -- renderer handles this elsewhere
function t.setVisible(_) end

View File

@@ -33,24 +33,39 @@ while true do
if data[1] == "mouse_click" then
for indx = #_G.windows, 1, -1 do
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
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
resizing = true
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 + 1 + (win.fullscreenButton and 1 or 0) <= 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
offsetX = win.x - data[3]
offsetY = win.y - data[4]
offsetX = x - data[3]
offsetY = y - data[4]
bringtofront(indx)
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)
bringtofront(indx)
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
threading.addThread(function() win.clicked(data[3] - win.x + 1, data[4] - win.y + 1, data[2]) end)
elseif y - 1 == data[4] and x+1 == data[3] and win.decorations and win.fullscreenButton then
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)
break
end
@@ -69,8 +84,19 @@ while true do
else
for indx = #_G.windows, 1, -1 do
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
threading.addThread(function() win.dragged(data[3] - win.x + 1, data[4] - win.y + 1, data[2]) end)
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 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)
break
end
@@ -83,8 +109,19 @@ while true do
else
for indx = #_G.windows, 1, -1 do
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
threading.addThread(function() win.released(data[3] - win.x + 1, data[4] - win.y + 1, data[2]) end)
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 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)
break
end
@@ -93,8 +130,19 @@ while true do
elseif data[1] == "mouse_scroll" then
for indx = #_G.windows, 1, -1 do
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
threading.addThread(function() win.scrolled(data[2], data[3] - win.x + 1, data[4] - win.y + 1) end)
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 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
end
end

View File

@@ -8,7 +8,7 @@ local wrap = require("cc.strings").wrap
_G.threads = {}
_G.windows = {}
_G.keybinds = {}
local nterm = term.native()
local nterm = term
local sx,sy = term.getSize()
local term = window.create("",sx,sy,1,1,true)
local event = { n = 0 }
@@ -61,10 +61,21 @@ end
local function windows()
term.setCursorBlink(false)
for id, win in ipairs(_G.windows) do
for cy = 1, win.h do
term.setCursorPos(win.x, win.y + cy - 1)
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
for cy = 1, h do
term.setCursorPos(x, y + cy - 1)
local line, fg, bg = "", "", ""
for cx = 1, win.w do
for cx = 1, w do
if win.buffer[cx] then
local cell = win.buffer[cx][cy]
if cell then
@@ -85,16 +96,18 @@ local function windows()
term.blit(line, fg, bg)
end
if win.decorations then
term.setCursorPos(win.x, win.y - 1)
term.setCursorPos(x, y - 1)
term.setTextColor(colors.white)
term.setBackgroundColor(colors.blue)
term.write(string.sub("X " .. win.name .. string.rep(" ", win.w - #win.name - 2),1,win.w))
if win.resizable then
term.setCursorPos(win.x+win.w-1,win.y+win.h-1)
local window_buttons = "X"
if win.fullscreenButton then window_buttons = window_buttons.."O" end
term.write(string.sub(window_buttons.." " .. win.name .. string.rep(" ", w - #win.name -1 -#window_buttons),1,w))
if win.resizable and not win.isFullscreen then
term.setCursorPos(x+w-1,y+h-1)
term.write("\127")
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)
if win.closing then
_G.windows[id] = nil