From 3fb4b15241515fc80d7e200c9805ad9fe88d4262 Mon Sep 17 00:00:00 2001 From: Paul Liverman III Date: Tue, 18 Apr 2017 22:44:42 -0700 Subject: [PATCH] removed unneeded checks in mouse handling --- init.lua | 30 +++++++++++++----------------- init.moon | 39 ++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 38 deletions(-) diff --git a/init.lua b/init.lua index 9c166f8..34e6871 100644 --- a/init.lua +++ b/init.lua @@ -246,13 +246,11 @@ pop.mousepressed = function(x, y, button, element) end end end - if not (handled) then - if element.mousepressed then - do - handled = element:mousepressed(x - element.data.x, y - element.data.y, button) - if handled then - pop.focused = element - end + if element.mousepressed then + do + handled = element:mousepressed(x - element.data.x, y - element.data.y, button) + if handled then + pop.focused = element end end end @@ -270,16 +268,14 @@ pop.mousereleased = function(x, y, button, element) return clickedHandled, mousereleasedHandled end end - if not (clickedHandled or mousereleasedHandled) then - if element.clicked then - clickedHandled = element:clicked(x - element.data.x, y - element.data.y, button) - end - if element.mousereleased then - mousereleasedHandled = element:mousereleased(x - element.data.x, y - element.data.y, button) - end - if clickedHandled then - pop.focused = element - end + if element.clicked then + clickedHandled = element:clicked(x - element.data.x, y - element.data.y, button) + end + if element.mousereleased then + mousereleasedHandled = element:mousereleased(x - element.data.x, y - element.data.y, button) + end + if clickedHandled then + pop.focused = element end end else diff --git a/init.moon b/init.moon index 7b39d98..2f5b3e7 100644 --- a/init.moon +++ b/init.moon @@ -318,12 +318,10 @@ pop.mousepressed = (x, y, button, element) -> if handled = pop.mousepressed x, y, button, element.child[i] return handled - -- if a child hasn't handled it yet (note: this check doesn't seem neccessary) - unless handled - -- if we can handle it, try to handle it, and set pop.focused - if element.mousepressed - if handled = element\mousepressed x - element.data.x, y - element.data.y, button - pop.focused = element + -- if a child hasn't handled it yet, try to handle it, and set pop.focused + if element.mousepressed + if handled = element\mousepressed x - element.data.x, y - element.data.y, button + pop.focused = element -- return whether or not we have handled the event return handled @@ -356,22 +354,21 @@ pop.mousereleased = (x, y, button, element) -> if clickedHandled or mousereleasedHandled return clickedHandled, mousereleasedHandled - -- if that doesn't work, we try to handle it ourselves (note: again, this check seems unneccessary) - unless clickedHandled or mousereleasedHandled - if element.clicked - clickedHandled = element\clicked x - element.data.x, y - element.data.y, button - if element.mousereleased - mousereleasedHandled = element\mousereleased x - element.data.x, y - element.data.y, button + -- if that doesn't work, we try to handle it ourselves + if element.clicked + clickedHandled = element\clicked x - element.data.x, y - element.data.y, button + if element.mousereleased + mousereleasedHandled = element\mousereleased x - element.data.x, y - element.data.y, button - -- if we clicked, we're focused! - if clickedHandled - pop.focused = element - --- @todo Figure out how to bring a focused element to the front of view (aka the first element in its parent's children). - --- (If I do it right here, the for loop above may break! I need to test/figure this out.) - --NOTE this might cause an error in the above for loop! - -- basically, move focused element to front of its parent's child - --element.parent\focusChild element - --table.insert element.parent, element.parent\removeChild(element), + -- if we clicked, we're focused! + if clickedHandled + pop.focused = element + --- @todo Figure out how to bring a focused element to the front of view (aka the first element in its parent's children). + --- (If I do it right here, the for loop above may break! I need to test/figure this out.) + --NOTE this might cause an error in the above for loop! + -- basically, move focused element to front of its parent's child + --element.parent\focusChild element + --table.insert element.parent, element.parent\removeChild(element), -- else, default to pop.screen to begin! (and print that we received an event) else