mouseU = true backgroundColor = colors.lightBlue windows = {NewWindow = function(name) windows.open[#windows.open + 1] = {POS = {x = 0, y = 0},SIZE = {x = 10, y = 9},NAME = name} end, open = {} } windows.NewWindow("TEST") function pixel(x,y,color,cahr) term.setCursorPos(x,y) term.setBackgroundColor(color) if not cahr then cahr = " " end write(cahr) term.setBackgroundColor(backgroundColor) end function mouse_up() startPOS = nil end function mouseDown(mx,my) if startPOS then oldPOS = {x=window.POS.x,y=window.POS.y} window.POS.x = mx - startPOS.x + oldPOS.x window.POS.y = my - startPOS.y + oldPOS.y startPOS = {x = mx,y = my} end end function mouseDownStart(mx,my) if mx >= window.POS.x and mx <= window.POS.x + window.SIZE.x - 1 then if my-1 == window.POS.y then startPOS = {x = mx,y = my} end end end function mouseClick(mb,mx,my) if mx == window.POS.x + window.SIZE.x then if my-1 == window.POS.y then window.NAME = "Close"..string.char(2) end end end while true do event,p1,p2,p3 = os.pullEvent() if event == "mouse_up" then mouseU = true mouse_up() elseif event == "mouse_drag" then if p1 == 1 then if mouseU then mouseDownStart(p2,p3) end mouseDown(p2,p3) mouseU = false end elseif event == "mouse_click" then mouseClick(p1,p2,p3) end --draw term.clear() for wi=1, #windows.open do window = windows.open[wi] for x=1, window.SIZE.x do for y=1,window.SIZE.y do c = colors.lightGray t=" " if y == 1 then c = colors.gray if x <= string.len(window.NAME) then t = string.sub(window.NAME,x,x) end if x == window.SIZE.x then c = colors.red end end pixel(window.POS.x+x,window.POS.y+y,c,t) end end end sleep(0.1) end