custom slider : mouseRelease & mouseUp not triggered

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
FredBeck
Posts: 77
Joined: Fri Nov 01, 2013 3:07 pm
Location: Paris
Contact:

custom slider : mouseRelease & mouseUp not triggered

Post by FredBeck » Tue Jan 19, 2016 3:07 pm

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
Attachments
slider.zip
(2.15 KiB) Downloaded 164 times

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: custom slider : mouseRelease & mouseUp not triggered

Post by Dixie » Tue Jan 19, 2016 3:44 pm

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 !?

FredBeck
Posts: 77
Joined: Fri Nov 01, 2013 3:07 pm
Location: Paris
Contact:

Re: custom slider : mouseRelease & mouseUp not triggered

Post by FredBeck » Tue Jan 19, 2016 4:03 pm

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: custom slider : mouseRelease & mouseUp not triggered

Post by bn » Tue Jan 19, 2016 4:37 pm

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

FredBeck
Posts: 77
Joined: Fri Nov 01, 2013 3:07 pm
Location: Paris
Contact:

Re: custom slider : mouseRelease & mouseUp not triggered

Post by FredBeck » Tue Jan 19, 2016 5:06 pm

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

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: custom slider : mouseRelease & mouseUp not triggered

Post by Klaus » Tue Jan 19, 2016 5:30 pm

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

FredBeck
Posts: 77
Joined: Fri Nov 01, 2013 3:07 pm
Location: Paris
Contact:

Re: custom slider : mouseRelease & mouseUp not triggered

Post by FredBeck » Tue Jan 19, 2016 6:21 pm

Klaus, thanks! All is well oiled now.
Now I remember reading this a couple years ago…
F.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”