Advertisement
SansIsLazy

GUI kit

Dec 9th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. --Variables
  2. local vesion = 0.01
  3. local running = true
  4.  
  5. --Booleans
  6. _ms = 0
  7.  
  8. --Functions
  9.  
  10. --Clears the screen
  11.  
  12. function clear()
  13.     term.clear()
  14.     term.setCursorPos(1,1)
  15.  end
  16.  
  17. --Stops the program
  18.  
  19. function stop()
  20.     term.setBackgroundColor(colors.black)
  21.     clear()
  22.     running = false
  23.     sleep(0.1)
  24.     print"Closed GUI"
  25.  end
  26.  
  27.  --Draws the window
  28.  
  29. function drawWindow()
  30.     term.setBackgroundColor(colors.white)
  31.     clear()
  32.     term.setBackgroundColor(colors.blue)
  33.     term.clearLine()
  34.     term.setCursorPos(51,1)
  35.     term.setBackgroundColor(colors.red)
  36.     term.setTextColor(colors.black)
  37.     print"X"
  38.     term.setBackgroundColor(colors.blue)
  39.     term.setTextColor(colors.white)
  40.     term.setCursorPos(2,3)
  41.     print" Hello "
  42.  end
  43.  
  44. --The runtime is the engine of the GUI. While this is running the GUI works
  45.  
  46. function runtime()
  47.     while running do
  48.         event, button, x, y = os.pullEventRaw("mouse_click")
  49.         if _ms == 0 and button == 1 and x == 51 and y == 1 then
  50.         stop()
  51.          elseif _ms == 0 and button == 1 and x >=2 and x < 9 and y == 3 then
  52.          stop()
  53.          print"Hello"
  54.         end
  55.     end
  56. end
  57.  
  58. --Initializes the GUI
  59.  
  60. function init()
  61.     _ms = 0
  62.     drawWindow()
  63.     runtime()
  64.  end
  65.  
  66. --Main Code
  67.  
  68. init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement