Advertisement
comfix

TouchAPI Beispiel

Feb 23rd, 2014
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 0 0
  1. -- TouchAPI-Beispiel zur Funktionalität
  2. -- Beispielprogramm von SomethingSpecialLP aka comfix
  3. ------ Defines
  4. monSide = "top" -- Monitorseite
  5. ButtonText_Open = "AUF" -- Buttonbeschriftung - Auf
  6. ButtonText_Close = "Z U" -- Buttonbeschriftung - Zu
  7.  
  8. ------ Functions
  9. function clear()
  10.     term.clear()
  11.     term.setCursorPos(1,1)
  12. end
  13.  
  14. function bp(TEXT,METHOD,X,Y,CO,BACO)-- BetterPrint "Monitor" -- Zur freien Verwendung / Kann über API eingebungen werden
  15.     if X ~= nil and Y ~= nil then
  16.         mon.setCursorPos(X,Y)
  17.     end
  18.     if CO ~= nil then
  19.         mon.setTextColor(CO)
  20.     end
  21.     if BACO ~= nil then
  22.         mon.setBackgroundColor(BACO)
  23.     end
  24.     if TEXT ~= nil and METHOD ~= nil then
  25.         if METHOD == "w" then
  26.         mon.write(TEXT)
  27.         end
  28.     else
  29.     --print("In BetterPrint muss 'TEXT' und 'METHOD' gesetzt sein!")
  30.     --term.setCursorPos(0,0)
  31.     print("Error: "..tostring(TEXT))
  32.     error()
  33.     end
  34.     TEXT,METHOD,X,Y,CO,BACO = nil
  35. end
  36.  
  37. function writeButtons()
  38.     clear()
  39.     bp(" "..ButtonText_Open.." ","w",1,1,1,32)
  40.     bp(" "..ButtonText_Close.." ","w",1,2,1,16384)
  41. end
  42. ------ Main Loop
  43. mon = peripheral.wrap(monSide)
  44. writeButtons()
  45. while true do
  46.     event, side, xPos, yPos = os.pullEvent("monitor_touch")
  47.     for _X=0,5 do
  48.         if _X == xPos and _Y == 1 then
  49.             -- Function OPEN
  50.         end
  51.         if _X == xPos and _Y == 2 then
  52.             -- Function CLOSE
  53.         end
  54.     end
  55. end
  56.  
  57. -- -- -- Farben Codes -- -- colors. -- --
  58. -- 1     - Weiss            -white
  59. -- 2     - Orange           -orange
  60. -- 4     - Magenta          -magenta
  61. -- 8     - Hellblau         -lightBlue
  62. -- 16    - Gelb             -yellow
  63. -- 32    - Hellgrün            -lime
  64. -- 64    - Rosa             -pink
  65. -- 128   - Grau             -grey
  66. -- 256   - Hellgrau         -lightGrey
  67. -- 512   - Türkis          -cyan
  68. -- 1024  - Violett          -purple
  69. -- 2048  - Blau             -blue
  70. -- 4069  - Braun            -brown
  71. -- 8192  - Grün                -green
  72. -- 16384 - Rot              -red
  73. -- 32768 - Schwarz          -black
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement