Advertisement
MoonlightOwl

HologramEditor v0.60 Beta (by NEO, Totoro) (English version)

Nov 11th, 2014
3,920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.83 KB | None | 0 0
  1. --         Hologram Editor
  2. -- by NEO, Totoro (aka MoonlightOwl)
  3. -- 10/14/2014, all right reserved =)
  4.  
  5. local unicode = require('unicode')
  6. local event = require('event')
  7. local term = require('term')
  8. local fs = require('filesystem')
  9. local com = require('component')
  10. local gpu = com.gpu
  11.  
  12. --   Constants   --
  13. HOLOH = 32
  14. HOLOW = 48
  15.  
  16. --     Colors     --
  17. backcolor = 0x000000
  18. forecolor = 0xFFFFFF
  19. infocolor = 0x0066FF
  20. errorcolor = 0xFF0000
  21. helpcolor = 0x006600
  22. graycolor = 0x080808
  23. goldcolor = 0xFFDF00
  24. --      ***      --
  25.  
  26.  
  27. -- loading add. components
  28. function trytofind(name)
  29.   if com.isAvailable(name) then
  30.     return com.getPrimary(name)
  31.   else
  32.     return nil
  33.   end
  34. end
  35.  
  36. local h = trytofind('hologram')
  37.  
  38. -- ========================================= H O L O G R A P H I C S ========================================= --
  39. holo = {}
  40. function set(x, y, z, value)
  41.   if holo[x] == nil then holo[x] = {} end
  42.   if holo[x][y] == nil then holo[x][y] = {} end
  43.   holo[x][y][z] = value
  44. end
  45. function get(x, y, z)
  46.   if holo[x] ~= nil and holo[x][y] ~= nil and holo[x][y][z] ~= nil then
  47.     return holo[x][y][z]
  48.   else
  49.     return 0
  50.   end
  51. end
  52.  
  53. function save(filename)
  54.   -- save palette
  55.   file = io.open(filename, 'wb')
  56.   for i=1, 3 do
  57.     for c=1, 3 do
  58.       file:write(string.char(colortable[i][c]))
  59.     end
  60.   end
  61.   -- save voxel array
  62.   for x=1, HOLOW do
  63.     for y=1, HOLOH do
  64.       for z=1, HOLOW, 4 do
  65.         a = get(x,y,z)
  66.         b = get(x,y,z+1)
  67.         c = get(x,y,z+2)
  68.         d = get(x,y,z+3)
  69.         byte = d*64 + c*16 + b*4 + a
  70.         file:write(string.char(byte))
  71.       end
  72.     end
  73.   end
  74.   file:close()
  75. end
  76.  
  77. function load(filename)
  78.   if fs.exists(filename) then
  79.     file = io.open(filename, 'rb')
  80.     -- load palette
  81.     for i=1, 3 do
  82.       for c=1, 3 do
  83.         colortable[i][c] = string.byte(file:read(1))
  84.       end
  85.       setHexColor(i,colortable[i][1],
  86.                     colortable[i][2],
  87.                     colortable[i][3])
  88.     end
  89.     -- load voxel array
  90.     holo = {}
  91.     for x=1, HOLOW do
  92.       for y=1, HOLOH do
  93.         for z=1, HOLOW, 4 do
  94.           byte = string.byte(file:read(1))
  95.           for i=0, 3 do
  96.             a = byte % 4
  97.             byte = math.floor(byte / 4)
  98.             if a ~= 0 then set(x,y,z+i, a) end
  99.           end
  100.         end
  101.       end
  102.     end
  103.     file:close()
  104.     return true
  105.   else
  106.     --print("[ERROR] File "..filename.." not found.")
  107.     return false
  108.   end
  109. end
  110.  
  111.  
  112. -- ============================================= G R A P H I C S ============================================= --
  113. -- check screen/graphics card resolution; for comfortable work necessary resolution is >=HOLOW in height and width
  114. OLDWIDTH, OLDHEIGHT = gpu.getResolution()
  115. WIDTH, HEIGHT = gpu.maxResolution()
  116. if HEIGHT < HOLOW+2 then
  117.   error("[ERROR] Your screen/graphics card does not support the required resolution.")
  118. else
  119.   WIDTH = HOLOW*2+40
  120.   HEIGHT = HOLOW+2
  121.   gpu.setResolution(WIDTH, HEIGHT)
  122. end
  123. gpu.setForeground(forecolor)
  124. gpu.setBackground(backcolor)
  125.  
  126. -- draw a line
  127. local strLine = "+"
  128. for i=1, WIDTH do
  129.   strLine = strLine..'-'
  130. end
  131. function line(x1, x2, y)
  132.   gpu.set(x1,y,string.sub(strLine, 1, x2-x1))
  133.   gpu.set(x2,y,'+')
  134. end
  135.  
  136. -- draw a frame
  137. function frame(x1, y1, x2, y2, caption)
  138.   line(x1, x2, y1)
  139.   line(x1, x2, y2)
  140.  
  141.   if caption ~= nil then
  142.     gpu.set(x1+(x2-x1)/2-unicode.len(caption)/2, y1, caption)
  143.   end
  144. end
  145.  
  146. -- draw grid
  147. local strGrid = ""
  148. for i=1, HOLOW/2 do
  149.   strGrid = strGrid.."██  "
  150. end
  151. function drawGrid(x, y)
  152.   gpu.fill(0, y, MENUX, HOLOW, ' ')
  153.   gpu.setForeground(graycolor)
  154.   for i=0, HOLOW-1 do
  155.     if view>0 and i==HOLOH then
  156.       gpu.setForeground(forecolor)
  157.       line(1, MENUX-1, y+HOLOH)
  158.       break
  159.     end
  160.     gpu.set(x+(i%2)*2, y+i, strGrid)
  161.   end
  162.   if view == 0 then gpu.setForeground(forecolor) end
  163. end
  164.  
  165. -- draw colored rectangle
  166. function drawRect(x, y, color)
  167.   gpu.set(x, y,   "╓──────╖")
  168.   gpu.set(x, y+1, "║      ║")
  169.   gpu.set(x, y+2, "╙──────╜")
  170.   gpu.setForeground(color)
  171.   gpu.set(x+2, y+1, "████")
  172.   gpu.setForeground(forecolor)
  173. end
  174.  
  175. MENUX = HOLOW*2+5
  176. BUTTONW = 12
  177.  
  178. -- draw "brush selector" menu
  179. function drawColorSelector()
  180.   frame(MENUX, 3, WIDTH-2, 16, "[ Palette ]")
  181.   for i=0, 3 do
  182.     drawRect(MENUX+1+i*8, 5, hexcolortable[i])
  183.   end
  184.   gpu.set(MENUX+1, 10, "R:")
  185.   gpu.set(MENUX+1, 11, "G:")
  186.   gpu.set(MENUX+1, 12, "B:")
  187. end
  188. function drawColorCursor(force)
  189.   if brush.color*8 ~= brush.x then brush.x = brush.color*8 end
  190.   if force or brush.gx ~= brush.x then
  191.     gpu.set(MENUX+1+brush.gx, 8, "        ")
  192.     if brush.gx < brush.x then brush.gx = brush.gx + 1 end
  193.     if brush.gx > brush.x then brush.gx = brush.gx - 1 end
  194.     gpu.set(MENUX+1+brush.gx, 8, " -^--^- ")
  195.   end
  196. end
  197. function drawLayerSelector()
  198.   frame(MENUX, 16, WIDTH-2, 28, "[ Layer ]")
  199.   gpu.set(MENUX+13, 18, "Hologram layer:")
  200.   gpu.set(MENUX+1, 23, "'Ghost' layer:")
  201. end
  202. function drawButtonsPanel()
  203.   frame(MENUX, 28, WIDTH-2, 36, "[ Manage ]")
  204. end
  205.  
  206. function mainScreen()
  207.   term.clear()
  208.   frame(1,1, WIDTH, HEIGHT, "{ Hologram Editor }")
  209.   -- "canvas"
  210.   drawLayer()
  211.   drawColorSelector()
  212.   drawColorCursor(true)
  213.   drawLayerSelector()
  214.   drawButtonsPanel()
  215.   buttonsDraw()
  216.   textboxesDraw()
  217.   -- "about" info
  218.   gpu.setForeground(infocolor)
  219.   gpu.setBackground(graycolor)
  220.   gpu.set(MENUX+3, HEIGHT-11, " Hologram Editor v0.60 Beta  ")
  221.   gpu.setForeground(forecolor)
  222.   gpu.set(MENUX+3, HEIGHT-10, "            * * *            ")
  223.   gpu.set(MENUX+3, HEIGHT-9,  " Programmers:                ")
  224.   gpu.set(MENUX+3, HEIGHT-8,  "         NEO, Totoro         ")
  225.   gpu.set(MENUX+3, HEIGHT-7,  "            * * *            ")
  226.   gpu.set(MENUX+3, HEIGHT-6,  " Contact:                    ")
  227.   gpu.set(MENUX+3, HEIGHT-5,  "   computercraft.ru/forum    ")
  228.   gpu.setBackground(backcolor)
  229.   -- exit program
  230.   gpu.set(MENUX, HEIGHT-2, "Quit: 'Q'  or ")
  231. end
  232.  
  233.  
  234. -- =============================================== L A Y E R S =============================================== --
  235. GRIDX = 3
  236. GRIDY = 2
  237. function drawLayer()
  238.   drawGrid(GRIDX, GRIDY)
  239.   -- top view (y)
  240.   if view == 0 then
  241.     for x=1, HOLOW do
  242.       for z=1, HOLOW do
  243.         gn = get(x, ghost_layer, z)
  244.         n = get(x, layer, z)
  245.         if n == 0 and gn ~= 0 then
  246.           gpu.setForeground(darkhexcolors[gn])
  247.           gpu.set((GRIDX-2) + x*2, (GRIDY-1) + z, "░░")
  248.         end
  249.         if n ~= 0 then
  250.           gpu.setForeground(hexcolortable[n])
  251.           gpu.set((GRIDX-2) + x*2, (GRIDY-1) + z, "██")
  252.         end
  253.       end
  254.     end
  255.   -- fore view (z)
  256.   elseif view == 1 then
  257.     for x=1, HOLOW do
  258.       for y=1, HOLOH do
  259.         n = get(x, y, layer)
  260.         gn = get(x, y, ghost_layer)
  261.         if n == 0 and gn ~= 0 then
  262.           gpu.setForeground(darkhexcolors[gn])
  263.           gpu.set((GRIDX-2) + x*2, (GRIDY+HOLOH) - y, "░░")
  264.         end
  265.         if n ~= 0 then
  266.           gpu.setForeground(hexcolortable[n])
  267.           gpu.set((GRIDX-2) + x*2, (GRIDY+HOLOH) - y, "██")
  268.         end
  269.       end
  270.     end
  271.   -- side view (x)
  272.   else
  273.     for z=1, HOLOW do
  274.       for y=1, HOLOH do
  275.         gn = get(ghost_layer, y, z)
  276.         n = get(layer, y, z)
  277.         if n == 0 and gn ~= 0 then
  278.           gpu.setForeground(darkhexcolors[gn])
  279.           gpu.set((GRIDX+HOLOW*2) - z*2, (GRIDY+HOLOH) - y, "░░")
  280.         end
  281.         if n ~= 0 then
  282.           gpu.setForeground(hexcolortable[n])
  283.           gpu.set((GRIDX+HOLOW*2) - z*2, (GRIDY+HOLOH) - y, "██")
  284.         end
  285.       end
  286.     end
  287.   end
  288.   gpu.setForeground(forecolor)
  289.   -- for messages
  290.   repaint = false
  291. end
  292. function fillLayer()
  293.   for x=1, HOLOW do
  294.     for z=1, HOLOW do
  295.       set(x, layer, z, brush.color)
  296.     end
  297.   end
  298.   drawLayer()
  299. end
  300. function clearLayer()
  301.   for x=1, HOLOW do
  302.     if holo[x] ~= nil then holo[x][layer] = nil end
  303.   end
  304.   drawLayer()
  305. end
  306.  
  307.  
  308. -- ============================================== B U T T O N S ============================================== --
  309. Button = {}
  310. Button.__index = Button
  311. function Button.new(func, x, y, text, color, width)
  312.   self = setmetatable({}, Button)
  313.  
  314.   self.form = '[ '
  315.   if width == nil then width = 0
  316.     else width = (width - unicode.len(text))-4 end
  317.   for i=1, math.floor(width/2) do
  318.     self.form = self.form.. ' '
  319.   end
  320.   self.form = self.form..text
  321.   for i=1, math.ceil(width/2) do
  322.     self.form = self.form.. ' '
  323.   end
  324.   self.form = self.form..' ]'
  325.  
  326.   self.func = func
  327.  
  328.   self.x = x; self.y = y
  329.   self.color = color
  330.   self.visible = true
  331.  
  332.   return self
  333. end
  334. function Button:draw(color)
  335.   if self.visible then
  336.     local color = color or self.color
  337.     gpu.setBackground(color)
  338.     if color > 0x888888 then gpu.setForeground(backcolor) end
  339.     gpu.set(self.x, self.y, self.form)
  340.     gpu.setBackground(backcolor)
  341.     if color > 0x888888 then gpu.setForeground(forecolor) end
  342.   end
  343. end
  344. function Button:click(x, y)
  345.   if self.visible then
  346.     if y == self.y then
  347.       if x >= self.x and x < self.x+unicode.len(self.form) then
  348.         self.func()
  349.         self:draw(self.color/2)
  350.         os.sleep(0.1)
  351.         self:draw()
  352.         return true
  353.       end
  354.     end
  355.   end
  356.   return false
  357. end
  358. buttons = {}
  359. function buttonsNew(func, x, y, text, color, width)
  360.   table.insert(buttons, Button.new(func, x, y, text, color, width))
  361. end
  362. function buttonsDraw()
  363.   for i=1, #buttons do
  364.     buttons[i]:draw()
  365.   end
  366. end
  367. function buttonsClick(x, y)
  368.   for i=1, #buttons do
  369.     buttons[i]:click(x, y)
  370.   end
  371. end
  372.  
  373. -- ================================ B U T T O N S   F U N C T I O N A L I T Y ================================ --
  374. function exit() running = false end
  375. function nextLayer()
  376.   -- different limits for different views
  377.   local limit = HOLOH
  378.   if view > 0 then limit = HOLOW end
  379.  
  380.   if layer < limit then
  381.     layer = layer + 1
  382.     tb_layer:setValue(layer)
  383.     tb_layer:draw(true)
  384.     moveGhost()
  385.     drawLayer()
  386.   end
  387. end
  388. function prevLayer()
  389.   if layer > 1 then
  390.     layer = layer - 1
  391.     tb_layer:setValue(layer)
  392.     tb_layer:draw(true)
  393.     moveGhost()
  394.     drawLayer()
  395.   end
  396. end
  397. function setLayer(value)
  398.   local n = tonumber(value)
  399.   local limit = HOLOH
  400.   if view > 0 then limit = HOLOW end
  401.   if n == nil or n < 1 or n > limit then return false end
  402.   layer = n
  403.   moveGhost()
  404.   drawLayer()
  405.   return true
  406. end
  407. function nextGhost()
  408.   local limit = HOLOH
  409.   if view > 0 then limit = HOLOW end
  410.  
  411.   if ghost_layer_below then
  412.     ghost_layer_below = false
  413.     if ghost_layer < limit then
  414.       ghost_layer = layer + 1
  415.     else ghost_layer = limit end
  416.     drawLayer()
  417.   else  
  418.     if ghost_layer < limit then
  419.       ghost_layer = ghost_layer + 1
  420.       drawLayer()
  421.     end
  422.   end
  423. end
  424. function prevGhost()
  425.   if not ghost_layer_below then
  426.     ghost_layer_below = true
  427.     if layer > 1 then
  428.       ghost_layer = layer - 1
  429.     else ghost_layer = 1 end
  430.     drawLayer()
  431.   else
  432.     if ghost_layer > 1 then
  433.       ghost_layer = ghost_layer - 1
  434.       drawLayer()
  435.     end
  436.   end
  437. end
  438. function setGhostLayer(value)
  439.   local n = tonumber(value)
  440.   local limit = HOLOH
  441.   if view > 0 then limit = HOLOW end
  442.   if n == nil or n < 1 or n > limit then return false end
  443.   ghost_layer = n
  444.   drawLayer()
  445.   return true
  446. end
  447. function moveGhost()
  448.   if ghost_layer_below then
  449.     if layer > 1 then ghost_layer = layer - 1
  450.     else ghost_layer = 1 end
  451.   else
  452.     local limit = HOLOH
  453.     if view > 0 then limit = HOLOW end
  454.     if layer < limit then ghost_layer = layer + 1
  455.     else ghost_layer = limit end
  456.   end
  457. end
  458.  
  459. function setFilename(str)
  460.   if str ~= nil and str ~= '' and unicode.len(str)<30 then
  461.     return true
  462.   else
  463.     return false
  464.   end
  465. end
  466.  
  467. function setHexColor(n, r, g, b)
  468.   local hexcolor = rgb2hex(r,g,b)
  469.   hexcolortable[n] = hexcolor
  470.   darkhexcolors[n] = bit32.rshift(bit32.band(hexcolor, 0xfefefe), 1)
  471. end
  472. function rgb2hex(r,g,b)
  473.   return r*65536+g*256+b
  474. end
  475. function changeRed(value) return changeColor(1, value) end
  476. function changeGreen(value) return changeColor(2, value) end
  477. function changeBlue(value) return changeColor(3, value) end
  478. function changeColor(rgb, value)
  479.   if value == nil then return false end
  480.   n = tonumber(value)
  481.   if n == nil or n < 0 or n > 255 then return false end
  482.   -- save data in table
  483.   colortable[brush.color][rgb] = n
  484.   setHexColor(brush.color, colortable[brush.color][1],
  485.                            colortable[brush.color][2],
  486.                            colortable[brush.color][3])
  487.   -- refresh colors menu
  488.   for i=0, 3 do
  489.     drawRect(MENUX+1+i*8, 5, hexcolortable[i])
  490.   end
  491.   return true
  492. end
  493.  
  494. function moveSelector(num)
  495.   brush.color = num
  496.   tb_red:setValue(colortable[num][1]); tb_red:draw(true)
  497.   tb_green:setValue(colortable[num][2]); tb_green:draw(true)
  498.   tb_blue:setValue(colortable[num][3]); tb_blue:draw(true)
  499. end
  500.  
  501. function setTopView()
  502.   view = 0
  503.   -- top view has less layers
  504.   if layer > HOLOH then layer = HOLOH end
  505.   drawLayer()
  506. end
  507. function setFrontView() view = 1; drawLayer() end
  508. function setSideView() view = 2; drawLayer() end
  509.  
  510. function drawHologram()
  511.   -- check hologram projector availability
  512.   h = trytofind('hologram')
  513.   if h ~= nil then
  514.     local depth = h.maxDepth()
  515.     -- clear projector
  516.     h.clear()
  517.     -- send palette
  518.     if depth == 2 then
  519.       for i=1, 3 do
  520.         h.setPaletteColor(i, hexcolortable[i])
  521.       end
  522.     else
  523.       h.setPaletteColor(1, hexcolortable[1])
  524.     end
  525.     -- send voxel array
  526.     for x=1, HOLOW do
  527.       for y=1, HOLOH do
  528.         for z=1, HOLOW do
  529.           n = get(x,y,z)
  530.           if n ~= 0 then
  531.             if depth == 2 then
  532.               h.set(x,y,z,n)
  533.             else
  534.               h.set(x,y,z,1)
  535.             end
  536.           end
  537.         end
  538.       end      
  539.     end
  540.   end
  541. end
  542.  
  543. function newHologram()
  544.   holo = {}
  545.   drawLayer()
  546. end
  547.  
  548. function saveHologram()
  549.   local filename = tb_file:getValue()
  550.   if filename ~= FILE_REQUEST then
  551.     -- warning
  552.     showMessage('Saving... Please wait.', '[ Attention ]', goldcolor)
  553.     -- add brand extension =)
  554.     if string.sub(filename, -3) ~= '.3d' then
  555.       filename = filename..'.3d'
  556.     end
  557.     -- save
  558.     save(filename)
  559.     -- done info
  560.     showMessage('   The file is saved!  ', '[ Done ]', goldcolor)
  561.     repaint = true
  562.   end
  563. end
  564.  
  565. function loadHologram()
  566.   local filename = tb_file:getValue()
  567.   if filename ~= FILE_REQUEST then
  568.     -- warning
  569.     showMessage('Loading...', '[ Attention ]', goldcolor)
  570.     -- add brand extension =)
  571.     if string.sub(filename, -3) ~= '.3d' then
  572.       filename = filename..'.3d'
  573.     end
  574.     -- load
  575.     load(filename)
  576.     -- refresh RGB textboxes
  577.     tb_red:setValue(colortable[brush.color][1]); tb_red:draw(true)
  578.     tb_green:setValue(colortable[brush.color][2]); tb_green:draw(true)
  579.     tb_blue:setValue(colortable[brush.color][3]); tb_blue:draw(true)
  580.     -- refresh colors menu
  581.     for i=0, 3 do
  582.       drawRect(MENUX+1+i*8, 5, hexcolortable[i])
  583.     end
  584.     -- refresh layer
  585.     drawLayer()
  586.   end
  587. end
  588.  
  589. -- ============================================ T E X T B O X E S ============================================ --
  590. Textbox = {}
  591. Textbox.__index = Textbox
  592. function Textbox.new(func, x, y, value, width)
  593.   self = setmetatable({}, Textbox)
  594.  
  595.   self.form = '>'
  596.   if width == nil then width = 10 end
  597.   for i=1, width-1 do
  598.     self.form = self.form..' '
  599.   end
  600.  
  601.   self.func = func
  602.   self.value = tostring(value)
  603.  
  604.   self.x = x; self.y = y
  605.   self.visible = true
  606.  
  607.   return self
  608. end
  609. function Textbox:draw(content)
  610.   if self.visible then
  611.     if content then gpu.setBackground(graycolor) end
  612.     gpu.set(self.x, self.y, self.form)
  613.     if content then gpu.set(self.x+2, self.y, self.value) end
  614.     gpu.setBackground(backcolor)
  615.   end
  616. end
  617. function Textbox:click(x, y)
  618.   if self.visible then
  619.     if y == self.y then
  620.       if x >= self.x and x < self.x+unicode.len(self.form) then
  621.         self:draw(false)
  622.         term.setCursor(self.x+2, self.y)
  623.         value = string.sub(term.read({self.value}), 1, -2)
  624.         if self.func(value) then
  625.           self.value = value
  626.         end
  627.         self:draw(true)
  628.         return true
  629.       end
  630.     end
  631.   end
  632.   return false
  633. end
  634. function Textbox:setValue(value)
  635.   self.value = tostring(value)
  636. end
  637. function Textbox:getValue()
  638.   return self.value
  639. end
  640. textboxes = {}
  641. function textboxesNew(func, x, y, value, width)
  642.   textbox = Textbox.new(func, x, y, value, width)
  643.   table.insert(textboxes, textbox)
  644.   return textbox
  645. end
  646. function textboxesDraw()
  647.   for i=1, #textboxes do
  648.     textboxes[i]:draw(true)
  649.   end
  650. end
  651. function textboxesClick(x, y)
  652.   for i=1, #textboxes do
  653.     textboxes[i]:click(x, y)
  654.   end
  655. end
  656.  
  657.  
  658. -- ============================================= M E S S A G E S ============================================= --
  659. repaint = false
  660. function showMessage(text, caption, color)
  661.   local x = WIDTH/2 - unicode.len(text)/2 - 4
  662.   local y = HEIGHT/2 - 2
  663.   gpu.fill(x, y, unicode.len(text)+8, 5, ' ')
  664.   frame(x, y, x+unicode.len(text)+7, y+4, caption)
  665.   gpu.setForeground(color)
  666.   gpu.set(x+4,y+2, text)
  667.   gpu.setForeground(forecolor)
  668. end
  669.  
  670.  
  671. -- =========================================== M A I N   C Y C L E =========================================== --
  672. -- init
  673. colortable = {{255, 0, 0}, {0, 255, 0}, {0, 102, 255}}
  674. colortable[0] = {0, 0, 0}
  675. hexcolortable = {}
  676. darkhexcolors = {}
  677. for i=0,3 do setHexColor(i, colortable[i][1], colortable[i][2], colortable[i][3]) end
  678. brush = {color = 1, x = 8, gx = 8}
  679. ghost_layer = 1
  680. ghost_layer_below = true
  681. layer = 1
  682. view = 0
  683. running = true
  684.  
  685. buttonsNew(exit, WIDTH-BUTTONW-2, HEIGHT-2, 'Exit', errorcolor, BUTTONW)
  686. buttonsNew(drawLayer, MENUX+10, 14, 'Refresh', goldcolor, BUTTONW)
  687. buttonsNew(prevLayer, MENUX+1, 19, '-', infocolor, 5)
  688. buttonsNew(nextLayer, MENUX+7, 19, '+', infocolor, 5)
  689. buttonsNew(setTopView, MENUX+1, 21, 'Top', infocolor, 10)
  690. buttonsNew(setFrontView, MENUX+12, 21, 'Front', infocolor, 10)
  691. buttonsNew(setSideView, MENUX+24, 21, 'Side', infocolor, 9)
  692.  
  693. buttonsNew(prevGhost, MENUX+1, 24, 'Below', infocolor, 5)
  694. buttonsNew(nextGhost, MENUX+11, 24, 'Above', infocolor, 5)
  695.  
  696. buttonsNew(clearLayer, MENUX+1, 26, 'Clear', infocolor, BUTTONW)
  697. buttonsNew(fillLayer, MENUX+2+BUTTONW, 26, 'Fill', infocolor, BUTTONW)
  698.  
  699. buttonsNew(drawHologram, MENUX+8, 30, 'To Projector', goldcolor, 16)
  700. buttonsNew(saveHologram, MENUX+1, 33, 'Save', helpcolor, BUTTONW)
  701. buttonsNew(loadHologram, MENUX+8+BUTTONW, 33, 'Load', infocolor, BUTTONW)
  702. buttonsNew(newHologram, MENUX+1, 35, 'New file', infocolor, BUTTONW)
  703.  
  704. tb_red = textboxesNew(changeRed, MENUX+5, 10, '255', WIDTH-MENUX-7)
  705. tb_green = textboxesNew(changeGreen, MENUX+5, 11, '0', WIDTH-MENUX-7)
  706. tb_blue = textboxesNew(changeBlue, MENUX+5, 12, '0', WIDTH-MENUX-7)
  707. tb_layer = textboxesNew(setLayer, MENUX+13, 19, '1', WIDTH-MENUX-15)
  708. tb_ghostlayer = textboxesNew(setGhostLayer, MENUX+21, 24, ' ', WIDTH-MENUX-23)
  709. FILE_REQUEST = 'Enter file name here'
  710. tb_file = textboxesNew(setFilename, MENUX+1, 32, FILE_REQUEST, WIDTH-MENUX-3)
  711. mainScreen()
  712.  
  713. while running do
  714.   if brush.x ~= brush.gx then name, add, x, y, b = event.pull(0.02)
  715.   else name, add, x, y, b = event.pull(1.0) end
  716.  
  717.   if name == 'key_down' then
  718.     -- if pressed key is 'Q' - quit
  719.     if y == 16 then break
  720.     elseif y == 41 then
  721.       moveSelector(0)
  722.     elseif y>=2 and y<=4 then
  723.       moveSelector(y-1)
  724.     elseif y == 211 then
  725.       clearLayer()
  726.     end
  727.   elseif name == 'touch' then
  728.     -- checking GUI
  729.     buttonsClick(x, y)
  730.     textboxesClick(x, y)
  731.     -- select color
  732.     if x>MENUX+1 and x<MENUX+37 then
  733.       if y>4 and y<8 then
  734.         moveSelector(math.floor((x-MENUX-1)/8))
  735.       end
  736.     end
  737.   end
  738.   if name == 'touch' or name == 'drag' then
  739.     -- "paint"
  740.     local limit = HOLOW
  741.     if view > 0 then limit = HOLOH end
  742.     if x >= GRIDX and x < GRIDX+HOLOW*2 then
  743.       if y >= GRIDY and y < GRIDY+limit then
  744.         -- refresh, after message box
  745.         if repaint then drawLayer() end
  746.         -- mouse click
  747.         if view == 0 then
  748.           dx = math.floor((x-GRIDX)/2)+1; gx = dx
  749.           dy = layer; gy = ghost_layer
  750.           dz = y-GRIDY+1; gz = dz
  751.         elseif view == 1 then
  752.           dx = math.floor((x-GRIDX)/2)+1; gx = dx
  753.           dy = HOLOH - (y-GRIDY); gy = dy
  754.           dz = layer; gz = ghost_layer
  755.         else
  756.           dx = layer; gx = ghost_layer
  757.           dy = HOLOH - (y-GRIDY); gy = dy
  758.           dz = HOLOW - math.floor((x-GRIDX)/2); gz = dz
  759.         end
  760.         if b == 0 and brush.color ~= 0 then
  761.           set(dx, dy, dz, brush.color)
  762.           gpu.setForeground(hexcolortable[brush.color])
  763.           gpu.set(x-(x-GRIDX)%2, y, "██")
  764.         else
  765.           set(dx, dy, dz, 0)
  766.           gpu.setForeground(darkhexcolors[get(gx,gy,gz)])
  767.           gpu.set(x-(x-GRIDX)%2, y, "░░")
  768.         end
  769.         gpu.setForeground(forecolor)
  770.       end
  771.     end
  772.   end
  773.  
  774.   drawColorCursor()
  775. end
  776.  
  777. -- finishing
  778. term.clear()
  779. gpu.setResolution(OLDWIDTH, OLDHEIGHT)
  780. gpu.setForeground(0xFFFFFF)
  781. gpu.setBackground(0x000000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement