| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- Gooey = class()
- function Gooey:init()
- self.components = {}
- self.focused = nil
- end
- function Gooey:update()
- self:call('update')
- end
- function Gooey:draw(component)
- if type(component) == 'string' then component = self:get(component) end
- if not component then return end
- component.lastDraw = tick
- component:render()
- end
- function Gooey:keypressed(key)
- self:call('keypressed', key)
- end
- function Gooey:keyreleased(key)
- self:call('keyreleased', key)
- end
- function Gooey:mousepressed(mx, my, b)
- self.hot = nil
- self:call('mousepressed', mx, my, b)
- end
- function Gooey:mousereleased(mx, my, b)
- self:call('mousereleased', mx, my, b)
- self.hot = nil
- end
- function Gooey:resize()
- self:call('resize')
- end
- function Gooey:get(code)
- return self.components[code]
- end
- function Gooey:call(method, ...)
- if self.focused then
- if self.focused[method] then
- if self.focused[method](self.focused, ...) then return end
- end
- end
- local components = table.filter(self.components, function(c) return c.lastDraw and tick - c.lastDraw <= 1 and c ~= self.focused end)
- return table.with(components, method, ...)
- end
- function Gooey:add(class, code, vars)
- local component = class()
- table.merge(vars, component, true)
- component.code = code
- component.gooey = self
- f.exe(component.activate, component)
- self.components[code] = component
- return component
- end
- function Gooey:focus(component)
- self.focused = component
- end
- function Gooey:unfocus()
- self.focused = nil
- end
|