I am currently trying to use my wacom intous to paint something on a canvas in my browser.
The code is pretty basic and does nothing other than finding the position of my mouse and drawing a path when the mouse is clicked.
This works as expected when I use my mouse. When I use my wacom tablet, the move will be canceled after ~20px and the lostpointercapture
event as well as the pointercancel
event will be fired.
This is the code:
(function() {
var canvas = document.querySelector('.canvas');
var ctx = canvas.getContext('2d');
var currentPosition = {
x: 0,
y: 0
};
function init() {
adjustCanvasSize();
}
function adjustCanvasSize() {
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;
}
function setPosition(ev) {
currentPosition.x = ev.clientX;
currentPosition.y = ev.clientY;
}
function draw(ev) {
ev.preventDefault();
if (ev.buttons !== 1) {
return;
}
ctx.beginPath();
ctx.lineWidth = 1;
ctx.lineCap = 'round';
ctx.strokeStyle = '#1a1b1c';
ctx.moveTo(currentPosition.x, currentPosition.y);
setPosition(ev);
ctx.lineTo(currentPosition.x, currentPosition.y);
ctx.stroke();
}
document.addEventListener('pointermove', draw);
document.addEventListener('pointerdown', setPosition);
document.addEventListener('pointerenter', setPosition);
init();
})();
Does anyone have an idea why the wacom stops drawing after a few pixel?