-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve webgl_canvas mouse event handling and fix mouse coordinates #207
Conversation
9d7f8a7
to
40a8627
Compare
I added a commit to also do some cleanup when the Kiss3d window is closed. |
48c91e4
to
b785bea
Compare
I've updated the branch to master but since this PR uses PointerEvent instead of MouseEvent it may not interact with TouchEvent nicely. The idea of PointerEvent is that it replaces both MouseEvent and TouchEvent, so the TouchEvent handlers will need to be modified to use PointerEvent handlers instead. @sebcrozet I would like to know how you feel about this before I move forward. Also, do the touch events actually do anything now in Kiss3d? I will need an example to test it. |
Hi! Sorry for the late answer. Thank you for this PR! I think it is misleading to expose pointer events behind events containing Now the question is whether or not we will want to emulate the pointer events when using the |
Here's the thing, "pointer events" are a consolidation of mouse, touch and pen events. Dispatching the pointer events of "mouse" type as mouse events is IMO quite acceptable. Pointer events of "touch" (assuming no touch event handlers are in use) and "pen" type will also, in one way or another, get translated to mouse events for compatibility if no pointer event handlers are in use, so it's not really so misleading to just map them to existing mouse events when Kiss3d did not have built-in handling for touch and pen events. Of course, with the introduction of (On a related note, Qt is doing the equivalent with Windows'
The
I'm not sure if it's worth putting To reiterate the reason of using pointer events: The problem is that adding the mouse event handlers to the canvas element would limit dragging actions to the bounds of the element, making it inconvenient for camera navigation especially when the canvas element is small in size. Using pointer events enables the use of However, I realize that part of the changes in this PR can be split into another PR that doesn't include pointer events, and since you may not agree with the change to use pointer events, here's what I plan to do:
|
Thank you for the explanation! So I guess we have two choices regarding pointer events:
The item 2 seems to be the most practical (and closest to what you have been doing here) because it would reduce cases of duplicate event handling code for mouse and touch. My main concern then is the platform support. Is there a way for kiss3d to provide the polyfills transparently? Without requiring the user to include them in their non-rust code?
Moving the mouse event handler to the canvas changes the current behavior too much (for example The transition towards pointer events should be smoother. To that end, I suggest to:
What do you think about that? |
I don't really have a preference for either one, but implementing the second choice would mean introducing a breaking API change - while it may not be hard to convert the code replacing A third option may be to keep just mouse events for compatibility and ease of use, but require the use of the unified pointer events if the user want to also handle touch events. However I have not thought of how it should be handled if built-in touch handling is added to the cameras.
I don't think you can easily include a polyfill... perhaps it can be done by appending a script tag to the document but it seems like a horrible hack, and what if it conflicts with other user code?
I understand, If it can't use
You will also need to make other native platforms support the Otherwise it sounds fine, but I can't promise to help with the implementation and testing so in the end it is still up to you to design and implement the new APIs. Perhaps you should open an issue to keep track of this and continue over there, while I try to fix up the current mouse event behaviour here. |
This prevents mouse events from being handled if the mouse down event started outside of the canvas element, while allowing them to be handled everywhere on the page if the mouse down event started inside of the canvas element.
0aa0df0
to
884f59c
Compare
Updated the mouse event handling without using pointer event. I think it now works in a satisfactory manner.
I guess I misremembered because this turns out to not be true. I might have confused it with alt-tabbing to another window. |
You are right that cursor events is not an easy topic and should be part of a separate issue. I've created #220. The changes you have made here are very interesting and look like a good way of achieving mouse capture-like behavior. Thank you for your involvement! |
A previous version of this PR narrowed the event listeners target, introduced the use of pointer events to enable pointer capturing via
setPointerCapture
and added some cleanup code. Following the comments, part of this PR was split into another PR #219. The current PR focuses on improving the mouse event handling without using pointer event.