SFML community forums

Help => General => Topic started by: flashrocket on May 04, 2014, 02:02:02 pm

Title: Differenciating mouse click and mouse drag
Post by: flashrocket on May 04, 2014, 02:02:02 pm
I want to perform different actions for mouse clicked and mouse dragged.
mouse drag means click and move mouse.
Title: Re: Differenciating mouse click and mouse drag
Post by: Geheim on May 04, 2014, 02:57:01 pm
So yeah... :D

Why don't you then go ahead and implement these things?
Or don't you know how to and ask for something specific?
Title: Re: Differenciating mouse click and mouse drag
Post by: Ixrec on May 04, 2014, 03:00:06 pm
The MouseButtonPressed, MouseButtonReleased and MouseMoved events should be all you need to implement drag-and-drop behavior.
Title: Re: Differenciating mouse click and mouse drag
Post by: Jesper Juhl on May 04, 2014, 03:02:51 pm
So, what you want is something like the following (I guess).

If you get a mouse down event this might mean either click or drag, so we'll defer judgement to later. For now just remember that we've received a down event.
If we receive a mouse up event without any mouse move events in between, then this was a click, so do whatever clicking is supposed to do.
If we get a move event before any up event then that's a signal that the user started a drag, so remember that so that when the mouse up event comes we can do whatever drag does.

Am I close? If not then please describe your problem in more detail.
Title: Re: Differenciating mouse click and mouse drag
Post by: flashrocket on May 04, 2014, 03:20:18 pm
@Jesper Juhl
Thanks that was exactly what i wanted.
Title: Re: Differenciating mouse click and mouse drag
Post by: Jesper Juhl on May 04, 2014, 04:11:24 pm
@Jesper Juhl
Thanks that was exactly what i wanted.

Great  :)
In the future you could help yourself a bit by being a bit more explicit about what you are asking. It wasn't entirely clear to me if you were expecting SFML to have some explicit drag-n-drop support or if you just didn't know how to build it yourself or something else. Extra details and explicit questions make everything easier for everyone.