Advertisement
Guest User

1

a guest
Nov 29th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.59 KB | None | 0 0
  1. local m = peripheral.wrap("right")
  2. local m_width, m_height = m.getSize()
  3.  
  4. function clear()
  5.   m.setBackgroundColor(colors.white)
  6.   m.clear()
  7. end
  8.  
  9. function writeToOption(option, text)
  10.   width, height = option.getSize()
  11.   option.setCursorPos((width - string.len(text))/2+1,2)
  12.   option.write(text)
  13.   option.redraw()
  14. end
  15.  
  16. --here i draw the button
  17. function createOption(x, y, width, height, text)
  18.   --i create a window here
  19.   local option = window.create(m, x, y, width, height)
  20.  
  21.   option.setCursorPos((width - string.len(text))/2+1,2)
  22.   option.write(text)
  23.   option.redraw()
  24.   return option
  25. end
  26.  
  27. clear()
  28.  
  29. option1 = createOption(m_width/10+1, 7, m_width-(m_width/10)-2, 3, "Access Reactor System")
  30. option2 = createOption(m_width/10+1, 11, m_width-(m_width/10)-2, 3, "Info About Program")
  31.  
  32. while true do
  33.   event, side, xPos, yPos = os.pullEvent("monitor_touch")
  34.   x, y = option1.getPosition()
  35.   width, height = option1.getSize()
  36.   if(xPos >= x and xPos <= x+width) then
  37.     if(yPos >= y and yPos <= y+height) then
  38.       --first option clicked
  39.       option1.setBackgroundColor(colors.blue)
  40.       option1.clear()
  41.       writeToOption(option1, "Access Reactor System")
  42.       sleep(1)
  43.       shell.run("reactor")
  44.       break
  45.     end
  46.   end
  47.  
  48.   x,y = option2.getPosition()
  49.   width, height = option2.getSize()
  50.   if(xPos >= x and xPos <= x+width) then
  51.     if(yPos >= y and yPos <= y+height) then
  52.       option2.setBackgroundColor(colors.blue)
  53.       option2.clear()
  54.       writeToOption(option2, "Info About Program")
  55.       sleep(1)
  56.       shell.run("info")
  57.       break
  58.     end
  59.   end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement