os.loadAPI("redirect")
os.loadAPI("goroutine")
function drawWindows()
term.clear()
for name, v in pairs(windowsdata) do
x = windowsdata[name]["x"]-1
y = windowsdata[name]["y"]-1
w = windowsdata[name]["w"]+1
h = windowsdata[name]["h"]+1
wx = w+x
running = windowsdata[name]["running"]
dl = paintutils.drawLine
dp = paintutils.drawPixel
dl(x, y, wx, y, colors.blue)
dl(x, h+y, wx, h+y, colors.blue)
dl(x, y, x, h+y, colors.blue)
dl(wx, y, wx, h+y)
dp(wx, y, colors.red)
dp(wx-1, y, colors.lightBlue)
y1 = y
x = nil
w = nil
h = nil
x, y = term.getCursorPos()
term.setCursorPos(wx-1, y1)
term.write("DX")
term.setCursorPos(x, y)
y = nil
wx = nil
y1 = nil
windows[name].makeActive(windowsdata[name]["x"], windowsdata[name]["y"])
end
end
function drag(name, x, y)
windowsdata[name]["x"] = x
windowsdata[name]["y"] = y
drawWindows()
end
function close(name)
goroutine.kill("windows - "..name)
windows[name] = nil
windowsdata[name] = nil
drawWindows()
end
function handleEvents()
while true do
evt, p1, p2, p3 = os.pullEventRaw()
for k, v in pairs(windowsdata) do
if evt=="mouse_click" then
if p1==v["w"] and p2==v["y"] then
close(k)
elseif p1==v["w"]-1 and p2==v["y"] then
while true do
evt2, a1, a2 = os.pullEventRaw()
if evt2=="mouse_click" then break end
if evt2=="mouse_drag" then drag(k, a1, a2) end
end
end
end
end
end
end
function runactual(name)
shell.run(windowsdata[name]["program"])
drawWindows()
end
function run(name)
for k, v in pairs(windowsdata) do
if k==name then
v["running"] = true
goroutine.spawnWithRedirect("windows - "..name,run,windows[k],name)
end
end
end
windows = {}
windowsdata = {}
function createWindow(name, w, h, x, y, prog)
windows[name] = redirect.createRedirectBuffer(w,h, nil, nil, true)
windowsdata[name]["x"] = x
windowsdata[name]["y"] = y
windowsdata[name]["w"] = w
windowsdata[name]["h"] = h
windowsdata[name]["program"] = prog
windowsdata[name]["running"] = false
end
paintutils.setBackgroundColor(colors.lightBlue)
term.clear()
while true do
term.setCursorPos(1,1)
print("#")
paintutils.drawPixel(1,1, colors.red)
evt, p1, p2 = os.pullEventRaw()
if evt=="mouse_click" and p1==1 and p2==1 then
term.setCursorPos(1,2)
b = read() or "rom/programs/shell"
term.clear()
a = a+1 or 1
createWindow(a, 10, 10, 10, 10, B)/>
run(a)
drawWindows()
end
end
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Window Manager
Started by FuuuAInfiniteLoop(F.A.I.L), 19 February 2013 - 01:49 AMPosted 19 February 2013 - 02:49 AM
Install goroutine and redirect and then use this
Posted 22 February 2013 - 04:36 AM
Spoiler please
Otherwise looks good
Otherwise looks good
Posted 22 February 2013 - 10:16 AM
Dropbox please
Posted 22 February 2013 - 11:08 AM
actually pastebin would be better….not many peopleprefer dropbox….even less for such a short script….Dropbox please
Posted 22 February 2013 - 12:44 PM
err thats what i meant lol idk about dropbox i wanted to download strait to the game :P/> my bad
Posted 24 February 2013 - 01:27 AM
maybe a description of what it does and how to use it. and some screenies
Posted 24 February 2013 - 05:38 AM
Great code. Thanks for posting.
Posted 24 February 2013 - 07:05 AM
Add a little more detail, too. Like how it works etc :)/>
Also, make it download the two needed api's.
Also screenshots! :>
Also, make it download the two needed api's.
Also screenshots! :>
Posted 24 February 2013 - 07:12 AM
Needs screenies!