Advertisement
ndfjay

GUI part 2

Jan 2nd, 2013
3,465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.67 KB | None | 0 0
  1. --Desktop
  2.  
  3. slc = 0
  4. tBarC = 8
  5. tBartC = 1
  6. backColor = 1
  7. term.setBackgroundColor(backColor)
  8. term.clear()
  9. contextX = 0
  10. contextY = 0
  11. function titleBar()
  12.   term.setCursorPos(1,1)
  13.   term.setBackgroundColor(tBarC)
  14.   term.setTextColor(tBartC)
  15.   term.clearLine()
  16.   term.setCursorPos(3, 1)
  17.   print("[Begin]")
  18. end
  19. function drawDesktop()
  20.   term.setBackgroundColor(backColor)
  21.   term.clear()
  22.   bground = paintutils.loadImage(".background")
  23.   paintutils.drawImage(bground,1,1)
  24.   icon = paintutils.loadImage("icon")
  25.   paintutils.drawImage(icon, 2, 3)
  26.   term.setBackgroundColor(backColor)
  27.   term.setTextColor(128)
  28.   term.setCursorPos(2,9)
  29.   print("icon 1")
  30.   titleBar()
  31.  
  32. end
  33.  
  34. function drawMenu1()
  35. term.setTextColor(256)
  36. term.setBackgroundColor(128)
  37. term.setCursorPos(1,2)
  38. print("          ")
  39. term.setCursorPos(1,3)
  40. print(" Shutdown ")
  41. term.setCursorPos(1,4)
  42. print(" Restart  ")
  43. term.setCursorPos(1,5)
  44. print("          ")
  45. end
  46. function drawMenu2()
  47. term.setBackgroundColor(128)
  48. term.setTextColor(256)
  49. term.setCursorPos(contextX, contextY)
  50. print("             ")
  51. term.setCursorPos(contextX, contextY+1)
  52. print(" Edit GUI    ")
  53. term.setCursorPos(contextX, contextY+2)
  54. print(" FileManager ")
  55. term.setCursorPos(contextX, contextY+3)
  56. print("             ")
  57. end
  58.  
  59. drawDesktop()
  60. while true do
  61. local event, button, X, Y = os.pullEventRaw()
  62.   if slc == 0 then
  63.     if event == "mouse_click" then
  64.       if X >=2 and X <=8 and Y==1 and button ==1 then
  65.       drawMenu1()
  66.       slc = 1
  67.         elseif X >=2 and X<=5 and Y>=3 and Y<=9 and button == 1 then
  68.         shell.run("file")
  69.           elseif X >= 1 and Y >=2 and button == 2 then slc = 2
  70.             if X >=38 then
  71.             contextX = 38
  72.             end
  73.             if Y >=14 then
  74.             contextY = 14
  75.             end
  76.             if X <= 38 then
  77.             contextX = X
  78.             end
  79.             if Y <= 14 then
  80.             contextY = Y
  81.             end
  82.             drawMenu2()
  83.         else
  84.         drawDesktop()
  85.       end
  86.     end
  87.    elseif slc == 1 then
  88.      if X >=1 and X <=11 and button == 1 and Y== 3 then slc = 0
  89.        os.shutdown()
  90.        elseif X>=1 and X<=11 and Y==4 and button ==1 then slc = 0
  91.        os.reboot()
  92.        else
  93.        slc = 0
  94.        drawDesktop()
  95.      
  96.      end
  97.   elseif slc == 2 then
  98.         if X >= contextX and X <= contextX+13 and Y==contextY+1 and button == 1 then slc = 0
  99.         shell.run("edit","gui")
  100.         drawDesktop()
  101.           elseif X>= contextX and X <=contextX+13 and Y==contextY+2 and button == 1 then slc = 0
  102.             shell.run("file")
  103.             drawDesktop()
  104.               else slc = 0
  105.               drawDesktop()
  106.         end
  107.   end
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement