Advertisement
programcreator

Interact

Apr 12th, 2015
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.95 KB | None | 0 0
  1. --[[
  2. Interact API in ComputerCraft
  3. by Creator
  4. Complete rewrite in OOP
  5. ]]--
  6.  
  7. --Variables
  8. local textutilsserialize = textutils.serialize
  9. local textutilsunserialize = textutils.unserialize
  10. local KeyCodes = {
  11. [ 2 ] = 1 ,
  12. [ 3 ] = 2,
  13. [ 4 ] = 3,
  14. [ 5 ] = 4,
  15. [ 6 ] = 5,
  16. [ 7 ] = 6,
  17. [ 8 ] = 7,
  18. [ 9 ] = 8,
  19. [ 10 ] = 9,
  20. [ 11 ] = 0,
  21. [ 12 ] = "-",
  22. [ 13 ] = "=",
  23. [ 14 ] = "Backspace",
  24. [ 15 ] = "Tab",
  25. [ 16 ] = "q",
  26. [ 17 ] = "w",
  27. [ 18 ] = "e",
  28. [ 19 ] = "r",
  29. [ 20 ] = "t",
  30. [ 21 ] = "y",
  31. [ 22 ] = "u",
  32. [ 23 ] = "i",
  33. [ 24 ] = "o",
  34. [ 25 ] = "p",
  35. [ 26 ] = "LeftBracket",
  36. [ 27 ] = "RightBracket",
  37. [ 28 ] = "Enter",
  38. [ 29 ] = "LeftControl",
  39. [ 30 ] = "a",
  40. [ 31 ] = "s",
  41. [ 32 ] = "d",
  42. [ 33 ] = "f",
  43. [ 34 ] = "g",
  44. [ 35 ] = "h",
  45. [ 36 ] = "j",
  46. [ 37 ] = "k",
  47. [ 38 ] = "l",
  48. [ 39 ] = ";",
  49. [ 40 ] = "\'",
  50. [ 41 ] = "`",
  51. [ 42 ] = "LeftShift",
  52. [ 43 ] = "Backslash",
  53. [ 44 ] = "z",
  54. [ 45 ] = "x",
  55. [ 46 ] = "c",
  56. [ 47 ] = "v",
  57. [ 48 ] = "b",
  58. [ 49 ] = "n",
  59. [ 50 ] = "m",
  60. [ 51 ] = ",",
  61. [ 52 ] = ".",
  62. [ 53 ] = "/",
  63. [ 54 ] = "RightShift",
  64. [ 55 ] = "*",
  65. [ 56 ] = "LeftAlt",
  66. [ 57 ] = " ",
  67. [ 58 ] = "CapsLock",
  68. [ 59 ] = "F1",
  69. [ 60 ] = "F2",
  70. [ 61 ] = "F3",
  71. [ 62 ] = "F4",
  72. [ 63 ] = "F5",
  73. [ 64 ] = "F6",
  74. [ 65 ] = "F7",
  75. [ 66 ] = "F8",
  76. [ 67 ] = "F9",
  77. [ 68 ] = "F10",
  78. [ 69 ] = "NumberLock",
  79. [ 70 ] = "ScrollLock",
  80. [ 71 ] = "NumPAd7",
  81. [ 72 ] = "NumPAd8",
  82. [ 73 ] = "NumPAd9",
  83. [ 74 ] = "Substract",
  84. [ 75 ] = "NumPAd4",
  85. [ 76 ] = "NumPAd5",
  86. [ 77 ] = "NumPAd6",
  87. [ 78 ] = "Add",
  88. [ 79 ] = "NumPAd1",
  89. [ 80 ] = "NumPAd2",
  90. [ 81 ] = "NumPAd3",
  91. [ 82 ] = "NumPAd0",
  92. [ 83 ] = "Decimal",
  93. [ 87 ] = "F11",
  94. [ 88 ] = "F12",
  95. [ 100] = "F13",
  96. [ 101] = "F14",
  97. [ 102] = "F15",
  98. [ 103] = "F16",
  99. [ 104] = "F17",
  100. [ 105] = "F18",
  101. [ 112] = "Kana",
  102. [ 113] = "F19",
  103. [ 121] = "Convert",
  104. [ 123] = "Noconvert",
  105. [ 125] = "Yen",
  106. [ 141] = "NumPadEquals",
  107. [ 144] = "^",
  108. [ 145] = "@",
  109. [ 146] = ":",
  110. [ 147] = "_",
  111. [ 148] = "Kanji",
  112. [ 149] = "Stop",
  113. [ 150] = "Ax",
  114. [ 151] = "Unlabeled",
  115. [ 156] = "NumPadEnter",
  116. [ 157] = "RightControl",
  117. [ 157] = "Section",
  118. [ 179] = "NumPadComma",
  119. [ 181] = "Dvide",
  120. [ 183] = "Sysrq",
  121. [ 184] = "RightAlt",
  122. [ 196] = "Function",
  123. [ 197] = "Pause",
  124. [ 199] = "Home",
  125. [ 200] = "Up",
  126. [ 201] = "PageUp",
  127. [ 203] = "Left",
  128. [ 205] = "Right",
  129. [ 207] = "End",
  130. [ 208] = "Down",
  131. [ 209] = "PageDown",
  132. [ 210] = "Insert",
  133. [ 211] = "Delete",
  134. }
  135.  
  136. --Class declarations--
  137. local Button = {}
  138. local Layout = {}
  139. local Toggle = {}
  140. local BackgroundColor = {}
  141. local ColorField = {}
  142. local BetterPaint = {}
  143. local Text = {}
  144. local TextBox = {}
  145. local Key = {}
  146.  
  147. function loadObjects(self)
  148. local output = {}
  149. output.Button = {}
  150. output.Toggle = {}
  151. output.ColorField = {}
  152. output.BetterPaint = {}
  153. output.Text = {}
  154. output.TextBox = {}
  155. output.Key = {}
  156. for o,v in pairs(output) do
  157. if self[o] == nil then
  158. self[o] = {}
  159. end
  160. end
  161. for i,v in pairs(self.Button) do
  162. output.Button[i] = Button.new(self.Button[i])
  163. end
  164. for i,v in pairs(self.Toggle) do
  165. output.Toggle[i] = Toggle.new(self.Toggle[i])
  166. end
  167. for i,v in pairs(self.ColorField) do
  168. output.ColorField[i] = ColorField.new(self.ColorField[i])
  169. end
  170. for i,v in pairs(self.BetterPaint) do
  171. output.BetterPaint[i] = BetterPaint.new(self.BetterPaint[i])
  172. end
  173. for i,v in pairs(self.Text) do
  174. output.Text[i] = Text.new(self.Text[i])
  175. end
  176. for i,v in pairs(self.TextBox) do
  177. output.TextBox[i] = TextBox.new(self.TextBox[i])
  178. end
  179. for i,v in pairs(self.Key) do
  180. output.Key[i] = Key.new(self.Key[i])
  181. end
  182. return output
  183. end
  184.  
  185. function loadLayout(input,output)
  186. for i,v in pairs(input.Button) do
  187. output:addButton(input.Button[i])
  188. end
  189. for i,v in pairs(input.Toggle) do
  190. output:addToggle(input.Toggle[i])
  191. end
  192. for i,v in pairs(input.ColorField) do
  193. output:addColorField(input.ColorField[i])
  194. end
  195. for i,v in pairs(input.BetterPaint) do
  196. output:addBetterPaint(input.BetterPaint[i])
  197. end
  198. for i,v in pairs(input.Text) do
  199. output:addText(input.Text[i])
  200. end
  201. for i,v in pairs(input.TextBox) do
  202. output:addTextBox(input.TextBox[i])
  203. end
  204. for i,v in pairs(input.Key) do
  205. output:addKey(input.Key[i])
  206. end
  207. end
  208.  
  209. --Class Layout--
  210. --Layout initialization function--
  211. Layout.new = function(input)
  212. local self = {}
  213. setmetatable(self,{__index = Layout})
  214. self.Button = {}
  215. self.Toggle = {}
  216. self.ColorField = {}
  217. self.BetterPaint = {}
  218. self.Text = {}
  219. self.TextBox = {}
  220. self.Key = {}
  221. self.BackgroundColor = 1
  222. self.xPos = input.xPos or 1
  223. self.yPos = input.yPos or 1
  224. self.xLength = input.xLength or 51
  225. self.yLength = input.yLength or 19
  226. self.nilClick = input.nilClick or false
  227. self.window = Screen.new(term.current(),self.xPos,self.yPos,self.xLength,self.yLength)
  228. return self
  229. end
  230.  
  231. --Add element function--
  232. Layout.addButton = function(self,_elementData)
  233. self.Button[_elementData.name] = _elementData
  234. end
  235.  
  236. Layout.addToggle = function(self,_elementData)
  237. self.Toggle[_elementData.name] = _elementData
  238. end
  239.  
  240. Layout.addBackgroundColor = function(self,_elementData)
  241. self.BackgroundColor = _elementData.color
  242. end
  243.  
  244. Layout.addColorField = function(self,_elementData)
  245. self.ColorField[_elementData.name] = _elementData
  246. end
  247.  
  248. Layout.addBetterPaint = function(self,_elementData)
  249. self.BetterPaint[_elementData.name] = _elementData
  250. end
  251.  
  252. Layout.addText = function(self,_elementData)
  253. self.Text[_elementData.name] = _elementData
  254. end
  255.  
  256. Layout.addTextBox = function(self,_elementData)
  257. self.TextBox[_elementData.name] = _elementData
  258. end
  259.  
  260. Layout.addKey = function(self,_elementData)
  261. self.Key[_elementData.name] = _elementData
  262. end
  263.  
  264. Layout.draw = function(self,xPlus,yPlus)
  265. local oldTerm= term.current()
  266. term.redirect(self.window)
  267. local buttonFunctions = {}
  268. local toggleFunctions = {}
  269. local colorFieldFunctions = {}
  270. local betterPaintFunctions = {}
  271. local textFunctions = {}
  272. local textBoxFunctions = {}
  273. setmetatable(buttonFunctions,{__index = Button})
  274. setmetatable(toggleFunctions,{__index = Toggle})
  275. setmetatable(colorFieldFunctions,{__index = ColorField})
  276. setmetatable(betterPaintFunctions,{__index = BetterPaint})
  277. setmetatable(textFunctions,{__index = Text})
  278. setmetatable(textBoxFunctions,{__index = TextBox})
  279. --paintutils.drawFilledBox(self.xPos,self.yPos,self.xPos+self.xLength-1,self.yPos+self.yLength-1,self.BackgroundColor)
  280. paintutils.drawFilledBox(1,1,self.xLength,self.yLength,self.BackgroundColor)
  281. for i,v in pairs(self.ColorField) do
  282. colorFieldFunctions.draw(v,self.xPos,self.yPos,xPlus,yPlus)
  283. end
  284. for i,v in pairs(self.Button) do
  285. buttonFunctions.draw(v,self.xPos,self.yPos,xPlus,yPlus)
  286. end
  287. for i,v in pairs(self.BetterPaint) do
  288. betterPaintFunctions.draw(v,self.xPos,self.yPos,xPlus,yPlus)
  289. end
  290. for i,v in pairs(self.Toggle) do
  291. toggleFunctions.draw(v,self.xPos,self.yPos,xPlus,yPlus)
  292. end
  293. for i,v in pairs(self.Text) do
  294. textFunctions.draw(v,self.xPos,self.yPos,xPlus,yPlus)
  295. end
  296. for i,v in pairs(self.TextBox) do
  297. textBoxFunctions.draw(v,self.xPos,self.yPos,xPlus,yPlus)
  298. end
  299. term.redirect(oldTerm)
  300. end
  301.  
  302. --Class Button--
  303. --Button initialization function
  304. Button.new = function(input)
  305. local self = {}
  306. setmetatable(self,{__index = Button})
  307. self.name = input.name
  308. self.label = input.label
  309. self.xPos = input.xPos
  310. self.yPos = input.yPos
  311. self.fgColor = input.fgColor
  312. self.bgColor = input.bgColor
  313. self.xLength = input.xLength
  314. self.yLength = input.yLength
  315. self.returnValue = input.returnValue
  316. self.xTextPos = input.xTextPos
  317. self.yTextPos = input.yTextPos
  318. self.onRightClick = input.onRightClick or nil
  319. self.onLeftClick = input.onLeftClick or nil
  320. return self
  321. end
  322.  
  323. --Draw function
  324. Button.draw = function(self,addX,addY)
  325. addX = addX or 0
  326. addY = addY or 0
  327. local finalX = self.xPos + addX
  328. local finalY = self.yPos + addY
  329.  
  330. self.finalX = finalX
  331. self.finalY = finalY
  332. local newText
  333. if #self.label > self.xLength then
  334. newText = string.sub(self.label,1,self.xLength)
  335. else
  336. newText = self.label
  337. end
  338. paintutils.drawFilledBox(finalX,finalY,finalX+self.xLength-1,finalY+self.yLength-1,self.bgColor)
  339. term.setTextColor(self.fgColor)
  340. term.setCursorPos(finalX+self.xTextPos-1,finalY+self.yTextPos-1)
  341. term.write(newText)
  342. end
  343.  
  344. --Return function--
  345. Button.returnData = function(self)
  346. local toReturn = {}
  347. for i,v in pairs(self) do
  348. toReturn[i] = v
  349. end
  350. return toReturn
  351. end
  352.  
  353. --Sample Input table--
  354. example = [[
  355. example = {
  356. name = "quickSettings",
  357. label = ">",
  358. xPos = 1,
  359. yPos = 3,
  360. xLength = 1,
  361. yLength = 6,
  362. xTextPos = 1,
  363. yTextPos = 1,
  364. fgColor = colors.blue,
  365. bgColor = colors.lightGray,
  366. returnValue = "quickSettings",
  367. },
  368. ]]
  369.  
  370. --Class Toggle--
  371. --Initialize Toggle Object--
  372. Toggle.new = function(input)
  373. local self = {}
  374. setmetatable(self,{__index = Toggle})
  375. self.name = input.name or "randomName"
  376. self.state = input.state or true
  377. self.xPos = input.xPos or 1
  378. self.yPos = input.yPos or 1
  379. self.trueColor = input.trueColor or colors.green
  380. self.falseColor = input.falseColor or colors.red
  381. self.trueText = input.trueText or "T"
  382. self.falseText = input.falseText or "F"
  383. self.selectedBg = input.selectedBg or colors.gray
  384. self.notSelectedBg = input.notSelectedBg or colors.lightGray
  385. self.returnValue = input.returnValue or "mmmmmmm"
  386. self.moveX = input.moveX or false
  387. self.moveY = input.moveY or false
  388. self.onRightClick = input.onRightClick or nil
  389. self.onLeftClick = input.onLeftClick or nil
  390. return self
  391. end
  392.  
  393. function Toggle.draw(self,addX,addY)
  394. addX = addX or 0
  395. addY = addY or 0
  396. local finalX = self.xPos + addX
  397. local finalY = self.yPos + addY
  398. self.finalX = finalX
  399. self.finalY = finalY
  400. term.setCursorPos(finalX,finalY)
  401. if self.state == false then
  402. term.setBackgroundColor(self.notSelectedBg)
  403. term.setTextColor(self.trueColor)
  404. term.write(string.sub(self.trueText,1,1))
  405. term.setBackgroundColor(self.selectedBg)
  406. term.setTextColor(self.falseColor)
  407. term.write(" "..string.sub(self.falseText,1,1).." ")
  408. elseif self.state == true then
  409. term.setBackgroundColor(self.selectedBg)
  410. term.setTextColor(self.trueColor)
  411. term.write(" "..string.sub(self.trueText,1,1).." ")
  412. term.setBackgroundColor(self.notSelectedBg)
  413. term.setTextColor(self.falseColor)
  414. term.write(string.sub(self.falseText,1,1))
  415. end
  416. end
  417.  
  418. function Toggle.returnData(self)
  419. local toReturn = {}
  420. for i,v in pairs(self) do
  421. toReturn[i] = v
  422. end
  423. return toReturn
  424. end
  425.  
  426. function Toggle.toggle(self)
  427. if self.state == true then
  428. self.state = false
  429. else
  430. self.state = true
  431. end
  432. end
  433.  
  434. function Toggle.getState(self)
  435. return self.state
  436. end
  437.  
  438. --BackgroundColor Class--
  439. function BackgroundColor.new(input)
  440. local self = {}
  441. setmetatable(self,{__index = BackgroundColor})
  442. self.color = input.color
  443. return self
  444. end
  445.  
  446. function BackgroundColor.setColor(self,color)
  447. self.color = color
  448. end
  449.  
  450. function BackgroundColor.returnData(self)
  451. local toReturn = {}
  452. for i,v in pairs(self) do
  453. toReturn[i] = v
  454. end
  455. return toReturn
  456. end
  457.  
  458. --ColorField Class--
  459. function ColorField.new(input)
  460. local self = {}
  461. setmetatable(self,{__index = ColorField})
  462. self.name = input.name
  463. self.xPos = input.xPos
  464. self.yPos = input.yPos
  465. self.xLength = input.xLength
  466. self.yLength = input.yLength
  467. self.color = input.color
  468. self.moveX = input.moveX or false
  469. self.moveY = input.moveY or false
  470. return self
  471. end
  472.  
  473. function ColorField.draw(self,addX,addY)
  474. addX = addX or 0
  475. addY = addY or 0
  476. local finalX = self.xPos + addX
  477. local finalY = self.yPos + addY
  478. self.finalX = finalX
  479. self.finalY = finalY
  480. term.setTextColor(colors.black)
  481. paintutils.drawFilledBox(finalX,finalY,finalX+self.xLength-1,finalY+self.yLength-1,self.color)
  482. end
  483.  
  484. function ColorField.returnData(self)
  485. local toReturn = {}
  486. for i,v in pairs(self) do
  487. toReturn[i] = v
  488. end
  489. return toReturn
  490. end
  491.  
  492. --BetterPaint Class--
  493. function BetterPaint.new(input)
  494. local self = {}
  495. setmetatable(self,{__index = BetterPaint})
  496. self.xPos = input.xPos
  497. self.yPos = input.yPos
  498. self.name = input.name
  499. self.path = input.path
  500. self.xLength = input.xLength
  501. self.yLength = input.yLength
  502. self.returnValue = input.returnValue
  503. self.label = input.label
  504. self.labelBg = input.labelBg
  505. self.labelFg = input.labelFg
  506. self.moveX = input.moveX or false
  507. self.moveY = input.moveY or false
  508. self.onRightClick = input.onRightClick or nil
  509. self.onLeftClick = input.onLeftClick or nil
  510. return self
  511. end
  512.  
  513. function BetterPaint.returnData(self)
  514. local toReturn = {}
  515. for i,v in pairs(self) do
  516. toReturn[i] = v
  517. end
  518. return toReturn
  519. end
  520.  
  521. function BetterPaint.draw(self,addX,addY)
  522. addX = addX or 0
  523. addY = addY or 0
  524. local finalX = self.xPos + addX
  525. local finalY = self.yPos + addY
  526. self.finalX = finalX
  527. self.finalY = finalY
  528. paint.drawImage(self.path,finalX,finalY)
  529. term.setCursorPos(finalX,finalY+self.yLength)
  530. term.setTextColor(self.labelFg)
  531. term.setBackgroundColor(self.labelBg)
  532. term.write(self.label)
  533. end
  534.  
  535. --Text Class--
  536. function Text.new(input)
  537. local self = {}
  538. setmetatable(self,{__index = Text})
  539. self.name = input.name
  540. self.text = input.text
  541. self.xPos = input.xPos
  542. self.yPos = input.yPos
  543. self.bgColor = input.bgColor
  544. self.fgColor = input.fgColor
  545. self.moveX = input.moveX or false
  546. self.moveY = input.moveY or false
  547. return self
  548. end
  549.  
  550. function Text.draw(self,addX,addY)
  551. addX = addX or 0
  552. addY = addY or 0
  553. local finalX = self.xPos + addX
  554. local finalY = self.yPos + addY
  555. self.finalX = finalX
  556. self.finalY = finalY
  557. term.setCursorPos(finalX,finalY)
  558. term.setTextColor(self.fgColor)
  559. term.setBackgroundColor(self.bgColor)
  560. term.write(self.text)
  561. end
  562.  
  563. function Text.returnData(self)
  564. local toReturn = {}
  565. for i,v in pairs(self) do
  566. toReturn[i] = v
  567. end
  568. return toReturn
  569. end
  570.  
  571. --TextBox Class
  572.  
  573. function TextBox.new(input)
  574. local self = {}
  575. setmetatable(self,{__index = TextBox})
  576. self.name = input.name
  577. self.helpText = input.helpText
  578. self.xPos = input.xPos
  579. self.yPos = input.yPos
  580. self.xLength = input.xLength
  581. self.yLength = input.yLength
  582. self.bgColor = input.bgColor
  583. self.fgColor = input.fgColor
  584. self.helpFgColor = input.helpFgColor
  585. self.charLimit = input.charLimit
  586. self.moveX = input.moveX or false
  587. self.moveY = input.moveY or false
  588. self.text = ""
  589. self.returnValue = input.returnValue
  590. self.confidential = input.confidential or false
  591. return self
  592. end
  593.  
  594. function TextBox.returnData(self)
  595. local toReturn = {}
  596. for i,v in pairs(self) do
  597. toReturn[i] = v
  598. end
  599. return toReturn
  600. end
  601.  
  602. function TextBox.draw(self,addX,addY)
  603. addX = addX or 0
  604. addY = addY or 0
  605. local finalX = self.xPos + addX
  606. local finalY = self.yPos + addY
  607. self.finalX = finalX
  608. self.finalY = finalY
  609. paintutils.drawFilledBox(finalX,finalY,finalX+self.xLength-1,finalY+self.yLength-1,self.bgColor)
  610. term.setBackgroundColor(self.bgColor)
  611. term.setCursorPos(self.finalX,self.finalY)
  612. if self.text == "" or self.confidential then
  613. term.setTextColor(self.helpFgColor)
  614. term.write(self.helpText)
  615. else
  616. term.setTextColor(self.fgColor)
  617. term.write(self.text)
  618. end
  619. end
  620.  
  621. function TextBox.read(self,_sReplaceChar, _tHistory)
  622. paintutils.drawFilledBox(self.finalX,self.finalY,self.finalX+self.xLength-1,self.finalY+self.yLength-1,self.bgColor)
  623. term.setTextColor(self.fgColor)
  624. term.setCursorPos(self.finalX,self.finalY)
  625. return read()
  626. end
  627.  
  628. --Key Class
  629. function Key.new(input)
  630. local self = {}
  631. setmetatable(self,{__index = TextBox})
  632. self.name = input.name
  633. self.key = input.key
  634. self.onPress = input.onPress or nil
  635. return self
  636. end
  637.  
  638. function Key.returnData(self)
  639. local toReturn = {}
  640. for i,v in pairs(self) do
  641. toReturn[i] = v
  642. end
  643. return toReturn
  644. end
  645.  
  646.  
  647.  
  648. --Event handler function--
  649. eventHandler = function(self)
  650. local toAddX = self.xPos - 1
  651. local toAddY = self.yPos - 1
  652. while true do
  653. local event, p1, p2, p3, p4, p5, p6 = os.pullEvent()
  654. if event == "mouse_click" then
  655. for i,v in pairs(self.Button) do
  656. if v.finalX + toAddX <= p2 and p2 <= v.finalX + v.xLength-1 + toAddX and v.finalY + toAddY <= p3 and p3 <= v.finalY + v.yLength-1 + toAddY then
  657. if p1 == 1 then
  658. if v.onLeftClick then
  659. v.onLeftClick()
  660. end
  661. elseif p1 == 2 then
  662. if v.onRightClick then
  663. v.onRightClick()
  664. end
  665. end
  666. return {"Button",tostring(v.returnValue),p1,p2,p3}
  667. end
  668. end
  669. for i,v in pairs(self.Toggle) do
  670. if v.finalX + toAddX <= p2 and p2 <= v.finalX + 3 + toAddX and v.finalY + toAddY == p3 then
  671. return {"Toggle",tostring(v.returnValue),p1,p2,p3}
  672. end
  673. end
  674. for i,v in pairs(self.BetterPaint) do
  675. if v.finalX + toAddX <= p2 and p2 <= v.finalX + v.xLength-1 + toAddX and v.finalY + toAddY <= p3 and p3 <= v.finalY + v.yLength-1 + toAddY then
  676. return {"Button",tostring(v.returnValue),p1,p2,p3}
  677. end
  678. end
  679. for i,v in pairs(self.TextBox) do
  680. if v.finalX + toAddX <= p2 and p2 <= v.finalX + v.xLength-1 + toAddX and v.finalY + toAddY <= p3 and p3 <= v.finalY + v.yLength-1 + toAddY then
  681. return {"TextBox",tostring(v.returnValue),p1,p2,p3}
  682. end
  683. end
  684. if self.nilClick then
  685. if not (self.xPos <= p2 and p2 <= self.xPos+self.xLength-1 and self.yPos <= p3 and p3 <= self.yPos+self.yLength-1) then
  686. return {"Nil","Nil",p1,p2,p3}
  687. end
  688. end
  689. elseif event == "key" then
  690. local pressedKey = p1
  691. for i,v in pairs(self.Key) do
  692. if v.key == KeyCodes[pressedKey] then
  693. if v.onPress then
  694. v.onPress()
  695. else
  696. return {"Key",KeyCodes[pressedKey],pressedKey}
  697. end
  698. end
  699.  
  700. end
  701. elseif event == "monitor_touch" then
  702. os.queueEvent("mouse_click", p1, p2, p3, p4, p5, p6)
  703. end
  704. end
  705. end
  706.  
  707. --Load Function--
  708. function Initialize()
  709. local toReturn = {}
  710. toReturn.Button = Button
  711. toReturn.Layout = Layout
  712. toReturn.Toggle = Toggle
  713. toReturn.BackgroundColor = BackgroundColor
  714. toReturn.ColorField = ColorField
  715. toReturn.BetterPaint = BetterPaint
  716. toReturn.Text = Text
  717. toReturn.TextBox = TextBox
  718. toReturn.Key = Key
  719. toReturn.eventHandler = eventHandler
  720. toReturn.loadObjects = loadObjects
  721. toReturn.loadLayout = loadLayout
  722. return toReturn
  723. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement