Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: double click ?  (Read 10174 times)

0 Members and 1 Guest are viewing this topic.

Phanoo

  • Full Member
  • ***
  • Posts: 136
    • View Profile
double click ?
« 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
« Last Edit: October 15, 2017, 04:19:06 pm by ratatax »

korczurekk

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • Email
Re: double click ?
« Reply #1 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.

Phanoo

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: double click ?
« Reply #2 on: October 15, 2017, 06:55:28 pm »
overhead for such thing are you serious ?

korczurekk

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • Email
Re: double click ?
« Reply #3 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.

Phanoo

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: double click ?
« Reply #4 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)
« Last Edit: October 15, 2017, 08:32:01 pm by ratatax »

FRex

  • Hero Member
  • *****
  • Posts: 1846
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: double click ?
« Reply #5 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.
Back to C++ gamedev with SFML in May 2023

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: double click ?
« Reply #6 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.
SFML / OS X developer

FRex

  • Hero Member
  • *****
  • Posts: 1846
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: double click ?
« Reply #7 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.
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: double click ?
« Reply #8 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.
Laurent Gomila - SFML developer

FRex

  • Hero Member
  • *****
  • Posts: 1846
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: double click ?
« Reply #9 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.
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: double click ?
« Reply #10 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".
Laurent Gomila - SFML developer

Phanoo

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: double click ?
« Reply #11 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
« Last Edit: October 17, 2017, 06:57:38 pm by ratatax »

AlejandroCoria

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
    • alejandrocoria.games
    • Email
Re: double click ?
« Reply #12 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.

FRex

  • Hero Member
  • *****
  • Posts: 1846
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: double click ?
« Reply #13 on: October 17, 2017, 07:45:33 pm »
Up to Laurent. The naming will be funny, we can't call it 'double'. ;D
Back to C++ gamedev with SFML in May 2023

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: double click ?
« Reply #14 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.
SFML / OS X developer