Advertisement
D_Puppy

VIsual Gui Editor

Jul 5th, 2017
3,632
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 48.04 KB | None | 1 0
  1. local component = require("component")
  2. local gpu = component.gpu
  3. gpu.setResolution(160,50)
  4. local gui = require("gui")
  5. local event = require("event")
  6. local ser = require("serialization")
  7.  
  8. local prgName = "Visual Gui"
  9. local version = "v0.1a"
  10.  
  11. gui.checkVersion(2, 5)
  12.  
  13. local guiVersion, guiMajor, guiMinor = gui.Version()
  14.  
  15. local buttonCounter = 0
  16. local labelCounter = 0
  17. local multiLabelCounter = 0
  18. local textCounter = 0
  19. local frameCounter = 0
  20. local hlineCounter = 0
  21. local checkboxCounter = 0
  22. local radioCounter = 0
  23. local hprogressCounter = 0
  24. local vprogressCounter = 0
  25. local listCounter = 0
  26. local vsliderCounter = 0
  27. local timelabelcounter = 0
  28. local datelabelcounter = 0
  29. --local chartCounter = 0
  30.  
  31. local dataTable = {}
  32. dataTable["filename"] = "noname"
  33. dataTable["topline"] = "noname"
  34. dataTable["bottomline"] = "Made with Visual Gui " .. version .. " and Gui library v" .. guiVersion
  35. dataTable["version"] = "1.0"
  36. dataTable["counter"] = 0
  37. dataTable["useExit"] = false
  38.  
  39.  
  40. -- display a button in workspace
  41. local function displayButton(id)
  42.   local x = 80 + dataTable[id].x
  43.   local y = 5 + dataTable[id].y
  44.   local t = "[" .. dataTable[id].text .. "]"
  45.   gpu.setBackground(0x0000FF)
  46.   gpu.setForeground(0xFFFFFF)
  47.   gpu.set(x, y, t)
  48. end
  49.  
  50. -- display a label in workspace
  51. local function displayLabel(id)
  52.   local x = 80 + dataTable[id].x
  53.   local y = 5 + dataTable[id].y
  54.   local t = dataTable[id].text
  55.   gpu.setBackground(0xCFCFCF)
  56.   gpu.setForeground(0x000000)
  57.   gpu.fill(x, y, dataTable[id].l, 1, " ")
  58.   gpu.set(x, y, t)
  59. end
  60.  
  61. -- display a time label in workspace
  62. local function displayTimeLabel(id)
  63.   local x = 80 + dataTable[id].x
  64.   local y = 5 + dataTable[id].y
  65.   local t = os.date("%H:%M", os.time())
  66.   gpu.setBackground(0xCFCFCF)
  67.   gpu.setForeground(0x000000)
  68.   gpu.set(x, y, t)
  69. end
  70.  
  71. -- display a date label in workspace
  72. local function displayDateLabel(id)
  73.   local x = 80 + dataTable[id].x
  74.   local y = 5 + dataTable[id].y
  75.   local t = ""
  76.   if dataTable[id].frm == false then
  77.     t = os.date("%d/%m/%Y")
  78.   elseif dataTable[id].frm == true then
  79.     t = os.date("%A %d. %B %Y")
  80.   end
  81.   gpu.setBackground(0xCFCFCF)
  82.   gpu.setForeground(0x000000)
  83.   gpu.set(x, y, t)
  84. end
  85.  
  86. -- display a multi line label in workspace
  87. local function displayMultiLine(id)
  88.   local x = 80 + dataTable[id].x
  89.   local y = 5 + dataTable[id].y
  90.   local t = dataTable[id].text
  91.   gpu.setBackground(0xCFCFCF)
  92.   gpu.setForeground(0x000000)
  93. --  gpu.set(x, y, t)
  94.   gpu.fill(x, y, dataTable[id].w, dataTable[id].h, " ")
  95. end
  96.  
  97. -- display a text in workspace
  98. local function displayText(id)
  99.   local x = 80 + dataTable[id].x
  100.   local y = 5 + dataTable[id].y
  101.   local t = dataTable[id].text
  102.   gpu.setBackground(0x000000)
  103.   gpu.setForeground(0xFFFFFF)
  104.   gpu.fill(x, y, dataTable[id].l, 1, " ")
  105.   gpu.set(x, y, t)
  106. end
  107.  
  108. -- display a horizontal line in workspace
  109. local function displayHLine(id)
  110.   local x = 80 + dataTable[id].x
  111.   local y = 5 + dataTable[id].y
  112.   gpu.setBackground(0xC0C0C0)
  113.   gpu.setForeground(0x000000)
  114.   gpu.fill(x, y, dataTable[id].l, 1, "═")
  115. end
  116.  
  117. -- display a checkbox in workspace
  118. local function displayCheckbox(id)
  119.   local x = 80 + dataTable[id].x
  120.   local y = 5 + dataTable[id].y
  121.   gpu.setBackground(0xC0C0C0)
  122.   gpu.setForeground(0x000000)
  123.   gpu.set(x, y, "[ ]")
  124. end
  125.  
  126. -- display a radio button in workspace
  127. local function displayRadio(id)
  128.   local x = 80 + dataTable[id].x
  129.   local y = 5 + dataTable[id].y
  130.   gpu.setBackground(0xC0C0C0)
  131.   gpu.setForeground(0x000000)
  132.   gpu.set(x, y, "( )")
  133. end
  134.  
  135. -- display a horizontal progressbar in workspace
  136. local function displayHProgress(id)
  137.   local x = 80 + dataTable[id].x
  138.   local y = 5 + dataTable[id].y
  139.   gpu.setBackground(0x000000)
  140.   gpu.setForeground(0x000000)
  141.   gpu.fill(x, y, dataTable[id].l, 1, " ")
  142.   gpu.setBackground(0x00FF00)
  143.   gpu.fill(x, y, dataTable[id].l/2, 1, " ")
  144.   if dataTable[id].number == true then
  145.     gpu.setBackground(0xC0C0C0)
  146.     gpu.setForeground(0x000000)
  147.     gpu.set(x + math.floor(dataTable[id].l/2) - 2, y - 1, "100%")
  148.   end
  149. end
  150.  
  151. -- display a vertical progressbar in workspace
  152. local function displayVProgress(id)
  153.   local x = 80 + dataTable[id].x
  154.   local y = 5 + dataTable[id].y
  155.   gpu.setBackground(0x00FF00)
  156.   gpu.setForeground(0x000000)
  157.   gpu.fill(x, y, dataTable[id].w, dataTable[id].l, " ")
  158.   gpu.setBackground(0x000000)
  159.   gpu.fill(x, y, dataTable[id].w, dataTable[id].l/2, " ")
  160. end
  161.  
  162. -- display a vertical slider in workspace
  163. local function displayVslider(id)
  164.   local x = 80 + dataTable[id].x
  165.   local y = 5 + dataTable[id].y
  166.   gpu.setBackground(0x000000)
  167.   gpu.setForeground(0xFFFFFF)
  168.   gpu.fill(x, y, dataTable[id].l, 1, " ")
  169.   gpu.setBackground(0x0000FF)
  170.   gpu.set(x, y, "-")
  171.   gpu.set(x + dataTable[id].l, y, "+")
  172. end
  173.  
  174. local function displayFrame(id)
  175.   gpu.setBackground(0xC0C0C0)
  176.   gpu.setForeground(0x000000)
  177.   local x = 80 + dataTable[id].x
  178.   local y = 5 + dataTable[id].y
  179.   gpu.fill(x, y, 1, dataTable[id].h, "║")
  180.   gpu.fill(x + dataTable[id].w - 1, y, 1, dataTable[id].h, "║")
  181.   gpu.fill(x, y, dataTable[id].w, 1, "═")
  182.   gpu.fill(x, y + dataTable[id].h - 1, dataTable[id].w, 1, "═")
  183.   gpu.set(x, y, "╔")
  184.   gpu.set(x + dataTable[id].w - 1 , y, "╗")
  185.   gpu.set(x, y + dataTable[id].h - 1 , "╚")
  186.   gpu.set(x + dataTable[id].w - 1 , y + dataTable[id].h - 1, "╝")
  187.   if dataTable[id].textEnabled == true then
  188.     gpu.set(x + math.floor((dataTable[id].w/2)) - math.floor((string.len(dataTable[id].text)/2)+1), y, "╡" .. dataTable[id].text .. "┝")
  189.   end
  190. end
  191.  
  192. -- display a list in workspace
  193. local function displayList(id)
  194.   local x = 80 + dataTable[id].x
  195.   local y = 5 + dataTable[id].y
  196.   local t = dataTable[id].text
  197.   gpu.setBackground(0x0000FF)
  198.   gpu.setForeground(0xFFFFFF)
  199.   gpu.fill(x, y, dataTable[id].w, dataTable[id].h, " ")
  200.   gpu.fill(x, y, dataTable[id].w, 1, "═")
  201.   gpu.fill(x, y + dataTable[id].h, dataTable[id].w, 1, "═")
  202.   gpu.set(x, y + dataTable[id].h, "[<]")
  203.   gpu.set(x + dataTable[id].w -3, y + dataTable[id].h, "[>]")
  204.   if dataTable[id].textEnabled == true then
  205.     gpu.set(x + math.floor((dataTable[id].w/2)) - math.floor((string.len(dataTable[id].text)/2)+1), y, "╡" .. dataTable[id].text .. "┝")
  206.   end
  207. end
  208.  
  209. -- refresh the workspace
  210. local function refresh()
  211.   gpu.setBackground(0xC0C0C0)
  212.   gpu.fill(81, 6, 76, 21, " ")
  213.   -- set the top and bottom
  214.   gpu.setBackground(0x0000FF)
  215.   gpu.setForeground(0xFFFFFF)
  216.   gpu.fill(79, 4, 79, 1, " ")
  217.   gpu.fill(79, 28, 79, 1, " ")
  218.   toptext = dataTable.topline
  219.   local x = 117 - (string.len(toptext)/2)
  220.   gpu.set(x, 4, toptext)
  221.   local x = 117 - (string.len(dataTable.bottomline)/2)
  222.   gpu.set(x, 28, dataTable.bottomline)
  223.   if dataTable.useExit == true then
  224.     gpu.set(152, 28, "[exit]")
  225.   end
  226.  
  227.   for i = 1, dataTable.counter do
  228.       if dataTable[i].type == "button" then
  229.     displayButton(i)
  230.       elseif dataTable[i].type == "label" then
  231.     displayLabel(i)
  232.       elseif dataTable[i].type == "timelabel" then
  233.     displayTimeLabel(i)
  234.       elseif dataTable[i].type == "datelabel" then
  235.     displayDateLabel(i)
  236.       elseif dataTable[i].type == "multilabel" then
  237.     displayMultiLine(i)
  238.       elseif dataTable[i].type == "text" then
  239.     displayText(i)
  240.       elseif dataTable[i].type == "frame" then
  241.     displayFrame(i)
  242.       elseif dataTable[i].type == "hline" then
  243.     displayHLine(i)
  244.       elseif dataTable[i].type == "checkbox" then
  245.     displayCheckbox(i)
  246.       elseif dataTable[i].type == "radio" then
  247.     displayRadio(i)
  248.       elseif dataTable[i].type == "hprogress" then
  249.     displayHProgress(i)
  250.       elseif dataTable[i].type == "vprogress" then
  251.     displayVProgress(i)
  252.       elseif dataTable[i].type == "list" then
  253.     displayList(i)
  254.       elseif dataTable[i].type == "vslider" then
  255.     displayVslider(i)
  256. --      elseif dataTable[i].type == "chart" then
  257.       end
  258.   end
  259.  
  260. end
  261.  
  262. local function disableAll()
  263.   gui.setSize(myGui, valuesFrame, 41, 7,false)
  264.   gui.setVisible(myGui, wLabel, false, false)
  265.   gui.setVisible(myGui, wInput, false, false)
  266. --  gui.setVisible(myGui, wSlider, false, false)
  267.   gui.setVisible(myGui, hLabel, false, false)
  268.   gui.setVisible(myGui, hInput, false, false)
  269. --  gui.setVisible(myGui, hSlider, false, false)
  270.   gui.setVisible(myGui, minLabel, false, false)
  271.   gui.setVisible(myGui, minInput, false, false)
  272.   gui.setVisible(myGui, maxLabel, false, false)
  273.   gui.setVisible(myGui, maxInput, false, false)
  274.   gui.setVisible(myGui, valueLabel, false, false)
  275.   gui.setVisible(myGui, valueInput, false, false)
  276.   gui.setVisible(myGui, textLabel, false, false)
  277.   gui.setVisible(myGui, textInput, false, false)
  278.   gui.setVisible(myGui, textEnable, false, false)
  279.   gui.setVisible(myGui, textEnableLabel, false, false)
  280.   gui.setVisible(myGui, funcLabel, false, false)
  281.   gui.setVisible(myGui, funcInput, false, false)
  282.   gui.setVisible(myGui, pwLabel, false, false)
  283.   gui.setVisible(myGui, pwCheck, false, false)
  284.   gui.setVisible(myGui, checkLabel, false, false)
  285.   gui.setVisible(myGui, checkCheck, false, false)
  286.   gui.setVisible(myGui, bgLabel, false, false)
  287.   gui.setVisible(myGui, bgInput, false, false)
  288.   gui.setVisible(myGui, fgLabel, false, false)
  289.   gui.setVisible(myGui, fgInput, false, false)
  290.   gui.setVisible(myGui, radioLabel, false, false)
  291.   gui.setVisible(myGui, downCheck, false, false)
  292.   gui.setVisible(myGui, numberLabel, false, false)
  293.   gui.setVisible(myGui, numberCheck, false, false)
  294.   gui.setVisible(myGui, lLabel, false, false)
  295.   gui.setVisible(myGui, lInput, false, false)
  296. --  gui.setVisible(myGui, lSlider, false, false)
  297.   gui.setVisible(myGui, dataFrame, false, false)
  298.   gui.setVisible(myGui, dataList, false, false)
  299.   gui.setVisible(myGui, dataInsertText, false, false)
  300.   gui.setVisible(myGui, dataInsertButton, false, false)
  301.   gui.setVisible(myGui, dataRemoveButton, false, false)
  302.   gui.setVisible(myGui, dateFormatLabel, false, false)
  303.   gui.setVisible(myGui, dateFormatCheck, false, false)
  304.   gui.setText(myGui, nameInput, "")
  305.   gui.setText(myGui, xInput, "")
  306.   gui.setText(myGui, yInput, "")
  307. end
  308.  
  309. local function display(id, x, y)
  310.   gui.setPosition(myGui, id, x, y,false)
  311.   gui.setEnable(myGui, id, true, false)
  312.   gui.setVisible(myGui, id, true, false)
  313. end
  314.  
  315. local function elementsListCallback(guiID, listID, selected, text)
  316.   disableAll()
  317.   for i = 1, dataTable.counter do
  318.     if dataTable[i].name == text then
  319.       gui.setText(myGui, nameInput, dataTable[i].name, false)
  320.       gui.setText(myGui, xInput, tostring(dataTable[i].x), false)
  321.       gui.setText(myGui, yInput, tostring(dataTable[i].y), false)
  322.       if dataTable[i].type == "button" then
  323.     frameheight = 11
  324.     display(textLabel, 3, 34)
  325.     display(textInput, 11, 34)
  326.     display(funcLabel, 3, 36)
  327.     display(funcInput, 11, 36)
  328.     gui.setText(myGui, funcInput, dataTable[i].func, false)
  329.     gui.setText(myGui, textInput, dataTable[i].text, false)
  330.       elseif dataTable[i].type == "label" then
  331.     frameheight = 15
  332.     display(lLabel, 3, 34)
  333.     display(lInput, 11, 34)
  334.     display(textLabel, 3, 36)
  335.     display(textInput, 11, 36)
  336.     display(bgLabel, 3, 38)
  337.     display(bgInput, 22, 38)
  338.     display(fgLabel, 3, 40)
  339.     display(fgInput, 22, 40)
  340.     gui.setText(myGui, textInput, dataTable[i].text, false)
  341.     gui.setText(myGui, lInput, tostring(dataTable[i].l), false)
  342.     gui.setText(myGui, bgInput, string.format("%x",dataTable[i].bg), false)
  343.     gui.setText(myGui, fgInput, string.format("%x",dataTable[i].fg), false)
  344.       elseif dataTable[i].type == "timelabel" then
  345.     frameheight = 11
  346.     display(bgLabel, 3, 34)
  347.     display(bgInput, 22, 34)
  348.     display(fgLabel, 3, 36)
  349.     display(fgInput, 22, 36)
  350.     gui.setText(myGui, bgInput, string.format("%x",dataTable[i].bg), false)
  351.     gui.setText(myGui, fgInput, string.format("%x",dataTable[i].fg), false)
  352.       elseif dataTable[i].type == "datelabel" then
  353.     frameheight = 13
  354.     display(dateFormatLabel, 3, 34)
  355.     display(dateFormatCheck, 15, 34)
  356.     display(bgLabel, 3, 36)
  357.     display(bgInput, 22, 36)
  358.     display(fgLabel, 3, 38)
  359.     display(fgInput, 22, 38)
  360.     gui.setText(myGui, bgInput, string.format("%x",dataTable[i].bg), false)
  361.     gui.setText(myGui, fgInput, string.format("%x",dataTable[i].fg), false)
  362.     gui.setCheckbox(myGui, dateFormatCheck, dataTable[i].frm)
  363.       elseif dataTable[i].type == "multilabel" then
  364.     frameheight = 17
  365.     display(wLabel, 3, 34)
  366.     display(wInput, 11, 34)
  367.     display(hLabel, 3, 36)
  368.     display(hInput, 11, 36)
  369.     display(textLabel, 3, 38)
  370.     display(textInput, 11, 38)
  371.     display(bgLabel, 3, 40)
  372.     display(bgInput, 22, 40)
  373.     display(fgLabel, 3, 42)
  374.     display(fgInput, 22, 42)
  375.     gui.setText(myGui, textInput, dataTable[i].text, false)
  376.     gui.setText(myGui, wInput, tostring(dataTable[i].w), false)
  377.     gui.setText(myGui, hInput, tostring(dataTable[i].h), false)
  378.     gui.setText(myGui, bgInput, string.format("%x",dataTable[i].bg), false)
  379.     gui.setText(myGui, fgInput, string.format("%x",dataTable[i].fg), false)
  380.       elseif dataTable[i].type == "text" then
  381.     frameheight = 17
  382.     display(lLabel, 3, 34)
  383.     display(lInput, 11, 34)
  384.     display(textLabel, 3, 36)
  385.     display(textInput, 11, 36)
  386.     display(funcLabel, 3, 38)
  387.     display(funcInput, 11, 38)
  388.     display(maxLabel, 3, 40)
  389.     display(maxInput, 11, 40)
  390.     display(pwLabel, 3, 42)
  391.     display(pwCheck, 12, 42)
  392.     gui.setText(myGui, funcInput, dataTable[i].func, false)
  393.     gui.setText(myGui, textInput, dataTable[i].text, false)
  394.     gui.setText(myGui, lInput, tostring(dataTable[i].l), false)
  395.     gui.setText(myGui, maxInput, tostring(dataTable[i].max), false)
  396.     gui.setCheckbox(myGui, pwCheck, dataTable[i].pass)
  397.       elseif dataTable[i].type == "frame" then
  398.     frameheight = 15
  399.     display(wLabel, 3, 34)
  400.     display(wInput, 11, 34)
  401.     display(hLabel, 3, 36)
  402.     display(hInput, 11, 36)
  403.     display(textLabel, 3, 38)
  404.     display(textInput, 11, 38)
  405.     display(textEnableLabel, 3, 40)
  406.     display(textEnable, 17, 40)
  407.     gui.setText(myGui, textInput, dataTable[i].text, false)
  408.     gui.setText(myGui, wInput, tostring(dataTable[i].w), false)
  409.     gui.setText(myGui, hInput, tostring(dataTable[i].h), false)
  410.     gui.setCheckbox(myGui, textEnable, dataTable[i].enabled)
  411.       elseif dataTable[i].type == "hline" then
  412.     frameheight = 9
  413.     display(lLabel, 3, 34)
  414.     display(lInput, 11, 34)
  415.     gui.setText(myGui, lInput, tostring(dataTable[i].l), false)
  416.       elseif dataTable[i].type == "checkbox" then
  417.     frameheight = 11
  418.     display(funcLabel, 3, 34)
  419.     display(funcInput, 11, 34)
  420.     display(checkLabel, 3, 36)
  421.     display(checkCheck, 11, 36)
  422.     gui.setText(myGui, funcInput, dataTable[i].func, false)
  423.     gui.setCheckbox(myGui, checkCheck, dataTable[i].checked)
  424.       elseif dataTable[i].type == "radio" then
  425.     frameheight = 9
  426.     display(funcLabel, 3, 34)
  427.     display(funcInput, 11, 34)
  428.     gui.setText(myGui, funcInput, dataTable[i].func, false)
  429.       elseif dataTable[i].type == "hprogress" then
  430.     frameheight = 17
  431.     display(lLabel, 3, 34)
  432.     display(lInput, 11, 34)
  433.     display(maxLabel, 3, 36)
  434.     display(maxInput, 11, 36)
  435.     display(valueLabel, 3, 38)
  436.     display(valueInput, 11, 38)
  437.     display(funcLabel, 3, 40)
  438.     display(funcInput, 11, 40)
  439.     display(numberLabel, 3, 42)
  440.     display(numberCheck, 15, 42)
  441.     gui.setText(myGui, funcInput, dataTable[i].func, false)
  442.     gui.setText(myGui, lInput, tostring(dataTable[i].l), false)
  443.     gui.setText(myGui, maxInput, tostring(dataTable[i].max), false)
  444.     gui.setText(myGui, valueInput, tostring(dataTable[i].value), false)
  445.     gui.setCheckbox(myGui, numberCheck, dataTable[i].number)
  446.       elseif dataTable[i].type == "vprogress" then
  447.     frameheight = 19
  448.     display(lLabel, 3, 34)
  449.     display(lInput, 11, 34)
  450.     display(wLabel, 3, 36)
  451.     display(wInput, 11, 36)
  452.     display(maxLabel, 3, 38)
  453.     display(maxInput, 11, 38)
  454.     display(valueLabel, 3, 40)
  455.     display(valueInput, 11, 40)
  456.     display(funcLabel, 3, 42)
  457.     display(funcInput, 11, 42)
  458.     display(radioLabel, 3, 44)
  459.     display(downCheck, 20, 44)
  460.     gui.setText(myGui, funcInput, dataTable[i].func, false)
  461.     gui.setText(myGui, wInput, tostring(dataTable[i].w), false)
  462.     gui.setText(myGui, lInput, tostring(dataTable[i].l), false)
  463.     gui.setText(myGui, maxInput, tostring(dataTable[i].max), false)
  464.     gui.setText(myGui, valueInput, tostring(dataTable[i].value), false)
  465.     gui.setCheckbox(myGui, downCheck, dataTable[i].direction)
  466.       elseif dataTable[i].type == "list" then
  467.     frameheight = 17
  468.     display(wLabel, 3, 34)
  469.     display(wInput, 11, 34)
  470.     display(hLabel, 3, 36)
  471.     display(hInput, 11, 36)
  472.     display(funcLabel, 3, 38)
  473.     display(funcInput, 11, 38)
  474.     display(textLabel, 3, 40)
  475.     display(textInput, 11, 40)
  476.     display(textEnableLabel, 3, 42)
  477.     display(textEnable, 17, 42)
  478.     gui.setSize(myGui, dataList, 30, 15, false)
  479.     display(dataFrame, 44, 24)
  480.     display(dataList, 45, 25)
  481.     display(dataInsertText, 44, 41)
  482.     display(dataInsertButton, 44, 43)
  483.     display(dataRemoveButton, 44, 45)
  484.     gui.setText(myGui, funcInput, dataTable[i].func, false)
  485.     gui.setText(myGui, textInput, dataTable[i].text, false)
  486.     gui.setText(myGui, wInput, tostring(dataTable[i].w), false)
  487.     gui.setText(myGui, hInput, tostring(dataTable[i].h), false)
  488.     gui.setCheckbox(myGui, textEnable, dataTable[i].enabled)
  489.     gui.clearList(myGui, dataList)
  490.     for k,v in pairs(dataTable[i].data) do
  491.       gui.insertList(myGui, dataList, v)
  492.     end
  493.       elseif dataTable[i].type == "vslider" then
  494.     frameheight = 17
  495.     display(lLabel, 3, 34)
  496.     display(lInput, 11, 34)
  497.     display(minLabel, 3, 36)
  498.     display(minInput, 11, 36)
  499.     display(maxLabel, 3, 38)
  500.     display(maxInput, 11, 38)
  501.     display(valueLabel, 3, 40)
  502.     display(valueInput, 11, 40)
  503.     display(funcLabel, 3, 42)
  504.     display(funcInput, 11, 42)
  505.     gui.setText(myGui, funcInput, dataTable[i].func, false)
  506.     gui.setText(myGui, lInput, tostring(dataTable[i].l), false)
  507.     gui.setText(myGui, maxInput, tostring(dataTable[i].max), false)
  508.     gui.setText(myGui, minInput, tostring(dataTable[i].min), false)
  509.     gui.setText(myGui, valueInput, tostring(dataTable[i].value), false)
  510. --[[      elseif dataTable[i].type == "chart" then
  511.     frameheight = 19
  512.     display(minLabel, 3, 34)
  513.     display(minInput, 11, 34)
  514.     display(maxLabel, 3, 36)
  515.     display(maxInput, 11, 36)
  516.     display(lLabel, 3, 38)
  517.     display(lInput, 11, 38)
  518.     display(hLabel, 3, 40)
  519.     display(hInput, 11, 40)
  520.     display(bgLabel, 3, 42)
  521.     display(bgInput, 22, 42)
  522.     display(fgLabel, 3, 44)
  523.     display(fgInput, 22, 44)
  524.     gui.setSize(myGui, dataList, 30, 19, false)
  525.     gui.setText(myGui, lInput, tostring(dataTable[i].l), false)
  526.     gui.setText(myGui, maxInput, tostring(dataTable[i].max), false)
  527.     gui.setText(myGui, minInput, tostring(dataTable[i].min), false)
  528.     gui.setText(myGui, hInput, tostring(dataTable[i].h), false)
  529.     display(dataList, 45, 25) ]]--
  530.       end
  531.       break
  532.     end
  533.   end
  534.   gui.setSize(myGui, valuesFrame, 40, frameheight)
  535.   refresh()
  536. end
  537.  
  538.  
  539. local function exitButtonCallback(guiID, id)
  540.   local result = gui.getYesNo("", "Do you really want to exit?", "")
  541.   if result == true then
  542.     gui.exit()
  543.   end
  544.   gui.displayGui(myGui)
  545.   refresh()
  546. end
  547.  
  548. -- Any option changed
  549. local function versionTextCallback(guiID, id)
  550.   dataTable.version = gui.getText(guiID, id)
  551.   refresh()
  552. end
  553. local function topLineTextCallback(guiID, id)
  554.   dataTable.topline = gui.getText(guiID, id)
  555.   refresh()
  556. end
  557. local function bottomLineTextCallback(guiID, id)
  558.   dataTable.bottomline = gui.getText(guiID, id)
  559.   refresh()
  560. end
  561.  
  562. -- file handling
  563. local function loadCallback(guiID, id)
  564.   dataTable = gui.loadTable("/home/" .. dataTable.filename .. ".vdat")
  565.   gui.setText(myGui, versionText, dataTable.version)
  566.   gui.setText(myGui, topLineText, dataTable.topline)
  567.   gui.setText(myGui, bottomLineText, dataTable.bottomline)
  568.   gui.setCheckbox(myGui, setExitButtonCheckbox, dataTable.useExit)
  569.   gui.clearList(guiID, elementsList)
  570.   for i = 1, dataTable.counter do
  571.     gui.insertList(guiID, elementsList, dataTable[i].name)
  572.   end
  573.   gui.setSelected(guiID, elementsList, 1)
  574.   elementsListCallback(myGui, elementsList, 1, dataTable[1].name)
  575.   refresh()
  576. end
  577. local function saveCallback(guiID, id)
  578.   gui.saveTable(dataTable, dataTable.filename .. ".vdat")
  579.   refresh()
  580. end
  581.  
  582. local function writeCallbackEnd(file, t)
  583.     file:write(t)
  584.     file:write("   -- Your code here\n")
  585.     file:write("end\n")
  586.     file:write("\n")
  587. end
  588.  
  589. local function writeCodeCallback(guiID, id)
  590.   local lines = 28
  591.   file,err = io.open(dataTable.filename .. ".lua" , "w" )
  592.  
  593.   file:write("local component = require(\"component\")\n")
  594.   file:write("local gpu = component.gpu\n")
  595.   file:write("gpu.setResolution(80,25)\n")
  596.   file:write("local gui = require(\"gui\")\n")
  597.   file:write("local event = require(\"event\")\n")
  598.   file:write("\n")
  599.   file:write("gui.checkVersion(" .. guiMajor .. "," .. guiMinor .. ")\n")
  600.   file:write("\n")
  601.   file:write("local prgName = \"" .. dataTable.filename .. "\"\n")
  602.   file:write("local version = \"v" .. dataTable.version .. "\"\n")
  603.   file:write("\n")
  604.   file:write("-- Begin: Callbacks\n")
  605.  
  606.   for i = 1, dataTable.counter do
  607.       local t = ""
  608.       if dataTable[i].type == "button" then
  609.     t = "local function " .. dataTable[i].func .. "(guiID, buttonID)\n"
  610.     writeCallbackEnd(file, t)
  611.     lines = lines + 4
  612.       elseif dataTable[i].type == "text" then
  613.     t = "local function " .. dataTable[i].func .. "(guiID, textID, text)\n"
  614.     writeCallbackEnd(file, t)
  615.     lines = lines + 4
  616.       elseif dataTable[i].type == "checkbox" then
  617.     t = "local function " .. dataTable[i].func .. "(guiID, checkboxID, status)\n"
  618.     writeCallbackEnd(file, t)
  619.     lines = lines + 4
  620.       elseif dataTable[i].type == "radio" then
  621.     t = "local function " .. dataTable[i].func .. "(guiID, radioID, status)\n"
  622.     writeCallbackEnd(file, t)
  623.     lines = lines + 4
  624.       elseif dataTable[i].type == "hprogress" then
  625.     t = "local function " .. dataTable[i].func .. "(guiID, hProgressID)\n"
  626.     writeCallbackEnd(file, t)
  627.     lines = lines + 4
  628.       elseif dataTable[i].type == "vprogress" then
  629.     t = "local function " .. dataTable[i].func .. "(guiID, vProgressID)\n"
  630.     writeCallbackEnd(file, t)
  631.     lines = lines + 4
  632.       elseif dataTable[i].type == "list" then
  633.     t = "local function " .. dataTable[i].func .. "(guiID, listID, selected, text)\n"
  634.     writeCallbackEnd(file, t)
  635.     lines = lines + 4
  636.       elseif dataTable[i].type == "vslider" then
  637.     t = "local function " .. dataTable[i].func .. "(guiID, vSliderID, value)\n"
  638.     writeCallbackEnd(file, t)
  639.     lines = lines + 4
  640. --      elseif dataTable[i].type == "chart" then
  641.       end
  642.   end
  643.  
  644.   if dataTable.useExit == true then
  645.     file:write("local function exitButtonCallback(guiID, id)\n")
  646.     file:write("   local result = gui.getYesNo(\"\", \"Do you really want to exit?\", \"\")\n")
  647.     file:write("   if result == true then\n")
  648.     file:write("      gui.exit()\n")
  649.     file:write("   end\n")
  650.     file:write("   gui.displayGui(mainGui)\n")
  651.     file:write("   refresh()\n")
  652.     file:write("end\n")
  653.     lines = lines + 8
  654.   end
  655.  
  656.   file:write("-- End: Callbacks\n")
  657.   file:write("\n")
  658.   file:write("-- Begin: Menu definitions\n")
  659.   file:write("mainGui = gui.newGui(1, 2, 79, 23, true)\n")
  660.  
  661.   for i = 1, dataTable.counter do
  662.       local t = ""
  663.       if dataTable[i].type == "button" then
  664.     t = dataTable[i].name .. " = gui.newButton(mainGui, " .. dataTable[i].x .. ", " .. dataTable[i].y .. ", \"" .. dataTable[i].text .. "\", " .. dataTable[i].func .. ")\n"
  665.     file:write(t)
  666.     lines = lines + 1
  667.       elseif dataTable[i].type == "label" then
  668.     t = dataTable[i].name .. " = gui.newLabel(mainGui, " .. dataTable[i].x .. ", " .. dataTable[i].y .. ", \"" .. dataTable[i].text .. "\", " .. string.format("0x%x, 0x%x, ", dataTable[i].bg, dataTable[i].fg) .. dataTable[i].l .. ")\n"
  669.     file:write(t)
  670.     lines = lines + 1
  671.       elseif dataTable[i].type == "timelabel" then
  672.     t = dataTable[i].name .. " = gui.newTimeLabel(mainGui, " .. dataTable[i].x .. ", " .. dataTable[i].y .. ", " .. string.format("0x%x, 0x%x", dataTable[i].bg, dataTable[i].fg) .. ")\n"
  673.     file:write(t)
  674.     lines = lines + 1
  675.       elseif dataTable[i].type == "datelabel" then
  676.     if dataTable[i].frm == true then
  677.       t = dataTable[i].name .. " = gui.newDateLabel(mainGui, " .. dataTable[i].x .. ", " .. dataTable[i].y .. ", " .. string.format("0x%x, 0x%x, ", dataTable[i].bg, dataTable[i].fg) .. tostring(dataTable[i].frm) .. ")\n"
  678.     else
  679.       t = dataTable[i].name .. " = gui.newDateLabel(mainGui, " .. dataTable[i].x .. ", " .. dataTable[i].y .. ", " .. string.format("0x%x, 0x%x", dataTable[i].bg, dataTable[i].fg) .. ")\n"
  680.     end
  681.     file:write(t)
  682.     lines = lines + 1
  683.       elseif dataTable[i].type == "multilabel" then
  684.     t = dataTable[i].name .. " = gui.newMultiLineLabel(mainGui, " .. dataTable[i].x .. ", " .. dataTable[i].y .. ", " .. dataTable[i].w .. ", " .. dataTable[i].h .. ", \"" .. dataTable[i].text .. "\", " .. string.format("0x%x, 0x%x)\n", dataTable[i].bg, dataTable[i].fg)
  685.     file:write(t)
  686.     lines = lines + 1
  687.       elseif dataTable[i].type == "text" then
  688.     t = dataTable[i].name .. " = gui.newText(mainGui, " .. dataTable[i].x .. ", " .. dataTable[i].y .. ", " .. dataTable[i].max .. ", \"" .. dataTable[i].text .. "\", " .. dataTable[i].func .. ", " .. dataTable[i].l .. ", " .. tostring(dataTable[i].pass) .. ")\n"
  689.     file:write(t)
  690.     lines = lines + 1
  691.       elseif dataTable[i].type == "frame" then
  692.     if dataTable[i].textEnabled == true then
  693.       t = dataTable[i].name .. " = gui.newFrame(mainGui, " .. dataTable[i].x .. ", " .. dataTable[i].y .. ", " .. dataTable[i].w .. ", " .. dataTable[i].h .. ", \"" .. dataTable[i].text .. "\")\n"
  694.     else
  695.       t = dataTable[i].name .. " = gui.newFrame(mainGui, " .. dataTable[i].x .. ", " .. dataTable[i].y .. ", " .. dataTable[i].w .. ", " .. dataTable[i].h .. ")\n"
  696.     end
  697.     file:write(t)
  698.     lines = lines + 1
  699.       elseif dataTable[i].type == "hline" then
  700.     t = dataTable[i].name .. " = gui.newHLine(mainGui, " .. dataTable[i].x .. ", " .. dataTable[i].y .. ", " .. dataTable[i].l .. ")\n"
  701.     file:write(t)
  702.     lines = lines + 1
  703.       elseif dataTable[i].type == "checkbox" then
  704.     t = dataTable[i].name .. " = gui.newCheckbox(mainGui, " .. dataTable[i].x .. ", " .. dataTable[i].y .. ", " .. tostring(dataTable[i].checked) .. ", " .. dataTable[i].func .. ")\n"
  705.     file:write(t)
  706.     lines = lines + 1
  707.       elseif dataTable[i].type == "radio" then
  708.     t = dataTable[i].name .. " = gui.newRadio(mainGui, " .. dataTable[i].x .. ", " .. dataTable[i].y .. ", " .. dataTable[i].func .. ")\n"
  709.     file:write(t)
  710.     lines = lines + 1
  711.       elseif dataTable[i].type == "hprogress" then
  712.     t = dataTable[i].name .. " = gui.newProgress(mainGui, " .. dataTable[i].x .. ", " .. dataTable[i].y .. ", " .. dataTable[i].l .. ", " .. dataTable[i].max .. ", " .. dataTable[i].value .. ", " .. dataTable[i].func .. ", " .. tostring(dataTable[i].number) .. ")\n"
  713.     file:write(t)
  714.     lines = lines + 1
  715.       elseif dataTable[i].type == "vprogress" then
  716.     t = dataTable[i].name .. " = gui.newVProgress(mainGui, " .. dataTable[i].x .. ", " .. dataTable[i].y .. ", " .. dataTable[i].l .. ", " .. dataTable[i].w .. ", " .. dataTable[i].max .. ", " .. dataTable[i].value .. ", " .. dataTable[i].func .. ", " .. tostring(dataTable[i].direction) .. ")\n"
  717.     file:write(t)
  718.     lines = lines + 1
  719.       elseif dataTable[i].type == "list" then
  720.     if dataTable[i].textEnabled == true then
  721.       t = dataTable[i].name .. " = gui.newList(mainGui, " .. dataTable[i].x .. ", " .. dataTable[i].y .. ", " .. dataTable[i].w .. ", " .. dataTable[i].h .. ", {}, " .. dataTable[i].func .. ", " .. dataTable[i].text .. ")\n"
  722.     else
  723.       t = dataTable[i].name .. " = gui.newList(mainGui, " .. dataTable[i].x .. ", " .. dataTable[i].y .. ", " .. dataTable[i].w .. ", " .. dataTable[i].h .. ", {}, " .. dataTable[i].func .. ")\n"
  724.     end
  725.     file:write(t)
  726.     lines = lines + 1
  727.     for k,v in pairs(dataTable[i].data) do
  728.       file:write("gui.insertList(mainGui, ".. dataTable[i].name ..", \"" .. v .. "\")\n")
  729.       lines = lines + 1
  730.     end
  731.       elseif dataTable[i].type == "vslider" then
  732.     t = dataTable[i].name .. " = gui.newVSlider(mainGui, " .. dataTable[i].x .. ", " .. dataTable[i].y .. ", " .. dataTable[i].l .. ", " ..dataTable[i].min .. ", " .. dataTable[i].max .. ", " .. dataTable[i].value .. ", " .. dataTable[i].func .. ")\n"
  733.     file:write(t)
  734.     lines = lines + 1
  735. --      elseif dataTable[i].type == "chart" then
  736.       end
  737.   end
  738.  
  739.   if dataTable.useExit == true then
  740.     t = "exitButton = gui.newButton(mainGui, 73, 23, \"exit\", exitButtonCallback)\n"
  741.     file:write(t)
  742.     lines = lines + 1
  743.   end
  744.  
  745.   file:write("-- End: Menu definitions\n")
  746.   file:write("\n")
  747.   file:write("gui.clearScreen()\n")
  748.   file:write("gui.setTop(\"" .. dataTable.topline .. "\")\n")
  749.   file:write("gui.setBottom(\"" .. dataTable.bottomline .. "\")\n")
  750.   file:write("\n")
  751.   file:write("-- Main loop\n")
  752.   file:write("while true do\n")
  753.   file:write("   gui.runGui(mainGui)\n")
  754.   file:write("end\n\n\n")
  755.  
  756.   file:close()
  757.  
  758.   gui.showMsg("File ".. dataTable.filename .. ".lua saved", "", string.format("%d lines written", lines))
  759.  
  760.   refresh()
  761. end
  762.  
  763.  
  764. local function newButtonCallback(guiID, id)
  765.   local tmpTable = {}
  766.   tmpTable["type"] = "button"
  767.   tmpTable["name"] = string.format("button_%d", buttonCounter)
  768.   buttonCounter = buttonCounter + 1
  769.   tmpTable["x"] = 1
  770.   tmpTable["y"] = 1
  771.   tmpTable["text"] = tmpTable["name"]
  772.   tmpTable["func"] = tmpTable["name"] .. "_callback"
  773.  
  774.   dataTable.counter = dataTable.counter + 1
  775.   table.insert(dataTable, tmpTable)
  776.   gui.insertList(myGui, elementsList, tmpTable.name)
  777.   gui.setSelected(myGui, elementsList, dataTable.counter)
  778.   elementsListCallback(myGui, elementsList, dataTable.counter, tmpTable.name)
  779.   refresh()
  780. end
  781. --[[
  782. local function newChartCallback(guiID, id)
  783.   local tmpTable = {}
  784.   tmpTable["type"] = "chart"
  785.   tmpTable["name"] = string.format("chart_%d", chartCounter)
  786.   chartCounter = chartCounter + 1
  787.   tmpTable["x"] = 1
  788.   tmpTable["y"] = 1
  789.   tmpTable["bg"] = 0x0000FF
  790.   tmpTable["fg"] = 0xFFFFFF
  791.   tmpTable["w"] = 10
  792.   tmpTable["h"] = 10
  793.   tmpTable["max"] = 1
  794.   tmpTable["min"] = 1
  795.   tmpTable["data"] = {}
  796.  
  797.   dataTable.counter = dataTable.counter + 1
  798.   table.insert(dataTable, tmpTable)
  799.   gui.insertList(myGui, elementsList, tmpTable.name)
  800.   gui.setSelected(myGui, elementsList, dataTable.counter)
  801.   elementsListCallback(myGui, elementsList, dataTable.counter, tmpTable.name)
  802.   refresh()
  803. end
  804. ]]--
  805. local function newCheckboxCallback(guiID, id)
  806.   local tmpTable = {}
  807.   tmpTable["type"] = "checkbox"
  808.   tmpTable["name"] = string.format("checkbox_%d", checkboxCounter)
  809.   checkboxCounter = checkboxCounter + 1
  810.   tmpTable["x"] = 1
  811.   tmpTable["y"] = 1
  812.   tmpTable["checked"] = false
  813.   tmpTable["func"] = tmpTable["name"] .. "_callback"
  814.  
  815.   dataTable.counter = dataTable.counter + 1
  816.   table.insert(dataTable, tmpTable)
  817.   gui.insertList(myGui, elementsList, tmpTable.name)
  818.   gui.setSelected(myGui, elementsList, dataTable.counter)
  819.   elementsListCallback(myGui, elementsList, dataTable.counter, tmpTable.name)
  820.   refresh()
  821. end
  822.  
  823. local function newFrameCallback(guiID, id)
  824.   local tmpTable = {}
  825.   tmpTable["type"] = "frame"
  826.   tmpTable["name"] = string.format("frame_%d", frameCounter)
  827.   frameCounter = frameCounter +1
  828.   tmpTable["x"] = 1
  829.   tmpTable["y"] = 1
  830.   tmpTable["text"] = tmpTable["name"]
  831.   tmpTable["w"] = 20
  832.   tmpTable["h"] = 10
  833.   tmpTable["textEnabled"] = false
  834.  
  835.   dataTable.counter = dataTable.counter + 1
  836.   table.insert(dataTable, tmpTable)
  837.   gui.insertList(myGui, elementsList, tmpTable.name)
  838.   gui.setSelected(myGui, elementsList, dataTable.counter)
  839.   elementsListCallback(myGui, elementsList, dataTable.counter, tmpTable.name)
  840.   refresh()
  841. end
  842.  
  843. local function newHLineCallback(guiID, id)
  844.   local tmpTable = {}
  845.   tmpTable["type"] = "hline"
  846.   tmpTable["name"] = string.format("hline_%d", hlineCounter)
  847.   hlineCounter = hlineCounter + 1
  848.   tmpTable["x"] = 1
  849.   tmpTable["y"] = 1
  850.   tmpTable["l"] = 10
  851.  
  852.   dataTable.counter = dataTable.counter + 1
  853.   table.insert(dataTable, tmpTable)
  854.   gui.insertList(myGui, elementsList, tmpTable.name)
  855.   gui.setSelected(myGui, elementsList, dataTable.counter)
  856.   elementsListCallback(myGui, elementsList, dataTable.counter, tmpTable.name)
  857.   refresh()
  858. end
  859.  
  860. local function newHProgressCallback(guiID, id)
  861.   local tmpTable = {}
  862.   tmpTable["type"] = "hprogress"
  863.   tmpTable["name"] = string.format("hprogress_%d", hprogressCounter)
  864.   hprogressCounter = hprogressCounter + 1
  865.   tmpTable["x"] = 1
  866.   tmpTable["y"] = 1
  867.   tmpTable["l"] = 10
  868.   tmpTable["func"] = tmpTable["name"] .. "_callback"
  869.   tmpTable["max"] = 10
  870.   tmpTable["value"] = 1
  871.   tmpTable["number"] = false
  872.  
  873.   dataTable.counter = dataTable.counter + 1
  874.   table.insert(dataTable, tmpTable)
  875.   gui.insertList(myGui, elementsList, tmpTable.name)
  876.   gui.setSelected(myGui, elementsList, dataTable.counter)
  877.   elementsListCallback(myGui, elementsList, dataTable.counter, tmpTable.name)
  878.   refresh()
  879. end
  880.  
  881. local function newLabelCallback(guiID, id)
  882.   local tmpTable = {}
  883.   tmpTable["type"] = "label"
  884.   tmpTable["name"] = string.format("label_%d", labelCounter)
  885.   labelCounter = labelCounter + 1
  886.   tmpTable["x"] = 1
  887.   tmpTable["y"] = 1
  888.   tmpTable["text"] = tmpTable["name"]
  889.   tmpTable["l"] = string.len(tmpTable["text"])
  890.   tmpTable["bg"] = 0xC0C0C0
  891.   tmpTable["fg"] = 0x000000
  892.  
  893.   dataTable.counter = dataTable.counter + 1
  894.   table.insert(dataTable, tmpTable)
  895.   gui.insertList(myGui, elementsList, tmpTable.name)
  896.   gui.setSelected(myGui, elementsList, dataTable.counter)
  897.   elementsListCallback(myGui, elementsList, dataTable.counter, tmpTable.name)
  898.   refresh()
  899. end
  900.  
  901. local function newTimeLabelCallback(guiID, id)
  902.   local tmpTable = {}
  903.   tmpTable["type"] = "timelabel"
  904.   tmpTable["name"] = string.format("timelabel_%d", timelabelcounter)
  905.   timelabelcounter = timelabelcounter + 1
  906.   tmpTable["x"] = 1
  907.   tmpTable["y"] = 1
  908.   tmpTable["bg"] = 0xC0C0C0
  909.   tmpTable["fg"] = 0x000000
  910.  
  911.   dataTable.counter = dataTable.counter + 1
  912.   table.insert(dataTable, tmpTable)
  913.   gui.insertList(myGui, elementsList, tmpTable.name)
  914.   gui.setSelected(myGui, elementsList, dataTable.counter)
  915.   elementsListCallback(myGui, elementsList, dataTable.counter, tmpTable.name)
  916.   refresh()
  917. end
  918.  
  919. local function newDateLabelCallback(guiID, id)
  920.   local tmpTable = {}
  921.   tmpTable["type"] = "datelabel"
  922.   tmpTable["name"] = string.format("datelabel_%d", datelabelcounter)
  923.   datelabelcounter = datelabelcounter + 1
  924.   tmpTable["x"] = 1
  925.   tmpTable["y"] = 1
  926.   tmpTable["bg"] = 0xC0C0C0
  927.   tmpTable["fg"] = 0x000000
  928.   tmpTable["frm"] = false
  929.  
  930.   dataTable.counter = dataTable.counter + 1
  931.   table.insert(dataTable, tmpTable)
  932.   gui.insertList(myGui, elementsList, tmpTable.name)
  933.   gui.setSelected(myGui, elementsList, dataTable.counter)
  934.   elementsListCallback(myGui, elementsList, dataTable.counter, tmpTable.name)
  935.   refresh()
  936. end
  937.  
  938. local function newListCallback(guiID, id)
  939.   local tmpTable = {}
  940.   tmpTable["type"] = "list"
  941.   tmpTable["name"] = string.format("list_%d", listCounter)
  942.   listCounter = listCounter + 1
  943.   tmpTable["x"] = 1
  944.   tmpTable["y"] = 1
  945.   tmpTable["text"] = tmpTable["name"]
  946.   tmpTable["func"] = tmpTable["name"] .. "_callback"
  947.   tmpTable["w"] = 20
  948.   tmpTable["h"] = 10
  949.   tmpTable["data"] = {}
  950.   tmpTable["textEnabled"] = false
  951.  
  952.   dataTable.counter = dataTable.counter + 1
  953.   table.insert(dataTable, tmpTable)
  954.   gui.insertList(myGui, elementsList, tmpTable.name)
  955.   gui.setSelected(myGui, elementsList, dataTable.counter)
  956.   elementsListCallback(myGui, elementsList, dataTable.counter, tmpTable.name)
  957.   refresh()
  958. end
  959.  
  960. local function newMultiLabelCallback(guiID, id)
  961.   local tmpTable = {}
  962.   tmpTable["type"] = "multilabel"
  963.   tmpTable["name"] = string.format("multilabel_%d", multiLabelCounter)
  964.   multiLabelCounter = multiLabelCounter + 1
  965.   tmpTable["x"] = 1
  966.   tmpTable["y"] = 1
  967.   tmpTable["text"] = tmpTable["name"]
  968.   tmpTable["bg"] = 0xC0C0C0
  969.   tmpTable["fg"] = 0xFFFFFF
  970.   tmpTable["w"] = 10
  971.   tmpTable["h"] = 10
  972.  
  973.   dataTable.counter = dataTable.counter + 1
  974.   table.insert(dataTable, tmpTable)
  975.   gui.insertList(myGui, elementsList, tmpTable.name)
  976.   gui.setSelected(myGui, elementsList, dataTable.counter)
  977.   elementsListCallback(myGui, elementsList, dataTable.counter, tmpTable.name)
  978.   refresh()
  979. end
  980.  
  981. local function newRadioButtonCallback(guiID, id)
  982.   local tmpTable = {}
  983.   tmpTable["type"] = "radio"
  984.   tmpTable["name"] = string.format("radiobutton_%d", radioCounter)
  985.   radioCounter = radioCounter + 1
  986.   tmpTable["x"] = 1
  987.   tmpTable["y"] = 1
  988.   tmpTable["func"] = tmpTable["name"] .. "_callback"
  989.  
  990.   dataTable.counter = dataTable.counter + 1
  991.   table.insert(dataTable, tmpTable)
  992.   gui.insertList(myGui, elementsList, tmpTable.name)
  993.   gui.setSelected(myGui, elementsList, dataTable.counter)
  994.   elementsListCallback(myGui, elementsList, dataTable.counter, tmpTable.name)
  995.   refresh()
  996. end
  997.  
  998. local function newTextCallback(guiID, id)
  999.   local tmpTable = {}
  1000.   tmpTable["type"] = "text"
  1001.   tmpTable["name"] = string.format("text_%d", textCounter)
  1002.   textCounter = textCounter + 1
  1003.   tmpTable["x"] = 1
  1004.   tmpTable["y"] = 1
  1005.   tmpTable["l"] = 10
  1006.   tmpTable["text"] = tmpTable["name"]
  1007.   tmpTable["func"] = tmpTable["name"] .. "_callback"
  1008.   tmpTable["max"] = 10
  1009.   tmpTable["pass"] = false
  1010.  
  1011.   dataTable.counter = dataTable.counter + 1
  1012.   table.insert(dataTable, tmpTable)
  1013.   gui.insertList(myGui, elementsList, tmpTable.name)
  1014.   gui.setSelected(myGui, elementsList, dataTable.counter)
  1015.   elementsListCallback(myGui, elementsList, dataTable.counter, tmpTable.name)
  1016.   refresh()
  1017. end
  1018.  
  1019. local function newVProgressCallback(guiID, id)
  1020.   local tmpTable = {}
  1021.   tmpTable["type"] = "vprogress"
  1022.   tmpTable["name"] = string.format("vprogress_%d", vprogressCounter)
  1023.   vprogressCounter = vprogressCounter + 1
  1024.   tmpTable["x"] = 1
  1025.   tmpTable["y"] = 1
  1026.   tmpTable["func"] = tmpTable["name"] .. "_callback"
  1027.   tmpTable["w"] = 1
  1028.   tmpTable["l"] = 10
  1029.   tmpTable["max"] = 10
  1030.   tmpTable["value"] = 1
  1031.   tmpTable["direction"] = false
  1032.  
  1033.   dataTable.counter = dataTable.counter + 1
  1034.   table.insert(dataTable, tmpTable)
  1035.   gui.insertList(myGui, elementsList, tmpTable.name)
  1036.   gui.setSelected(myGui, elementsList, dataTable.counter)
  1037.   elementsListCallback(myGui, elementsList, dataTable.counter, tmpTable.name)
  1038.   refresh()
  1039. end
  1040.  
  1041. local function newVSliderCallback(guiID, id)
  1042.   local tmpTable = {}
  1043.   tmpTable["type"] = "vslider"
  1044.   tmpTable["name"] = string.format("vslider_%d", vsliderCounter)
  1045.   vsliderCounter = vsliderCounter + 1
  1046.   tmpTable["x"] = 1
  1047.   tmpTable["y"] = 1
  1048.   tmpTable["l"] = 10
  1049.   tmpTable["func"] = tmpTable["name"] .. "_callback"
  1050.   tmpTable["max"] = 10
  1051.   tmpTable["min"] = 1
  1052.   tmpTable["value"] = 1
  1053.  
  1054.   dataTable.counter = dataTable.counter + 1
  1055.   table.insert(dataTable, tmpTable)
  1056.   gui.insertList(myGui, elementsList, tmpTable.name)
  1057.   gui.setSelected(myGui, elementsList, dataTable.counter)
  1058.   elementsListCallback(myGui, elementsList, dataTable.counter, tmpTable.name)
  1059.   refresh()
  1060. end
  1061.  
  1062.  
  1063. local function nameInputCallback(guiID, id)
  1064.   dataTable[gui.getSelected(guiID, elementsList)].name = gui.getText(guiID, id)
  1065.   gui.renameList(guiID, elementsList, gui.getSelected(guiID, elementsList) , gui.getText(guiID, id))
  1066.   refresh()
  1067. end
  1068.  
  1069. local function xInputCallback(guiID, id)
  1070.   dataTable[gui.getSelected(guiID, elementsList)].x = tonumber(gui.getText(guiID, id))
  1071.   refresh()
  1072. end
  1073.  
  1074. local function yInputCallback(guiID, id)
  1075.   dataTable[gui.getSelected(guiID, elementsList)].y = tonumber(gui.getText(guiID, id))
  1076.   refresh()
  1077. end
  1078.  
  1079. local function wInputCallback(guiID, id)
  1080.   dataTable[gui.getSelected(guiID, elementsList)].w = tonumber(gui.getText(guiID, id))
  1081.   refresh()
  1082. end
  1083.  
  1084. local function hInputCallback(guiID, id)
  1085.   dataTable[gui.getSelected(guiID, elementsList)].h = tonumber(gui.getText(guiID, id))
  1086.   refresh()
  1087. end
  1088.  
  1089. local function lInputCallback(guiID, id)
  1090.   dataTable[gui.getSelected(guiID, elementsList)].l = tonumber(gui.getText(guiID, id))
  1091.   refresh()
  1092. end
  1093.  
  1094. local function bgInputCallback(guiID, id)
  1095.   dataTable[gui.getSelected(guiID, elementsList)].bg = tonumber(gui.getText(guiID, id),16)
  1096.   refresh()
  1097. end
  1098.  
  1099. local function fgInputCallback(guiID, id)
  1100.   dataTable[gui.getSelected(guiID, elementsList)].fg = tonumber(gui.getText(guiID, id),16)
  1101.   refresh()
  1102. end
  1103.  
  1104. local function funcInputCallback(guiID, id)
  1105.   dataTable[gui.getSelected(guiID, elementsList)].func = gui.getText(guiID, id)
  1106.   refresh()
  1107. end
  1108.  
  1109. local function textInputCallback(guiID, id)
  1110.   dataTable[gui.getSelected(guiID, elementsList)].text = gui.getText(guiID, id)
  1111.   refresh()
  1112. end
  1113.  
  1114. local function minInputCallback(guiID, id)
  1115.   dataTable[gui.getSelected(guiID, elementsList)].min = tonumber(gui.getText(guiID, id))
  1116.   refresh()
  1117. end
  1118.  
  1119. local function maxInputCallback(guiID, id)
  1120.   dataTable[gui.getSelected(guiID, elementsList)].max = tonumber(gui.getText(guiID, id))
  1121.   refresh()
  1122. end
  1123.  
  1124. local function valueInputCallback(guiID, id)
  1125.   dataTable[gui.getSelected(guiID, elementsList)].value = tonumber(gui.getText(guiID, id))
  1126.   refresh()
  1127. end
  1128.  
  1129. local function fileNameTextCallback(guiID, id)
  1130.   dataTable.filename = gui.getText(guiID, id)
  1131.   refresh()
  1132. end
  1133.  
  1134. local function deleteButtonCallback(guiID, id)
  1135.   if gui.getSelected(guiID, elementsList) > 0 then
  1136.     table.remove(dataTable, gui.getSelected(guiID, elementsList))
  1137.     gui.removeList(guiID, elementsList, gui.getSelected(guiID, elementsList))
  1138.     dataTable.counter = dataTable.counter - 1
  1139.     if dataTable.counter > 0 then
  1140.       gui.setSelected(guiID, elementsList, 1)
  1141.       elementsListCallback(myGui, elementsList, 1, dataTable[1].name)
  1142.     else
  1143.       disableAll()
  1144.       gui.setSize(myGui, valuesFrame, 40, 7)
  1145.     end
  1146.   end
  1147.   refresh()
  1148. end
  1149.  
  1150. local function dataRemoveButtonCallback(guiID, id)
  1151.   gui.removeList(guiID, dataList, gui.getSelected(guiID, dataList))
  1152.   refresh()
  1153. end
  1154.  
  1155. local function dataInsertButtonCallback(guiID, id)
  1156.   if string.len(gui.getText(guiID, dataInsertText)) > 0 then
  1157.     table.insert(dataTable[gui.getSelected(guiID, elementsList)].data, gui.getText(guiID, dataInsertText))
  1158.     gui.insertList(guiID, dataList, gui.getText(guiID, dataInsertText))
  1159.     gui.setText(guiID, dataInsertText, "")
  1160.     refresh()
  1161.   end
  1162. end
  1163.  
  1164. local function setExitButtonCallback(guiID, id, status)
  1165.   dataTable.useExit = status
  1166.   refresh()
  1167. end
  1168.  
  1169. local function pwCheckCallback(guiID, id, status)
  1170.   dataTable[gui.getSelected(guiID, elementsList)].pass = status
  1171.   refresh()
  1172. end
  1173.  
  1174. local function checkCheckCallback(guiID, id, status)
  1175.   dataTable[gui.getSelected(guiID, elementsList)].checked = status
  1176.   refresh()
  1177. end
  1178.  
  1179. local function numCheckCallback(guiID, id, status)
  1180.   dataTable[gui.getSelected(guiID, elementsList)].number = status
  1181.   refresh()
  1182. end
  1183.  
  1184. local function downCheckCallback(guiID, id, status)
  1185.   dataTable[gui.getSelected(guiID, elementsList)].direction = status
  1186.   refresh()
  1187. end
  1188.  
  1189. local function dateFormatCheckCallback(guiID, id, status)
  1190.   dataTable[gui.getSelected(guiID, elementsList)].frm = status
  1191.   refresh()
  1192. end
  1193.  
  1194. local function textEnableCallback(guiID, id, status)
  1195.   dataTable[gui.getSelected(guiID, elementsList)].textEnabled = status
  1196.   refresh()
  1197. end
  1198.  
  1199. -- main gui setup
  1200. myGui = gui.newGui(1, 2, 159, 48, true)
  1201.  
  1202. -- work area
  1203. gui.newFrame(myGui, 77, 1, 81, 27)
  1204. gui.newFrame(myGui, 78, 3, 79, 23)
  1205.  
  1206. -- file menu on bottom line
  1207. gui.newLabel(myGui, 2, 48, "File name :", 0x0000FF, 0xFFFFFF)
  1208. fileNameText = gui.newText(myGui, 14, 48, 10, dataTable.filename, fileNameTextCallback, 10)
  1209. loadButton = gui.newButton(myGui, 25, 48, "load", loadCallback)
  1210. saveButton = gui.newButton(myGui, 32, 48, "save", saveCallback)
  1211. writeCodeButton = gui.newButton(myGui, 39, 48, "write code", writeCodeCallback)
  1212.  
  1213. -- program options
  1214. gui.newFrame(myGui, 118, 28, 40, 11, "Options")
  1215. gui.newLabel(myGui, 119, 30, "Version  :")
  1216. versionText = gui.newText(myGui, 134, 30, 80, dataTable.version, versionTextCallback, 22)
  1217. gui.newLabel(myGui, 119, 32, "Top line :")
  1218. topLineText = gui.newText(myGui, 134, 32, 80, dataTable.topline, topLineTextCallback, 22)
  1219. gui.newLabel(myGui, 119, 34, "Bottom line :")
  1220. bottomLineText = gui.newText(myGui, 134, 34, 80, dataTable.bottomline, bottomLineTextCallback, 22)
  1221. gui.newLabel(myGui, 119, 36, "Insert exit button :")
  1222. setExitButtonCheckbox = gui.newCheckbox(myGui, 140, 36, false, setExitButtonCallback)
  1223.  
  1224. -- selection list for elements and guis
  1225. --gui.newFrame(myGui, 1, 1, 75, 46)
  1226. elementsList = gui.newList(myGui, 2, 2, 40, 20, {}, elementsListCallback, "Selection")
  1227. gui.newLabel(myGui, 2, 22, "", 0x0000FF, 0xFFFFFF, 40)
  1228. deleteButton = gui.newButton(myGui, 16, 22, "remove", deleteButtonCallback)
  1229. gui.newFrame(myGui, 44, 2, 30, 20, "Insert new")
  1230. gui.newButton(myGui, 45, 3,  "Button                    ", newButtonCallback)
  1231. gui.newButton(myGui, 45, 4,  "Label                     ", newLabelCallback)
  1232. gui.newButton(myGui, 45, 5,  "Multi line label          ", newMultiLabelCallback)
  1233. gui.newButton(myGui, 45, 6,  "Text field                ", newTextCallback)
  1234. gui.newButton(myGui, 45, 7,  "Frame                     ", newFrameCallback)
  1235. gui.newButton(myGui, 45, 8,  "Horizontal line           ", newHLineCallback)
  1236. gui.newButton(myGui, 45, 9,  "Checkbox                  ", newCheckboxCallback)
  1237. gui.newButton(myGui, 45, 10, "Radio button              ", newRadioButtonCallback)
  1238. gui.newButton(myGui, 45, 11, "Horiontal progress bar    ", newHProgressCallback)
  1239. gui.newButton(myGui, 45, 12, "Vertical progress bar     ", newVProgressCallback)
  1240. gui.newButton(myGui, 45, 13, "List                      ", newListCallback)
  1241. gui.newButton(myGui, 45, 14, "Horizontal slider         ", newVSliderCallback)
  1242. gui.newButton(myGui, 45, 15, "Time label                ", newTimeLabelCallback)
  1243. gui.newButton(myGui, 45, 16, "Date label                ", newDateLabelCallback)
  1244. --gui.newButton(myGui, 45, 15, "Chart                     ", newChartCallback)
  1245.  
  1246. -- element values
  1247. valuesFrame = gui.newFrame(myGui, 2, 25, 40, 7, "Element values")
  1248. nameLabel = gui.newLabel(myGui, 3, 26, "Name :")
  1249. nameInput = gui.newText(myGui, 10, 26, 100, "", nameInputCallback, 30)
  1250.  
  1251. xLabel = gui.newLabel(myGui, 3, 28, "X :")
  1252. xInput = gui.newText(myGui, 7, 28, 5, "", xInputCallback, 5)
  1253. --xSlider = gui.newVSlider(myGui, 14, 27, 24, 0, 80, 0, func)
  1254.  
  1255. yLabel = gui.newLabel(myGui, 3, 30, "Y :")
  1256. yInput = gui.newText(myGui, 7, 30, 5, "", yInputCallback, 5)
  1257. --ySlider = gui.newVSlider(myGui, 14, 29, 24, 0, 80, 0, func)
  1258.  
  1259. wLabel = gui.newLabel(myGui, 3, 30, "W :")
  1260. wInput = gui.newText(myGui, 7, 30, 5, "", wInputCallback, 5)
  1261. --wSlider = gui.newVSlider(myGui, 14, 30, 24, 0, 80, 0, func)
  1262.  
  1263. hLabel = gui.newLabel(myGui, 3, 31, "H :")
  1264. hInput = gui.newText(myGui, 7, 31, 5, "", hInputCallback, 5)
  1265. --hSlider = gui.newVSlider(myGui, 14, 31, 24, 0, 80, 0, func)
  1266.  
  1267. minLabel = gui.newLabel(myGui, 3, 32, "Min   :")
  1268. minInput = gui.newText(myGui, 11, 32, 5, "", minInputCallback, 5)
  1269.  
  1270. maxLabel = gui.newLabel(myGui, 3, 33, "Max   :")
  1271. maxInput = gui.newText(myGui, 11, 33, 5, "", maxInputCallback, 5)
  1272.  
  1273. valueLabel = gui.newLabel(myGui, 3, 34, "Value :")
  1274. valueInput = gui.newText(myGui, 11, 34, 5, "", valueInputCallback, 5)
  1275.  
  1276. textLabel = gui.newLabel(myGui, 3, 35, "Text  :")
  1277. textInput = gui.newText(myGui, 11, 35, 78, "", textInputCallback, 25)
  1278.  
  1279. textEnableLabel = gui.newLabel(myGui, 3, 35, "Enable text :")
  1280. textEnable = gui.newCheckbox(myGui, 17, 37, false, textEnableCallback)
  1281.  
  1282. funcLabel = gui.newLabel(myGui, 3, 36, "Func  :")
  1283. funcInput = gui.newText(myGui, 11, 36, 100, "", funcInputCallback, 29)
  1284.  
  1285. pwLabel = gui.newLabel(myGui, 3, 37, "Password")
  1286. pwCheck = gui.newCheckbox(myGui, 12, 37, false, pwCheckCallback)
  1287.  
  1288. checkLabel = gui.newLabel(myGui, 3, 38, "Checked")
  1289. checkCheck = gui.newCheckbox(myGui, 11, 38, false,checkCheckCallback)
  1290.  
  1291. bgLabel = gui.newLabel(myGui, 3, 39, "Background color :")
  1292. bgInput = gui.newText(myGui, 22, 39, 8, "", bgInputCallback, 8)
  1293.  
  1294. fgLabel = gui.newLabel(myGui, 3, 40, "Foreground color :")
  1295. fgInput = gui.newText(myGui, 22, 40, 8, "", fgInputCallback, 8)
  1296.  
  1297. radioLabel = gui.newLabel(myGui, 3, 41, "Direction down :")
  1298. downCheck = gui.newCheckbox(myGui, 20, 41, false, downCheckCallback)
  1299.  
  1300. numberLabel = gui.newLabel(myGui, 3, 42, "Show number")
  1301. numberCheck = gui.newCheckbox(myGui, 15, 42, false, numCheckCallback)
  1302.  
  1303. dateFormatLabel = gui.newLabel(myGui, 3, 42, "Long format")
  1304. dateFormatCheck = gui.newCheckbox(myGui, 15, 42, false, dateFormatCheckCallback)
  1305.  
  1306. lLabel = gui.newLabel(myGui, 3, 43, "l :")
  1307. lInput = gui.newText(myGui, 7, 43, 5, "", lInputCallback, 5)
  1308. --lSlider = gui.newVSlider(myGui, 14, 43, 24, 0, 80, 0, func)
  1309.  
  1310.  
  1311. dataFrame = gui.newFrame(myGui, 43, 22, 32, 23)
  1312. dataList = gui.newList(myGui, 44, 23, 30, 20, {}, nil, "Element data")
  1313. dataInsertText = gui.newText(myGui, 44, 39, 100, "", nil, 30)
  1314. dataInsertButton = gui.newButton(myGui, 44, 41, "           Insert           ", dataInsertButtonCallback)
  1315. dataRemoveButton = gui.newButton(myGui, 44, 43, "           Remove           ", dataRemoveButtonCallback)
  1316.  
  1317. exitButton = gui.newButton(myGui, 153, 48, "exit", exitButtonCallback)
  1318.  
  1319.  
  1320. disableAll()
  1321.  
  1322. gui.clearScreen()
  1323. gui.setTop(prgName .. " " .. version)
  1324. gui.setBottom("(c)2017 by S.Kempa")
  1325.  
  1326. gui.runGui(myGui)
  1327. refresh()
  1328.  
  1329. while true do
  1330.   gui.runGui(myGui)
  1331. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement