Skip to content

Commit 8c64504

Browse files
authored
Merge branch 'dev-2.0' into fix/usampler-user-shader-override
2 parents ab90d41 + beff79e commit 8c64504

3 files changed

Lines changed: 59 additions & 2 deletions

File tree

src/events/pointer.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function pointer(p5, fn, lifecycles){
99
const events = [
1010
'pointerdown',
1111
'pointerup',
12+
'pointercancel',
1213
'pointermove',
1314
'dragend',
1415
'dragover',
@@ -1394,6 +1395,16 @@ function pointer(p5, fn, lifecycles){
13941395
fn._ondragend = fn._onpointerup;
13951396
fn._ondragover = fn._onpointermove;
13961397

1398+
fn._onpointercancel = function(e) {
1399+
this._activePointers.delete(e.pointerId);
1400+
this._setMouseButton(e);
1401+
this._updatePointerCoords(e);
1402+
1403+
if (this._activePointers.size === 0) {
1404+
this.mouseIsPressed = false;
1405+
}
1406+
};
1407+
13971408
/**
13981409
* A function that's called once after a mouse button is pressed and released.
13991410
*

src/shape/attributes.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,9 @@ function attributes(p5, fn){
513513
* Sets the width of the stroke used for points, lines, and the outlines of
514514
* shapes.
515515
*
516-
* Note: `strokeWeight()` is affected by transformations, especially calls to
517-
* <a href="#/p5/scale">scale()</a>.
516+
* Note: In 2D mode, `strokeWeight()` is affected by transformations,
517+
* especially calls to <a href="#/p5/scale">scale()</a>. It isn't affected by
518+
* transformations in WebGL and WebGPU modes.
518519
*
519520
* Calling `strokeWeight()` without an argument returns the current stroke weight as a number.
520521
*

test/unit/events/touch.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ suite('Touch Events', function() {
3232
myp5.remove();
3333
});
3434

35+
beforeEach(function() {
36+
// Reset pointer state so tests don't leak active pointers into each other.
37+
myp5._activePointers.clear();
38+
myp5.touches = [];
39+
myp5.mouseIsPressed = false;
40+
});
41+
3542
suite('p5.prototype.touches', function() {
3643
test('should be an empty array', function() {
3744
assert.deepEqual(myp5.touches, []);
@@ -44,7 +51,45 @@ suite('Touch Events', function() {
4451
});
4552

4653
test('should contain the touch registered', function() {
54+
window.dispatchEvent(touchEvent1);
4755
assert.strictEqual(myp5.touches[0].id, 1);
4856
});
4957
});
58+
59+
suite('p5.prototype._onpointercancel', function() {
60+
test('should remove the cancelled touch from touches', function() {
61+
window.dispatchEvent(touchEvent1);
62+
window.dispatchEvent(touchEvent2);
63+
assert.strictEqual(myp5.touches.length, 2);
64+
65+
// A cancelled pointer must be cleaned up even though no
66+
// 'pointerup' event is dispatched.
67+
const cancelEvent = new PointerEvent('pointercancel', {
68+
pointerId: 1,
69+
clientX: 100,
70+
clientY: 100,
71+
pointerType: 'touch'
72+
});
73+
window.dispatchEvent(cancelEvent);
74+
75+
assert.strictEqual(myp5.touches.length, 1);
76+
assert.strictEqual(myp5.touches[0].id, 2);
77+
});
78+
79+
test('should reset mouseIsPressed once all pointers are cancelled', function() {
80+
window.dispatchEvent(touchEvent1);
81+
assert.strictEqual(myp5.mouseIsPressed, true);
82+
83+
const cancelEvent = new PointerEvent('pointercancel', {
84+
pointerId: 1,
85+
clientX: 100,
86+
clientY: 100,
87+
pointerType: 'touch'
88+
});
89+
window.dispatchEvent(cancelEvent);
90+
91+
assert.strictEqual(myp5.touches.length, 0);
92+
assert.strictEqual(myp5.mouseIsPressed, false);
93+
});
94+
});
5095
});

0 commit comments

Comments
 (0)