SFML community forums

General => Feature requests => Topic started by: Phanoo on October 15, 2017, 01:46:51 pm

Title: double click ?
Post by: Phanoo on October 15, 2017, 01:46:51 pm
Maybe it's me but i didnt find a mouse DoubleClick event. Would be nice if included.

It's not reliable to do it manually, since the double click speed is user-configurable in most operating systems, doing it with a hard coded timer (like suggested in an old post i found) would not be good for user experience
Title: Re: double click ?
Post by: korczurekk on October 15, 2017, 06:53:53 pm
Double–click event could actually have some considerable overhead, so I don't really want to see it being included in SFML. sf::Time getDoubleClickTime(), on the other hand, would be great.
Title: Re: double click ?
Post by: Phanoo on October 15, 2017, 06:55:28 pm
overhead for such thing are you serious ?
Title: Re: double click ?
Post by: korczurekk on October 15, 2017, 07:03:27 pm
It has to keep track of timing (i.e. remember when last click happened) and I can imagine situations where this could be undesirable. Anyway, it's up to SFML devs to decide, this feature, either as an event or in the way I described, has many use–cases, so it would be nice to have it.
Title: Re: double click ?
Post by: Phanoo on October 15, 2017, 08:21:26 pm
I'm not sure it has to keep track of the timing since it's an event sent by the operating system (just guessing here I didnt looked the docs, but I really doubt every application handle that with custom timing code).

I remember in applications like The Games Factory or Multimedia Fusion (game making tools) I had to check for Click and DoubleClick if i wanted my game to handle fast clicks without missing some of them, because the operating system would send alternatively Click and DoubleClick events on fast repeated button presses. So maybe SFML already has this bit of code somewhere (faking single clicks when a DoubleClick event is received)
Title: Re: double click ?
Post by: FRex on October 15, 2017, 10:21:20 pm
Windows has special events for double clicks https://msdn.microsoft.com/en-us/library/windows/desktop/ms645606(v=vs.85).aspx SFML doesn't catch these kinds of events at all because it (probably) doesn't have the CS_DBLCLKS style set.
Title: Re: double click ?
Post by: Hiura on October 16, 2017, 05:41:48 pm
It's not reliable to do it manually, since the double click speed is user-configurable in most operating systems, doing it with a hard coded timer (like suggested in an old post i found) would not be good for user experience

I think this is a sensible argument. Would you create a PR for that? Shouldn't be that hard I guess.

Performance wise, there's probably no concern to have I would say, but it's always good to double check of course.
Title: Re: double click ?
Post by: FRex on October 17, 2017, 12:31:44 pm
I could try make a Windows implementation later this week if the OP doesn't, WinAPI seems simple enough. I'm a bit busy lately though and don't have time or patience to dig into X/Linux windowing right now but I'd assume it has similar features but a different API since many environments let you configure double click speed. No idea about Mac.

The bigger problem here is the API. I.e.: should this be on by default or not and should it be toggleable, should it be a bool field in the current mouse down or a separate new event, etc.
Title: Re: double click ?
Post by: Laurent on October 17, 2017, 12:36:52 pm
Quote
should this be on by default or not and should it be toggleable
Why would we make an event optional? The only reason would be if it messes up with single clicks, but then there are probably better solutions.

Quote
should it be a bool field in the current mouse down or a separate new event
A separate event.
Title: Re: double click ?
Post by: FRex on October 17, 2017, 12:52:08 pm
It'll be a regression, someone updating the SFML and keeping all of their code the same will now miss these presses that are part of a double click (they will get: press, release, double, release instead of current: press, release, press, release). As in the doc I linked (it's for left button but right and middle have corresponding ones of the same kind which I'd assume will work the same):
Quote
Double-clicking the left mouse button actually generates a sequence of four messages: WM_LBUTTONDOWN, WM_LBUTTONUP, WM_LBUTTONDBLCLK, and WM_LBUTTONUP.
Title: Re: double click ?
Post by: Laurent on October 17, 2017, 01:50:09 pm
Ok, that's precisely what I had in mind with "if it messes up with single clicks".
Title: Re: double click ?
Post by: Phanoo on October 17, 2017, 06:55:58 pm
mmmh that's what i though about the single / double click sequence. I guess something like this would be needed for compatibility : (and to me it's the way it should have been done directly by the Windows programmers)

Quote
Single click OS event : trigger Single click SFML event

Double click OS event : trigger Double click SFML event AND Single click SFML event

I'm not familiar with SFML internal code neither Windows API, but i can look at that when i have time
Title: Re: double click ?
Post by: AlejandroCoria on October 17, 2017, 07:38:05 pm
Maybe we should put a bool in MouseButtonEvent that says whether it is a double click or not. That way, those clicks do not send two events. I do not know if it is a good idea or if it is used in other libraries.
Title: Re: double click ?
Post by: FRex on October 17, 2017, 07:45:33 pm
Up to Laurent. The naming will be funny, we can't call it 'double'. ;D
Title: Re: double click ?
Post by: Hiura on October 17, 2017, 09:54:37 pm
Quote
Single click OS event : trigger Single click SFML event

Double click OS event : trigger Double click SFML event AND Single click SFML event

That won't do it: how do you know a single click event is not *also* a double click event? You can't.

Maybe we should put a bool in MouseButtonEvent that says whether it is a double click or not. That way, those clicks do not send two events. I do not know if it is a good idea or if it is used in other libraries. One just needs to read the `clickCount` property of an `NSEvent` to support this -- in case one of you decide to implement this.

I think this is close to optimal. To fully leverage what macOS offers in SFML we could use an integer instead of a boolean. I don't know about other OSes, but this counter enables us to (for example) double click on a word to select it and triple click to select the whole paragraph.
Title: Re: double click ?
Post by: FRex on October 19, 2017, 08:33:41 pm
CS_DBLCLKS is a window class style, we have one window class that is shared between all windows so we can't set/unset it per window (I didn't even yet see if you can set class window styles at creation or later too like with SetWindowLongPtr for window styles per handle). :'(

On the other hand, there is this function to query: https://msdn.microsoft.com/en-us/library/windows/desktop/ms646258(v=vs.85).aspx

There also isn't a triple click.
Maybe we should go with an int after all? Or even just expose the above function as static in Window or Mouse and make it return Time?

First draft for sequence field in event (beware, the int will be uninitialized outside Windows  :P ):
Branch: https://github.com/FRex/SFML/tree/multiclickwin32only
Test: https://gist.github.com/FRex/83ab096bacb356afcf6fabd97f7ab841
Title: Re: double click ?
Post by: barnack on October 26, 2017, 03:19:25 pm
Yeah, Windows offers you a double click event, but you gotta check if Linux does as well.
Also, yes, as you said double click timing is an user setting on Windows, but you can check in many games, there's an in-game setting for double click timing. Can't you do the same?
(Also note, to distinct double clicks you'd also have to delay the single click event, since when the first click occurs you have no way to know if the second is coming or not. Unless you want to do statistics based on mouse position over certain items, but that'd be crazy, un efficient and... crazy)
Title: Re: double click ?
Post by: FRex on October 26, 2017, 03:37:35 pm
Windows doesn't delay the first event so neither should we, that'd be a horrible lag if it did that.

Setting double click time in the app regardless of what the OS has.. I'm not sure. You can handle it ALL (timing, handling double, triple, qurduple, etc. click events in your code) yourself then using what SFML now has.

Although getting double click time from the OS might be a nice default/reset for your setting (i.e. it's adjustable but you can reset it to 'get double click time from OS') so there's a use case.

On the other hand, X apparently has no double click (the WM does): https://github.com/glfw/glfw/issues/462 so.. yeah. We're left with:

I also have no idea about Mac (I don't own one, I don't know Obj C, it's hard and illegal to run OS X on non-Apple machines, etc.).