Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.46 KB | None | 0 0
  1. local GCGUI = {}
  2.  
  3. function GCGUI.newGroup()
  4.   local myGroup = {}
  5.   myGroup.elements = {}
  6.  
  7.     function myGroup:addElement(pElement)
  8.        table.insert(self.elements,pElement)
  9.     end
  10.     function myGroup:setVisible(pVisible)
  11.        for n,v in pairs(myGroup.elements) do
  12.           v:setVisible(pVisible)
  13.        end
  14.     end
  15.     function myGroup:draw()
  16.       love.graphics.push()
  17.       for n,v in pairs(myGroup.elements) do
  18.           v:draw()
  19.       end
  20.       love.graphics.pop()
  21.     end
  22.    
  23.     return myGroup
  24. end
  25.  
  26. local function newElement(pX,pY)
  27.   local myElement = {}
  28.   myElement.x = pX
  29.   myElement.y = pY
  30.   function myElement:draw()
  31.  
  32.   end
  33.   function myElement:setVisible(pVisible)
  34.      self.visible = pVisible
  35.   end
  36.   return myElement
  37. end
  38.  
  39. function GCGUI.newPanel(pX,pY,pW,pH)
  40.    local myPanel = newElement(pX,pY)
  41.    myPanel.W = pW
  42.    myPanel.H = pH
  43.    myPanel.image = nil
  44.     function myPanel:setImage(pImage)
  45.       self.image = pImage
  46.       self.W = pImage:getWidth()
  47.       self.H = pImage:getHeight()
  48.     end
  49.     function myPanel:drawPanel()
  50.      love.graphics.setColor(1,1,1)
  51.         if self.image == nil then
  52.             love.graphics.rectangle("line",self.x,self.y,self.W,self.H)
  53.         else
  54.             love.graphics.draw(self.image,self.x,self.y)
  55.         end
  56.     end
  57.     function myPanel:draw()
  58.        if self.visible == false then return end
  59.        self:drawPanel()
  60.     end
  61.     return myPanel
  62. end
  63.  
  64. return GCGUI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement