From 6c1df2ca55c6ee9cded5239a409bba08b9c0c42b Mon Sep 17 00:00:00 2001 From: Paul Liverman III Date: Fri, 1 Apr 2016 20:45:43 -0700 Subject: [PATCH] re-organized, mousemove events, extensions --- build.sh | 5 ++ demo/main.lua | 10 ++- demo/pop/elements/element.lua | 6 ++ demo/pop/elements/window.lua | 44 ++++++++-- demo/pop/extensions/streamlined_get_set.lua | 44 ++++++++++ demo/pop/init.lua | 92 ++++++++++++++------- demo/pop/util.lua | 19 +++++ lib/pop/elements/element.lua | 6 ++ lib/pop/elements/window.lua | 44 ++++++++-- lib/pop/extensions/streamlined_get_set.lua | 44 ++++++++++ lib/pop/init.lua | 92 ++++++++++++++------- lib/pop/util.lua | 19 +++++ src/pop/elements/element.moon | 6 ++ src/pop/elements/window.moon | 37 ++++++++- src/pop/extensions/streamlined_get_set.moon | 35 ++++++++ src/pop/init.moon | 73 ++++++++-------- src/pop/util.moon | 17 ++++ 17 files changed, 479 insertions(+), 114 deletions(-) create mode 100755 build.sh create mode 100644 demo/pop/extensions/streamlined_get_set.lua create mode 100644 demo/pop/util.lua create mode 100644 lib/pop/extensions/streamlined_get_set.lua create mode 100644 lib/pop/util.lua create mode 100644 src/pop/util.moon diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..d9ec838 --- /dev/null +++ b/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash +cd src +moonc -t ../lib . +cd .. +cp -rf ./lib/pop/* ./demo/pop/ diff --git a/demo/main.lua b/demo/main.lua index 04df5c5..3b3bc6a 100644 --- a/demo/main.lua +++ b/demo/main.lua @@ -23,9 +23,11 @@ function love.load() --]] --c:move(100) - pop.box({255, 0, 0, 255}):position(50, 600) -- testing streamlined_get_set extension & optional parents + pop.box({255, 0, 0, 255}):position(50, 500) -- testing streamlined_get_set extension & optional parents + --b:margin(2) -- testing streamlined_get_set extension + b:fill() -- testing fill! - --[[ + ---[[ w2 = pop.window(nil, "Window") w2:move(100, 100) w2:setWidth(500) @@ -67,6 +69,10 @@ function love.draw() end end +function love.mousemoved(x, y, dx, dy) + pop.mousemoved(x, y, dx, dy) +end + function love.mousepressed(x, y, button) pop.mousepressed(x, y, button) end diff --git a/demo/pop/elements/element.lua b/demo/pop/elements/element.lua index d94dae6..60ab9df 100644 --- a/demo/pop/elements/element.lua +++ b/demo/pop/elements/element.lua @@ -196,6 +196,12 @@ do end, getMargin = function(self) return self.margin + end, + fill = function(self) + self.x = self.parent.x + self.margin + self.y = self.parent.y + self.margin + self.w = self.parent.w - self.margin * 2 + self.h = self.parent.h - self.margin * 2 end } _base_0.__index = _base_0 diff --git a/demo/pop/elements/window.lua b/demo/pop/elements/window.lua index f98d497..a3b8f47 100644 --- a/demo/pop/elements/window.lua +++ b/demo/pop/elements/window.lua @@ -9,6 +9,23 @@ local path = sub(..., 1, len(...) - len("/window")) local element = require(tostring(path) .. "/element") local box = require(tostring(path) .. "/box") local text = require(tostring(path) .. "/text") +local left = 1 +local move_event = true +do + local major, minor, revision = love.getVersion() + if (major == 0) and (minor == 10) and ((revision == 0) or (revision == 1)) then + left = 1 + end + if (major == 0) and (minor == 9) then + left = "l" + if revision == 1 then + move_event = false + end + else + print("elements/window: unrecognized LÖVE version: " .. tostring(major) .. "." .. tostring(minor) .. "." .. tostring(revision)) + print(" assuming LÖVE version > 0.10.1 (there may be bugs)") + end +end local window do local _class_0 @@ -94,7 +111,7 @@ do _base_0.__index = _base_0 setmetatable(_base_0, _parent_0.__base) _class_0 = setmetatable({ - __init = function(self, parent, title, tBackground) + __init = function(self, parent, title, tBackground, tColor, wBackground) if title == nil then title = "window" end @@ -106,15 +123,26 @@ do 255 } end + if tColor == nil then + tColor = { + 255, + 255, + 255, + 255 + } + end + if wBackground == nil then + wBackground = { + 200, + 200, + 210, + 255 + } + end _class_0.__parent.__init(self, parent) self.head = box(self, tBackground) - self.title = text(self, title) - self.window = box(self, { - 0, - 0, - 0, - 255 - }) + self.title = text(self, title, tColor) + self.window = box(self, wBackground) local height = self.title:getHeight() self.head:setSize(self.w, height) self.window:move(nil, height) diff --git a/demo/pop/extensions/streamlined_get_set.lua b/demo/pop/extensions/streamlined_get_set.lua new file mode 100644 index 0000000..7f95704 --- /dev/null +++ b/demo/pop/extensions/streamlined_get_set.lua @@ -0,0 +1,44 @@ +local graphics +graphics = love.graphics +local sub, len +do + local _obj_0 = string + sub, len = _obj_0.sub, _obj_0.len +end +local path = sub(..., 1, len(...) - len("/extensions/streamlined_get_set")) +local element = require(tostring(path) .. "/elements/element") +element.__base.position = function(self, x, y) + if x or y then + return self:setPosition(x, y) + else + return self:getPosition() + end +end +element.__base.size = function(self, w, h) + if w or h then + return self:setSize(w, h) + else + return self:getSize() + end +end +element.__base.width = function(self, w) + if w then + return self:setWidth(w) + else + return self:getWidth() + end +end +element.__base.height = function(self, h) + if h then + return self:setHeight(h) + else + return self:getHeight() + end +end +element.__base.margin = function(self, m) + if m then + return self:setMargin(m) + else + return self:getMargin() + end +end diff --git a/demo/pop/init.lua b/demo/pop/init.lua index 33069fe..e27518c 100644 --- a/demo/pop/init.lua +++ b/demo/pop/init.lua @@ -1,3 +1,6 @@ +if not (love.getVersion) then + error("Pop.Box only supports LÖVE versions >= 0.9.1") +end local filesystem, graphics do local _obj_0 = love @@ -5,10 +8,13 @@ do end local insert insert = table.insert +local inheritsFromElement +inheritsFromElement = require(tostring(...) .. "/util").inheritsFromElement local path = ... local pop = { } pop.elements = { } pop.skins = { } +pop.events = { } pop.screen = false pop.focused = false pop.load = function() @@ -56,36 +62,38 @@ pop.load = function() break end end - pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight()) - return print("created \"pop.screen\"") -end -local instanceOfElement -instanceOfElement = function(object) - if object and object.__class then - local cls = object.__class - if cls.__name == "element" then - return true - end - while cls.__parent do - cls = cls.__parent - if cls.__name == "element" then - return true + local extensions = filesystem.getDirectoryItems(tostring(path) .. "/extensions") + for i = 1, #extensions do + local _continue_0 = false + repeat + if not (extensions[i]:sub(-4) == ".lua") then + _continue_0 = true + break end + local name = extensions[i]:sub(1, -5) + require(tostring(path) .. "/extensions/" .. tostring(name)) + print("extension loaded: \"" .. tostring(name) .. "\"") + _continue_0 = true + until true + if not _continue_0 then + break end end - return false + pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight()) + return print("created \"pop.screen\"") end pop.create = function(element, parent, ...) if parent == nil then parent = pop.screen end - if instanceOfElement(parent) then + if inheritsFromElement(parent) then element = pop.elements[element](parent, ...) + insert(parent.child, element) + elseif parent == false then + element = pop.elements[element](false, ...) else element = pop.elements[element](pop.screen, parent, ...) - end - if parent then - insert(parent.child, element) + insert(pop.screen.child, element) end return element end @@ -115,12 +123,16 @@ pop.draw = function(element) end end end -pop.mousepressed = function(x, y, button, element) - if element == nil then - element = pop.screen +pop.mousemoved = function(self, x, y, dx, dy) + if pop.focused and pop.focused.mousemoved then + return pop.focused:mousemoved(x, y, dx, dy) end - if element == pop.screen then - print("mousepressed", x, y, button, element) + return false +end +pop.mousepressed = function(x, y, button, element) + if not (element) then + print("mousepressed", x, y, button) + element = pop.screen end local handled = false if (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) then @@ -139,13 +151,37 @@ pop.mousepressed = function(x, y, button, element) end end end + if handled then + pop.events[button] = element + end return handled end -pop.mousereleased = function(x, y, button, element) - if element == nil then - element = pop.screen +pop.mousereleased = function(x, y, button) + print("mousereleased", x, y, button) + local clickedHandled = false + local mousereleasedHandled = false + do + local element = pop.events[button] + if element then + if element.clicked and (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) then + do + clickedHandled = element:clicked(x - element.x, y - element.y, button) + if clickedHandled then + pop.events[button] = nil + end + end + end + if element.mousereleased then + do + mousereleasedHandled = element:mousereleased(x - element.x, y - element.y, button) + if mousereleasedHandled then + pop.events[button] = nil + end + end + end + end end - return false + return clickedHandled, mousereleasedHandled end pop.keypressed = function(key) print("keypressed", key) diff --git a/demo/pop/util.lua b/demo/pop/util.lua new file mode 100644 index 0000000..0804d8b --- /dev/null +++ b/demo/pop/util.lua @@ -0,0 +1,19 @@ +local inheritsFromElement +inheritsFromElement = function(object) + if object and object.__class then + local cls = object.__class + if cls.__name == "element" then + return true + end + while cls.__parent do + cls = cls.__parent + if cls.__name == "element" then + return true + end + end + end + return false +end +return { + inheritsFromElement = inheritsFromElement +} diff --git a/lib/pop/elements/element.lua b/lib/pop/elements/element.lua index d94dae6..60ab9df 100644 --- a/lib/pop/elements/element.lua +++ b/lib/pop/elements/element.lua @@ -196,6 +196,12 @@ do end, getMargin = function(self) return self.margin + end, + fill = function(self) + self.x = self.parent.x + self.margin + self.y = self.parent.y + self.margin + self.w = self.parent.w - self.margin * 2 + self.h = self.parent.h - self.margin * 2 end } _base_0.__index = _base_0 diff --git a/lib/pop/elements/window.lua b/lib/pop/elements/window.lua index f98d497..a3b8f47 100644 --- a/lib/pop/elements/window.lua +++ b/lib/pop/elements/window.lua @@ -9,6 +9,23 @@ local path = sub(..., 1, len(...) - len("/window")) local element = require(tostring(path) .. "/element") local box = require(tostring(path) .. "/box") local text = require(tostring(path) .. "/text") +local left = 1 +local move_event = true +do + local major, minor, revision = love.getVersion() + if (major == 0) and (minor == 10) and ((revision == 0) or (revision == 1)) then + left = 1 + end + if (major == 0) and (minor == 9) then + left = "l" + if revision == 1 then + move_event = false + end + else + print("elements/window: unrecognized LÖVE version: " .. tostring(major) .. "." .. tostring(minor) .. "." .. tostring(revision)) + print(" assuming LÖVE version > 0.10.1 (there may be bugs)") + end +end local window do local _class_0 @@ -94,7 +111,7 @@ do _base_0.__index = _base_0 setmetatable(_base_0, _parent_0.__base) _class_0 = setmetatable({ - __init = function(self, parent, title, tBackground) + __init = function(self, parent, title, tBackground, tColor, wBackground) if title == nil then title = "window" end @@ -106,15 +123,26 @@ do 255 } end + if tColor == nil then + tColor = { + 255, + 255, + 255, + 255 + } + end + if wBackground == nil then + wBackground = { + 200, + 200, + 210, + 255 + } + end _class_0.__parent.__init(self, parent) self.head = box(self, tBackground) - self.title = text(self, title) - self.window = box(self, { - 0, - 0, - 0, - 255 - }) + self.title = text(self, title, tColor) + self.window = box(self, wBackground) local height = self.title:getHeight() self.head:setSize(self.w, height) self.window:move(nil, height) diff --git a/lib/pop/extensions/streamlined_get_set.lua b/lib/pop/extensions/streamlined_get_set.lua new file mode 100644 index 0000000..7f95704 --- /dev/null +++ b/lib/pop/extensions/streamlined_get_set.lua @@ -0,0 +1,44 @@ +local graphics +graphics = love.graphics +local sub, len +do + local _obj_0 = string + sub, len = _obj_0.sub, _obj_0.len +end +local path = sub(..., 1, len(...) - len("/extensions/streamlined_get_set")) +local element = require(tostring(path) .. "/elements/element") +element.__base.position = function(self, x, y) + if x or y then + return self:setPosition(x, y) + else + return self:getPosition() + end +end +element.__base.size = function(self, w, h) + if w or h then + return self:setSize(w, h) + else + return self:getSize() + end +end +element.__base.width = function(self, w) + if w then + return self:setWidth(w) + else + return self:getWidth() + end +end +element.__base.height = function(self, h) + if h then + return self:setHeight(h) + else + return self:getHeight() + end +end +element.__base.margin = function(self, m) + if m then + return self:setMargin(m) + else + return self:getMargin() + end +end diff --git a/lib/pop/init.lua b/lib/pop/init.lua index 33069fe..e27518c 100644 --- a/lib/pop/init.lua +++ b/lib/pop/init.lua @@ -1,3 +1,6 @@ +if not (love.getVersion) then + error("Pop.Box only supports LÖVE versions >= 0.9.1") +end local filesystem, graphics do local _obj_0 = love @@ -5,10 +8,13 @@ do end local insert insert = table.insert +local inheritsFromElement +inheritsFromElement = require(tostring(...) .. "/util").inheritsFromElement local path = ... local pop = { } pop.elements = { } pop.skins = { } +pop.events = { } pop.screen = false pop.focused = false pop.load = function() @@ -56,36 +62,38 @@ pop.load = function() break end end - pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight()) - return print("created \"pop.screen\"") -end -local instanceOfElement -instanceOfElement = function(object) - if object and object.__class then - local cls = object.__class - if cls.__name == "element" then - return true - end - while cls.__parent do - cls = cls.__parent - if cls.__name == "element" then - return true + local extensions = filesystem.getDirectoryItems(tostring(path) .. "/extensions") + for i = 1, #extensions do + local _continue_0 = false + repeat + if not (extensions[i]:sub(-4) == ".lua") then + _continue_0 = true + break end + local name = extensions[i]:sub(1, -5) + require(tostring(path) .. "/extensions/" .. tostring(name)) + print("extension loaded: \"" .. tostring(name) .. "\"") + _continue_0 = true + until true + if not _continue_0 then + break end end - return false + pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight()) + return print("created \"pop.screen\"") end pop.create = function(element, parent, ...) if parent == nil then parent = pop.screen end - if instanceOfElement(parent) then + if inheritsFromElement(parent) then element = pop.elements[element](parent, ...) + insert(parent.child, element) + elseif parent == false then + element = pop.elements[element](false, ...) else element = pop.elements[element](pop.screen, parent, ...) - end - if parent then - insert(parent.child, element) + insert(pop.screen.child, element) end return element end @@ -115,12 +123,16 @@ pop.draw = function(element) end end end -pop.mousepressed = function(x, y, button, element) - if element == nil then - element = pop.screen +pop.mousemoved = function(self, x, y, dx, dy) + if pop.focused and pop.focused.mousemoved then + return pop.focused:mousemoved(x, y, dx, dy) end - if element == pop.screen then - print("mousepressed", x, y, button, element) + return false +end +pop.mousepressed = function(x, y, button, element) + if not (element) then + print("mousepressed", x, y, button) + element = pop.screen end local handled = false if (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) then @@ -139,13 +151,37 @@ pop.mousepressed = function(x, y, button, element) end end end + if handled then + pop.events[button] = element + end return handled end -pop.mousereleased = function(x, y, button, element) - if element == nil then - element = pop.screen +pop.mousereleased = function(x, y, button) + print("mousereleased", x, y, button) + local clickedHandled = false + local mousereleasedHandled = false + do + local element = pop.events[button] + if element then + if element.clicked and (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) then + do + clickedHandled = element:clicked(x - element.x, y - element.y, button) + if clickedHandled then + pop.events[button] = nil + end + end + end + if element.mousereleased then + do + mousereleasedHandled = element:mousereleased(x - element.x, y - element.y, button) + if mousereleasedHandled then + pop.events[button] = nil + end + end + end + end end - return false + return clickedHandled, mousereleasedHandled end pop.keypressed = function(key) print("keypressed", key) diff --git a/lib/pop/util.lua b/lib/pop/util.lua new file mode 100644 index 0000000..0804d8b --- /dev/null +++ b/lib/pop/util.lua @@ -0,0 +1,19 @@ +local inheritsFromElement +inheritsFromElement = function(object) + if object and object.__class then + local cls = object.__class + if cls.__name == "element" then + return true + end + while cls.__parent do + cls = cls.__parent + if cls.__name == "element" then + return true + end + end + end + return false +end +return { + inheritsFromElement = inheritsFromElement +} diff --git a/src/pop/elements/element.moon b/src/pop/elements/element.moon index 45a9d32..b3f8c83 100644 --- a/src/pop/elements/element.moon +++ b/src/pop/elements/element.moon @@ -223,3 +223,9 @@ class element getMargin: => return @margin + + fill: => + @x = @parent.x + @margin + @y = @parent.y + @margin + @w = @parent.w - @margin*2 + @h = @parent.h - @margin*2 diff --git a/src/pop/elements/window.moon b/src/pop/elements/window.moon index c356c95..c25a2d2 100644 --- a/src/pop/elements/window.moon +++ b/src/pop/elements/window.moon @@ -6,13 +6,29 @@ element = require "#{path}/element" box = require "#{path}/box" text = require "#{path}/text" +-- version compatibility +left = 1 -- what is the left mouse button? +move_event = true -- is the mousemoved event available? + +do + major, minor, revision = love.getVersion! + if (major == 0) and (minor == 10) and ((revision == 0) or (revision == 1)) + left = 1 -- redundant, but whatever + if (major == 0) and (minor == 9) + left = "l" + if revision == 1 + move_event = false + else + print "elements/window: unrecognized LÖVE version: #{major}.#{minor}.#{revision}" + print " assuming LÖVE version > 0.10.1 (there may be bugs)" + class window extends element - new: (parent, title="window", tBackground={25, 180, 230, 255}) => + new: (parent, title="window", tBackground={25, 180, 230, 255}, tColor={255, 255, 255, 255}, wBackground={200, 200, 210, 255}) => super parent @head = box @, tBackground -- title box at top - @title = text @, title -- text at top - @window = box @, {0,0,0,255} -- main window area + @title = text @, title, tColor -- text at top + @window = box @, wBackground -- main window area -- correct placement / sizes of elements height = @title\getHeight! @@ -25,6 +41,9 @@ class window extends element @head, @title, @window } + --@selected = false -- whether or not the window title (and thus, the window) has been selected + --NOTE all of these commented out, because I realized these event handlers should be attached to the title element + debugDraw: => graphics.setLineWidth 0.5 graphics.setColor 0, 0, 0, 100 @@ -36,6 +55,18 @@ class window extends element return @ + --update: => + -- if selected, set position based on current mouse position relative to position it was when mousepressed + + --mousemoved: (x, y, dx, dy) => + -- if selected, set position based on new mouse position relative to position it was when mousepressed + + --mousepressed: (x, y, button) => + -- if button == "l" -> selected = true, mouse position saved + + --mousereleased: (x, y, button) => + -- if button == "l" -> set position based on position relative to when mousepressed, selected == false + setSize: (w, h) => x = 0 y = 0 diff --git a/src/pop/extensions/streamlined_get_set.moon b/src/pop/extensions/streamlined_get_set.moon index bfd8ab3..3ffed7a 100644 --- a/src/pop/extensions/streamlined_get_set.moon +++ b/src/pop/extensions/streamlined_get_set.moon @@ -12,3 +12,38 @@ element.__base.position = (x, y) => return @setPosition x, y else return @getPosition! + +element.__base.size = (w, h) => + if w or h + return @setSize w, h + else + return @getSize! + +element.__base.width = (w) => + if w + return @setWidth w + else + return @getWidth! + +element.__base.height = (h) => + if h + return @setHeight h + else + return @getHeight! + +element.__base.margin = (m) => + if m + return @setMargin m + else + return @getMargin! + +--oldinit = element.__init +-- +--element.__init = (...) -> +-- object = oldinit ... +-- value = object.margin +-- +-- object.margin = setmetatable {:value}, { +-- __call: (...) -> +-- print ... +-- } diff --git a/src/pop/init.moon b/src/pop/init.moon index ba3c848..5f7e48b 100644 --- a/src/pop/init.moon +++ b/src/pop/init.moon @@ -1,5 +1,9 @@ +unless love.getVersion + error "Pop.Box only supports LÖVE versions >= 0.9.1" + import filesystem, graphics from love import insert from table +import inheritsFromElement from require "#{...}/util" path = ... @@ -7,6 +11,7 @@ pop = {} pop.elements = {} pop.skins = {} +pop.events = {} pop.screen = false -- initialized in pop.load() pop.focused = false @@ -57,29 +62,19 @@ pop.load = -> name = extensions[i]\sub 1, -5 require "#{path}/extensions/#{name}" + print "extension loaded: \"#{name}\"" + -- main window (called screen because there will be a window element class) pop.screen = pop.create("element", false)\setSize(graphics.getWidth!, graphics.getHeight!) print "created \"pop.screen\"" -instanceOfElement = (object) -> - if object and object.__class - cls = object.__class - - if cls.__name == "element" - return true - - while cls.__parent - cls = cls.__parent - if cls.__name == "element" - return true - - return false - -- creates an element with specified parent (parent can be false or non-existent) pop.create = (element, parent=pop.screen, ...) -> - if instanceOfElement parent + if inheritsFromElement parent element = pop.elements[element](parent, ...) insert parent.child, element + elseif parent == false + element = pop.elements[element](false, ...) else element = pop.elements[element](pop.screen, parent, ...) insert pop.screen.child, element @@ -102,11 +97,19 @@ pop.draw = (element=pop.screen) -> for i = 1, #element.child pop.draw element.child[i] -pop.mousepressed = (x, y, button, element=pop.screen) -> - if element == pop.screen - print "mousepressed", x, y, button, element +pop.mousemoved = (x, y, dx, dy) => + if pop.focused and pop.focused.mousemoved + return pop.focused\mousemoved x, y, dx, dy + + return false + +pop.mousepressed = (x, y, button, element) -> + unless element + print "mousepressed", x, y, button + element = pop.screen handled = false + if (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) if element.mousepressed handled = element\mousepressed x - element.x, y - element.y, button @@ -118,31 +121,27 @@ pop.mousepressed = (x, y, button, element=pop.screen) -> if handled pop.focused = element.child[i] break + if handled + pop.events[button] = element + return handled -pop.mousereleased = (x, y, button, element=pop.screen) -> - --[[ - --if element == pop.screen - -- print "mousereleased", x, y, button, element +pop.mousereleased = (x, y, button) -> + print "mousereleased", x, y, button - --clickHandled = false - --mouseReleaseHandled = false + clickedHandled = false + mousereleasedHandled = false - --if (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) - -- if element.mousereleased - -- mouseReleaseHandled = element\mousereleased x - element.x, y - element.y, button - -- unless mouseReleaseHandled - -- for i = 1, #element.child - -- clickHandled, mouseReleaseHandled = pop.mousereleased x, y, button, element.child[i] - -- if mouseReleaseHandled - -- break + if element = pop.events[button] + if element.clicked and (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) + if clickedHandled = element\clicked x - element.x, y - element.y, button + pop.events[button] = nil - --if element == pop.focused + if element.mousereleased + if mousereleasedHandled = element\mousereleased x - element.x, y - element.y, button + pop.events[button] = nil - --return mouseReleaseHandled - --]] - - return false -- ugh this sucks + return clickedHandled, mousereleasedHandled pop.keypressed = (key) -> print "keypressed", key diff --git a/src/pop/util.moon b/src/pop/util.moon new file mode 100644 index 0000000..b985e13 --- /dev/null +++ b/src/pop/util.moon @@ -0,0 +1,17 @@ +inheritsFromElement = (object) -> + if object and object.__class + cls = object.__class + + if cls.__name == "element" + return true + + while cls.__parent + cls = cls.__parent + if cls.__name == "element" + return true + + return false + +return { + :inheritsFromElement +}