@@ -1468,6 +1468,8 @@ function onMouseDown(event) {
1468
1468
}
1469
1469
1470
1470
function pressureToLineWidth ( event ) {
1471
+ //event.button === 0 could be wrong, as it can also be the uninitialized state.
1472
+ //Therefore we use event.buttons, which works differently.
1471
1473
if ( event . buttons !== 1 || event . pressure === 0 || event . pointerType === "touch" ) {
1472
1474
return 0 ;
1473
1475
}
@@ -1477,11 +1479,32 @@ function pressureToLineWidth(event) {
1477
1479
return Math . ceil ( event . pressure * 32 ) ;
1478
1480
}
1479
1481
1482
+ // Previously the onMouseMove handled leave, but we do this separately now for
1483
+ // proper pen support. Otherwise leave leads to a loss of the pen pressure, as
1484
+ // we are handling that with mouseleave instead of pointerleave. pointerlave
1485
+ // is not triggered until the pen is let go.
1486
+ function onMouseLeave ( event ) {
1487
+ if ( allowDrawing
1488
+ && lastLineWidth
1489
+ && localTool !== fillBucket ) {
1490
+
1491
+ // calculate the offset coordinates based on client mouse position and drawing board client origin
1492
+ const clientRect = drawingBoard . getBoundingClientRect ( ) ;
1493
+ const offsetX = ( event . clientX - clientRect . left ) ;
1494
+ const offsetY = ( event . clientY - clientRect . top ) ;
1495
+
1496
+ // drawing functions must check for context boundaries
1497
+ drawLineAndSendEvent ( context , lastX , lastY , offsetX , offsetY , lastLineWidth ) ;
1498
+ lastX = offsetX ;
1499
+ lastY = offsetY ;
1500
+ }
1501
+ }
1502
+
1503
+ let lastLineWidth ;
1480
1504
function onMouseMove ( event ) {
1481
1505
const pressureLineWidth = pressureToLineWidth ( event ) ;
1506
+ lastLineWidth = pressureLineWidth ;
1482
1507
1483
- //event.button === 0 could be wrong, as it can also be the uninitialized state.
1484
- //Therefore we use event.buttons, which works differently.
1485
1508
if ( allowDrawing
1486
1509
&& pressureLineWidth
1487
1510
&& localTool !== fillBucket ) {
@@ -1513,7 +1536,7 @@ function onMouseClick(event) {
1513
1536
1514
1537
drawingBoard . addEventListener ( 'pointerdown' , onMouseDown )
1515
1538
drawingBoard . addEventListener ( 'pointermove' , onMouseMove ) ;
1516
- drawingBoard . addEventListener ( 'mouseleave' , onMouseMove ) ;
1539
+ drawingBoard . addEventListener ( 'mouseleave' , onMouseLeave ) ;
1517
1540
drawingBoard . addEventListener ( 'click' , onMouseClick ) ;
1518
1541
1519
1542
function onGlobalMouseMove ( event ) {
0 commit comments