Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Multi Mon Api

DerMarten Jul 28th, 2015 (edited) 217 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. local button={}
  2.  
  3. function clearTable(mon)
  4.    button = {}
  5.    mon.clear()
  6. end
  7. function initMon(mon)
  8.         mon.setTextScale(1)
  9.         mon.setTextColor(colors.white)
  10.         mon.setBackgroundColor(colors.black)
  11. end              
  12. function setTable(name, func, xmin, xmax, ymin, ymax)
  13.    button[name] = {}
  14.    button[name]["func"] = func
  15.    button[name]["active"] = false
  16.    button[name]["xmin"] = xmin
  17.    button[name]["ymin"] = ymin
  18.    button[name]["xmax"] = xmax
  19.    button[name]["ymax"] = ymax
  20. end
  21.  
  22. function funcName()
  23.    print("You clicked buttonText")
  24. end
  25.        
  26. function fillTable()
  27.    setTable("ButtonText", funcName, 5, 25, 4, 8)
  28. end    
  29.  
  30. function fill(text, color, bData, mon)
  31.    mon.setBackgroundColor(color)
  32.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  33.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  34.    for j = bData["ymin"], bData["ymax"] do
  35.       mon.setCursorPos(bData["xmin"], j)
  36.       if j == yspot then
  37.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  38.             if k == xspot then
  39.                mon.write(text)
  40.             else
  41.                mon.write(" ")
  42.             end
  43.          end
  44.       else
  45.          for i = bData["xmin"], bData["xmax"] do
  46.             mon.write(" ")
  47.          end
  48.       end
  49.    end
  50.    mon.setBackgroundColor(colors.black)
  51. end
  52.      
  53. function screen(mon)
  54.    local currColor
  55.    for name,data in pairs(button) do
  56.       local on = data["active"]
  57.       if on == true then currColor = colors.lime else currColor = colors.red end
  58.       fill(name, currColor, data, mon)
  59.    end
  60. end
  61.  
  62. function toggleButton(name, mon)
  63.    button[name]["active"] = not button[name]["active"]
  64.    screen(mon)
  65. end    
  66.  
  67. function flash(name,mon)
  68.    toggleButton(name)
  69.    screen(mon)
  70.    sleep(0.15)
  71.    toggleButton(name)
  72.    screen(mon)
  73. end
  74.                                              
  75. function checkxy(x, y)
  76.    for name, data in pairs(button) do
  77.       if y>=data["ymin"] and  y <= data["ymax"] then
  78.          if x>=data["xmin"] and x<= data["xmax"] then
  79.             data["func"]()
  80.             return true
  81.             --data["active"] = not data["active"]
  82.             --print(name)
  83.          end
  84.       end
  85.    end
  86.    return false
  87. end
  88.      
  89. function heading(text, mon)
  90.    w, h = mon.getSize()
  91.    mon.setCursorPos((w-string.len(text))/2+1, 1)
  92.    mon.write(text)
  93. end
  94.      
  95. function label(w, h, text, mon)
  96.    mon.setCursorPos(w, h)
  97.    mon.write(text)
  98. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top