Advertisement
Guest User

test.lua

a guest
Feb 26th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. local event = require("event")
  2. local component = require("component")
  3. local Button = require("button")
  4. local gpu = component.gpu
  5. gpu.setResolution(160, 50)
  6. -- gpu.setResolution(80,25)
  7. local w, h = gpu.getResolution()
  8. local backgroundColor = 0x696969
  9. local sizes = {}
  10. local buttons = {}
  11.  
  12. function fillBackground(color)
  13.   gpu.setForeground(0x000000)
  14.   gpu.setBackground(color)
  15.   gpu.fill(1, 1, w, h, " ")
  16. end
  17.  
  18. function calculateSize()
  19.  sizes.buttonWidth = math.floor(w/3)
  20.  sizes.buttonHeight = math.floor(h/5)
  21.  sizes.buttonColumnGap = math.floor(w/8)
  22.  sizes.buttonRowGap = math.floor(h/15)
  23. end
  24.  
  25. --only on startup
  26. function start()
  27.   fillBackground(backgroundColor)
  28.   calculateSize()
  29.  -- drawRectangleWithText(6, 4, 70, 10, 0xffffc0, 0xffff80, 1, "Sand")
  30.  -- drawRectangleWithText(6, 17, 70, 10, 0x5a5a5a, 0x4b4b4b, 1, "Gravel")
  31.  -- drawRectangleWithText(6, 30, 70, 10, 0xf0f0f0, 0xffffc0, 1, "Dust")
  32.  -- drawRectangleWithText(86, 4, 70, 10, 0x332400, 0x330000, 1, "Soulsand")
  33.  -- drawRectangleWithText(86, 17, 70, 10, 0x990000, 0x660000, 1, "Netherrack")
  34.  -- drawRectangleWithText(86, 30, 70, 10, 0xccc0db, 0xccc0ff, 1, "Endstone")
  35.   local gravel = Button:new{
  36.     x = sizes.buttonColumnGap,
  37.     y = sizes.buttonRowGap,
  38.     width = sizes.buttonWidth,
  39.     height = sizes.buttonHeight,
  40.     borderColor = 0x4b4b4b,
  41.     fillColor = 0x5a5a5a,
  42.     text = "Gravel"
  43.   }
  44.   local
  45.   table.insert(buttons, gravel)
  46.   buttons[1]:draw()
  47. end
  48.  
  49. --actions when running
  50. function update()
  51.   repeat
  52.     local ev, _, x, y, user = event.pull()
  53.     if ev == "touch" then
  54.      print(#buttons)
  55.      print(buttons[1]:checkClick(x, y))
  56.     end    
  57.   until false
  58. end
  59.  
  60.  
  61. start()
  62. update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement