summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid McMackins II <contact@mcmackins.org>2017-09-01 07:00:21 -0500
committerDavid McMackins II <contact@mcmackins.org>2017-09-01 07:00:21 -0500
commitb11650117c6927b4a8a4d80697c7903c3a7341c8 (patch)
tree629a0fe634af5b6328f9be0809f4e981a679b462
parentb0a8a67b895e03b095bb897d7b7a89193b130d65 (diff)
Add Gui class
-rw-r--r--gui.lua51
1 files changed, 51 insertions, 0 deletions
diff --git a/gui.lua b/gui.lua
index 5b3ea83..ebd5c25 100644
--- a/gui.lua
+++ b/gui.lua
@@ -40,6 +40,57 @@ require 'class'
local defaultfont = love.graphics.getFont()
+Gui = class()
+
+function Gui:__init()
+ self._components = {}
+ self._active = nil
+end
+
+function Gui:addcomponent(component)
+ table.insert(self._components, component)
+end
+
+function Gui:mousepressed(x, y, button)
+ for _,component in ipairs(self._components) do
+ if component:mousepressed(x, y, button) then
+ return true
+ end
+ end
+
+ return false
+end
+
+function Gui:mousereleased(x, y, button)
+ for _,component in ipairs(self._components) do
+ if component:mousereleased(x, y, button) then
+ return true
+ end
+ end
+
+ return false
+end
+
+function Gui:textinput(c)
+ for _,component in ipairs(self._components) do
+ if component:textinput(c) then
+ return true
+ end
+ end
+
+ return false
+end
+
+function Gui:keypressed(key, isrepeat)
+ for _,component in ipairs(self._components) do
+ if component:keypressed(key, isrepeat) then
+ return true
+ end
+ end
+
+ return false
+end
+
local function normalizedim(d)
if type(d) ~= 'function' then
return function(self) return d end