-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Differently support multi mouse events #5785
Conversation
src/mixins/canvas_events.mixin.js
Outdated
@@ -16,7 +16,7 @@ | |||
addEventOptions = { passive: false }; | |||
|
|||
function checkClick(e, value) { | |||
return 'which' in e ? e.which === value : e.button === value - 1; | |||
return e.button === value - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was something pre ie10. We do not need it anymore
*/ | ||
_getEventPrefix: function () { | ||
return this.enablePointerEvents ? 'pointer' : 'mouse'; | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just to allow the minifier to work better and reuse code.
|
||
var changedTouches = event.changedTouches; | ||
if (changedTouches) { | ||
return changedTouches[0] && changedTouches[0].identifier; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to verify what changeTouches contains and in what order.
@dirkluijk @ arcatdmz Today i digged up my pointer event device and formatted/reinstalled it ( forgot password ) so that i can move on with this. We need to understand how we can: Define if we want hardcode in fabric that object transformations are done with left mouse button and with no buttons for touch/pointer events ( ok fingers do not have button ). How touch events and pointer events fire things with multiple finger/pencils that move or goes up ath the same time. if i have 2 fingers down on the screen and i pull up one, do i get a mouse up events? I did not try yet. |
src/mixins/canvas_events.mixin.js
Outdated
if (!this._isMainEvent(e)) { | ||
return; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this repeated for down/up/move is needed to avoid doing stuff in fabricjs object transformations when we are outside the single pointer movement, main touch changes.
For now is broken, but i m here with my multitouch stuff to test it |
src/mixins/canvas_events.mixin.js
Outdated
@@ -60,8 +85,7 @@ | |||
functor(canvasElement, 'wheel', this._onMouseWheel); | |||
functor(canvasElement, 'contextmenu', this._onContextMenu); | |||
functor(canvasElement, 'dblclick', this._onDoubleClick); | |||
functor(canvasElement, 'touchstart', this._onMouseDown, addEventOptions); | |||
functor(canvasElement, 'touchmove', this._onMouseMove, addEventOptions); | |||
functor(canvasElement, 'touchstart', this._onTouchStart, addEventOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not register touchMove by default. is not used if not after a touchStart. Use specifct onTouchStart instead of _onMouseDown.
this._willAddMouseDown = setTimeout(function() { | ||
addListener(_this.upperCanvasEl, eventTypePrefix + 'down', _this._onMouseDown); | ||
_this._willAddMouseDown = 0; | ||
}, 400); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add some clearTimeout logic to avoid registering multiple mousedown when another touchend would happen before 400 ms
return pointer; | ||
} | ||
|
||
if (fabric.isTouchSupported) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this. isTouchSupport
is randomly broken depending on browsers and security and privacy concerns. If the event has a changedTouches
then is a touch event.
Ok this starts to work |
Nice work @asturur ! I will test this PR today and come back at you with feedback. |
I tested this on a touch screen. The fix does not seem to work. Steps to reproduce
Expected result Actual result
|
This is not going to fix brushes. You can add to the brush events informations like pointerId, activePointers, and mainPointer andavoid it do stop drawing or drawing too much when there are too many fingers, or when the finger is not the main one. |
All right, I'll check if this PR is OK for a brush fix. I'll get back at you with feedback. |
Some comments:
I tried to fix the brush issue in this branch, but I encountered very strange behaviour:
In onMouseDown: function(pointer, data) {
if (this.canvas.activePointerIds.length > 1) {
return;
}
/* ... */
}
onMouseMove: function(pointer, data) {
if (this.canvas.getPointerId(data.e) !== this.canvas.mainPointerId) {
return;
}
/* ... */
}
onMouseUp: function(data) {
if (this.canvas.getPointerId(data.e) !== this.canvas.mainPointerId) {
return;
}
/* ... */
} However, I cannot get it working. I feel a bit more comfortable with my original PR. Can you take a look? |
Yes but your original PR makes an hard choice of locking events completely when are from more than one finger. That feels bad to me. |
Can you explain me this a bit more? activePointers give us a glimps of how many touches are there, mainPointerId is just a memo to know what event started the current ongoing event flow. |
Yeah, I agree with that.
Awesome! 🎉
Yeah, my comment was about
I don't understand this function really. What does it really do? Shouldn't it only check |
well i wrote it so it would work most of the time. |
Any chance to take a look at my issue? 😎 |
To be totally honest i didn't. I have been taken by some videogame ( wow, new patch, new farming ). |
here i am, wired with the touch device, resuming work. |
I was about to give up today. I did not get to the brush problem yet. |
This is not perfect by any mean, but the brush now works correctly. There is some strange interaction with firefox but ie10, ie11, edge, chrome work good. |
Ok i m going to merge it. The pencil works good now with many fingers on the screen. |
Thanks @asturur! I'll test it tomorrow morning right away. |
Works perfect!! |
I have microsoft surface, a stylus , firefox and i could freedraw both with finger and pencil. can you start a fiddle with latest 3.3.2 where the freedrawing does not work? |
@asturur it works, sorry about that. |
@@ -49,7 +52,10 @@ | |||
* Inovoked on mouse move | |||
* @param {Object} pointer | |||
*/ | |||
onMouseMove: function(pointer) { | |||
onMouseMove: function(pointer, options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add extra options parameter in doc
This PR is a proof of concepts for handling multi touch / multi pointer events
It aims at taking track of all events that gets generated on the canvas and identify the owner of the transformation, while letting everything else flow to eventually brushes and events firing.