From 630cb51b59f3cb21f321ce5d24dddc4eea53d702 Mon Sep 17 00:00:00 2001 From: Paul Liverman III Date: Wed, 12 Apr 2017 03:37:29 -0700 Subject: [PATCH] more updates! --- docs/classes/element.html | 2 +- docs/classes/window.html | 2 +- docs/index.html | 2 +- docs/modules/Element.html | 2 +- docs/modules/main.html | 2 +- docs/modules/pop.html | 37 ++++++++++++++++++++++++++++++++++++- docs/modules/util.html | 2 +- elements/element.lua | 3 +++ elements/element.moon | 1 + init.lua | 18 ++++++++++++++++-- init.moon | 27 +++++++++++++++++++++++++-- 11 files changed, 87 insertions(+), 11 deletions(-) diff --git a/docs/classes/element.html b/docs/classes/element.html index 1f596f7..b47c802 100644 --- a/docs/classes/element.html +++ b/docs/classes/element.html @@ -426,7 +426,7 @@
generated by LDoc 1.4.3 -Last updated 2017-04-11 10:42:17 +Last updated 2017-04-12 03:37:15
diff --git a/docs/classes/window.html b/docs/classes/window.html index 42c1cad..1a13454 100644 --- a/docs/classes/window.html +++ b/docs/classes/window.html @@ -144,7 +144,7 @@
generated by LDoc 1.4.3 -Last updated 2017-04-11 10:42:17 +Last updated 2017-04-12 03:37:15
diff --git a/docs/index.html b/docs/index.html index 9560101..11bd9a2 100644 --- a/docs/index.html +++ b/docs/index.html @@ -84,7 +84,7 @@
generated by LDoc 1.4.3 -Last updated 2017-04-11 10:42:17 +Last updated 2017-04-12 03:37:15
diff --git a/docs/modules/Element.html b/docs/modules/Element.html index db21abb..876ccca 100644 --- a/docs/modules/Element.html +++ b/docs/modules/Element.html @@ -491,7 +491,7 @@
generated by LDoc 1.4.3 -Last updated 2017-04-11 10:42:17 +Last updated 2017-04-12 03:37:15
diff --git a/docs/modules/main.html b/docs/modules/main.html index c21791c..107af7c 100644 --- a/docs/modules/main.html +++ b/docs/modules/main.html @@ -105,7 +105,7 @@
generated by LDoc 1.4.3 -Last updated 2017-04-11 10:42:17 +Last updated 2017-04-12 03:37:15
diff --git a/docs/modules/pop.html b/docs/modules/pop.html index 3e762e1..1f436c8 100644 --- a/docs/modules/pop.html +++ b/docs/modules/pop.html @@ -99,6 +99,10 @@ Event handler for love.mousereleased(). + wheelmoved (x, y) + Event handler for love.wheelmoved() + + keypressed (key) Event handler for love.keypressed(). @@ -427,6 +431,37 @@ table.insert element.parent, element.parent\removeChild(element), + +
+ + wheelmoved (x, y) +
+
+ Event handler for love.wheelmoved() + + +

Parameters:

+ + +

Returns:

+
    + + boolean + Was the event handled? +
+ + + +
@@ -723,7 +758,7 @@ table.insert element.parent, element.parent\removeChild(element),
generated by LDoc 1.4.3 -Last updated 2017-04-11 10:42:17 +Last updated 2017-04-12 03:37:15
diff --git a/docs/modules/util.html b/docs/modules/util.html index a97b5d8..4a5fad1 100644 --- a/docs/modules/util.html +++ b/docs/modules/util.html @@ -126,7 +126,7 @@
generated by LDoc 1.4.3 -Last updated 2017-04-11 10:42:17 +Last updated 2017-04-12 03:37:15
diff --git a/elements/element.lua b/elements/element.lua index c992d35..7eef533 100644 --- a/elements/element.lua +++ b/elements/element.lua @@ -172,6 +172,9 @@ do if self.data.draw == nil then self.data.draw = true end + if self.data.hoverable == nil then + self.data.hoverable = true + end if not (self.data.type) then self.data.type = "element" end diff --git a/elements/element.moon b/elements/element.moon index 1a316c9..bcd5582 100644 --- a/elements/element.moon +++ b/elements/element.moon @@ -23,6 +23,7 @@ class element @data.h = 0 unless @data.h @data.update = true if @data.update == nil @data.draw = true if @data.draw == nil + @data.hoverable = true if @data.hoverable == nil @data.type = "element" unless @data.type @data.align = true if (@data.align == nil) and @parent @data.vertical = "top" unless @data.vertical diff --git a/init.lua b/init.lua index 206db11..9c166f8 100644 --- a/init.lua +++ b/init.lua @@ -213,9 +213,9 @@ pop.mousemoved = function(x, y, dx, dy, element) if element == nil then element = pop.screen end - if element.data.draw and (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h) then + if element.data.draw and element.data.hoverable and (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h) then pop.hovered = element - for i = #element.child, 1, -1 do + for i = 1, #element.child do pop.mousemoved(x, y, dx, dy, element.child[i]) end end @@ -226,6 +226,13 @@ pop.mousemoved = function(x, y, dx, dy, element) end pop.mousepressed = function(x, y, button, element) if not (element) then + if button == "wd" then + pop.wheelmoved(0, -1) + return true + elseif button == "wu" then + pop.wheelmoved(0, 1) + return true + end log("mousepressed", x, y, button) element = pop.screen end @@ -281,6 +288,13 @@ pop.mousereleased = function(x, y, button, element) end return clickedHandled, mousereleasedHandled end +pop.wheelmoved = function(x, y) + log("wheelmoved", x, y) + if pop.hovered and pop.hovered.wheelmoved then + return pop.hovered:wheelmoved(x, y) + end + return false +end pop.keypressed = function(key) log("keypressed", key) local element = pop.focused diff --git a/init.moon b/init.moon index b3998a6..7b39d98 100644 --- a/init.moon +++ b/init.moon @@ -267,11 +267,11 @@ pop.draw = (element=pop.screen) -> pop.mousemoved = (x, y, dx, dy, element=pop.screen) -> -- first we find out if we're hovering over anything and set pop.hovered - if element.data.draw and (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h) + if element.data.draw and element.data.hoverable and (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h) -- okay, we're over this element for sure, but let's check its children pop.hovered = element -- check in reverse order, it will set pop.hovered to any that match - for i = #element.child, 1, -1 + for i = 1, #element.child pop.mousemoved x, y, dx, dy, element.child[i] --- @todo Implement a way for an element to attach itself to `love.mousemoved()` events? @@ -297,6 +297,14 @@ pop.mousemoved = (x, y, dx, dy, element=pop.screen) -> pop.mousepressed = (x, y, button, element) -> -- start at the screen, print that we received an event unless element + -- take pre 0.10.0 wheel movement and pass it along + if button == "wd" + pop.wheelmoved 0, -1 + return true + elseif button == "wu" + pop.wheelmoved 0, 1 + return true + log "mousepressed", x, y, button element = pop.screen @@ -374,6 +382,21 @@ pop.mousereleased = (x, y, button, element) -> +--- Event handler for `love.wheelmoved()` +--- @function wheelmoved +--- @tparam number x The distance the wheel moved on the x-axis. +--- @tparam number y The distance the wheel moved on the y-axis. +--- @treturn boolean Was the event handled? +pop.wheelmoved = (x, y) -> + log "wheelmoved", x, y + + if pop.hovered and pop.hovered.wheelmoved + return pop.hovered\wheelmoved x, y + + return false + + + --- Event handler for `love.keypressed()`. --- @function keypressed --- @tparam string key The key that was pressed.