Author: tom
Date: Wed Feb 25 13:37:57 2009
New Revision: 4471

URL: http://svn.slimdevices.com/jive?rev=4471&view=rev
Log:
Bug: N/A
Description:
Slider: now more correctly returns EVENT_CONSUME for mouse and scroll events.
Slider: Mouse event stickiness is now working for sliders in a group. Allows 
slider mouse drag to consitnue outside slider bounds. 
Volume/Scanner: now use closure for slider mouse and scroll activity

Modified:
    7.4/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/Scanner.lua
    7.4/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/Volume.lua
    7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Slider.lua

Modified: 
7.4/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/Scanner.lua
URL: 
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/Scanner.lua?rev=4471&r1=4470&r2=4471&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/Scanner.lua 
(original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/Scanner.lua 
Wed Feb 25 13:37:57 2009
@@ -107,8 +107,12 @@
        local title = Label("title", "")
        popup:addWidget(title)
 
-       local slider = Slider("scanner")
-       slider:setRange(0, tonumber(self.duration), tonumber(self.elapsed))
+       local slider = Slider("scanner", 0, tonumber(self.duration), 
tonumber(self.elapsed),
+                       function(slider, value, done)
+                               self.delta = value - self.elapsed
+                               self.elapsed = value
+                               _updateSelectedTime(self)
+                       end)
        self.scannerGroup = Group("scannerGroup", {
                                              elapsed = Label("text", ""),
                                              slider = slider,
@@ -149,7 +153,7 @@
 end
 
 
-local function _updateSelectedTime(self)
+function _updateSelectedTime(self)
        if not self.popup then
                self.displayTimer:stop()
                self.holdTimer:stop()
@@ -235,19 +239,7 @@
 
        local type = event:getType()
        
-       if type == EVENT_SCROLL then
-               local scroll = event:getScroll()
-
-               if scroll > 0 then
-                       self.delta = 1
-               elseif scroll < 0 then
-                       self.delta = -1
-               else
-                       self.delta = 0
-               end
-               _updateSelectedTime(self)
-
-       elseif type == ACTION then
+       if type == ACTION then
                local action = event:getAction()
 
                -- GO closes the popup & executes any pending change

Modified: 
7.4/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/Volume.lua
URL: 
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/Volume.lua?rev=4471&r1=4470&r2=4471&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/Volume.lua 
(original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/Volume.lua 
Wed Feb 25 13:37:57 2009
@@ -1,5 +1,5 @@
 
--- Private class to handle player volume 
+-- Private class to handle player volume
 
 local tostring = tostring
 
@@ -72,15 +72,19 @@
        local title = Label("title", "")
        popup:addWidget(title)
 
-       local slider = Slider("volume")
-       slider:setRange(-1, 100, self.volume)
+       --slider is focused widget so it will receive events before popup gets 
a chance
+       local slider = Slider("slider", -1, 100, self.volume,
+                              function(slider, value, done)
+                                       self.delta = value - self.volume
+                                       self:_updateVolume(false, value)
+                              end)
        popup:addWidget(Group("volumeGroup", {
                                      Icon("volumeMin"),
                                      slider,
                                      Icon("volumeMax")
                              }))
 
-       popup:addListener(ACTION | EVENT_KEY_ALL | EVENT_SCROLL,
+       popup:addListener(ACTION | EVENT_KEY_ALL,
                          function(event)
                                  return self:event(event)
                          end)
@@ -95,7 +99,7 @@
 
        _updateDisplay(self)
 
-       popup:showBriefly(2000,
+       popup:showBriefly(3000,
                function()
                        self.popup = nil
                end,
@@ -105,7 +109,7 @@
 end
 
 
-local function _updateVolume(self, mute)
+function _updateVolume(self, mute, directSet)
        if not self.popup then
                self.timer:stop()
                return
@@ -126,21 +130,27 @@
                return _updateDisplay(self)
        end
 
-       -- accelation
-       local now = Framework:getTicks()
-       if self.accelDelta ~= self.delta or (now - self.lastUpdate) > 350 then
-               self.accelCount = 0
-       end
-
-       self.accelCount = math.min(self.accelCount + 1, 20)
-       self.accelDelta = self.delta
-       self.lastUpdate = now
-
-       -- change volume
-       local accel = self.accelCount / 4
-       local new = math.abs(self.volume) + self.delta * accel * VOLUME_STEP
-       
-       if new > 100 then 
+       local new
+
+       if directSet then
+               new = math.floor(directSet)
+       else
+               -- accelation
+               local now = Framework:getTicks()
+               if self.accelDelta ~= self.delta or (now - self.lastUpdate) > 
350 then
+                       self.accelCount = 0
+               end
+
+               self.accelCount = math.min(self.accelCount + 1, 20)
+               self.accelDelta = self.delta
+               self.lastUpdate = now
+
+               -- change volume
+               local accel = self.accelCount / 4
+               new = math.floor(math.abs(self.volume) + self.delta * accel * 
VOLUME_STEP)
+       end
+
+       if new > 100 then
                new = 100
        elseif new < 0 then
                new = 0
@@ -178,20 +188,8 @@
        end
 
        local type = event:getType()
-       
-       if type == EVENT_SCROLL then
-               local scroll = event:getScroll()
-
-               if scroll > 0 then
-                       self.delta = 1
-               elseif scroll < 0 then
-                       self.delta = -1
-               else
-                       self.delta = 0
-               end
-               _updateVolume(self)
-
-       elseif type == ACTION then
+
+       if type == ACTION then
                local action = event:getAction()
                if action == "volume_up" then
                        self.delta = 1
@@ -253,7 +251,7 @@
                        _updateVolume(self)
                        self.delta = 0
                end
-                                       
+
                return EVENT_CONSUME
 
        else

Modified: 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Slider.lua
URL: 
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Slider.lua?rev=4471&r1=4470&r2=4471&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Slider.lua (original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Slider.lua Wed Feb 25 
13:37:57 2009
@@ -48,8 +48,12 @@
 local EVENT_SCROLL    = jive.ui.EVENT_SCROLL
 local EVENT_CONSUME   = jive.ui.EVENT_CONSUME
 local EVENT_UNUSED    = jive.ui.EVENT_UNUSED
-local EVENT_MOUSE_DOWN = jive.ui.EVENT_MOUSE_DOWN
-local EVENT_MOUSE_DRAG = jive.ui.EVENT_MOUSE_DRAG
+local EVENT_MOUSE_HOLD        = jive.ui.EVENT_MOUSE_HOLD
+local EVENT_MOUSE_DRAG        = jive.ui.EVENT_MOUSE_DRAG
+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 KEY_BACK        = jive.ui.KEY_BACK
 local KEY_UP          = jive.ui.KEY_UP
@@ -79,7 +83,7 @@
 
        obj:addActionListener("go", obj, _callClosureAction)
        obj:addActionListener("play", obj, _callClosureAction)
-       obj:addListener(EVENT_SCROLL | EVENT_KEY_PRESS | EVENT_MOUSE_DOWN | 
EVENT_MOUSE_DRAG,
+       obj:addListener(EVENT_SCROLL | EVENT_KEY_PRESS | EVENT_MOUSE_ALL,
                        function(event)
                                return obj:_eventHandler(event)
                        end)
@@ -204,8 +208,7 @@
 
        if type == EVENT_SCROLL then
                self:_moveSlider(event:getScroll())
-               return EVENT_UNUSED --current usages need this so they can 
handle the scroll directly
-
+               return EVENT_CONSUME
        elseif type == EVENT_MOUSE_DOWN or
                type == EVENT_MOUSE_DRAG then
 
@@ -218,7 +221,12 @@
                        -- vertical
                        self:_setSlider(y / h)
                end
-               return EVENT_UNUSED --current usages need this so they can 
handle the scroll directly
+               return EVENT_CONSUME
+       elseif type == EVENT_MOUSE_UP or
+               type == EVENT_MOUSE_PRESS or
+               type == EVENT_MOUSE_HOLD then
+               --ignore
+               return EVENT_CONSUME
 
        elseif type == EVENT_KEY_PRESS then
                local keycode = event:getKeycode()
@@ -227,6 +235,8 @@
                if keycode == KEY_FWD then
                        return _callClosureAction(self, event)
                end
+
+               return EVENT_UNUSED
        end
 end
 

_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/jive-checkins

Reply via email to