--os api

dBack = "none"

tbColor = 128
tbtColor = 512
dBack = "documents/pictures/.background"
dCol=1


function drawIcon(label, X, Y)
term.setBackgroundColour(128)
term.setCursorPos(X, Y)
print("   ")
term.setCursorPos(X, Y+1)
print("    ")
term.setCursorPos(X, Y+2)
print("    ")
term.setCursorPos(X, Y+3)
print("    ")
term.setBackgroundColour(colors.white)
term.setTextColor(128)
term.setCursorPos(X, Y+5)
print(label)
end


--Logo
function drawLogo(X, Y)
term.setCursorPos(X+1, Y)
term.setBackgroundColour(colours.cyan)
print("          ")
term.setCursorPos(X, Y+1) 
print("   0    0   ")
term.setCursorPos(X, Y+2)
print("            ")
term.setCursorPos(X, Y+3)
print("            ")
term.setCursorPos(X+12, Y+3)
print(" ")
term.setCursorPos(X+13, Y+2)
print(" ")
term.setCursorPos(X+14, Y+2)
print(" ")
term.setCursorPos(X+15, Y+1)
print(" ")
term.setCursorPos(X+16, Y+1)
print(" ")
term.setCursorPos(X+1, Y+4)
print("          ")

term.setBackgroundColour(colours.white)
term.setCursorPos(X+3, Y+1)
print(" ")
term.setCursorPos(X+8, Y+1)
print(" ")
term.setCursorPos(X+2, Y+3)
print("        ")
term.setBackgroundColour(colors.white)
term.setTextColour(128)
term.setCursorPos(X+2, Y+6)
print("NDFSolus")
end

function printN()
term.setCursorPos(9,5)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(9,6)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(9,7)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(9,8)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(9,9)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(9,10)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(9,11)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(9,12)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(9,13)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(9,14)
term.setBackgroundColor(colors.black)
print(" ")


term.setCursorPos(10,6)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(11,7)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(12,8)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(13,9)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(14,10)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(15,11)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(16,12)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(17,13)
term.setBackgroundColor(colors.black)
print(" ")



term.setCursorPos(18,5)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(18,6)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(18,7)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(18,8)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(18,9)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(18,10)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(18,11)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(18,12)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(18,13)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(18,14)
term.setBackgroundColor(colors.black)
print(" ")

end

function printD()
term.setCursorPos(21,5)
term.setBackgroundColor(colors.black)
print("    ")
term.setCursorPos(21,6)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(21,7)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(21,8)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(21,9)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(21,10)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(21,11)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(21,12)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(21,13)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(21,14)
term.setBackgroundColor(colors.black)
print("    ")


term.setCursorPos(25,6)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(26,7)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(27,8)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(28,9)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(28,10)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(27,11)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(26,12)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(25,13)
term.setBackgroundColor(colors.black)
print(" ")


end


function printF()
term.setCursorPos(31,5)
term.setBackgroundColor(colors.black)
print("              ")
term.setCursorPos(31,6)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(31,7)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(31,8)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(31,9)
term.setBackgroundColor(colors.black)
print("         ")
term.setCursorPos(31,10)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(31,11)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(31,12)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(31,13)
term.setBackgroundColor(colors.black)
print(" ")
term.setCursorPos(31,14)
term.setBackgroundColor(colors.black)
print(" ")


end

--Menus


function desktopContextMenu1Text(x, y)
if getLine(".var/settings", 4)=="Show Icons: True" then
term.setBackgroundColor(128)
term.setTextColor(colors.white)
term.setCursorPos(x,y)
print("             ")
term.setCursorPos(x,y+1)
print("  About      ")
term.setCursorPos(x,y+2)
print("  Hide Icons ")
term.setCursorPos(x,y+3)
print("  Desktop    ")
term.setCursorPos(x,y+4)
print("  Shutdown   ")
term.setCursorPos(x,y+5)
print("  Properties ")
term.setCursorPos(x,y+6)
print("             ")
elseif getLine(".var/settings", 4)=="Show Icons: False" then
term.setBackgroundColor(128)
term.setTextColor(colors.white)
term.setCursorPos(x,y)
print("             ")
term.setCursorPos(x,y+1)
print("  About      ")
term.setCursorPos(x,y+2)
print("  Show Icons ")
term.setCursorPos(x,y+3)
print("  Desktop    ")
term.setCursorPos(x,y+4)
print("  Shutdown   ")
term.setCursorPos(x,y+5)
print("  Properties ")
term.setCursorPos(x,y+6)
print("             ")
end
end

function iconContextMenu1Text(x, y)
term.setBackgroundColor(128)
term.setTextColor(colors.white)
term.setCursorPos(x,y)
print("         ")
term.setCursorPos(x,y+1)
print(" Ch Icon ")
term.setCursorPos(x,y+2)
print(" Ch Link ")
term.setCursorPos(x,y+3)
print(" Rename  ")
term.setCursorPos(x,y+4)
print("         ")
end

function GCSContextMenu1Text(x, y)
term.setBackgroundColor(128)
term.setTextColor(colors.white)
term.setCursorPos(x,y)
print("             ")
term.setCursorPos(x,y+1)
print("  About      ")
term.setCursorPos(x,y+2)
print("  Toggle All ")
term.setCursorPos(x,y+3)
print("  Desktop    ")
term.setCursorPos(x,y+4)
print("  Shutdown   ")
term.setCursorPos(x,y+5)
print("  Properties ")
term.setCursorPos(x,y+6)
print("             ")
end


function GCSContextMenu2Text(x, y)
term.setBackgroundColor(colors.gray)
term.setTextColor(colors.white)
term.setCursorPos(x,y)
print(" .:OFF:.  ")
term.setCursorPos(x,y+1)
print(" .:ON :.  ")
end

function drawStartMenu(x, y)
term.setBackgroundColor(128)
term.setTextColor(colors.white)
term.setCursorPos(x,y)
print("                ")
term.setCursorPos(x,y+1)
print("  Help          ")
term.setCursorPos(x,y+2)
print("  Control Panel ")
term.setCursorPos(x,y+3)
print("  Programs      ")
term.setCursorPos(x,y+4)
print("  Reboot        ")
term.setCursorPos(x,y+5)
print("  Shutdown      ")
term.setCursorPos(x,y+6)
print("                ")
end

function drawCTXMenu(x, y)
term.setBackgroundColor(128)
term.setTextColor(colors.white)
term.setCursorPos(x,y)
print("                ")
term.setCursorPos(x,y+1)
print("  Help          ")
term.setCursorPos(x,y+2)
print("  Close         ")
term.setCursorPos(x,y+3)
print("                ")
end


function drawContextMenu2(x, y, a, b)
term.setBackgroundColor(colors.gray)
for x=x, a do
for y=y, b do
term.setCursorPos(x,y)
print(" ")
end
end  
end



function drawActionMenu1()
term.setBackgroundColor(colors.gray)
term.setTextColour(colours.white)
print("              ")
print("              ")
print("              ")
print("              ")
print("              ")
print("              ")
print("              ")
print("              ")


end


function drawActionMenu2()
term.setBackgroundColor(colors.gray)
term.setTextColour(colours.white)
print("              ")
print("              ")
print("              ")
print("              ")
print("              ")
print("              ")
print("              ")
print("              ")
print("              ")
print("              ")


end


function drawAbout()



end


function titleTime()
term.setBackgroundColor(tbColor)
term.setTextColor(tbtColor)

term.setCursorPos(43,1)
print(textutils.formatTime(os.time()))

end

--Title Bars/Features

function titleBar()
term.setBackgroundColor(tbColor)
term.setTextColor(tbtColor)
term.setCursorPos(1,1)
term.clearLine()
term.setCursorPos(2,1)
print("[Begin]")
	if getLine(".var/settings", 6)=="OSTime: Visible" then
	titleTime()
	else
	end
end

function programTitle()
term.setBackgroundColor(128)
term.setTextColor(colors.cyan)
term.setCursorPos(1,1)
term.clearLine()
term.setCursorPos(2,1)
print("[Begin]")
term.setCursorPos(10,1)
print("[Close]")
	if getLine(".var/settings", 6)=="OSTime: Visible" then
	titleTime()
	else
	end
end

--File System

function exists(path)
	local file = assert(io.open(path, "r"))
	if file ~= nil then
		file:close()
		return true
	end
	
	return false
end

function getTable(path)
	if exists(path) then
		local file = io.open(path, "r")
		local lines = {}
		local i = 1
		local line = file:read("*l")
		while line ~= nil do
			lines[i] = line
			line = file:read("*l")
			i = i + 1
		end
		file:close()
		return lines
	end
	return {}
end

function getLine(path, n)
	if exists(path) then
		local lines = getTable(path)
		return lines[n]
	end
	return ""
end

function getText(path)
	if exists(path) then
		local file = assert(io.open(path, "r"))
		return file:read("*a")
	end
	return ""
end

function fappend(path, text)
	local file = assert(io.open(path, "a"))
	file:write(text.."\n")
	file:close()
end 

function fwrite(path, text)
	local file = assert(io.open(path, "w"))
	file:write(text)
	file:close()
end

function fwriteAtStart(path, text)
	local _text = getText(path)
	fwrite(path, text.."\n".._text)
end

function fwriteFromTable(path, t)
	local text = ""
	for _, line in pairs(t) do
		text = text..line.."\n"
	end
	fwrite(path, text)
end

function fappendFromTable(path, t)
	local text = ""
	for _, line in pairs(t) do
		text = text..line.."\n"
	end
	fappend(path, text)
end 

function fwriteAtStartFromTable(path, t)
	local text = ""
	for _, line in pairs(t) do
		text = text..line.."\n"
	end
	fwriteAtStart(path, text)
end

function replaceLine(path, n, text)
	local lines = getTable(path)
	lines[n] = text
	fwriteFromTable(path, lines)
end

function getName(path)
	if exists(path) then
		local lastSlashPos = 1
		for i = 1, path:len() do
			if path:sub(i, i) == "/" then
				lastSlashPos = i
			end
		end
		
		return path:sub(lastSlashPos + 1)
	end
	return ""
end

function getPath(path)
	if exists(path) then
		local lastSlashPos = 1
		for i = 1, path:len() do
			if path:sub(i, i) == "/" then
				lastSlashPos = i
			end
		end
		
		return path:sub(1, lastSlashPos)
	end
	return ""
end

function fremove(path)
	os.remove(path)
end


--Program Styles

function drawCP()
term.setBackgroundColour(colors.white)
term.setTextColor(128)
term.clear()

print("                                                   ")
print("                                                   ")
print("                      NDF-OS                       ")
print("               System Control Panel                ")
print("                                                   ")
print("                                                   ")
print("  Startup       >                                  ")
print("  Desktop       >                                  ")
print("  User Accounts >                                  ")
print("  Background    >                                  ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")


end

function drawCPBackground()
term.setBackgroundColour(colors.white)
term.setTextColor(128)
term.clear()

print("                                                   ")
print("                                                   ")
print("                      NDF-OS                       ")
print("               System Control Panel                ")
print("                                                   ")
print("                                                   ")
print("  Startup       >        Background Image:         ")
print("  Desktop       >                           <      ")
print("  User Accounts >                                  ")
print("  Background    >                                  ")
print("                         Background Color          ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
term.setCursorPos(2,10)
term.setBackgroundColor(256)
term.setTextColor(128)
print(" Background    > ")

if getLine("programs/.system/control.nse", 9)=='dBack = "documents/pictures/.backgroundCC"' then
	term.setBackgroundColor(colors.white)
	term.setTextColor(256)
	term.setCursorPos(26,8)
	print("ComputerCraft")
		elseif getLine("programs/.system/control.nse", 9)=='dBack = "documents/pictures/.background"' then
			term.setBackgroundColor(colors.white)
			term.setTextColor(256)
			term.setCursorPos(26 ,8)
			print("NDFSolus")
else
	term.setBackgroundColor(colors.white)
	term.setTextColor(256)
	term.setCursorPos(26 ,8)
	print("Custom")
end



end


function drawCPStartup()
term.setBackgroundColour(colors.white)
term.setTextColor(128)
term.clear()

print("                                                   ")
print("                                                   ")
print("                      NDF-OS                       ")
print("               System Control Panel                ")
print("                                                   ")
print("                                                   ")
print("  Startup       >       Auto Log-in:          <    ")
print("  Desktop       >                                  ")
print("  User Accounts >       Quiet Boot:           <    ")
print("  Background    >                                  ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
term.setCursorPos(2,7)
term.setBackgroundColor(256)
term.setTextColor(128)
print(" Startup       > ")

if getLine(".var/settings", 3)=="Auto Log-in: True" then
	term.setBackgroundColor(colors.white)
	term.setTextColor(256)
	term.setCursorPos(39 ,7)
	print("True")
		elseif getLine(".var/settings", 3)=="Auto Log-in: False" then
			term.setBackgroundColor(colors.white)
			term.setTextColor(256)
			term.setCursorPos(39 ,7)
			print("False")
end

if getLine(".var/settings", 7)=="Startup Logo: Hidden" then
	term.setBackgroundColor(colors.white)
	term.setTextColor(256)
	term.setCursorPos(39 ,9)
	print("True")
		elseif getLine(".var/settings", 7)=="Startup Logo: Visible" then
			term.setBackgroundColor(colors.white)
			term.setTextColor(256)
			term.setCursorPos(39 ,9)
			print("False")
end




end


function drawCPDesktop()
term.setBackgroundColour(colors.white)
term.setTextColor(128)
term.clear()

print("                                                   ")
print("                                                   ")
print("                      NDF-OS                       ")
print("               System Control Panel                ")
print("                                                   ")
print("                                                   ")
print("  Startup       >        Show Icons:          <    ")
print("  Desktop       >                                  ")
print("  User Accounts >        Show Time:           <    ")
print("  Background    >                                  ")
print("                         Title Bar Color:     <    ")
print("                                                   ")
print("                         Title Bar Text       <    ")
print("                         Color                     ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
term.setCursorPos(2,8)
term.setBackgroundColor(256)
term.setTextColor(128)
print(" Desktop       > ")



if getLine(".var/settings", 4)=="Show Icons: True" then
	term.setBackgroundColor(colors.white)
	term.setTextColor(256)
	term.setCursorPos(39 ,7)
	print("True")
		elseif getLine(".var/settings", 4)=="Show Icons: False" then
			term.setBackgroundColor(colors.white)
			term.setTextColor(256)
			term.setCursorPos(39 ,7)
			print("False")
end

if getLine(".var/settings", 6)=="OSTime: Visible" then
	term.setBackgroundColor(colors.white)
	term.setTextColor(256)
	term.setCursorPos(39 ,9)
	print("True")
		elseif getLine(".var/settings", 6)=="OSTime: Hidden" then
			term.setBackgroundColor(colors.white)
			term.setTextColor(256)
			term.setCursorPos(39 ,9)
			print("False")
end

end

function drawCPUA()
term.setBackgroundColour(colors.white)
term.setTextColor(128)
term.clear()

print("                                                   ")
print("                                                   ")
print("                      NDF-OS                       ")
print("               System Control Panel                ")
print("                                                   ")
print("                      User 1                       ")
print("  Startup       >          Username:               ")
print("  Desktop       >          Password:               ")
print("  User Accounts >     User 2                       ")
print("  Background    >          Username:               ")
print("                           Password:               ")
print("                      User 3                       ")
print("                           Username:               ")
print("                           Password:               ")
print("                      User 4                       ")
print("                           Username:               ")
print("                           Password:               ")
print("                                                   ")
term.setCursorPos(2,9)
term.setBackgroundColor(256)
term.setTextColor(128)
print(" User Accounts > ")
usrn1 = getLine(".var/uaconf", 10)
usrp1 = getLine(".var/uaconf", 12)
usrn2 = getLine(".var/uaconf", 15)
usrp2 = getLine(".var/uaconf", 17)
usrn3 = getLine(".var/uaconf", 20)
usrp3 = getLine(".var/uaconf", 22)
usrn4 = getLine(".var/uaconf", 25)
usrp4 = getLine(".var/uaconf", 27)

term.setBackgroundColor(colors.white)
term.setTextColor(256)
term.setCursorPos(39 ,7)
print(usrn1)
term.setCursorPos(39 ,8)
print(usrp1)
term.setCursorPos(39 ,10)
print(usrn2)
term.setCursorPos(39 ,11)
print(usrp2)
term.setCursorPos(39 ,13)
print(usrn3)
term.setCursorPos(39 ,14)
print(usrp3)
term.setCursorPos(39 ,16)
print(usrn4)
term.setCursorPos(39 ,17)
print(usrp4)




end

function drawCPallet(x,y)
term.setCursorPos(x-1,y-1)
term.setBackgroundColor(128)
print("          ")

term.setCursorPos(x-1,y)
term.setBackgroundColor(128)
print("          ")

term.setCursorPos(x-1,y+1)
term.setBackgroundColor(128)
print("          ")

term.setCursorPos(x-1,y+2)
term.setBackgroundColor(128)
print("          ")

term.setCursorPos(x-1,y+3)
term.setBackgroundColor(128)
print("          ")

term.setCursorPos(x-1,y+4)
term.setBackgroundColor(128)
print("          ")

term.setCursorPos(x,y)
term.setBackgroundColor(1)
print("  ")

term.setCursorPos(x+2,y)
term.setBackgroundColor(2)
print("  ")

term.setCursorPos(x+4,y)
term.setBackgroundColor(4)
print("  ")

term.setCursorPos(x+6,y)
term.setBackgroundColor(8)
print("  ")

term.setCursorPos(x,y+1)
term.setBackgroundColor(16)
print("  ")

term.setCursorPos(x+2,y+1)
term.setBackgroundColor(32)
print("  ")

term.setCursorPos(x+4,y+1)
term.setBackgroundColor(64)
print("  ")

term.setCursorPos(x+6,y+1)
term.setBackgroundColor(128)
print("  ")

term.setCursorPos(x,y+2)
term.setBackgroundColor(256)
print("  ")

term.setCursorPos(x+2,y+2)
term.setBackgroundColor(512)
print("  ")

term.setCursorPos(x+4,y+2)
term.setBackgroundColor(1024)
print("  ")

term.setCursorPos(x+6,y+2)
term.setBackgroundColor(2048)
print("  ")

term.setCursorPos(x,y+3)
term.setBackgroundColor(4096)
print("  ")

term.setCursorPos(x+2,y+3)
term.setBackgroundColor(8192)
print("  ")

term.setCursorPos(x+4,y+3)
term.setBackgroundColor(16384)
print("  ")

term.setCursorPos(x+6,y+3)
term.setBackgroundColor(32768)
print("  ")



end


function drawDesktop()

icon1 = ".var/.icons/FireWolf.nfp"
icon2 = ".var/.icons/nPaintPro.nfp"
icon3 = ".var/.icons/LuaBasic.nfp"
label1 = kernal.getLine(".var/labels", 1)
label2 = kernal.getLine(".var/labels", 2)
label3 = kernal.getLine(".var/labels", 3)


term.setBackgroundColour(dCol)
term.clear()
if fs.exists(dBack) then
image = paintutils.loadImage(dBack)
paintutils.drawImage(image,1 ,1)
else
image = paintutils.loadImage("documents/pictures/.background")
paintutils.drawImage(image,1 ,1)
end	
	if kernal.getLine(".var/settings", 4)=="Show Icons: True" then
			image = paintutils.loadImage(icon1)
			paintutils.drawImage(image,3 ,3)
			term.setBackgroundColor(1)
			term.setTextColor(colors.red)
			term.setCursorPos(2, 7)
			print("+")
			term.setTextColor(128)
			term.setCursorPos(3, 8)
			print(label1)
			
			image = paintutils.loadImage(icon2)
			paintutils.drawImage(image,3 ,11)
			term.setBackgroundColor(1)
			term.setTextColor(colors.red)
			term.setCursorPos(2, 15)
			print("+")
			term.setTextColor(128)
			term.setCursorPos(3, 16)
			print(label2)
			
			image = paintutils.loadImage(icon3)
			paintutils.drawImage(image,41 ,3)
			term.setBackgroundColor(1)
			term.setTextColor(colors.red)
			term.setCursorPos(40, 7)
			print("+")
			term.setTextColor(128)
			term.setCursorPos(41, 8)
			print(label3)
			--kernal.iconFireWolf(3, 3)
			--kernal.iconNPaintPro(3, 11)
			--kernal.iconLuaBasic(41, 3)
			else
	end

end

function allowTerminate()
--os.pullEvent = os.pullEventRaw
end

function drawLuaBasic()

term.setBackgroundColour(colors.white)
term.setTextColour(128)
term.clear()
print("                                                   ")
print("                                                   ")
print("              Welcome to Lua Basic                 ")
print("           What would you like to do?              ")
print("                                                   ")
print("                                                   ")
print("  ##################       ###################     ")
print("  #                #       #                 #     ")
print("  #  New Project   #       #  Edit Existing  #     ")
print("  #                #       #                 #     ")
print("  ##################       ###################     ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
term.setCursorPos(3,7)
term.setBackgroundColor(colors.white)
print("                  ")
term.setCursorPos(3,8)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(3,9)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(3,10)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(3,11)
term.setBackgroundColor(colors.white)
print("                  ")

term.setCursorPos(20,8)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(20,9)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(20,10)
term.setBackgroundColor(colors.white)
print(" ")


term.setCursorPos(28,7)
term.setBackgroundColor(colors.white)
print("                   ")
term.setCursorPos(28,8)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(28,9)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(28,10)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(28,11)
term.setBackgroundColor(colors.white)
print("                   ")

term.setCursorPos(46,8)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(46,9)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(46,10)
term.setBackgroundColor(colors.white)
print(" ")


term.setCursorPos(4,8)
term.setBackgroundColor(colors.gray)
print("                ")
term.setCursorPos(4,9)
term.setBackgroundColor(colors.gray)
print("                ")
term.setCursorPos(6,9)
term.setTextColor(colors.white)
print("New Project")
term.setCursorPos(4,10)
term.setBackgroundColor(colors.gray)
print("                ")

term.setCursorPos(29,8)
term.setBackgroundColor(colors.gray)
print("                 ")
term.setCursorPos(29,9)
term.setBackgroundColor(colors.gray)
print("                 ")
term.setCursorPos(31,9)
term.setTextColor(colors.white)
print("Edit Existing")
term.setCursorPos(29,10)
term.setBackgroundColor(colors.gray)
print("                 ")
end

function drawnPaintPro()

term.setBackgroundColour(colors.white)
term.setTextColour(128)
term.clear()
print("                                                   ")
print("                                                   ")
print("              Welcome to nPaintPro                 ")
print("           What would you like to do?              ")
print("                                                   ")
print("                                                   ")
print("  ##################       ###################     ")
print("  #                #       #                 #     ")
print("  #  New Picture   #       #  Edit Existing  #     ")
print("  #                #       #                 #     ")
print("  ##################       ###################     ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
print("                                                   ")
term.setCursorPos(3,7)
term.setBackgroundColor(colors.white)
print("                  ")
term.setCursorPos(3,8)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(3,9)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(3,10)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(3,11)
term.setBackgroundColor(colors.white)
print("                  ")

term.setCursorPos(20,8)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(20,9)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(20,10)
term.setBackgroundColor(colors.white)
print(" ")


term.setCursorPos(28,7)
term.setBackgroundColor(colors.white)
print("                   ")
term.setCursorPos(28,8)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(28,9)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(28,10)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(28,11)
term.setBackgroundColor(colors.white)
print("                   ")

term.setCursorPos(46,8)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(46,9)
term.setBackgroundColor(colors.white)
print(" ")
term.setCursorPos(46,10)
term.setBackgroundColor(colors.white)
print(" ")


term.setCursorPos(4,8)
term.setBackgroundColor(colors.gray)
print("                ")
term.setCursorPos(4,9)
term.setBackgroundColor(colors.gray)
print("                ")
term.setCursorPos(6,9)
term.setTextColor(colors.white)
print("New Picture")
term.setCursorPos(4,10)
term.setBackgroundColor(colors.gray)
print("                ")

term.setCursorPos(29,8)
term.setBackgroundColor(colors.gray)
print("                 ")
term.setCursorPos(29,9)
term.setBackgroundColor(colors.gray)
print("                 ")
term.setCursorPos(31,9)
term.setTextColor(colors.white)
print("Edit Existing")
term.setCursorPos(29,10)
term.setBackgroundColor(colors.gray)
print("                 ")
end


--OS Features

function osShutdown()
term.setBackgroundColor(colors.white)
term.clear()
printN()
printD()
printF()
drawLogo(33, 11)
sleep(0.7)
term.clear()
printD()
printF()
drawLogo(33, 11)
sleep(0.7)
term.clear()
printF()
drawLogo(33, 11)
sleep(0.7)
term.clear()
drawLogo(33, 11)
sleep(0.7)
term.clear()
os.shutdown()
end

function osReboot()
term.setBackgroundColor(colors.white)
term.clear()
printN()
printD()
printF()
drawLogo(33, 11)
sleep(0.7)
term.clear()
printD()
printF()
drawLogo(33, 11)
sleep(0.7)
term.clear()
printF()
drawLogo(33, 11)
sleep(0.7)
term.clear()
drawLogo(33, 11)
sleep(0.7)
term.clear()
os.reboot()

end

function NDFboot()
term.setBackgroundColor(1)
term.clear()
image = paintutils.loadImage(".var/.boot/Boot1.nfp")
paintutils.drawImage(image,1 ,1)

sleep(0.2)

term.setBackgroundColor(1)
term.clear()
image = paintutils.loadImage(".var/.boot/Boot2.nfp")
paintutils.drawImage(image,1 ,1)

sleep(0.4)

term.setBackgroundColor(1)
term.clear()
image = paintutils.loadImage(".var/.boot/Boot3.nfp")
paintutils.drawImage(image,1 ,1)

sleep(0.7)

term.setBackgroundColor(1)
term.clear()
image = paintutils.loadImage(".var/.boot/Boot4.nfp")
paintutils.drawImage(image,1 ,1)

sleep(0.4)

term.setBackgroundColor(1)
term.clear()
image = paintutils.loadImage(".var/.boot/Boot5.nfp")
paintutils.drawImage(image,1 ,1)



end


function drawUpdate()
term.setBackgroundColor(colors.cyan)
		term.setTextColor(colors.white)
		term.setCursorPos(1, 5)
		term.clearLine()
		term.setCursorPos(1, 6)
		term.clearLine()
		term.setCursorPos(1, 7)
		term.clearLine()
		term.setCursorPos(1, 8)
		term.clearLine()
		term.setCursorPos(1, 9)
		term.clearLine()
		term.setCursorPos(1, 10)
		term.clearLine()
		term.setCursorPos(11, 6)
		print("There is an update for your OS")
		term.setCursorPos(11, 7)
		print("  Would you like to update?")
		term.setCursorPos(17, 9)
		print("[ Yes ]")
		term.setCursorPos(27, 9)
		print("[ No ]")
end


--Bjornir90's GUI functions
function getVersion() 
 return 1.5 
end 

--Declaration of variables 
runButton = {} 
runHeader = {} 
coordButton = {} 
list = {} 
--End of declaration 

function buttonClick(x, y, a, b) 
 event, clic, x1, y1 = os.pullEvent("mouse_click") 
 if x1 <= a and x1 >= x and y1 <= b and y1 >= y then 
 return "true" 
 else 
 return "false" 
 end 
end 

function buttonWaitClick(x, y, a, b) 
 clicked = "false" 
 while clicked == "false" do 
  event, button, x1, y1 = os.pullEvent("mouse_click") 
  if  x1 <= a and x1 >= x and y1 <= b and y1 >= y then 
   clicked = "true" 
  else 
   clicked = "false" 
  end 
 end 
 return clicked 
end 

function setButton(x, y, text, colorLine, color, clear) 
if tostring(clear) == "true" then 
 clear() 
end 
if colorLine then 
 colorL = colorLine 
else 
 colorL = colors.white 
end 
if color then 
 colorB = color 
else 
 colorB = colors.black 
end 
 local sizeText = #text 
 a = x+1+sizeText 
 b = y+2 
 table.insert(runButton, x) 
 table.insert(runButton, y) 
 table.insert(runButton, a) 
 table.insert(runButton, b) 
 table.insert(runButton, text) 
 table.insert(runButton, colorL) 
 table.insert(runButton, colorB) 
 table.insert(coordButton, x) 
 table.insert(coordButton, y) 
 table.insert(coordButton, a) 
 table.insert(coordButton, b) 
end 

function drawButton(x, y, a, b, text, colorLine, color) 
if colorLine then 
 colorL = colorLine 
else 
 colorL = colors.white 
end 
if color then 
 colorB = color 
else 
colorB = colors.black 
end 
paintutils.drawLine(x, y, a, y, colorL) --draw the top line 
paintutils.drawLine(x, y, x, b, colorL) --draw the left line 
paintutils.drawLine(a, y, a, b, colorL) --draw the right line 
paintutils.drawLine(x, b, a, b, colorL) --draw the bottom line 
fill(x+1, y+1, a-1, b-1, colorB) 
term.setCursorPos(x+1, y+1)--Print the text in the button 
term.write(text) 
end 

function setHeader(text, colorLine) 
if colorLine then 
 colorL = colorLine 
else 
 colorL = colors.white 
end 
table.insert(runHeader, text) 
table.insert(runHeader, colorL) 
end 

function drawHeader(text, colorLine) 
if colorLine then 
 colorL = colorLine 
else 
 colorL = colors.white 
end 
term.setCursorPos(1,1) 
term.write(text) 
xScreen, yScreen = term.getSize() 
paintutils.drawLine(1, 2, xScreen, 2, colorL) 
term.setCursorPos(1, 3) 
term.setBackgroundColor(colors.black) 
end 

function clear() 
 term.clear() 
 term.setCursorPos(1, 1) 
 term.setBackgroundColor(colors.black) 
 term.setTextColor(colors.white) 
end 

function fill(x, y, a, b, color) 
 term.setBackgroundColor(color) 
 oldY = y 
 for x=x, a do 
  for y=y, b do 
   term.setCursorPos(x,y) 
   print(" ") 
  end 
 end 
end 

function render(reset) 
 clear() 
 local sizeBut = #runButton 
 local sizeHead = #runHeader 
 for x=1, sizeBut, 7 do 
  drawButton(runButton[x], runButton[x+1], runButton[x+2], runButton[x+3], runButton[x+4], runButton[x+5], runButton[x+6]) --Run the functions to redraw it 
 end 
 for x=1, sizeHead, 2 do 
  drawHeader(runHeader[x], runHeader[x+1]) --Run the function to redraw it 
 end 
 if tostring(reset) == "true" then 
 clearBuffer() 
 end 
end 

function clearBuffer() 
  runButton = {} 
  runHeader = {} 
  coordButton = {} 
end 

function getSelection() 
 local sizeButton = #coordButton 
 detectButton = {} 
 for x=1, sizeButton, 4 do 
  table.insert(detectButton, function() buttonWaitClick(coordButton[x], coordButton[x+1], coordButton[x+2], coordButton[x+3]) end) 
  end 
  local input = parallel.waitForAny(unpack(detectButton)) 
 return input 
end 

function animation(x, y, colorL) 
for g=1, 8 do 
paintutils.drawLine(x-g, y-g, x+g, y-g, colorL) --draw the top line 
paintutils.drawLine(x-g, y-g, x-g, y+g, colorL) --draw the left line 
paintutils.drawLine(x+g, y-g, x+g, y+g, colorL) --draw the right line 
paintutils.drawLine(x-g, y+g, x+g, y+g, colorL) --draw the bottom line 
sleep(0.03) 
render() 
end 
local g = 9 
paintutils.drawLine(x-g, y-g, x+g, y-g, colorL) --draw the top line 
paintutils.drawLine(x-g, y-g, x-g, y+g, colorL) --draw the left line 
paintutils.drawLine(x+g, y-g, x+g, y+g, colorL) --draw the right line 
paintutils.drawLine(x-g, y+g, x+g, y+g, colorL) --draw the bottom line 
end 

function popUp(title, text, x, y, colorLine, color, textB1, textB2) 
 sizeTitle = #title 
 sizeText = #text 
if textB2 then 
 sizeB1 = #textB1 
 sizeB2 = #textB2 
 mustButton = "true" 
else 
 mustButton = "false" 
end 
 if sizeTitle >= sizeText then 
  greaterS = sizeTitle 
 else 
  greaterS = sizeText 
 end 
 if colorLine then 
 colorL = colorLine 
else 
 colorL = colors.white 
end 
if color then 
 colorB = color 
else 
colorB = colors.black 
end 
local a = x+greaterS+1 
local b = y+4 
paintutils.drawLine(x, y, a, y, colorL) --draw the top line 
paintutils.drawLine(x, y, x, b, colorL) --draw the left line 
paintutils.drawLine(a, y, a, b, colorL) --draw the right line 
paintutils.drawLine(x, b, a, b, colorL) --draw the bottom line 
fill(x+1, y+1, a-1, b-1, colorB) 
term.setCursorPos(x+1, y+1) --Print the title 
term.write(title) 
paintutils.drawLine(x, y+2, a, b-2, colorL) --Draw the line for the title 
term.setBackgroundColor(colorB) 
term.setCursorPos(x+1, y+3) 
term.write(text) --Print the text 
if mustButton == "true" then 
term.setCursorPos(a-sizeB2-sizeB1-3, b) 
term.write(textB1) 
term.setCursorPos(a-sizeB2-1, b) 
term.write(textB2) 
clickedB = parallel.waitForAny(buttonWaitClick(a-sizeB2-sizeB1-3, b+1, a-sizeB2-3, b+1), buttonWaitClick(a-sizeB2-1, b, a-1, b+1)) 
return clickedB 
else 
 clickedPopup = buttonWaitClick(x, y, a, b) 
 return clickedPopup 
end 
end 

--End of GUI functions