Advertisement
funnybunnyofdoom

Untitled

Mar 2nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. --This program handles backgrounds
  2. --bg(COLOR) pass a color in the colors.black forman
  3. --fg(X,Y,Xlen,Ylen) x,y = begin x and y Xlen,Ylen = size
  4.  
  5. --options for the gui
  6. options = {
  7. ' Edit ',
  8. ' Run ',
  9. ' Power '
  10. }
  11.  
  12. menuOpen = false
  13.  
  14.  
  15.  
  16. function bg(COLOR)
  17. if COLOR == nil then COLOR = colors.lightGray end
  18. term.setBackgroundColor(COLOR)
  19. term.clear()
  20. end
  21.  
  22. function fg(X,Y,Xlen,Ylen)
  23. if X == nil then X = 2 end
  24. if Y == nil then Y = 2 end
  25. local x,y = term.getSize()
  26. if Xlen == nil then Xlen = x-2 end
  27. if Ylen == nil then Ylen = y-2 end
  28. local window = window.create(term.current(),X,Y,Xlen,Ylen)
  29. return window
  30. end
  31.  
  32. function menuBar(Win,Color)
  33. if Color == nil then Color = colors.gray end
  34. local x,y = Win.getSize()
  35. Win.setCursorPos(1,y)
  36. Win.setBackgroundColor(Color)
  37. Win.write(" Menu ")
  38. end
  39.  
  40. function extendBar(Win,select)
  41. if select == nil then select = 0 end
  42. local x,y = Win.getSize()
  43. Win.setBackgroundColor(colors.lightGray)
  44. Win.setCursorPos(1,y)
  45. Win.write(" Menu ")
  46. Win.setBackgroundColor(colors.gray)
  47. for c=1,#options do
  48. if select == c then
  49. Win.setBackgroundColor(colors.lightBlue)
  50. end
  51. Win.setCursorPos(1,y-c)
  52. Win.write(options[c])
  53. Win.setBackgroundColor(colors.gray)
  54. end
  55. end
  56.  
  57. function touchMenu()
  58. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  59.  
  60. --print(xPos..' '..yPos)
  61. if xPos > 1 and xPos < 9 then
  62. if menuOpen == false then
  63. extendBar(win)
  64. menuOpen = true
  65. else
  66. win.setBackgroundColor(colors.blue)
  67. win.clear()
  68. menuBar(win)
  69. menuOpen = false
  70. end
  71. end
  72. end
  73.  
  74. bg()
  75. win = fg()
  76. win.setBackgroundColor(colors.blue)
  77. win.clear()
  78. menuBar(win,colors.gray)
  79.  
  80. term.setCursorPos(1,1)
  81. term.setBackgroundColor(colors.lightGray)
  82. while true do
  83. touchMenu()
  84. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement