Advertisement
Guest User

buttonAPI

a guest
Apr 6th, 2020
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. --[[
  2.  
  3.     (C) Button API made by (C) LeV__oid
  4.     This ButtonAPI is used to make the creation of buttons easier
  5.  
  6.     Loading this API is easily done by writing "os.loadAPI("buttonAPI")" at the top of your script.
  7.     From there on you will be able to call every function like so:
  8.     (Example:)
  9.     buttonAPI.mkBtn(5, 5, 13, 13, colors.lime, "Test")
  10.  
  11.     help() - Prints a list of all available functions this API adds.
  12.     (Example:)
  13.     buttonAPI.help()
  14.  
  15.     mkBtn(xmin, ymin, xmax, ymax, color, name) - Draws a Button to the screen starting at P1(xmin, ymin) and going to P2(xmax, ymax). It will have the specified color and Text.
  16.     (Example:)
  17.     buttonAPI.mkBtn(5, 5, 13, 13, colors.lime, "Test")
  18.  
  19.     Soon to be added:
  20.     I am planning on adding a feature that will let you make sliders (for example: for the rod insertion of big reactors) and also filling bars/diagrams (for example: for showing how much RF/EU/Whatever is stored in whatever container)
  21.     I am also planning on making this a standalone API because currently you will still have to set your mouseclick detection manually
  22.  
  23.     Thank you for trying out my API.
  24.     Have fun!
  25.  
  26. ]]--
  27.  
  28. function help()
  29.  
  30.     term.setTextColor(colors.yellow)
  31.  
  32.         print("Functions: ")
  33.         print("mkBtn(xmin, ymin, xmax, ymax, color, displayName)")
  34.         print("Draws a Button starting at xmin and ymin, going to xmax and ymax with the specified color.")
  35.  
  36.     term.setTextColor(colors.white)
  37.  
  38. end
  39.  
  40. function mkBtn(xmin, ymin, xmax, ymax, color, name)
  41.  
  42.     if name == nil then
  43.         name = "Test"
  44.     end
  45.  
  46.     if color == nil then
  47.         color = colors.lime
  48.     end
  49.  
  50.     if xmin == nil or xmax == nil or ymin == nil or ymax == nil then
  51.         error("Error: Expected xmin, ymin, xmax, ymax (color, name)")
  52.     end
  53.  
  54.     paintutils.drawFilledBox(xmin, ymin, xmax, ymax, color)
  55.  
  56.     midX = (xmin + xmax) / 2
  57.     midX = midX - (#name / 2)
  58.     midX = math.floor(midX)
  59.  
  60.     midY = (ymin + ymax) / 2
  61.     midY = math.floor(midY)
  62.  
  63.     term.setCursorPos(midX, midY)
  64.     term.write(name)
  65.     term.setBackgroundColor(colors.black)
  66.     x = 0
  67.     y = 0
  68.  
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement