Advertisement
Margresse404

windowTest

Jun 16th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. local m
  2. m = peripheral.wrap("left")
  3. m.clear()
  4. os.loadAPI("scripts/functions")
  5. local timeTick = 3
  6.  
  7. --Some constants
  8. local longString = "sahadhgsahsdjasdasdahsdjkashdjkashdkjsahdjkahsjkdhaskjdhaksjdhajksdsasdkaksdkhdsajkdfsdfadsdasd"
  9.  
  10. screenSize = m.getSize()
  11. --Create windows
  12. topPart = window.create(m, 1,1, 50, 4)
  13. topPart.setCursorPos(1, 1)
  14.  
  15. infoField = window.create(m, 1,5, 50, 3)
  16. infoField.setCursorPos(1, 1)
  17.  
  18. textField = window.create(m, 1,9, 50, 20)
  19.  
  20. createdWindows = functions.returnWindows(m, 1, 30, 50, 3, 3, true)
  21.  
  22. local switchButton = createdWindows[1]
  23. local viewHistoryButton = createdWindows[2]
  24. local exitButton = createdWindows[3]
  25.  
  26. topPart.setBackgroundColor(16384)
  27. topPart.setTextColor(1)
  28. textField.setBackgroundColor(32)
  29.  
  30.  
  31.  
  32. function createTopPart(w)
  33. w.setBackgroundColor(16384) --Red
  34. w.setTextColor(32768) --Black
  35. w.write("****************************************************************")
  36. functions.newLine(w)
  37. w.write("*********** REACTOR CONTROL PROGRAM ********************************")
  38. functions.newLine(w)
  39. w.write("****************************************************************")
  40. functions.newLine(w)
  41. w.setTextColor(64) --Pink
  42. w.setBackgroundColor(32768) --Black
  43. w.write("Written by Merlione404")
  44. end
  45.  
  46. function fillWindow(w, bgcolor)
  47. w.setBackgroundColor(bgcolor) --Red
  48. w.setTextColor(32768) --Black
  49. for i = 1, 80, 1 do
  50. w.write(longString)
  51. functions.newLine(w)
  52. end
  53. end
  54.  
  55. function exitButtonClick()
  56. os.exit([code])
  57. end
  58.  
  59.  
  60. createTopPart(topPart)
  61. fillWindow(textField, 64)
  62. fillWindow(switchButton, 2)
  63. fillWindow(viewHistoryButton, 4)
  64. fillWindow(exitButton, 8)
  65. fillWindow(infoField, 1024)
  66.  
  67.  
  68. counter2 = 0
  69.  
  70. textField.clear()
  71.  
  72.  
  73. function touchEvent(xPos, yPos)
  74. if checkInRangeWindow(switchButton, xPos, yPos) then
  75. --
  76. elseif checkInRangeWindow(viewHistoryButton, xPos, yPos) then
  77. --
  78. elseif checkInRangeWindow(exitButton, xPos, yPos) then
  79. --
  80. end
  81. end
  82.  
  83.  
  84. function processEvents(event)
  85.  
  86. for i = 1, #event, 1 do
  87. textField.write(tostring(event[i]))
  88. functions.newLine(textField)
  89. end
  90.  
  91. if event[1] == "monitor_touch" then
  92. touchEvent(event[3], event[4])
  93. end
  94.  
  95. end
  96.  
  97.  
  98.  
  99.  
  100.  
  101. local function wait (time)
  102. local timer = os.startTimer(time)
  103.  
  104. while true do
  105. local event = {os.pullEvent()}
  106.  
  107. if (event[1] == "timer" and event[2] == timer) then
  108. break
  109. else
  110. processEvents(event) -- a custom function in which you would deal with received events
  111. end
  112. end
  113. end
  114.  
  115. textField.setTextColor(32768)
  116. textField.setCursorPos(1, 1)
  117.  
  118.  
  119.  
  120. while true do
  121.  
  122. if counter2 == 20 then
  123. textField.setCursorPos(1, 1)
  124. textField.clear()
  125. end
  126.  
  127. wait(timeTick)
  128. textField.write(tostring(counter2))
  129. textField.write("hoi")
  130. functions.newLine(textField)
  131.  
  132. topPart.clear()
  133. topPart.write(tostring(xPos))
  134.  
  135.  
  136. counter2 = counter2 + 1
  137. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement