diff --git a/docs/classes/element.html b/docs/classes/element.html index 9ef8ca4..8cfa5bb 100644 --- a/docs/classes/element.html +++ b/docs/classes/element.html @@ -71,6 +71,10 @@ Constructor expects nothing, or a data table describing it. + element.debugDraw (self) + Slightly modified from pop.debugDraw + + element.setSize (w, h) Sets an element's width/height. @@ -133,6 +137,32 @@ + +
+ + element.debugDraw (self) +
+
+ Slightly modified from pop.debugDraw + + +

Parameters:

+ + + + +

See also:

+ + +
@@ -313,7 +343,7 @@
generated by LDoc 1.4.3 -Last updated 2016-09-07 21:37:53 +Last updated 2016-10-30 22:18:17
diff --git a/docs/index.html b/docs/index.html index 443ee57..f236873 100644 --- a/docs/index.html +++ b/docs/index.html @@ -79,7 +79,7 @@
generated by LDoc 1.4.3 -Last updated 2016-09-07 21:37:53 +Last updated 2016-10-30 22:18:17
diff --git a/docs/modules/Element.html b/docs/modules/Element.html index ad2f6a3..1ed9713 100644 --- a/docs/modules/Element.html +++ b/docs/modules/Element.html @@ -490,7 +490,7 @@
generated by LDoc 1.4.3 -Last updated 2016-09-07 21:37:53 +Last updated 2016-10-30 22:18:17
diff --git a/docs/modules/main.html b/docs/modules/main.html index 73891de..addf8ed 100644 --- a/docs/modules/main.html +++ b/docs/modules/main.html @@ -71,7 +71,7 @@
generated by LDoc 1.4.3 -Last updated 2016-09-07 21:37:53 +Last updated 2016-10-30 22:18:17
diff --git a/docs/modules/pop.html b/docs/modules/pop.html index a5e0234..56931e8 100644 --- a/docs/modules/pop.html +++ b/docs/modules/pop.html @@ -665,7 +665,7 @@ table.insert element.parent, element.parent\removeChild(element),
generated by LDoc 1.4.3 -Last updated 2016-09-07 21:37:53 +Last updated 2016-10-30 22:18:17
diff --git a/docs/modules/util.html b/docs/modules/util.html index 98b9fd3..f23c191 100644 --- a/docs/modules/util.html +++ b/docs/modules/util.html @@ -125,7 +125,7 @@
generated by LDoc 1.4.3 -Last updated 2016-09-07 21:37:53 +Last updated 2016-10-30 22:18:17
diff --git a/elements/element.lua b/elements/element.lua index f054a04..01d17b7 100644 --- a/elements/element.lua +++ b/elements/element.lua @@ -1,7 +1,18 @@ +local graphics +graphics = love.graphics local element do local _class_0 local _base_0 = { + debugDraw = function(self) + graphics.setLineWidth(1) + graphics.setColor(0, 20, 0, 100) + graphics.rectangle("fill", self.data.x, self.data.y, self.data.w, self.data.h) + graphics.setColor(150, 255, 150, 150) + graphics.rectangle("line", self.data.x, self.data.y, self.data.w, self.data.h) + graphics.setColor(200, 255, 200, 255) + return graphics.print("e", self.data.x, self.data.y) + end, setSize = function(self, w, h) if w then self.data.w = w @@ -63,6 +74,7 @@ do if self.data.draw == nil then self.data.draw = true end + self.child = { } end, __base = _base_0, __name = "element" diff --git a/elements/element.moon b/elements/element.moon index 150735e..475117f 100644 --- a/elements/element.moon +++ b/elements/element.moon @@ -3,6 +3,8 @@ --- @copyright Paul Liverman III (2016) --- @license The MIT License (MIT) +import graphics from love + class element --- Constructor expects nothing, or a data table describing it. --- @tparam ?Element|false parent The parent element. @@ -12,7 +14,7 @@ class element if type @data != "table" @data = {} - @data.parent = false unless @data.parent --included for correctness + @data.parent = false unless @data.parent @data.child = {} unless @data.child @data.x = 0 unless @data.x @data.y = 0 unless @data.y @@ -21,6 +23,19 @@ class element @data.update = false if @data.update == nil @data.draw = true if @data.draw == nil + @child = {} + + --- Slightly modified from pop.debugDraw + --- @see pop.debugDraw + debugDraw: => + graphics.setLineWidth 1 + graphics.setColor 0, 20, 0, 100 + graphics.rectangle "fill", @data.x, @data.y, @data.w, @data.h + graphics.setColor 150, 255, 150, 150 + graphics.rectangle "line", @data.x, @data.y, @data.w, @data.h + graphics.setColor 200, 255, 200, 255 + graphics.print "e", @data.x, @data.y + --- Sets an element's width/height. --- @tparam integer w[opt] Width. --- @tparam integer h[opt] Height. diff --git a/elements/window.lua b/elements/window.lua index b164cad..a48f4e3 100644 --- a/elements/window.lua +++ b/elements/window.lua @@ -1,21 +1,36 @@ +local element = require(tostring((...):sub(1, -7)) .. "/element") local window do local _class_0 + local _parent_0 = element local _base_0 = { setSize = function(self) end } _base_0.__index = _base_0 + setmetatable(_base_0, _parent_0.__base) _class_0 = setmetatable({ __init = function(self, parent, data) if data == nil then data = { } end self.parent, self.data = parent, data + return _class_0.__parent.__init(self, self.parent, self.data) end, __base = _base_0, - __name = "window" + __name = "window", + __parent = _parent_0 }, { - __index = _base_0, + __index = function(cls, name) + local val = rawget(_base_0, name) + if val == nil then + local parent = rawget(cls, "__parent") + if parent then + return parent[name] + end + else + return val + end + end, __call = function(cls, ...) local _self_0 = setmetatable({}, _base_0) cls.__init(_self_0, ...) @@ -23,6 +38,9 @@ do end }) _base_0.__class = _class_0 + if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) + end window = _class_0 return _class_0 end diff --git a/elements/window.moon b/elements/window.moon index a06d55a..02336ec 100644 --- a/elements/window.moon +++ b/elements/window.moon @@ -3,9 +3,13 @@ --- @copyright Paul Liverman III (2016) --- @license The MIT License (MIT) -class window +element = require "#{(...)\sub 1, -7}/element" + +class window extends element --- Constructor expects nothing, or a data table describing it. new: (@parent, @data={}) => + super @parent, @data + --- @todo if data, do stuff about it setSize: => diff --git a/init.lua b/init.lua index 2ec7ac5..114e070 100644 --- a/init.lua +++ b/init.lua @@ -5,16 +5,21 @@ local pop = { _LICENSE = 'The MIT License (MIT)', _AUTHOR = 'Paul Liverman III' } +local log +log = function(...) + return print("[Pop.Box]", ...) +end if not (love.getVersion) then error("Pop.Box only supports LOVE versions >= 0.9.1") end -local path = ... +local path = (...):gsub("%.", "/") if (...):sub(-4) == "init" then path = (...):sub(1, -5) if not (path) then path = "." end end +log("Require path detected: \"" .. tostring(path) .. "\"") local filesystem, graphics do local _obj_0 = love @@ -29,21 +34,25 @@ pop.skins = { } pop.extensions = { } pop.screen = false pop.focused = false +pop.log = log pop.load = function() + log("Loading elements from \"" .. tostring(path) .. "/elements\"") local elements = filesystem.getDirectoryItems(tostring(path) .. "/elements") for i = 1, #elements do local _continue_0 = false repeat if not (elements[i]:sub(-4) == ".lua") then + log("Ignored non-Lua file \"" .. tostring(path) .. "/elements/" .. tostring(elements[i]) .. "\"") _continue_0 = true break end local name = elements[i]:sub(1, -5) + log("Requiring \"" .. tostring(name) .. "\" from \"" .. tostring(path) .. "/elements/" .. tostring(name) .. "\"") pop.elements[name] = require(tostring(path) .. "/elements/" .. tostring(name)) if pop.elements[name].load then pop.elements[name].load(pop) end - print("element loaded: \"" .. tostring(name) .. "\"") + log("Element loaded: \"" .. tostring(name) .. "\"") if not (pop[name]) then if pop.elements[name].wrap then pop[name] = pop.elements[name].wrap(pop) @@ -52,7 +61,7 @@ pop.load = function() return pop.create(name, ...) end end - print("wrapper created: \"pop." .. tostring(name) .. "()\"") + log("Wrapper created: \"pop." .. tostring(name) .. "()\"") end _continue_0 = true until true @@ -65,15 +74,17 @@ pop.load = function() local _continue_0 = false repeat if not (skins[i]:sub(-4) == ".lua") then + log("Ignored non-Lua file \"" .. tostring(path) .. "/skins/" .. tostring(skins[i]) .. "\"") _continue_0 = true break end local name = skins[i]:sub(1, -5) + log("Requiring \"" .. tostring(name) .. "\" from \"" .. tostring(path) .. "/skins/" .. tostring(name) .. "\"") pop.skins[name] = require(tostring(path) .. "/skins/" .. tostring(name)) if pop.skins[name].load then pop.skins[name].load(pop) end - print("skin loaded: \"" .. tostring(name) .. "\"") + log("Skin loaded: \"" .. tostring(name) .. "\"") _continue_0 = true until true if not _continue_0 then @@ -85,15 +96,17 @@ pop.load = function() local _continue_0 = false repeat if not (extensions[i]:sub(-4) == ".lua") then + log("Ignored non-Lua file \"" .. tostring(path) .. "/extensions/" .. tostring(extensions[i]) .. "\"") _continue_0 = true break end local name = extensions[i]:sub(1, -5) + log("Requiring \"" .. tostring(name) .. "\" from \"" .. tostring(path) .. "/extensions/" .. tostring(name) .. "\"") pop.extensions[name] = require(tostring(path) .. "/extensions/" .. tostring(name)) if pop.extensions[name].load then pop.extensions[name].load(pop) end - print("extension loaded: \"" .. tostring(name) .. "\"") + log("Extension loaded: \"" .. tostring(name) .. "\"") _continue_0 = true until true if not _continue_0 then @@ -101,7 +114,7 @@ pop.load = function() end end pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight()) - return print("created \"pop.screen\"") + return log("Created \"pop.screen\"") end pop.create = function(element, parent, ...) if parent == nil then @@ -160,7 +173,7 @@ pop.mousemoved = function(x, y, dx, dy) end pop.mousepressed = function(x, y, button, element) if not (element) then - print("mousepressed", x, y, button) + log("mousepressed", x, y, button) element = pop.screen end local handled = false @@ -210,13 +223,13 @@ pop.mousereleased = function(x, y, button, element) end end else - print("mousereleased", x, y, button) + log("mousereleased", x, y, button) pop.mousereleased(x, y, button, pop.screen) end return clickedHandled, mousereleasedHandled end pop.keypressed = function(key) - print("keypressed", key) + log("keypressed", key) local element = pop.focused if element and element.keypressed and element.data.draw then return element.keypressed(key) @@ -224,7 +237,7 @@ pop.keypressed = function(key) return false end pop.keyreleased = function(key) - print("keyreleased", key) + log("keyreleased", key) local element = pop.focused if element and element.keyreleased then return element.keyreleased(key) @@ -232,7 +245,7 @@ pop.keyreleased = function(key) return false end pop.textinput = function(text) - print("textinput", text) + log("textinput", text) local element = pop.focused if element and element.textinput and element.data.draw then return element.textinput(text) @@ -247,7 +260,7 @@ pop.debugDraw = function(element) element:debugDraw() else graphics.setLineWidth(1) - graphics.setLineColor(0, 0, 0, 100) + graphics.setColor(0, 0, 0, 100) graphics.rectangle("fill", element.data.x, element.data.y, element.data.w, element.data.h) graphics.setColor(150, 150, 150, 150) graphics.rectangle("line", element.data.x, element.data.y, element.data.w, element.data.h) @@ -275,7 +288,7 @@ pop.printElementTree = function(element, depth) end cls = cls .. " (" .. tostring(bg) .. ")" end - print(string.rep("-", depth) .. " " .. tostring(cls)) + log(string.rep("-", depth) .. " " .. tostring(cls)) for i = 1, #element.child do pop.printElementTree(element.child[i], depth + 1) end diff --git a/init.moon b/init.moon index 4cfb6d6..1d4aec5 100644 --- a/init.moon +++ b/init.moon @@ -12,16 +12,21 @@ pop = { _AUTHOR: 'Paul Liverman III' } +log = (...) -> + print "[Pop.Box]", ... + unless love.getVersion error "Pop.Box only supports LOVE versions >= 0.9.1" -path = ... +path = (...)\gsub "%.", "/" if (...)\sub(-4) == "init" path = (...)\sub 1, -5 unless path path = "." +log "Require path detected: \"#{path}\"" + import filesystem, graphics from love import insert from table import inheritsFromElement from require "#{path}/util" @@ -42,6 +47,7 @@ pop.skins = {} pop.extensions = {} pop.screen = false pop.focused = false +pop.log = log @@ -56,21 +62,24 @@ pop.focused = false pop.load = -> --@todo @ see Skins --@todo @ see Extensions + log "Loading elements from \"#{path}/elements\"" elements = filesystem.getDirectoryItems "#{path}/elements" for i = 1, #elements -- ignore non-Lua files unless elements[i]\sub(-4) == ".lua" + log "Ignored non-Lua file \"#{path}/elements/#{elements[i]}\"" continue -- require into pop.elements table by filename name = elements[i]\sub 1, -5 + log "Requiring \"#{name}\" from \"#{path}/elements/#{name}\"" pop.elements[name] = require "#{path}/elements/#{name}" -- call the element's load function if it exists if pop.elements[name].load pop.elements[name].load pop - print "element loaded: \"#{name}\"" + log "Element loaded: \"#{name}\"" -- create "pop.element()" function wrapper if possible unless pop[name] @@ -80,46 +89,50 @@ pop.load = -> pop[name] = (...) -> return pop.create(name, ...) - print "wrapper created: \"pop.#{name}()\"" + log "Wrapper created: \"pop.#{name}()\"" skins = filesystem.getDirectoryItems "#{path}/skins" for i = 1, #skins -- ignore non-Lua files unless skins[i]\sub(-4) == ".lua" + log "Ignored non-Lua file \"#{path}/skins/#{skins[i]}\"" continue -- require into pop.skins table by filename name = skins[i]\sub 1, -5 + log "Requiring \"#{name}\" from \"#{path}/skins/#{name}\"" pop.skins[name] = require "#{path}/skins/#{name}" -- call the skin's load function if it exists if pop.skins[name].load pop.skins[name].load pop - print "skin loaded: \"#{name}\"" + log "Skin loaded: \"#{name}\"" extensions = filesystem.getDirectoryItems "#{path}/extensions" for i = 1, #extensions -- ignore non-Lua files unless extensions[i]\sub(-4) == ".lua" + log "Ignored non-Lua file \"#{path}/extensions/#{extensions[i]}\"" continue -- require into pop.extensions by filename name = extensions[i]\sub 1, -5 + log "Requiring \"#{name}\" from \"#{path}/extensions/#{name}\"" pop.extensions[name] = require "#{path}/extensions/#{name}" -- call the extension's load function if it exists if pop.extensions[name].load pop.extensions[name].load pop - print "extension loaded: \"#{name}\"" + log "Extension loaded: \"#{name}\"" -- Initialize pop.screen (top element, GUI area) pop.screen = pop.create("element", false)\setSize(graphics.getWidth!, graphics.getHeight!) - print "created \"pop.screen\"" + log "Created \"pop.screen\"" @@ -227,7 +240,7 @@ pop.mousemoved = (x, y, dx, dy) -> pop.mousepressed = (x, y, button, element) -> -- start at the screen, print that we received an event unless element - print "mousepressed", x, y, button + log "mousepressed", x, y, button element = pop.screen -- have we handled the event? @@ -298,7 +311,7 @@ pop.mousereleased = (x, y, button, element) -> -- else, default to pop.screen to begin! (and print that we received an event) else - print "mousereleased", x, y, button + log "mousereleased", x, y, button pop.mousereleased x, y, button, pop.screen return clickedHandled, mousereleasedHandled @@ -311,7 +324,7 @@ pop.mousereleased = (x, y, button, element) -> --- @treturn boolean Was the event handled? pop.keypressed = (key) -> - print "keypressed", key + log "keypressed", key -- keypressed events must be on visible elements element = pop.focused @@ -328,7 +341,7 @@ pop.keypressed = (key) -> --- @treturn boolean Was the event handled? pop.keyreleased = (key) -> - print "keyreleased", key + log "keyreleased", key -- keyreleased events are always called element = pop.focused @@ -345,7 +358,7 @@ pop.keyreleased = (key) -> --- @treturn boolean Was the text input handled? pop.textinput = (text) -> - print "textinput", text + log "textinput", text -- textinput events must be on visible elements element = pop.focused @@ -368,7 +381,7 @@ pop.debugDraw = (element=pop.screen) -> element\debugDraw! else graphics.setLineWidth 1 - graphics.setLineColor 0, 0, 0, 100 + graphics.setColor 0, 0, 0, 100 graphics.rectangle "fill", element.data.x, element.data.y, element.data.w, element.data.h graphics.setColor 150, 150, 150, 150 graphics.rectangle "line", element.data.x, element.data.y, element.data.w, element.data.h @@ -400,7 +413,7 @@ pop.printElementTree = (element=pop.screen, depth=0) -> cls = cls .. " (#{bg})" - print string.rep("-", depth) .. " #{cls}" + log string.rep("-", depth) .. " #{cls}" for i = 1, #element.child pop.printElementTree element.child[i], depth + 1