Author: tom
Date: Tue Feb 17 13:35:28 2009
New Revision: 4263
URL: http://svn.slimdevices.com/jive?rev=4263&view=rev
Log:
Bug: N/A
Description:
- Mouse DOWN Stickiness (for container widgets Window and Group) - widget that
consumes DOWN will receive all mouse events until the UP.
- Button - button action will still occur after a drag if within a buffer
distance of the button mouse bounds.
- Group - if no contained widget consumes the mouse down event due to failing
mouseInside(), the closest contained widget to the pointer receives the DOWN
event.
- Menu - on down in the scrollbar, EVENT_CONSUME was not being returned
(needed for mouse DOWN stickiness)
Modified:
7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Button.lua
7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Group.lua
7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Menu.lua
7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Window.lua
7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_window.c
Modified: 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Button.lua
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Button.lua?rev=4263&r1=4262&r2=4263&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Button.lua (original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Button.lua Tue Feb 17
13:35:28 2009
@@ -1,4 +1,4 @@
-local _assert, pairs, string, tostring, type = _assert, pairs, string,
tostring, type
+local _assert, pairs, string, tostring, type, math = _assert, pairs, string,
tostring, type, math
local getmetatable = getmetatable
local oo = require("loop.base")
@@ -9,10 +9,16 @@
local EVENT_MOUSE_ALL = jive.ui.EVENT_MOUSE_ALL
local EVENT_MOUSE_PRESS = jive.ui.EVENT_MOUSE_PRESS
+local EVENT_MOUSE_DOWN = jive.ui.EVENT_MOUSE_DOWN
+local EVENT_MOUSE_DRAG = jive.ui.EVENT_MOUSE_DRAG
+local EVENT_MOUSE_UP = jive.ui.EVENT_MOUSE_UP
+local EVENT_FOCUS_LOST = jive.ui.EVENT_FOCUS_LOST
local EVENT_CONSUME = jive.ui.EVENT_CONSUME
local EVENT_UNUSED = jive.ui.EVENT_UNUSED
+
+local BUFFER_DISTANCE = 75
module(...)
oo.class(_M, oo.class)
@@ -25,12 +31,82 @@
function(event)
local type = event:getType()
+ if type == EVENT_MOUSE_DOWN then
+ --uncomment when pressed changes are merged
+-- widget:setStyleModifier("pressed")
+ widget:reDraw()
+ return EVENT_CONSUME
+ end
+
+ if type == EVENT_MOUSE_UP then
+ widget:setStyleModifier(nil)
+ widget:reDraw()
+
+ if mouseInsideBufferDistance(widget, event) then
+ return action()
+ end
+ --else nothing (i.e. cancel)
+ return EVENT_CONSUME
+ end
+
+ if type == EVENT_MOUSE_DRAG then
+
+ if mouseInsideBufferDistance(widget, event) then
+ --uncomment when pressed changes are
merged
+-- widget:setStyleModifier("pressed")
+ widget:reDraw()
+ else
+ widget:setStyleModifier(nil)
+ widget:reDraw()
+ end
+
+ return EVENT_CONSUME
+ end
+
if type == EVENT_MOUSE_PRESS then
return action()
end
+
+ --todo handle hold - will probably need a passed in
holdAction or pass back the state to action()
return EVENT_CONSUME
end)
return widget
end
+
+
+function mouseInsideBufferDistance(widget, event)
+ local mouseX, mouseY = event:getMouse()
+
+ local widgetX, widgetY, widgetW, widgetH = widget:getBounds()
+
+ --shortest line distances
+ local distanceX, distanceY
+
+ if mouseX < widgetX then
+ distanceX = widgetX - mouseX
+ elseif mouseX > widgetX + widgetW then
+ distanceX = mouseX - (widgetX + widgetW)
+ else
+ distanceX = 0
+ end
+
+ if mouseY < widgetY then
+ distanceY = widgetY - mouseY
+ elseif mouseY > widgetY + widgetH then
+ distanceY = mouseY - (widgetY + widgetH)
+ else
+ distanceY = 0
+ end
+
+ if distanceX == 0 and distanceY == 0 then
+ --inside mouse bounds
+ return true
+ end
+
+ --shortest distance to button bounds
+ local distance = math.sqrt( math.pow(distanceX ,2) + math.pow(distanceY
,2) )
+
+ return distance < BUFFER_DISTANCE
+end
Modified: 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Group.lua
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Group.lua?rev=4263&r1=4262&r2=4263&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Group.lua (original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Group.lua Tue Feb 17
13:35:28 2009
@@ -38,6 +38,9 @@
local EVENT_ALL = jive.ui.EVENT_ALL
local EVENT_MOUSE_ALL = jive.ui.EVENT_MOUSE_ALL
+local EVENT_MOUSE_DOWN = jive.ui.EVENT_MOUSE_DOWN
+local EVENT_MOUSE_UP = jive.ui.EVENT_MOUSE_UP
+local EVENT_MOUSE_MOVE = jive.ui.EVENT_MOUSE_MOVE
local EVENT_UNUSED = jive.ui.EVENT_UNUSED
local EVENT_SHOW = jive.ui.EVENT_SHOW
@@ -69,20 +72,73 @@
-- forward events to contained widgets
obj:addListener(EVENT_ALL,
function(event)
- local notMouse = (event:getType() &
EVENT_MOUSE_ALL) == 0
-
- for _,widget in pairs(obj.widgets) do
- if notMouse or
widget:mouseInside(event) then
- local r = widget:_event(event)
+ local notMouse = (event:getType() &
EVENT_MOUSE_ALL) == 0
+ local r = EVENT_UNUSED
+ if event:getType() == EVENT_MOUSE_MOVE then
+ local mouseX, mouseY = event:getMouse()
+ end
+
+ for _,widget in pairs(obj.widgets) do
+ if notMouse
+ or self._mouseEventFocusWidget ==
widget
+ or (not self._mouseEventFocusWidget
and widget:mouseInside(event)) then
+ r = widget:_event(event)
if r ~= EVENT_UNUSED then
- return r
+ --Consumer of
MOUSE_DOWN that is in mouse bounds will be given mouse event focus
+ if event:getType() ==
EVENT_MOUSE_DOWN then
+
self:setMouseEventFocusWidget(widget)
+ end
+ break
end
end
- end
- return EVENT_UNUSED
+ end
+
+ if r == EVENT_UNUSED and event:getType() ==
EVENT_MOUSE_DOWN then
+ log:error("here looking for a group
widget")
+
+ --no match for the down found, send to
closest group member
+ local mouseX, mouseY = event:getMouse()
+ local closestDistance = 99999
+ local closestWidget
+ for _,widget in pairs(obj.widgets) do
+ local widgetX, widgetY,
widgetW, widgetH = widget:getBounds()
+
+ local widgetDistance
+ if mouseX >= widgetW + widgetX
then
+ widgetDistance = mouseX
- (widgetW + widgetX)
+ else
+ widgetDistance =
widgetX - mouseX
+ end
+
+ if widgetDistance <
closestDistance then
+ closestDistance =
widgetDistance
+ closestWidget = widget
+ end
+ end
+ if closestWidget then
+ r = closestWidget:_event(event)
+ if r ~= EVENT_UNUSED then
+ --closest Consumer of
MOUSE_DOWN will be given mouse event focus
+ if event:getType() ==
EVENT_MOUSE_DOWN then
+
self:setMouseEventFocusWidget(closestWidget)
+ end
+ end
+ end
+ end
+
+ if event:getType() == EVENT_MOUSE_UP then
+ self:setMouseEventFocusWidget(nil)
+ end
+
+ return r
end)
return obj
+end
+
+
+function setMouseEventFocusWidget(self, widget)
+ self._mouseEventFocusWidget = widget
end
Modified: 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Menu.lua
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Menu.lua?rev=4263&r1=4262&r2=4263&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Menu.lua (original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Menu.lua Tue Feb 17
13:35:28 2009
@@ -232,7 +232,12 @@
self.sliderDragInProgress = true
end
-- forward event to scrollbar
- return self.scrollbar:_event(event)
+ local r = self.scrollbar:_event(event)
+ if evtype == EVENT_MOUSE_DOWN then
+ --slider doesnt' consume the DOWN, but we
require it to be consumed so menu is marked as the mouse focus widget.
+ r = EVENT_CONSUME
+ end
+ return r
else
--mouse is inside menu region
Modified: 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Window.lua
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Window.lua?rev=4263&r1=4262&r2=4263&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Window.lua (original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Window.lua Tue Feb 17
13:35:28 2009
@@ -64,6 +64,8 @@
local EVENT_MOUSE_HOLD = jive.ui.EVENT_MOUSE_HOLD
local EVENT_MOUSE_PRESS = jive.ui.EVENT_MOUSE_PRESS
local EVENT_MOUSE_DOWN = jive.ui.EVENT_MOUSE_DOWN
+local EVENT_MOUSE_UP = jive.ui.EVENT_MOUSE_UP
+local EVENT_MOUSE_ALL = jive.ui.EVENT_MOUSE_ALL
local EVENT_ACTION = jive.ui.EVENT_ACTION
local EVENT_SCROLL = jive.ui.EVENT_SCROLL
local EVENT_KEY_PRESS = jive.ui.EVENT_KEY_PRESS
@@ -1413,13 +1415,47 @@
function _event(self, event)
- local r = self:_eventHandler(event)
+ local notMouse = (event:getType() & EVENT_MOUSE_ALL) == 0
+
+ local r
+ if notMouse then
+ r = self:_eventHandler(event)
+ else
+ --handle mouse locally, no need for C optimization on mouse
platforms
+ r = self:iterate(
+ function(widget)
+ if self._mouseEventFocusWidget == widget or
(not self._mouseEventFocusWidget and widget:mouseInside(event)) then
+ local rClosure = widget:_event(event)
+ if rClosure ~= EVENT_UNUSED then
+ --Consumer of MOUSE_DOWN that
is in mouse bounds will be given mouse event focus
+ if event:getType() ==
EVENT_MOUSE_DOWN then
+
self:setMouseEventFocusWidget(widget)
+ end
+ return rClosure
+ end
+
+ end
+ end
+ )
+
+ if event:getType() == EVENT_MOUSE_UP then
+ self:setMouseEventFocusWidget(nil)
+ end
+
+ end
if r & EVENT_CONSUME == 0 then
r = Widget._event(self, event)
end
return r
+end
+
+
+function setMouseEventFocusWidget(self, widget)
+ log:debug("setMouseEventFocusWidget: ", widget)
+
+ self._mouseEventFocusWidget = widget
end
Modified: 7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_window.c
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_window.c?rev=4263&r1=4262&r2=4263&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_window.c (original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_window.c Tue Feb 17
13:35:28 2009
@@ -367,6 +367,7 @@
case JIVE_EVENT_MOUSE_MOVE:
case JIVE_EVENT_MOUSE_DRAG:
/* Forward mouse events to the enclosed widgets */
+ /* C side mouse handling is no longer used, is now handled
inside the Lua code */
if (jive_getmethod(L, 1, "iterate")) {
lua_pushvalue(L, 1); // widget
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/jive-checkins