Advertisement
DaBananaboat

[FTB] Touchscreentest

Mar 30th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.84 KB | None | 0 0
  1. local side = "right"
  2. local m = peripheral.wrap(side)
  3. local w, h = m.getSize()
  4.  
  5. -- moitor properties
  6. m.clear()
  7. m.setCursorPos(1, 1)
  8. m.setTextScale(1)
  9. m.setTextColor(colors.white)
  10. m.setBackgroundColor(colors.black)
  11.  
  12. local btns = {}
  13.  
  14. function addButton(name, xmin, ymin, xmax, ymax, text)
  15.   btns[name] = {}
  16.   btns[name]["xmin"] = xmin
  17.   btns[name]["ymin"] = ymin
  18.   btns[name]["xmax"] = xmax
  19.   btns[name]["ymax"] = ymax
  20.   btns[name]["active"] = false
  21.   btns[name]["text"] = text
  22. end
  23.  
  24. function toggleActive(btnName)
  25.   if btns[btnName]["active"] == true then
  26.     btns[btnName]["active"] = false
  27.   else
  28.     brns[brnName]["active"] = true
  29.   end
  30. end
  31.  
  32. function drawButtons()
  33.   for key, value in pairs(btns) do
  34.     btn = btns[key]
  35.     btnColor = colors.red
  36.  
  37.     if btn["active"] == true then
  38.       btnColor = colors.green
  39.     end
  40.    
  41.     m.setBackgroundColor(btnColor)
  42.  
  43.     fill(btn["text"], btnColor, value)
  44.   end
  45.  
  46.   m.setBackgroundColor(colors.black)
  47. end
  48.  
  49. function fill(text, color, bData)
  50.   m.setBackgroundColor(color)
  51.   local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  52.   local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  53.   for j = bData["ymin"], bData["ymax"] do
  54.     m.setCursorPos(bData["xmin"], j)
  55.     if j == yspot then
  56.       for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  57.         if k == xspot then
  58.           m.write(text)
  59.         else
  60.           m.write(" ")
  61.         end
  62.       end
  63.     else
  64.       for i = bData["xmin"], bData["xmax"] do
  65.         m.write(" ")
  66.       end
  67.     end
  68.   end
  69.   m.setBackgroundColor(colors.black)
  70. end
  71.  
  72. addButton("test", 1, 3, 3, 5, "Hello!")
  73. addButton("test2", 3, 6, 5, 8, "HAI!")
  74. drawButtons()
  75.  
  76. while true do
  77.   event, p, x, y = os.pullEvent("mitor_touch")
  78.  
  79.   for key, value in pairs(btns) do
  80.     btn = btns[key]
  81.   end
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement