Advertisement
PandaDoddo72Rus

draw

Aug 18th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.88 KB | None | 0 0
  1. local cmp = require('component')
  2. local event = require('event')
  3. local serialization = require('serialization')
  4. local gpu=cmp.gpu
  5. local filesystem=require('filesystem')
  6. local term =require('term')
  7. local computer = require('computer')
  8. local unicode = require('unicode')
  9. local draw = {}
  10.  
  11. function draw.colorSelector(txt)
  12.   oldBac=gpu.getBackground()
  13.   buttonsSelector={
  14.   {54,20,1,1}, --<settings>
  15.   {55,20,1,1},
  16.   {56,20,1,1},
  17.   {57,20,1,1},
  18.   {58,20,1,1},
  19.   {59,20,1,1},
  20.   {54,22,1,1},
  21.   {55,22,1,1},
  22.   {56,22,1,1},
  23.   {57,22,1,1},
  24.   {58,22,1,1},
  25.   {59,22,1,1},
  26.   {65,21,20,3},  --</settings>
  27. }
  28.   local colorPos1 = 0
  29.   local colorPos2 = 0
  30.   local colorPos3 = 0
  31.   local colorPos4 = 0
  32.   local colorPos5 = 0
  33.   local colorPos6 = 0
  34.   local function F16(n)
  35.     N=nil
  36.     if n > 9 then
  37.     if n==10 then
  38.       N = 'A'
  39.     elseif n == 11 then
  40.       N = 'B'
  41.     elseif n == 12 then
  42.       N = 'C'
  43.     elseif n == 13 then
  44.       N = 'D'
  45.     elseif n == 14 then
  46.       N = 'E'
  47.     elseif n == 15 then
  48.       N = 'F'
  49.     else N = n
  50.     end
  51.   end
  52.   if N == nil then N=n end
  53.     return N
  54.   end
  55.   draw.field(30,15,60,11,' ',0x505050,0x505050)
  56.   draw.clound('┌','┐','└','┘','│','─',30,15,60,11,0x505050,0xFFFFFF)
  57.   draw.text(40,17,40,txt,0x505050,0xFFFFFF)
  58.   gpu.setBackground(0)
  59.   gpu.set(52,21,'0x')
  60.   gpu.set(54,21,'000000')
  61.   draw.field(47,21,2,1,' ',0,0x505050)
  62.   draw.clound('┌','┐','└','┘','│','─',46,20,4,3,0x505050,0xFFFFFF)
  63.   gpu.setBackground(0x505050)
  64.   gpu.setForeground(0xFFAA00)
  65.   gpu.set(54,20,'▲▲▲▲▲▲')
  66.   gpu.set(54,22,'▼▼▼▼▼▼')
  67.   gpu.setForeground(0xFFFFFF)
  68.   gpu.setBackground(0x898989)
  69.   gpu.fill(64,20,20,3,' ')
  70.   gpu.set(73,21,'OK')
  71.   gpu.setBackground(0x505050)
  72.   gpu.setBackground(oldBac)
  73.   newColor=0
  74. while true do
  75.   local key,posSettingMenu,clickMouse,name = draw.getRawEvent(buttonsSelector)
  76.   if key == 'touch' then
  77.   if posSettingMenu > 0 and posSettingMenu < 13 then
  78.     if posSettingMenu == 1 then
  79.       colorPos1 = colorPos1+1
  80.     elseif posSettingMenu == 2 then
  81.       colorPos2 = colorPos2+1
  82.     elseif posSettingMenu == 3 then
  83.       colorPos3 = colorPos3 + 1
  84.     elseif posSettingMenu == 4 then
  85.       colorPos4 = colorPos4 + 1
  86.     elseif posSettingMenu == 5 then
  87.       colorPos5 = colorPos5 + 1
  88.     elseif posSettingMenu == 6 then
  89.       colorPos6 = colorPos6 + 1
  90.     elseif posSettingMenu == 7 then
  91.       colorPos1 = colorPos1-1
  92.     elseif posSettingMenu == 8 then
  93.       colorPos2 = colorPos2-1
  94.     elseif posSettingMenu == 9 then
  95.       colorPos3 = colorPos3 - 1
  96.     elseif posSettingMenu == 10 then
  97.       colorPos4 = colorPos4 - 1
  98.     elseif posSettingMenu == 11 then
  99.       colorPos5 = colorPos5 - 1
  100.     elseif posSettingMenu == 12 then
  101.       colorPos6 = colorPos6 - 1
  102.     end
  103.     if colorPos1 > 15 then
  104.       colorPos1 = 15
  105.     elseif colorPos2 > 15 then
  106.       colorPos2 = 15
  107.     elseif colorPos3 > 15 then
  108.       colorPos3 = 15
  109.     elseif colorPos4 > 15 then
  110.       colorPos4 = 15
  111.     elseif colorPos5 > 15 then
  112.      colorPos5 = 15
  113.     elseif colorPos6 > 15 then
  114.       colorPos6 = 15
  115.     end
  116.     if colorPos1 < 0 then
  117.       colorPos1 = 0
  118.     elseif colorPos2 < 0 then
  119.       colorPos2 = 0
  120.     elseif colorPos3 < 0 then
  121.       colorPos3 = 0
  122.     elseif colorPos4 < 0 then
  123.       colorPos4 = 0
  124.     elseif colorPos5 < 0 then
  125.       colorPos5 = 0
  126.     elseif colorPos6 < 0 then
  127.       colorPos6 = 0
  128.     end
  129.     local F1=F16(colorPos1)
  130.     local F2=F16(colorPos2)
  131.     local F3=F16(colorPos3)
  132.     local F4=F16(colorPos4)
  133.     local F5=F16(colorPos5)
  134.     local F6=F16(colorPos6)
  135.     gpu.setBackground(0)
  136.     gpu.set(54,21,tostring(F1..F2..F3..F4..F5..F6))
  137.     newColor=tonumber('0x'..F1..F2..F3..F4..F5..F6)
  138.     draw.field(47,21,2,1,' ',newColor,0x505050)
  139.     draw.clound('┌','┐','└','┘','│','─',40,46,4,3,0x505050,0xFFFFFF)
  140.     gpu.setBackground(0x505050)
  141.     gpu.setBackground(oldBac)
  142.     end
  143.   if posSettingMenu == 13 then
  144.     gpu.setBackground(oldBac)
  145.     term.clear()
  146.     break
  147.   end
  148.   end
  149.   end
  150.   gpu.setBackground(oldBac)
  151.   return newColor
  152. end
  153.  
  154. function draw.enter(x,y,w,h,mode,color_back,color_fore)
  155.   function drawTextInPass(x,y,w,h,txt,col)
  156.     draw.field(x+1,y+1,w-1,1,' ',color_back,color_fore)
  157.     draw.text(x+1,y+1,h-2,txt,color_back,col)
  158.   end
  159.   draw.field(x,y,w,h,' ',color_back,color_fore)
  160.   draw.clound('┌','┐','└','┘','│','─',x,y,w,h,color_back,color_fore)
  161.   local function getKey(s)
  162.     local _, _, _, code, _ = event.pull("key_up")
  163.     return code
  164.   end
  165.   local function enterPass()
  166.   try = ""
  167.   ex=true
  168.   while ex do
  169.     local err, f = pcall(getKey)
  170.     if not err then
  171.       return err, try
  172.     end
  173.     if keyboard.keys[f] == 'grave' then ex=false end
  174.     if f < 60 and f > 0 then
  175.       if keyboard.keys[f] == 'enter' then
  176.         return err, try
  177.       end
  178.       if keyboard.keys[f] == 'back' then
  179.         if unicode.len(try) > 0 then
  180.           try=unicode.sub(try,0,unicode.len(try)-1)
  181.           if mode == 'pass' then
  182.             if try ~= nil then
  183.               try2='' for l=1,unicode.len(try) do try2=try2..'*' end
  184.             end
  185.             drawTextInPass(x,y,w,h,try2,color_fore)
  186.           elseif mode ~= 'pass' then
  187.             drawTextInPass(x,y,w,h,try,color_fore)
  188.           end
  189.          
  190.         end
  191.       end
  192.       if unicode.len(keyboard.keys[f]) == 1 and unicode.len(try) < 28 then
  193.         try = try..keyboard.keys[f]
  194.         if mode == 'pass' then
  195.           if try ~= nil then
  196.             try2='' for l=1,unicode.len(try) do try2=try2..'*' end
  197.             drawTextInPass(x,y,w,h,try2,color_fore)
  198.           end
  199.         elseif mode ~= 'pass' then
  200.           drawTextInPass(x,y,w,h,try,color_fore)
  201.         end
  202.       end
  203.     end
  204.   end
  205. end
  206.   while true do
  207.     err, try = enterPass()
  208.     if try == try then -- success
  209.       break
  210.     elseif try == "cancel" then -- admin pass
  211.       break
  212.     end
  213.   end
  214.   return try
  215. end
  216.  
  217. function draw.err(text,mode,SleepTime)
  218.   draw.field(30,13,60,9,' ',0x505050,0x505050)
  219.   if mode == 1 then
  220.     errColor=0xFFFFFF
  221.   elseif mode == 2 then
  222.     errColor = 0xAA0000
  223.   elseif mode == 3 then
  224.     errColor = 0xFFAA00
  225.   end
  226.   draw.clound('┌','┐','└','┘','│','─',30,13,60,9,0x505050,errColor)
  227.   draw.text(32,17,56,text,0x505050,0xFFFFFF)
  228.   if SleepTime ~= 0 then
  229.   os.sleep(SleepTime)
  230.   end
  231. end
  232.  
  233. function draw.fileList(backColor,ForeColor,x,y,w,h,topText,arr,mode,name,page,colorSelectFore,colorSelectBack)
  234.   local oldF=gpu.getForeground()
  235.   local oldB=gpu.getBackground()
  236.   draw.field(x,y,w,h,' ',backColor,ForeColor)
  237.   draw.clound('┌','┐','└','┘','│','─',x,y,w,h,backColor,ForeColor)
  238.   draw.text(x,y,w,topText,backColor,ForeColor)
  239.   gpu.setForeground(ForeColor)
  240.   gpu.setBackground(backColor)
  241.   local filesInList=y+h-2
  242.   local filesInListLen=x+w-2
  243.   local p = 1+page
  244.   local k = p+filesInList-4
  245.   local pos = 0
  246.   if mode == 1 then
  247.     for j=p,k-1 do
  248.       if arr[j]~= nil and arr[j]==name then
  249.       gpu.setForeground(colorSelectFore)
  250.         gpu.setBackground(colorSelectBack)
  251.       gpu.fill(x+1,y+pos,w-2,1,' ')
  252.       gpu.set(x+1,y+pos,unicode.sub(arr[j],0,w-2))
  253.       gpu.setForeground(ForeColor)
  254.       gpu.setBackground(backColor)
  255.       pos=pos+1
  256.     elseif arr[j]~= name and arr[j]~= nil then
  257.         gpu.fill(x+1,y+1+pos,w-2,1,' ')
  258.       gpu.set(x+1,y+1+pos,unicode.sub(arr[j],0,w-2))
  259.       pos=pos+1
  260.     end
  261.     end
  262.   elseif mode == 2 then
  263.     for j=p,k-1 do
  264.     if arr[j]~= nil then
  265.         gpu.fill(x+1,y+1+pos,w-2,1,' ')
  266.       gpu.set(x+1,y+1+pos,unicode.sub(arr[j],0,w-2))
  267.       pos=pos+1
  268.     end
  269.     end
  270.   end
  271.   gpu.setForeground(oldF)
  272.   gpu.setBackground(oldB)
  273. end
  274.  
  275. function draw.getRawEvent(arr)
  276.   local N = nil
  277.   local key,_,x,y,clickMouse,name=event.pull()
  278.   if key ~= 'scroll' then
  279.   for i=1,#arr do
  280.     if x > arr[i][1]-1 and x < arr[i][1]+arr[i][3] and y > arr[i][2]-1 and y < arr[i][2]+arr[i][4] then
  281.     N=i
  282.     break
  283.   end
  284.   end
  285.   end
  286.   if N == nil then
  287.     N = 0
  288.   end
  289.   return key,N,clickMouse,name  
  290. end
  291.  
  292. function draw.button(buttons,N)
  293.     oldFore=gpu.getForeground()
  294.   oldBack=gpu.getBackground()
  295.   if pos== N then
  296.     gpu.setForeground(buttons[N][11])
  297.   gpu.setBackground(buttons[N][10])
  298.   else
  299.   gpu.setForeground(buttons[N][9])
  300.   gpu.setBackground(buttons[N][8]) end
  301.     gpu.fill(buttons[N][1],buttons[N][2],buttons[N][3],buttons[N][4],' ')
  302.   gpu.setForeground(buttons[N][9])
  303.   gpu.set(buttons[N][6],buttons[N][7],buttons[N][5])
  304.   gpu.setForeground(oldFore)
  305.   gpu.setBackground(oldBack)
  306. end
  307.  
  308. function draw.field(x,y,w,h,s,c1,c2)
  309.   oldBack=gpu.getBackground()
  310.   oldFore=gpu.getForeground()
  311.   gpu.setBackground(c1)
  312.   gpu.setForeground(c2)
  313.   gpu.fill(x,y,w,h,s)
  314.   gpu.setBackground(oldBack)
  315.   gpu.setForeground(oldFore)
  316. end
  317.  
  318. function draw.frame(color,frames,N)    
  319.   gpu.setBackground(color)
  320.   gpu.fill(1,1,A,1,' ')
  321.   for i=1,#frames[N] do
  322.     drawButton(frames[N][i])
  323.   end
  324. end
  325.  
  326. function draw.clound(s,s2,s3,s4,s5,s6,x,y,w,h,c1,c2)  
  327.   oldFore=gpu.getForeground()
  328.   oldBack=gpu.getBackground()
  329.   gpu.setBackground(c1)
  330.   gpu.setForeground(c2)
  331.   gpu.set(x,y,s)
  332.   gpu.fill(x+1,y,w-1,1,s6)
  333.   gpu.set(x,y+h-1,s3)
  334.   gpu.fill(x,y+1,1,h-2,s5)
  335.   gpu.fill(x+w-1,y+1,1,h-2,s5)
  336.   gpu.set(x+w-1,y,s2)
  337.   gpu.fill(x+1,y+h-1,w-2,1,s6)
  338.   gpu.set(x+w-1,y+h-1,s4)
  339.   gpu.setBackground(oldBack)
  340.   gpu.setForeground(oldFore)
  341. end
  342.  
  343. function draw.exit(C,D,OldResX,OldResY)
  344.   gpu.setBackground(C)
  345.   gpu.setForeground(D)
  346.   gpu.setResolution(OldResX,OldResY)
  347.   term.clear()
  348. end
  349.  
  350. function draw.text(x,y,leght,txt,col_back,col_fore)
  351.   local oldB=gpu.getBackground()
  352.   local oldF=gpu.getForeground()
  353.   local txt = tostring(txt)
  354.   gpu.setBackground(col_back)
  355.   gpu.setForeground(col_fore)
  356.   if unicode.len(txt) > leght then
  357.     txt=unicode.sub(txt,0,leght)
  358.   end
  359.   gpu.set(x+math.floor((leght-unicode.len(txt))/2),y,txt)
  360.   gpu.setBackground(oldB)
  361.   gpu.setForeground(oldF)
  362. end
  363.  
  364. function draw.emptyField(frame,mode,txt)
  365. gpu.setBackground(0x505050)
  366.  if mode == 1 then
  367.    drawFrame(frame)
  368.  elseif mode == 2 then
  369.   draw.field(1,1,120,1,' ',0x505050,0x505050)
  370.   draw.field(1,2,120,1,'▀',0xDCDCDC,0x505050)
  371.   draw.field(1,3,120,37,' ',0xDCDCDC,0x505050)
  372.  end
  373.  draw.field(1,4,120,38,' ',0xDCDCDC,0x505050)
  374.  draw.field(1,40,120,1,' ',0x505050,0x505050)
  375.  draw.field(1,39,120,1,'▄',0xDCDCDC,0x505050)
  376.  gpu.set(3,40,txt)
  377.  gpu.set(90,40,'Autor: PandaDoddo72Rus (vah)')
  378. end
  379.  
  380. function draw.buttonsCatch(frames,buttons,N,mode)
  381.   if pos~=nil then oldPos=pos end
  382.   pos = nil
  383.   local _,_,p1,p2,_,nick=event.pull('touch')
  384.   for i=1,#frames[N] do
  385.     if p1 > buttons[frames[N][i]][1]-1 and p1 < buttons[frames[N][i]][1]+buttons[frames[N][i]][3] and p2 > buttons[frames[N][i]][2]-1 and p2 < buttons[frames[N][i]][2]+buttons[frames[N][i]][4] then    
  386.    pos=i break
  387.     end
  388.   end
  389.   if mode == 1 then
  390.     if pos==nil then pos=oldPos end
  391.   elseif mode == 2 then
  392.     if pos==nil then pos=0 end
  393.   end
  394.   return pos,nick
  395. end
  396.  
  397. return draw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement