Advertisement
jamawie

Buttons

May 6th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1. function bdraw(xp1,yp1,xp2,yp2,txt,col)
  2.  if col==nil then
  3.  mon.setBackgroundColor(colors.lime)
  4.  else
  5.  mon.setBackgroundColor(col)
  6.  end
  7.  mon.setCursorPos(xp1,yp1)
  8.  for i=1,(xp2-xp1) do
  9.   mon.write("-")
  10.  end
  11.  mon.setCursorPos(xp1,yp2)
  12.  for i=1,(xp2-xp1) do
  13.   mon.write("-")
  14.  end
  15.  for i=yp1,yp2 do
  16.   mon.setCursorPos(xp1,i)
  17.   mon.write("|")
  18.   mon.setCursorPos(xp2,i)
  19.   mon.write("|")
  20.  end
  21.  for i=(yp1+1),(yp2-1) do
  22.   mon.setCursorPos((xp1+1),i)
  23.   for j=(xp1+1),(xp2-1) do
  24.    mon.write(" ")
  25.    j = j+1
  26.   end
  27.   i = i+1
  28.  end
  29.  if math.floor(((xp2-xp1)-#txt)/2)==0 then
  30.   xp1 = xp1+1
  31.  end
  32.  mon.setCursorPos(math.floor(((xp2-xp1)-#txt)/2)+xp1,math.floor((yp2-yp1)/2)+yp1)
  33.  print(math.floor(((xp2-xp1)-#txt)/2))
  34.  mon.write(txt)
  35. end
  36.  
  37. function bdrawnb(x1,y1,x2,y2,text,color,tcol)
  38.     mon.setBackgroundColor(color)
  39.  
  40.     for i=y1,y2 do
  41.         mon.setCursorPos(x1,i)
  42.         for j=x1,x2 do
  43.             mon.write(" ")
  44.         end
  45.     end
  46.  
  47.     if (x2-x1)<=#text then
  48.         mon.setCursorPos(x1,math.floor((y2-y1)/2)+y1)
  49.     else
  50.         mon.setCursorPos(math.floor(((x2-x1)-#text)/2)+x1,math.floor((y2-y1)/2)+y1)
  51.     end
  52.     if tcol==nil then
  53.         mon.setTextColor(colors.gray)
  54.     else
  55.         mon.setTextColor(tcol)
  56.     end
  57.     mon.write(text)
  58.     mon.setTextColor(colors.gray)
  59. end
  60.  
  61.  
  62. function checkButtons(xPos, yPos)
  63.     if not event=="monitor_touch" then
  64.         return
  65.     end
  66.     if xPos>=2 and xPos<=18 and yPos>=y-3 and yPos<=y-1 then
  67.         bdraw(2,y-3,18,y-1,"Button 1",colors.magenta)
  68.         //hier kommt das hin was passieren soll wenn der Button gedrueckt wird
  69.         sleep(0.25)
  70.     end
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement