Page 1 of 1

custom slider : mouseRelease & mouseUp not triggered

Posted: Tue Jan 19, 2016 3:07 pm
by FredBeck
Hi,
I must be missing something here...
A group contains three objects with no script
the group script is below
the mouseUp and mouseRelease messages are not hadled consistently to say the least.
stack attached
Thanks...
Fred.

LC 7 stable

Code: Select all

local sLeft, sRight
local sX, sY

on mouseDown pBtn
   # the vertical position
   put item 2 of the loc of grc "Axis" of  me  into sY
   
   # left and right limits
   put the left of grc "Axis" of me + (the width of btn "Thumb" of me / 2) into sLeft
   put the right of grc "Axis" of me - (the width of btn "Thumb" of me / 2) into sRight
      
   repeat while the mouse is down
      lock screen

      put item 1 of the mouseLoc into sX
      
      # check against limits
      if sX < sLeft then put sLeft into sX
      if sX > sRight then put sRight into sX
      
      # set thumb btn loc
      set the loc of btn "Thumb" of me to sX, sY
      
      set the text of fld "Label" of me to the uThumb of me -- for now
      
       # set label fld loc
      if sX < sLeft + (sRight - sLeft) / 2 then
         set the left of fld "Label" of me to the right of btn "Thumb" of me
         set the textAlign of fld "Label" of me to left
      else
         set the right of fld "Label" of me to the left of btn "Thumb" of me
         set the textAlign of fld "Label" of me to right
      end if
      
      unlock screen
   end repeat
   
   pass mouseDown
end mouseDown


setProp uThumb pValue
   # set normalized value
   put item 2 of the loc grc "Axis" of  me  into sY
   put the left of grc "Axis" of  me  into sLeft
   put the right of grc "Axis" of me  into sRight
   put pValue * (sRight - sLeft) +sLeft into sX
   set the loc of btn "Thumb" of me to sX, sY
   pass uThumb
end uThumb

getProp uThumb
   # get normalized value
   return (sX - sLeft) / (sRight - sLeft)
end uThumb


-- I dont want to send the value untill I release the mouse button 
-- but these seem to be triggered only once in a while...

on mouseUp pBtn
   set the backColor of btn "Thumb" of me to black
   wait for 0.3 sec
   set the backColor of btn "Thumb" of me to white
   answer "mouseUp"
   pass mouseUp
end mouseUp

on mouseRelease pBtn
   set the backColor of btn "Thumb" of me to black
   wait for 0.3 sec
   set the backColor of btn "Thumb" of me to white
   answer "mouseRelease"
   pass mouseRelease
end mouseRelease

Re: custom slider : mouseRelease & mouseUp not triggered

Posted: Tue Jan 19, 2016 3:44 pm
by Dixie
Since you, as the author, were making the statement 'mouseRelease & mouseUp not triggered'... I expected that to be the case... However, it works for me...:-) If I release the mouse whilst still inside the graphic 'thumb' then, mouseUp is fired... outside the graphic 'thumb' mouseRealease is fired...

I don't see the problem !?

Re: custom slider : mouseRelease & mouseUp not triggered

Posted: Tue Jan 19, 2016 4:03 pm
by FredBeck
Dixie wrote:Since you, as the author, were making the statement 'mouseRelease & mouseUp not triggered'... I expected that to be the case... However, it works for me...:-) If I release the mouse whilst still inside the graphic 'thumb' then, mouseUp is fired... outside the graphic 'thumb' mouseRealease is fired...

I don't see the problem !?
Do I need to post a video on the tube??
Well I have no clue...
I can see the messages in the message watcher but the only way I found to trigger them 100% of the time is to click 2 mouse buttons.
This also happens in standalone.
Anyway I found the solution to my problem but still I'm quite puzzled.
F

Re: custom slider : mouseRelease & mouseUp not triggered

Posted: Tue Jan 19, 2016 4:37 pm
by bn
Hi Fred,
Anyway I found the solution to my problem but still I'm quite puzzled.
Would you mind sharing your solution?

I can not reproduce your problem either. Which version of LC7 stable? Which input device? Mouse, trackpad etc. Which operating version?

Kind regards
Bernd

Re: custom slider : mouseRelease & mouseUp not triggered

Posted: Tue Jan 19, 2016 5:06 pm
by FredBeck
Bernd,
Solution : do my stuff at the end of the mouseDown...

LC version : 7.1.1 STABLE (16 dec 2015)
OS : Win 7 Pro 64bits
Device : Mouse

Thanks for your interest!

Fred.

This works for me :

Code: Select all

on mouseDown pBtn
   # the vertical position
   put item 2 of the loc of grc "Axis" of  me  into sY
   
   # left and right limits
   put the left of grc "Axis" of me + (the width of btn "Thumb" of me / 2) into sLeft
   put the right of grc "Axis" of me - (the width of btn "Thumb" of me / 2) into sRight
   
   repeat while the mouse is down
      lock screen
      put item 1 of the mouseLoc into sX
      
      # check against limits
      if sX < sLeft then put sLeft into sX
      if sX > sRight then put sRight into sX
      
      # set thumb btn loc
      set the loc of btn "Thumb" of me to sX, sY
      
      set the text of fld "Label" of me to the uThumb of me -- for now
      
      # set label fld loc
      if sX < sLeft + (sRight - sLeft) / 2 then
         set the left of fld "Label" of me to the right of btn "Thumb" of me
         set the textAlign of fld "Label" of me to left
      else
         set the right of fld "Label" of me to the left of btn "Thumb" of me
         set the textAlign of fld "Label" of me to right
      end if
      
      unlock screen
   end repeat
   
   
   -- solution : do my stuff at the end of the mouseDown...
   dispatch "sliderUpdated"
   
   pass mouseDown
end mouseDown
   
      
command sliderUpdated
   set the backColor of btn "Thumb" of me to black
   wait for 0.2 sec with messages
   set the backColor of btn "Thumb" of me to white
   pass sliderUpdated
end sliderUpdated

Re: custom slider : mouseRelease & mouseUp not triggered

Posted: Tue Jan 19, 2016 5:30 pm
by Klaus
Hi guys,

I grew up in a time where polling the mouse ate lots of cpu resources, so I always use "mousemove"
for things like custom sliders etc... :D

Here a good read about the issue: http://www.hyperactivesw.com/resources_polling.html


Best

Klaus

Re: custom slider : mouseRelease & mouseUp not triggered

Posted: Tue Jan 19, 2016 6:21 pm
by FredBeck
Klaus, thanks! All is well oiled now.
Now I remember reading this a couple years ago…
F.