Advertisement
nik1111

tiles

May 19th, 2022
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. --
  2. -- Created by Grcpils
  3. -- 04/03/2021
  4. -- Github: https://github.com/grcpils/cc-gui_api
  5. -- Please do not delete this header ;)
  6. --
  7.  
  8. local Utils = require("GUI/utils")
  9.  
  10. local drawLabel = function(tl)
  11. local Y = math.floor((tl.ymin + tl.ymax) / 2)
  12. local X = math.floor((tl.xmax + tl.xmin - string.len(tl.label)) / 2) + 1
  13. GUI_MONITOR.setBackgroundColor(tl.color)
  14. GUI_MONITOR.setCursorPos(X, Y)
  15. GUI_MONITOR.write(tl.label)
  16. GUI_MONITOR.setBackgroundColor(colors.black)
  17. end
  18.  
  19. local draw = function(tl)
  20. GUI_MONITOR.setBackgroundColor(tl.color)
  21. Utils.drawShape(tl)
  22. drawLabel(tl)
  23. GUI_MONITOR.setBackgroundColor(colors.black)
  24. end
  25.  
  26. local drawAll = function()
  27. table.foreach(GUI_TILES, function (key, tl)
  28. Utils.printInfo("[GUI] Draw tile '%s' (id:%s)\n", tl.label, key)
  29. draw(tl)
  30. end)
  31. end
  32.  
  33. local new = function(label, pos, size, color)
  34. local xmin, xmax, ymin, ymax = Utils.getCoordonate(pos, size)
  35. local Tile = {
  36. label = label,
  37. xmin = xmin,
  38. xmax = xmax,
  39. ymin = ymin,
  40. ymax = ymax,
  41. color = color
  42. }
  43.  
  44. local setColor = function(color)
  45. Tile.color = color
  46. draw(Tile)
  47. end
  48.  
  49. local setLabel = function(label)
  50. Tile.label = label
  51. draw(Tile)
  52. end
  53.  
  54. table.insert(GUI_TILES, Tile)
  55. return {
  56. setColor = setColor
  57. }
  58. end
  59.  
  60. return {
  61. new = new,
  62. drawAll = drawAll
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement