ryanisaacg / quicksilver

A simple framework for 2D games on desktop and web
https://ryanisaacg.github.io/quicksilver
Other
782 stars 77 forks source link

More advanced click handling… #640

Open bwinton opened 4 years ago

bwinton commented 4 years ago

Describe the problem you want to solve So, I've got my code running on a web page, and it's great from a desktop computer, but on my phone it's much harder to type into a web page, so I'm hoping to use double-click for the secondary function, but that will involve a lot of code on my part. Also, when I click to scroll the page around, the click gets passed into my event handler, which I'd rather it wasn't.

Describe the solution you'd like A new (perhaps opt-in for performance reasons) api for double-clicks would be nice, as would filtering out touches that are used to pan and zoom on mobile devices.

Are you interested in contributing? I'd (still) love to, but lack of time doesn't allow me to more than offering the occasional suggestion.

ryanisaacg commented 4 years ago

Currently mobile support isn't really in scope, I'm sorry to say. To do it well would require significant design and development work, which I don't think I can take on.

bwinton commented 4 years ago

Yeah, that's understandable. How about double-clicks? :)

lenscas commented 4 years ago

how do you want quicksilver to handle them?

If it is done like any other event, then should the first click still be registered as a click, or should that even be fired as normal? What about the second? Should that only cause the "double click" event or also the normal click event?

Or do you rather have a seperate struct that you configure with the maximum time between clicks and has a method that takes a reference to the click event and tells you whether it is a double click?

If the separate struct is good enough then I can probably open a pull request in a few days. Just want to know if that is useful, if it would be accepted, etc, etc before I start working on it.

bwinton commented 4 years ago

I would be happy with any of the things you suggested, but I suspect people writing games wouldn't want the first click to be paused for an arbitrary amount of time, so perhaps the first click should fire as normal, and then the second would fire as a double-click event (along with another normal click event, for backwards compatibility)?

I'm a little hesitant to suggest we follow what JavaScript does 😉, but the MDN page says:

The MouseEvent object passed into the event handler for click has its detail property set to the number of times the target was clicked. In other words, detail will be 2 for a double-click, 3 for triple-click, and so forth. This counter resets after a short interval without any clicks occurring; the specifics of how long that interval is may vary from browser to browser and across platforms. The interval is also likely to be affected by user preferences; for example, accessibility options may extend this interval to make it easier to perform multiple clicks with adaptive interfaces.

which seems reasonable to my not-particularly-advanced eyes…