Advertisement
GravityCube

windowAPI

Mar 31st, 2019
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. local Window = {
  2. clear = function(self)
  3. local x_string = ""
  4. for x = 1, self.width do
  5. x_string = x_string .. " "
  6. end
  7. for y = 1, self.heigth do
  8. self:setCursorPos(1,y)
  9. self:write(x_string)
  10. end
  11. end,
  12.  
  13. setCursorPos = function(self, x, y)
  14. self.mon.setCursorPos(x+self.init_x, y+self.init_y)
  15. end,
  16.  
  17. write = function (self, text)
  18. self.mon.write(text)
  19. end,
  20.  
  21. setBackgroundColor = function(self, color)
  22. self.mon.setBackgroundColor(color)
  23. end,
  24.  
  25. setTextColor = function(self, color)
  26. self.mon.setTextColor(color)
  27. end,
  28.  
  29. getCursorPos = function(self)
  30. local x, y = self.mon.getCursorPos()
  31. local lx = x - self.init_x
  32. local ly = y - self.init_y
  33.  
  34. return lx, ly
  35. end,
  36.  
  37. getSize = function(self)
  38. return self.width, self.heigth
  39. end,
  40.  
  41.  
  42. }
  43.  
  44. function numberBetween(v1, v2, v3)
  45. if v1 >= v2 and v1 <= v3 then
  46. return true
  47. end
  48. return false
  49. end
  50.  
  51.  
  52. function newWindow(mon, x, y, width, heigth)
  53. local max_x, max_y = mon.getSize()
  54.  
  55. local window = {
  56. item = gcapi.deepCopy(row_data),
  57. init_x = x-1,
  58. init_y = y-1,
  59. buttons_map = {}
  60. }
  61. for x=1, max_x do
  62. window.buttons_map[x] = {}
  63. end
  64.  
  65. window.mon = mon
  66.  
  67. window.width = width
  68. window.heigth = heigth
  69.  
  70. setmetatable(window, {__index = Window})
  71. return window
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement