Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("Menu")
- -----------Global Values-----------
- slc = 0
- tBarC = 2048
- tBartC = 1
- backColor = 1
- selMenu = 2048
- selItem = 128
- term.setBackgroundColor(backColor)
- deltaX = 1
- term.clear()
- menus = {}
- -----------Functions-----------
- --titlebar = creates the titlebar and adds all menus, completing the status bar
- function titlebar()
- term.clear()
- deltaX = 1
- term.setCursorPos(deltaX, 1)
- term.setBackgroundColor(tBarC)
- term.setTextColor(tBartC)
- term.clearLine()
- for _,v in pairs(menus) do
- print(v.getName())
- deltaX = deltaX + 13
- term.setCursorPos(deltaX, 1)
- end
- term.setBackgroundColor(selMenu)
- showMenu()
- term.setBackgroundColor(1)
- end
- function showMenu()
- if slc ~= 0 then
- deltaX = 1 + 13*slc - 13
- addMenu(menus[slc])
- term.setCursorPos(deltaX, 1)
- end
- end
- --addMenu = adds a menu to the titlebar
- function addMenu(menu)
- term.setCursorPos(deltaX, 1)
- print(menu.getName())
- term.setBackgroundColor(selItem)
- for _,v in pairs(menu.getItems()) do
- x, y = term.getCursorPos()
- term.setCursorPos(deltaX, y)
- print(v.getName())
- end
- end
- function drawDesktop()
- --print("drawing desktop...")
- --bground = paintutils.loadImage(".background")
- --paintutils.drawImage(bground, 1, 1)
- titlebar()
- end
- function debugSlc()
- term.setTextColor(32768)
- term.setCursorPos(1,5)
- print("Clicked outside titlebar with slc = "..slc)
- term.setCursorPos(1,1)
- sleep(2)
- end
- -----------Main-----------
- functions = Menu.Menu(" functions ")
- functions.addItem(" Shutdown ", "os.shutdown()")
- functions.addItem(" Reboot ", "os.reboot()")
- programs = Menu.Menu(" Programs ")
- programs.addItem(" Updater ", "u init")
- programs.addItem(" TankMonitor ", "TankMonitor")
- programs.addItem(" Test ", "shell.run(Test)")
- menu3 = Menu.Menu(" Menu3 ")
- menu3.addItem("Function test", "FunctionTest")
- table.insert(menus, functions)
- table.insert(menus, menu3)
- table.insert(menus, programs)
- --term.setCursorPos(1,1)
- --term.setBackgroundColor(colors.black)
- for _,v in pairs(menus) do
- -- print(v.getName())
- end
- --sleep(1)
- drawDesktop()
- while true do
- local event, button, X, Y = os.pullEventRaw()
- if event == "mouse_click" then
- if X < 39 and Y == 1 and button == 1 then
- slc = math.floor(X / 13 + 1)
- drawDesktop()
- elseif math.floor(X / 13 + 1) == slc and Y > 1 then
- if menus[slc].getName() == " Programs " then
- shell.run(menus[slc].getItem(Y-1).go())
- else
- func = loadstring(menus[slc].getItem(Y-1).go())
- func()
- end
- drawDesktop()
- else
- slc = 0
- drawDesktop()
- end
- end
- end
- -----------Notes-----------
- --backup of addMenu with space correction
- --addMenu = adds a menu to the titlebar
- --function addMenu(menu)
- -- spaceStr = nil
- -- spaces = math.floor((12 -#menu.getName())/2)
- -- for i=1,spaces do
- -- spaceStr = spaceStr + " "
- -- if #menu.getName() == 0 then
- -- print(spaceStr..menu.getName()..spaceStr)
- -- else
- -- print(spaceStr..menu.getName()..spaceStr + " ")
- -- for _,v in pairs(menus) do
- --end
- --| programs |
- --| functions |
- --| TankMonitor |
- --| Updater |
- --| Shutdown |
- --| Reboot |
- --| test |
- --|Function test|
- --| Menu3 |
- --while true do
- -- local event, X, Y = os.pullEventRaw()
- -- if slc == 0 then
- -- if event == "mouse_click" then
- -- if X >= 2 and X <= 8 and Y == 1 and button == 1 then
- -- term.clear()
- -- else
- -- drawDesktop()
- -- end
- -- end
- -- end
- --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement