View difference between Paste ID: XVuSA68R and LBWLkpqK
SHOW: | | - or go back to the newest paste.
1-
--Desktop
1+
os.loadAPI("Menu")
2
3-
tBarC = 8
3+
-----------Global Values-----------
4
5
slc = 0
6
tBarC = 2048
7
tBartC = 1
8
backColor = 1
9
selMenu = 2048
10
selItem = 128
11-
  term.setCursorPos(1,1)
11+
12
deltaX = 1
13
term.clear()
14
menus = {}
15-
  term.setCursorPos(3, 1)
15+
16-
  print("[Begin]")
16+
-----------Functions-----------
17
18
--titlebar = creates the titlebar and adds all menus, completing the status bar
19
function titlebar()
20
  term.clear()
21
  deltaX = 1
22
  term.setCursorPos(deltaX, 1)
23
  term.setBackgroundColor(tBarC)
24
  term.setTextColor(tBartC)
25
  term.clearLine()
26
  for _,v in pairs(menus) do
27
    print(v.getName())
28-
  local event, X, Y = os.pullEventRaw()
28+
    deltaX = deltaX + 13
29-
  if slc == 0 then
29+
    term.setCursorPos(deltaX, 1)
30-
    if event == "mouse_click" then
30+
  end
31-
      if X >= 2 and X <= 8 and Y == 1 and button == 1 then 
31+
   term.setBackgroundColor(selMenu)
32-
        term.clear()
32+
  showMenu()
33
   term.setBackgroundColor(1)
34-
        drawDesktop()
34+
35
36-
    end 
36+
function showMenu()
37-
  end    
37+
  if slc ~= 0 then
38-
end
38+
    deltaX = 1 + 13*slc - 13
39
    addMenu(menus[slc])
40
    term.setCursorPos(deltaX, 1)
41
  end
42
end
43
44
--addMenu = adds a menu to the titlebar
45
function addMenu(menu)
46
  term.setCursorPos(deltaX, 1)
47
  print(menu.getName())
48
  term.setBackgroundColor(selItem)
49
  for _,v in pairs(menu.getItems()) do
50
    x, y = term.getCursorPos()
51
    term.setCursorPos(deltaX, y)
52
    print(v.getName())
53
  end
54
end
55
56
function drawDesktop()
57
  --print("drawing desktop...")
58
  --bground = paintutils.loadImage(".background")
59
  --paintutils.drawImage(bground, 1, 1)
60
  titlebar()
61
end
62
63
function debugSlc()
64
      term.setTextColor(32768)
65
      term.setCursorPos(1,5)
66
      print("Clicked outside titlebar with slc = "..slc)
67
      term.setCursorPos(1,1)
68
      sleep(2)
69
end
70
71
-----------Main-----------
72
73
functions = Menu.Menu("  functions  ")
74
functions.addItem("  Shutdown   ", "os.shutdown()")
75
functions.addItem("   Reboot    ", "os.reboot()")
76
77
programs = Menu.Menu("  Programs   ")
78
programs.addItem("   Updater   ", "u init")
79
programs.addItem(" TankMonitor ", "TankMonitor")
80
programs.addItem("    Test     ", "shell.run(Test)")
81
82
menu3 = Menu.Menu("    Menu3    ")
83
menu3.addItem("Function test", "FunctionTest")
84
 
85
table.insert(menus, functions)
86
table.insert(menus, menu3)
87
table.insert(menus, programs)
88
--term.setCursorPos(1,1)
89
--term.setBackgroundColor(colors.black)
90
for _,v in pairs(menus) do
91
 -- print(v.getName())
92
end
93
--sleep(1)
94
drawDesktop()
95
96
while true do
97
  local event, button, X, Y = os.pullEventRaw()
98
  if event == "mouse_click" then
99
    if X < 39 and Y == 1 and button == 1 then
100
      slc = math.floor(X / 13 + 1)
101
      drawDesktop()
102
    elseif math.floor(X / 13 + 1) == slc and Y > 1 then
103
      if menus[slc].getName() == "  Programs   " then
104
        shell.run(menus[slc].getItem(Y-1).go())
105
      else
106
        func = loadstring(menus[slc].getItem(Y-1).go())
107
        func()
108
      end
109
      drawDesktop()
110
    else 
111
      slc = 0
112
      drawDesktop()
113
    end
114
  end
115
end
116
117
118
119
-----------Notes-----------
120
121
--backup of addMenu with space correction
122
--addMenu = adds a menu to the titlebar
123
--function addMenu(menu)
124
--  spaceStr = nil
125
--  spaces = math.floor((12 -#menu.getName())/2)
126
--  for i=1,spaces do
127
--    spaceStr = spaceStr + " "
128
--  if #menu.getName() == 0 then
129
--    print(spaceStr..menu.getName()..spaceStr)
130
--  else
131
--    print(spaceStr..menu.getName()..spaceStr + " ")
132
--  for _,v in pairs(menus) do
133
--end
134
135
--|  programs   |
136
--|  functions  |
137
--| TankMonitor |
138
--|   Updater   |
139
--|  Shutdown   |
140
--|   Reboot    |
141
--|    test     |
142
--|Function test|
143
--|    Menu3    |
144
145
--while true do
146
--  local event, X, Y = os.pullEventRaw()
147
--  if slc == 0 then
148
--    if event == "mouse_click" then
149
--      if X >= 2 and X <= 8 and Y == 1 and button == 1 then 
150
--        term.clear()
151
--      else
152
--        drawDesktop()
153
--      end
154
--    end 
155
--  end    
156
--end