chanind / hanzi-writer

Chinese character stroke order animations and practice quizzes
https://hanziwriter.org
MIT License
3.56k stars 557 forks source link

bad mouse tracking in quiz #83

Closed larhun closed 6 years ago

larhun commented 6 years ago

The browser used by the Anki flashcard application (windows desktop edition) does not track the real mouse position when quizzing a character. As suggested in https://stackoverflow.com/questions/20957627/how-do-you-transform-event-coordinates-to-svg-coordinates-despite-bogus-getbound, the following works fine:

function HanziWriter(element, character) {
  ...
  this._pt = this._canvas.svg.createSVGPoint();
}

HanziWriter.prototype._getMousePoint = function (evt) {
  this._pt.x = evt.clientX;
  this._pt.y = evt.clientY;
  var _local = this._pt.matrixTransform(this._canvas.svg.getScreenCTM().inverse());
  return { x: _local.x, y: _local.y };
};
chanind commented 6 years ago

Awesome, thanks for figuring this out! I'll experiment with the technique and try to put together a PR (or feel free to submit a PR if you're up for it!). Should this technique be used in all browsers or just in Anki? Is there an Anki plugin you're using that integrates Hanzi Writer that can be used for testing?

larhun commented 6 years ago

This fix should work an all browsers. I started using Anki today and do not have any new plugin.

chanind commented 6 years ago

I'll merge #84 once I can verify that it works as expected in IE

kokone commented 6 years ago

I'm still having issues with bad mouse tracking despite the fix. Could you share your Anki note configuration, @larhun ?