Player: how to create a dragStop message ?

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
sandoval31
Posts: 9
Joined: Wed Dec 14, 2016 3:44 pm

Player: how to create a dragStop message ?

Post by sandoval31 » Fri Jan 06, 2017 11:47 am

Hi,

Within a player, I would like to allow the user to manually drag the boundary of the selection (start time and end time).
I can use a dragStart message to catch if the user start to drag, but I can't get the final positions of the elements, because I don't know when the user stop to drag.

I have tried something like this:

Code: Select all

on dragStart
   repeat until the mouse is up
      wait 5
   end repeat
   put the timeScale of me into sr
   put the endTime of me into endT
   put endT/sr
end dragStart
But the player is frozen with the wait command. So the user can't move the boundaries, and I can't get the final position of the "endTime".
How to wait until the mouse is up, but without frozen the player?

Thanks a lot. :D

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

Re: Player: how to create a dragStop message ?

Post by Klaus » Fri Jan 06, 2017 3:22 pm

Hi sandoval31,

1. welcome to the forum! :D

2. Since you have a "wait" command inside of the "repeat" loop, this will of course
accumulate and when the mouse is finally up, the engine may have summed up all this
and will wait EONS! :D

And "wait" is blocking, so it will seem that everything is frozen.
If you want a non-locking wait, add "with messages"
...
wait 5 with messages
...
This will give the engine time to handle other "events" during the wait!

3. "dragstart" is not the right command for this task!
Simply add a "mouseup" handler to the player object and check the starttime and/or endtime
"showselection" of the player needs to be set to true (= checked in inspector for the player)

Just made a quick test, see below and works fine.

Code: Select all

on mouseup
   put the starttime of me && the endtime of me into fld 1
end mouseup
I got the new selection of the player in my field after "dragging" the selection handles.

Hope that helps!


Best

Klaus

Martin Koob
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 256
Joined: Sun May 27, 2007 8:19 pm

Re: Player: how to create a dragStop message ?

Post by Martin Koob » Fri Jan 06, 2017 3:47 pm

Hi

if you have the highlite selection property of the player set to true you don't need dragStart. You can use the mouseUp button to capture both the start time and endtime when the dragging of the playhead/thumb of the scroller.

Code: Select all

on mouseup
   put the timescale of me into tTimeScale
   put the starttime of me / tTimeScale into tStartTime
   put the endtime of me / tTimeScale into tEndTime
   put tStartTime & comma & tEndTime 
end mouseup
If for some reason you did not want have the hilite of the selection set to true you could use a combination of DragStart and MouseUp to capture that information.

Code: Select all

local sDragStart, sDragEnd, sSelectionTimes, sTimeScale

on mouseDown
   # clear selection
   put empty into sDragStart
   put empty into sDragEnd
   put the timescale of me into sTimeScale
end mouseDown

on dragstart
   #Get the start time
   put the currenttime of me / sTimeScale into sDragStart
end dragstart

on mouseUp
   if  sDragStart is not empty then
      # get the end time if there is a selection started.
      put the currenttime of me  / sTimeScale into sDragEnd
   end if
   # Order of Time Points
   # sDragStart will contain the time point the selection started
   # sDragEnd will contain the time point the selection ended
   # you have to determine whether the variables go into startTime or endTime
   if sDragStart < sDragEnd then
      put sDragStart into item 1of sSelectiontimes
      put sDragEnd into item 2 of sSelectiontimes
   else
      put sDragStart into item 2of sSelectiontimes
      put sDragEnd into item 1 of sSelectiontimes
   end if
   set the starttime of me to item 1 of sSelectionTimes * sTimeScale
   set the endtime of me to item 2 of sSelectionTimes * sTimeScale
   
   put sSelectionTimes into message
   put CR & the starttime of me after message
   put comma & the endtime of me after message
end mouseUp
Martin

Martin Koob
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 256
Joined: Sun May 27, 2007 8:19 pm

Re: Player: how to create a dragStop message ?

Post by Martin Koob » Fri Jan 06, 2017 4:01 pm

Sorry just noticed that Klaus posted while I was typing my response. So my first answer is basically what he said but he said it more succinctly :D

Martin

sandoval31
Posts: 9
Joined: Wed Dec 14, 2016 3:44 pm

Re: Player: how to create a dragStop message ?

Post by sandoval31 » Fri Jan 06, 2017 4:47 pm

Thank you Klaus and Martin for your answers,

It definitely works fine with a simple mouseup handler.

Just a subsidiary question... for a better GUI! With the "currentTimeChanged" handler, I am able to display the time value of the cursor in real time.
With the mouseup handler, however, the endTime is displayed only when the mouse button is released, but not in real time. Is there a way to display it in real time (i.e. when the user is currently dragging the endTime boundary ) ?

Thanks again.

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

Re: Player: how to create a dragStop message ?

Post by Klaus » Fri Jan 06, 2017 5:34 pm

Hola sandoval31,

add another "trigger" to the player object:

Code: Select all

on selectionchanged
   put the endtime of me into fld 1
end selectionchanged
Works here, but did not test with Martins script with "mouseup"!


Best

Klaus

sandoval31
Posts: 9
Joined: Wed Dec 14, 2016 3:44 pm

Re: Player: how to create a dragStop message ?

Post by sandoval31 » Wed Jan 11, 2017 11:18 am

Thanks Klaus,

It works very well with the handler "selectionchanged".
"Mouseup" is not needed anymore!
Moreover, there is some drawbacks with mouse up (for instance the position of the mouse when the button is released, on the player or not) that does not exist with "selectionchanged".

Actually, I wasn't aware that this message could be used!
"Selectionchanged" does not appear in the dictionary. Why that ? Is there other message that I can use with the player that are not in the dictionary ?

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

Re: Player: how to create a dragStop message ?

Post by Klaus » Wed Jan 11, 2017 12:20 pm

sandoval31 wrote:"Selectionchanged" does not appear in the dictionary. Why that ? Is there other message that I can use with the player that are not in the dictionary ?
It is in the dictionary of LC 8.1.2 and also in LC 9 dp4!? :shock:
What version are you using?

Martin Koob
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 256
Joined: Sun May 27, 2007 8:19 pm

Re: Player: how to create a dragStop message ?

Post by Martin Koob » Wed Jan 11, 2017 1:50 pm

I thought maybe you had selected a filter in the dictionary like 'stack' or something other than player and that was causing it not to be visible.

Actually I found that in LC 8.1.2 and LC 9.0.0 if you select the player filter and type selectionChanged in the search box the message is not shown in the search results.

If there is no filter selected the selectionChanged message is shown. Obviously this a documentation bug.

Sandoval31 you should post a bug at http://quality.livecode.com.

This does not happen in LC 6.3.1 and selectionChanged is included in search results if Player is selected as a filter.

I am not sure if there are other commands or messages that this has happened to. You could compare what is shown in LC 6.7.x and in LC 8 and LC 9

Martin

sandoval31
Posts: 9
Joined: Wed Dec 14, 2016 3:44 pm

Re: Player: how to create a dragStop message ?

Post by sandoval31 » Wed Jan 11, 2017 2:13 pm

I am using Livecode community 9.0.
I don't know if your messages are relevant with the community version? Is it the same dictionary?


Actually I can find the "selectionchanged" message page in the dictionary,
but the "selectionchanged" message is not mentioned in the "player" object page.

I don't know if this is a bug or if I don't use the dictionary properly.

Martin Koob
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 256
Joined: Sun May 27, 2007 8:19 pm

Re: Player: how to create a dragStop message ?

Post by Martin Koob » Wed Jan 11, 2017 2:44 pm

I am using the Business version. It is Probably best for you to go ahead and post it as a bug in Community 9.0 and put all the cases you found it in. Let us know the bug number here and Others can add to the bug where we see it. Then the LiveCode team can determine whether it is a bug or not and then take action.

Just so you can see the entry in the dictionary for selectionChanged here it is in the online dictionary.

https://livecode.com/resources/api/#liv ... ionchanged

It looks like the bug is that in the Associations field it only has 'field'. It should also have 'player'

Martin

sandoval31
Posts: 9
Joined: Wed Dec 14, 2016 3:44 pm

Re: Player: how to create a dragStop message ?

Post by sandoval31 » Wed Jan 11, 2017 2:57 pm

Thanks for the explanation.
I reported a bug: bug 19083

Post Reply

Return to “Multimedia”