Advertisement
GNOOR1S

GUI API for the OS

Jan 31st, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.77 KB | None | 0 0
  1. local version = "1.4.2"
  2. local textColor = colors.white
  3.  
  4. local resetCurs = function()
  5.   term.setCursorPos(1, 1)
  6. end
  7.  
  8. local set = function()
  9.   term.setTextColor(textColor)
  10. end
  11.  
  12. --Returns version of API
  13. getVersion = function()
  14.   return version
  15. end
  16.  
  17. getTextColor = function()
  18.   return textColor
  19. end
  20.  
  21. setTextColor = function(textcolor)
  22.   textColor = textcolor
  23. end
  24.  
  25. --Gets the string length and subtracts it to get
  26. --cursor position for text to be centered
  27. centeredText = function( y, str )
  28.   set()
  29.   local w, h = term.getSize()
  30.   term.setCursorPos( math.floor( w - #str) / 2, y )
  31.   term.write( str )
  32.   --resetCurs()
  33. end
  34.  
  35.  
  36. --Gets color and cords to draw a rectangle
  37. coloredBox = function( color, sx, sy, ex, ey )
  38.   set()
  39.   term.setBackgroundColor(color)
  40.   for i = sx, ex do
  41.     for k = sy, ey do
  42.       term.setCursorPos( i, k )
  43.       term.write(" ")
  44.     end
  45.   end
  46.   resetCurs()
  47. end
  48.  
  49. --Line on the X axes
  50. coloredHorzLine = function( color, sx, ex, y)
  51.   set()
  52.   term.setBackgroundColor(color)
  53.   for i = sx, ex do
  54.     term.setCursorPos( i, y)
  55.     term.write(" ")
  56.   end
  57.   resetCurs()
  58. end
  59.  
  60. --Sets a colored rectangle in the full terminal
  61. setBackground = function( color )
  62.   local w, h = term.getSize()
  63.   coloredBox(color, 1, 1, w, h)
  64.   resetCurs()
  65. end
  66.  
  67. --Draws with a background color
  68. drawString = function( str, color, x, y )
  69.   set()
  70.   term.setTextColor(colors.white)
  71.   term.setBackgroundColor(color)
  72.   term.setCursorPos(x, y)
  73.   term.write(str)
  74.   resetCurs()
  75. end
  76.  
  77. --Given bounds and ran in a statement then it will return
  78. getClickInBounds = function( sx, sy, ex, ey )
  79.   set()
  80.   event, button, x, y = os.pullEvent("mouse_click")
  81.   if x <= ex and x >= sx and y <= ey and y >= sy then
  82.     return true
  83.   else
  84.     return false
  85.   end
  86. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement