q5 2.10.7 → 2.10.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deno.json +35 -0
- package/package.json +3 -6
- package/q5-deno-server.js +38 -0
- package/q5-server.js +3 -3
- package/q5.js +14 -8
- package/q5.min.js +1 -1
- package/src/q5-canvas.js +14 -8
- package/test/core.test.js +33 -0
- package/test/readme.md +5 -0
- package/.vscode/launch.json +0 -26
- package/.vscode/settings.json +0 -3
- package/bun.lockb +0 -0
- package/p5-tests/js/chai_helpers.js +0 -20
- package/p5-tests/js/mocha_setup.js +0 -2
- package/p5-tests/js/modernizr.js +0 -5
- package/p5-tests/js/p5_helpers.js +0 -135
- package/p5-tests/js/sinon.js +0 -5949
- package/p5-tests/mocha.css +0 -289
- package/p5-tests/test.html +0 -71
- package/p5-tests/unit/color/color_conversion.js +0 -68
- package/p5-tests/unit/color/creating_reading.js +0 -217
- package/p5-tests/unit/color/p5.Color.js +0 -1000
- package/p5-tests/unit/color/setting.js +0 -289
- package/p5-tests/unit/core/2d_primitives.js +0 -490
- package/p5-tests/unit/core/attributes.js +0 -115
- package/p5-tests/unit/core/curves.js +0 -139
- package/p5-tests/unit/core/environment.js +0 -248
- package/p5-tests/unit/core/error_helpers.js +0 -1158
- package/p5-tests/unit/core/main.js +0 -340
- package/p5-tests/unit/core/p5.Element.js +0 -773
- package/p5-tests/unit/core/p5.Graphics.js +0 -179
- package/p5-tests/unit/core/preload.js +0 -285
- package/p5-tests/unit/core/rendering.js +0 -116
- package/p5-tests/unit/core/structure.js +0 -293
- package/p5-tests/unit/core/transform.js +0 -144
- package/p5-tests/unit/core/version.js +0 -28
- package/p5-tests/unit/core/vertex.js +0 -137
- package/p5-tests/unit/dom/dom.js +0 -2146
- package/p5-tests/unit/events/acceleration.js +0 -213
- package/p5-tests/unit/events/keyboard.js +0 -179
- package/p5-tests/unit/events/mouse.js +0 -487
- package/p5-tests/unit/events/touch.js +0 -180
- package/p5-tests/unit/image/downloading.js +0 -379
- package/p5-tests/unit/image/filters.js +0 -92
- package/p5-tests/unit/image/loading.js +0 -413
- package/p5-tests/unit/image/p5.Image.js +0 -201
- package/p5-tests/unit/image/pixels.js +0 -234
- package/p5-tests/unit/io/files.js +0 -378
- package/p5-tests/unit/io/loadBytes.js +0 -149
- package/p5-tests/unit/io/loadImage.js +0 -123
- package/p5-tests/unit/io/loadJSON.js +0 -185
- package/p5-tests/unit/io/loadModel.js +0 -215
- package/p5-tests/unit/io/loadShader.js +0 -176
- package/p5-tests/unit/io/loadStrings.js +0 -140
- package/p5-tests/unit/io/loadTable.js +0 -183
- package/p5-tests/unit/io/loadXML.js +0 -127
- package/p5-tests/unit/io/saveModel.js +0 -113
- package/p5-tests/unit/io/saveTable.js +0 -142
- package/p5-tests/unit/math/calculation.js +0 -452
- package/p5-tests/unit/math/noise.js +0 -66
- package/p5-tests/unit/math/p5.Vector.js +0 -1886
- package/p5-tests/unit/math/random.js +0 -177
- package/p5-tests/unit/math/trigonometry.js +0 -144
- package/p5-tests/unit/spec.js +0 -50
- package/p5-tests/unit/typography/attributes.js +0 -120
- package/p5-tests/unit/typography/loadFont.js +0 -162
- package/p5-tests/unit/typography/p5.Font.js +0 -63
- package/p5-tests/unit/utilities/conversion.js +0 -329
- package/p5-tests/unit/utilities/time_date.js +0 -133
|
@@ -1,487 +0,0 @@
|
|
|
1
|
-
suite('Mouse Events', function() {
|
|
2
|
-
let myp5;
|
|
3
|
-
|
|
4
|
-
let canvas;
|
|
5
|
-
let rect;
|
|
6
|
-
let sx;
|
|
7
|
-
let sy;
|
|
8
|
-
let touchObj1;
|
|
9
|
-
let touchObj2;
|
|
10
|
-
let touchEvent1;
|
|
11
|
-
let touchEvent2;
|
|
12
|
-
|
|
13
|
-
setup(function(done) {
|
|
14
|
-
new p5(function(p) {
|
|
15
|
-
p.setup = function() {
|
|
16
|
-
myp5 = p;
|
|
17
|
-
canvas = myp5._curElement.elt;
|
|
18
|
-
rect = canvas.getBoundingClientRect();
|
|
19
|
-
sx = canvas.scrollWidth / myp5.width;
|
|
20
|
-
sy = canvas.scrollHeight / myp5.height;
|
|
21
|
-
touchObj1 = new Touch({
|
|
22
|
-
target: canvas,
|
|
23
|
-
identifier: Date.now(),
|
|
24
|
-
clientX: 100,
|
|
25
|
-
clientY: 100
|
|
26
|
-
});
|
|
27
|
-
touchObj2 = new Touch({
|
|
28
|
-
target: canvas,
|
|
29
|
-
identifier: Date.now() + 1,
|
|
30
|
-
clientX: 200,
|
|
31
|
-
clientY: 200
|
|
32
|
-
});
|
|
33
|
-
touchEvent1 = new TouchEvent('touchmove', {
|
|
34
|
-
touches: [touchObj1, touchObj2]
|
|
35
|
-
});
|
|
36
|
-
touchEvent2 = new TouchEvent('touchmove', {
|
|
37
|
-
touches: [touchObj2]
|
|
38
|
-
});
|
|
39
|
-
done();
|
|
40
|
-
};
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
teardown(function() {
|
|
45
|
-
myp5.remove();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
let mouseEvent1 = new MouseEvent('mousemove', { clientX: 100, clientY: 100 });
|
|
49
|
-
let mouseEvent2 = new MouseEvent('mousemove', { clientX: 200, clientY: 200 });
|
|
50
|
-
|
|
51
|
-
suite('p5.prototype._hasMouseInteracted', function() {
|
|
52
|
-
test('_hasMouseInteracted should be a boolean', function() {
|
|
53
|
-
assert.isBoolean(myp5._hasMouseInteracted);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('_hasMouseInteracted should be false before mouse interaction', function() {
|
|
57
|
-
assert.strictEqual(myp5._hasMouseInteracted, false);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('_hasMouseInteracted should be true on mouse interaction', function() {
|
|
61
|
-
window.dispatchEvent(mouseEvent1);
|
|
62
|
-
assert.strictEqual(myp5._hasMouseInteracted, true);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test('_hasMouseInteracted should be true on touch interaction', function() {
|
|
66
|
-
window.dispatchEvent(touchEvent1);
|
|
67
|
-
assert.strictEqual(myp5._hasMouseInteracted, true);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
suite('p5.prototype.mouseX', function() {
|
|
72
|
-
test('mouseX should be a number', function() {
|
|
73
|
-
assert.isNumber(myp5.mouseX);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test('mouseX should be current horizontal position of mouse relative to the canvas', function() {
|
|
77
|
-
let result = (mouseEvent1.clientX - rect.left) / sx;
|
|
78
|
-
window.dispatchEvent(mouseEvent1);
|
|
79
|
-
assert.strictEqual(myp5.mouseX, result);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('mouseX should be current horizontal position of touch relative to the canvas', function() {
|
|
83
|
-
let result = (touchObj1.clientX - rect.left) / sx;
|
|
84
|
-
window.dispatchEvent(touchEvent1);
|
|
85
|
-
assert.strictEqual(myp5.mouseX, result);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
suite('p5.prototype.mouseY', function() {
|
|
90
|
-
test('mouseY should be a number', function() {
|
|
91
|
-
assert.isNumber(myp5.mouseY);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
test('mouseY should be current vertical position of mouse relative to the canvas', function() {
|
|
95
|
-
let result = (mouseEvent1.clientY - rect.top) / sy;
|
|
96
|
-
window.dispatchEvent(mouseEvent1);
|
|
97
|
-
assert.strictEqual(myp5.mouseY, result);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test('mouseY should be current vertical position of touch relative to the canvas', function() {
|
|
101
|
-
let result = (touchObj1.clientY - rect.top) / sy;
|
|
102
|
-
window.dispatchEvent(touchEvent1);
|
|
103
|
-
assert.strictEqual(myp5.mouseY, result);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
suite('p5.prototype.pmouseX', function() {
|
|
108
|
-
test('pmouseX should be a number', function() {
|
|
109
|
-
assert.isNumber(myp5.pmouseX);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test('pmouseX should be previous horizontal position of mouse relative to the canvas', function() {
|
|
113
|
-
window.dispatchEvent(mouseEvent1); // dispatch first mouse event
|
|
114
|
-
window.dispatchEvent(mouseEvent2); // dispatch second mouse event
|
|
115
|
-
let result = (mouseEvent1.clientX - rect.left) / sx;
|
|
116
|
-
assert.strictEqual(myp5.pmouseX, result);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test('pmouseX should be previous horizontal position of touch relative to the canvas', function() {
|
|
120
|
-
window.dispatchEvent(touchEvent1); // dispatch first touch event
|
|
121
|
-
window.dispatchEvent(touchEvent2); // dispatch second touch event
|
|
122
|
-
let result = (touchObj1.clientX - rect.left) / sx;
|
|
123
|
-
assert.strictEqual(myp5.pmouseX, result);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
suite('p5.prototype.pmouseY', function() {
|
|
128
|
-
test('pmouseY should be a number', function() {
|
|
129
|
-
assert.isNumber(myp5.pmouseY);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test('pmouseY should be previous vertical position of mouse relative to the canvas', function() {
|
|
133
|
-
window.dispatchEvent(mouseEvent1); // dispatch first mouse event
|
|
134
|
-
window.dispatchEvent(mouseEvent2); // dispatch second mouse event
|
|
135
|
-
let result = (mouseEvent1.clientY - rect.top) / sy;
|
|
136
|
-
assert.strictEqual(myp5.pmouseY, result);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
test('pmouseY should be previous vertical position of touch relative to the canvas', function() {
|
|
140
|
-
window.dispatchEvent(touchEvent1); // dispatch first touch event
|
|
141
|
-
window.dispatchEvent(touchEvent2); // dispatch second touch event
|
|
142
|
-
let result = (touchObj1.clientY - rect.top) / sy;
|
|
143
|
-
assert.strictEqual(myp5.pmouseY, result);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
suite('p5.prototype.winMouseX', function() {
|
|
147
|
-
test('winMouseX should be a number', function() {
|
|
148
|
-
assert.isNumber(myp5.winMouseX);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
test('winMouseX should be current horizontal position of mouse relative to the window', function() {
|
|
152
|
-
window.dispatchEvent(mouseEvent1);
|
|
153
|
-
assert.strictEqual(myp5.winMouseX, mouseEvent1.clientX);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
test('winMouseX should be current horizontal position of touch relative to the window', function() {
|
|
157
|
-
window.dispatchEvent(touchEvent1);
|
|
158
|
-
assert.strictEqual(myp5.winMouseX, touchObj1.clientX);
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
suite('p5.prototype.winMouseY', function() {
|
|
163
|
-
test('winMouseY should be a number', function() {
|
|
164
|
-
assert.isNumber(myp5.winMouseY);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
test('winMouseY should be current vertical position of mouse relative to the window', function() {
|
|
168
|
-
window.dispatchEvent(mouseEvent1);
|
|
169
|
-
assert.strictEqual(myp5.winMouseY, mouseEvent1.clientY);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
test('winMouseY should be current vertical position of touch relative to the window', function() {
|
|
173
|
-
window.dispatchEvent(touchEvent1);
|
|
174
|
-
assert.strictEqual(myp5.winMouseY, touchObj1.clientY);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
suite('p5.prototype.pwinMouseX', function() {
|
|
179
|
-
test('pwinMouseX should be a number', function() {
|
|
180
|
-
assert.isNumber(myp5.pwinMouseX);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
test('pwinMouseX should be previous horizontal position of mouse relative to the window', function() {
|
|
184
|
-
window.dispatchEvent(mouseEvent1); // dispatch first mouse event
|
|
185
|
-
window.dispatchEvent(mouseEvent2); // dispatch second mouse event
|
|
186
|
-
assert.strictEqual(myp5.pwinMouseX, mouseEvent1.clientX);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
test('pwinMouseX should be previous horizontal position of touch relative to the window', function() {
|
|
190
|
-
window.dispatchEvent(touchEvent1); // dispatch first touch event
|
|
191
|
-
window.dispatchEvent(touchEvent2); // dispatch second touch event
|
|
192
|
-
assert.strictEqual(myp5.pwinMouseX, touchObj1.clientX);
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
suite('p5.prototype.pwinMouseY', function() {
|
|
197
|
-
test('pwinMouseY should be a number', function() {
|
|
198
|
-
assert.isNumber(myp5.pwinMouseY);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
test('pwinMouseY should be previous vertical position of mouse relative to the window', function() {
|
|
202
|
-
window.dispatchEvent(mouseEvent1); // dispatch first mouse event
|
|
203
|
-
window.dispatchEvent(mouseEvent2); // dispatch second mouse event
|
|
204
|
-
assert.strictEqual(myp5.pwinMouseY, mouseEvent1.clientY);
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
test('pwinMouseY should be previous vertical position of touch relative to the window', function() {
|
|
208
|
-
window.dispatchEvent(touchEvent1); // dispatch first touch event
|
|
209
|
-
window.dispatchEvent(touchEvent2); // dispatch second touch event
|
|
210
|
-
assert.strictEqual(myp5.pwinMouseY, touchObj1.clientY);
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
suite('p5.prototype.mouseButton', function() {
|
|
215
|
-
test('_hasMouseInteracted should be a number', function() {
|
|
216
|
-
assert.isNumber(myp5.mouseButton);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
test('mouseButton should 0 for uninitialised', function() {
|
|
220
|
-
assert.strictEqual(myp5.mouseButton, 0);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
test('mouseButton should be "left" on left mouse button click', function() {
|
|
224
|
-
window.dispatchEvent(new MouseEvent('mousedown', { button: 0 }));
|
|
225
|
-
assert.strictEqual(myp5.mouseButton, 'left');
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
test('mouseButton should be "center" on auxillary mouse button click', function() {
|
|
229
|
-
window.dispatchEvent(new MouseEvent('mousedown', { button: 1 }));
|
|
230
|
-
assert.strictEqual(myp5.mouseButton, 'center');
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
test('mouseButton should be "right" on right mouse button click', function() {
|
|
234
|
-
window.dispatchEvent(new MouseEvent('mousedown', { button: 2 }));
|
|
235
|
-
assert.strictEqual(myp5.mouseButton, 'right');
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
suite('p5.prototype.mouseIsPressed', function() {
|
|
240
|
-
test('mouseIsPressed should be a boolean', function() {
|
|
241
|
-
assert.isBoolean(myp5.mouseIsPressed);
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
test('mouseIsPressed should be false if mouse is not pressed', function() {
|
|
245
|
-
assert.strictEqual(myp5.mouseIsPressed, false);
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
test('mouseIsPressed should be true if mouse is pressed', function() {
|
|
249
|
-
window.dispatchEvent(new MouseEvent('mousedown'));
|
|
250
|
-
assert.strictEqual(myp5.mouseIsPressed, true);
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
suite('mouseMoved', function() {
|
|
255
|
-
test('mouseMoved function must run when mouse is moved', async function() {
|
|
256
|
-
let count = 0;
|
|
257
|
-
|
|
258
|
-
myp5.mouseMoved = function() {
|
|
259
|
-
count += 1;
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
window.dispatchEvent(new MouseEvent('mousemove'));
|
|
263
|
-
window.dispatchEvent(new MouseEvent('mousemove'));
|
|
264
|
-
assert.deepEqual(count, 2);
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
test('mouseMoved functions on multiple instances must run once', async function() {
|
|
268
|
-
let sketchFn = function(sketch, resolve, reject) {
|
|
269
|
-
let count = 0;
|
|
270
|
-
|
|
271
|
-
sketch.mouseMoved = function() {
|
|
272
|
-
count += 1;
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
sketch.finish = function() {
|
|
276
|
-
resolve(count);
|
|
277
|
-
};
|
|
278
|
-
};
|
|
279
|
-
let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches
|
|
280
|
-
await sketches.setup; //wait for all sketches to setup
|
|
281
|
-
window.dispatchEvent(new MouseEvent('mousemove')); //dispatch a mouse event to trigger the mouseMoved functions
|
|
282
|
-
sketches.end(); //resolve all sketches by calling their finish functions
|
|
283
|
-
let counts = await sketches.result; //get array holding number of times mouseMoved was called. Rejected sketches also thrown here
|
|
284
|
-
assert.deepEqual(counts, [1, 1]);
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
suite('mouseDragged', function() {
|
|
289
|
-
test('mouseDragged function must run when mouse is dragged', async function() {
|
|
290
|
-
let count = 0;
|
|
291
|
-
|
|
292
|
-
myp5.mouseDragged = function() {
|
|
293
|
-
count += 1;
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
window.dispatchEvent(new MouseEvent('mousedown')); //dispatch a mousedown event
|
|
297
|
-
window.dispatchEvent(new MouseEvent('mousemove')); //dispatch mousemove event while mouse is down to trigger mouseDragged
|
|
298
|
-
assert.deepEqual(count, 1);
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
test('mouseDragged functions on multiple instances must run once', async function() {
|
|
302
|
-
let sketchFn = function(sketch, resolve, reject) {
|
|
303
|
-
let count = 0;
|
|
304
|
-
|
|
305
|
-
sketch.mouseDragged = function() {
|
|
306
|
-
count += 1;
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
sketch.finish = function() {
|
|
310
|
-
resolve(count);
|
|
311
|
-
};
|
|
312
|
-
};
|
|
313
|
-
let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches
|
|
314
|
-
await sketches.setup; //wait for all sketches to setup
|
|
315
|
-
window.dispatchEvent(new MouseEvent('mousedown')); //dispatch a mousedown event
|
|
316
|
-
window.dispatchEvent(new MouseEvent('mousemove')); //dispatch mousemove event while mouse is down to trigger mouseDragged
|
|
317
|
-
sketches.end(); //resolve all sketches by calling their finish functions
|
|
318
|
-
let counts = await sketches.result; //get array holding number of times mouseDragged was called. Rejected sketches also thrown here
|
|
319
|
-
assert.deepEqual(counts, [1, 1]);
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
suite('mousePressed', function() {
|
|
324
|
-
test('mousePressed function must run when mouse is pressed', async function() {
|
|
325
|
-
let count = 0;
|
|
326
|
-
|
|
327
|
-
myp5.mousePressed = function() {
|
|
328
|
-
count += 1;
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
window.dispatchEvent(new MouseEvent('mousedown'));
|
|
332
|
-
assert.deepEqual(count, 1);
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
test('mousePressed functions on multiple instances must run once', async function() {
|
|
336
|
-
let sketchFn = function(sketch, resolve, reject) {
|
|
337
|
-
let count = 0;
|
|
338
|
-
|
|
339
|
-
sketch.mousePressed = function() {
|
|
340
|
-
count += 1;
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
sketch.finish = function() {
|
|
344
|
-
resolve(count);
|
|
345
|
-
};
|
|
346
|
-
};
|
|
347
|
-
let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches
|
|
348
|
-
await sketches.setup; //wait for all sketches to setup
|
|
349
|
-
window.dispatchEvent(new MouseEvent('mousedown'));
|
|
350
|
-
sketches.end(); //resolve all sketches by calling their finish functions
|
|
351
|
-
let counts = await sketches.result; //get array holding number of times mouseDragged was called. Rejected sketches also thrown here
|
|
352
|
-
assert.deepEqual(counts, [1, 1]);
|
|
353
|
-
});
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
suite('mouseReleased', function() {
|
|
357
|
-
test('mouseReleased function must run when mouse is released', async function() {
|
|
358
|
-
let count = 0;
|
|
359
|
-
|
|
360
|
-
myp5.mouseReleased = function() {
|
|
361
|
-
count += 1;
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
window.dispatchEvent(new MouseEvent('mouseup'));
|
|
365
|
-
assert.deepEqual(count, 1);
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
test('mouseReleased functions on multiple instances must run once', async function() {
|
|
369
|
-
let sketchFn = function(sketch, resolve, reject) {
|
|
370
|
-
let count = 0;
|
|
371
|
-
|
|
372
|
-
sketch.mouseReleased = function() {
|
|
373
|
-
count += 1;
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
sketch.finish = function() {
|
|
377
|
-
resolve(count);
|
|
378
|
-
};
|
|
379
|
-
};
|
|
380
|
-
let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches
|
|
381
|
-
await sketches.setup; //wait for all sketches to setup
|
|
382
|
-
window.dispatchEvent(new MouseEvent('mouseup'));
|
|
383
|
-
sketches.end(); //resolve all sketches by calling their finish functions
|
|
384
|
-
let counts = await sketches.result; //get array holding number of times mouseReleased was called. Rejected sketches also thrown here
|
|
385
|
-
assert.deepEqual(counts, [1, 1]);
|
|
386
|
-
});
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
suite('mouseClicked', function() {
|
|
390
|
-
test('mouseClicked function must run when mouse is clicked', async function() {
|
|
391
|
-
let count = 0;
|
|
392
|
-
|
|
393
|
-
myp5.mouseClicked = function() {
|
|
394
|
-
count += 1;
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
window.dispatchEvent(new MouseEvent('click'));
|
|
398
|
-
assert.deepEqual(count, 1);
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
test('mouseClicked functions on multiple instances must run once', async function() {
|
|
402
|
-
let sketchFn = function(sketch, resolve, reject) {
|
|
403
|
-
let count = 0;
|
|
404
|
-
|
|
405
|
-
sketch.mouseClicked = function() {
|
|
406
|
-
count += 1;
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
sketch.finish = function() {
|
|
410
|
-
resolve(count);
|
|
411
|
-
};
|
|
412
|
-
};
|
|
413
|
-
let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches
|
|
414
|
-
await sketches.setup; //wait for all sketches to setup
|
|
415
|
-
window.dispatchEvent(new MouseEvent('click'));
|
|
416
|
-
sketches.end(); //resolve all sketches by calling their finish functions
|
|
417
|
-
let counts = await sketches.result; //get array holding number of times mouseClicked was called. Rejected sketches also thrown here
|
|
418
|
-
assert.deepEqual(counts, [1, 1]);
|
|
419
|
-
});
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
suite('doubleClicked', function() {
|
|
423
|
-
test('doubleClicked function must run when mouse is double clicked', async function() {
|
|
424
|
-
let count = 0;
|
|
425
|
-
|
|
426
|
-
myp5.doubleClicked = function() {
|
|
427
|
-
count += 1;
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
window.dispatchEvent(new MouseEvent('dblclick'));
|
|
431
|
-
assert.deepEqual(count, 1);
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
test('doubleClicked functions on multiple instances must run once', async function() {
|
|
435
|
-
let sketchFn = function(sketch, resolve, reject) {
|
|
436
|
-
let count = 0;
|
|
437
|
-
|
|
438
|
-
sketch.doubleClicked = function() {
|
|
439
|
-
count += 1;
|
|
440
|
-
};
|
|
441
|
-
|
|
442
|
-
sketch.finish = function() {
|
|
443
|
-
resolve(count);
|
|
444
|
-
};
|
|
445
|
-
};
|
|
446
|
-
let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches
|
|
447
|
-
await sketches.setup; //wait for all sketches to setup
|
|
448
|
-
window.dispatchEvent(new MouseEvent('dblclick'));
|
|
449
|
-
sketches.end(); //resolve all sketches by calling their finish functions
|
|
450
|
-
let counts = await sketches.result; //get array holding number of times doubleClicked was called. Rejected sketches also thrown here
|
|
451
|
-
assert.deepEqual(counts, [1, 1]);
|
|
452
|
-
});
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
suite('mouseWheel', function() {
|
|
456
|
-
test('mouseWheel function must run when mouse wheel event is detected', async function() {
|
|
457
|
-
let count = 0;
|
|
458
|
-
|
|
459
|
-
myp5.mouseWheel = function() {
|
|
460
|
-
count += 1;
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
window.dispatchEvent(new MouseEvent('wheel'));
|
|
464
|
-
assert.deepEqual(count, 1);
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
test('mouseWheel functions on multiple instances must run once', async function() {
|
|
468
|
-
let sketchFn = function(sketch, resolve, reject) {
|
|
469
|
-
let count = 0;
|
|
470
|
-
|
|
471
|
-
sketch.mouseWheel = function() {
|
|
472
|
-
count += 1;
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
sketch.finish = function() {
|
|
476
|
-
resolve(count);
|
|
477
|
-
};
|
|
478
|
-
};
|
|
479
|
-
let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches
|
|
480
|
-
await sketches.setup; //wait for all sketches to setup
|
|
481
|
-
window.dispatchEvent(new MouseEvent('wheel'));
|
|
482
|
-
sketches.end(); //resolve all sketches by calling their finish functions
|
|
483
|
-
let counts = await sketches.result; //get array holding number of times mouseWheel was called. Rejected sketches also thrown here
|
|
484
|
-
assert.deepEqual(counts, [1, 1]);
|
|
485
|
-
});
|
|
486
|
-
});
|
|
487
|
-
});
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
suite('Touch Events', function() {
|
|
2
|
-
let myp5;
|
|
3
|
-
|
|
4
|
-
let canvas;
|
|
5
|
-
let touchObj1;
|
|
6
|
-
let touchObj2;
|
|
7
|
-
let touchEvent1;
|
|
8
|
-
let touchEvent2;
|
|
9
|
-
|
|
10
|
-
setup(function(done) {
|
|
11
|
-
new p5(function(p) {
|
|
12
|
-
p.setup = function() {
|
|
13
|
-
myp5 = p;
|
|
14
|
-
canvas = myp5._curElement.elt;
|
|
15
|
-
touchObj1 = new Touch({
|
|
16
|
-
target: canvas,
|
|
17
|
-
clientX: 100,
|
|
18
|
-
clientY: 100,
|
|
19
|
-
identifier: 36
|
|
20
|
-
});
|
|
21
|
-
touchObj2 = new Touch({
|
|
22
|
-
target: canvas,
|
|
23
|
-
clientX: 200,
|
|
24
|
-
clientY: 200,
|
|
25
|
-
identifier: 35
|
|
26
|
-
});
|
|
27
|
-
touchEvent1 = new TouchEvent('touchmove', {
|
|
28
|
-
touches: [touchObj1, touchObj2]
|
|
29
|
-
});
|
|
30
|
-
touchEvent2 = new TouchEvent('touchmove', {
|
|
31
|
-
touches: [touchObj2]
|
|
32
|
-
});
|
|
33
|
-
done();
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
teardown(function() {
|
|
39
|
-
myp5.remove();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
suite('p5.prototype.touches', function() {
|
|
43
|
-
test('should be an empty array', function() {
|
|
44
|
-
assert.deepEqual(myp5.touches, []);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('should be an array of multiple touches', function() {
|
|
48
|
-
window.dispatchEvent(touchEvent1);
|
|
49
|
-
assert.strictEqual(myp5.touches.length, 2);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test('should contain the touch registered', function() {
|
|
53
|
-
window.dispatchEvent(touchEvent2);
|
|
54
|
-
assert.strictEqual(myp5.touches[0].id, 35);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
suite('touchStarted', function() {
|
|
59
|
-
test('touchStarted should be fired when a touch is registered', function() {
|
|
60
|
-
let count = 0;
|
|
61
|
-
myp5.touchStarted = function() {
|
|
62
|
-
count += 1;
|
|
63
|
-
};
|
|
64
|
-
window.dispatchEvent(new TouchEvent('touchstart'));
|
|
65
|
-
assert.strictEqual(count, 1);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('should be fired when a touch starts over the element', function() {
|
|
69
|
-
let count = 0;
|
|
70
|
-
let div = myp5.createDiv();
|
|
71
|
-
let divTouchStarted = function() {
|
|
72
|
-
count += 1;
|
|
73
|
-
};
|
|
74
|
-
div.touchStarted(divTouchStarted);
|
|
75
|
-
div.elt.dispatchEvent(new TouchEvent('touchstart'));
|
|
76
|
-
assert.strictEqual(count, 1);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test('touchStarted functions on multiple instances must run once', async function() {
|
|
80
|
-
let sketchFn = function(sketch, resolve, reject) {
|
|
81
|
-
let count = 0;
|
|
82
|
-
sketch.touchStarted = function() {
|
|
83
|
-
count += 1;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
sketch.finish = function() {
|
|
87
|
-
resolve(count);
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches
|
|
91
|
-
await sketches.setup; //wait for all sketches to setup
|
|
92
|
-
window.dispatchEvent(new TouchEvent('touchstart'));
|
|
93
|
-
sketches.end(); //resolve all sketches by calling their finish functions
|
|
94
|
-
let counts = await sketches.result;
|
|
95
|
-
assert.deepEqual(counts, [1, 1]);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
suite('touchMoved', function() {
|
|
100
|
-
test('touchMoved should be fired when a touchmove is registered', function() {
|
|
101
|
-
let count = 0;
|
|
102
|
-
myp5.touchMoved = function() {
|
|
103
|
-
count += 1;
|
|
104
|
-
};
|
|
105
|
-
window.dispatchEvent(touchEvent2);
|
|
106
|
-
assert.strictEqual(count, 1);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test('should be fired when a touchmove is registered over the element', function() {
|
|
110
|
-
let count = 0;
|
|
111
|
-
let div = myp5.createDiv();
|
|
112
|
-
let divTouchMoved = function() {
|
|
113
|
-
count += 1;
|
|
114
|
-
};
|
|
115
|
-
div.touchMoved(divTouchMoved);
|
|
116
|
-
div.elt.dispatchEvent(touchEvent2);
|
|
117
|
-
assert.strictEqual(count, 1);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
test('touchMoved functions on multiple instances must run once', async function() {
|
|
121
|
-
let sketchFn = function(sketch, resolve, reject) {
|
|
122
|
-
let count = 0;
|
|
123
|
-
sketch.touchMoved = function() {
|
|
124
|
-
count += 1;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
sketch.finish = function() {
|
|
128
|
-
resolve(count);
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches
|
|
132
|
-
await sketches.setup; //wait for all sketches to setup
|
|
133
|
-
window.dispatchEvent(touchEvent2);
|
|
134
|
-
sketches.end(); //resolve all sketches by calling their finish functions
|
|
135
|
-
let counts = await sketches.result;
|
|
136
|
-
assert.deepEqual(counts, [1, 1]);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
suite('touchEnded', function() {
|
|
141
|
-
test('touchEnded must run when a touch is registered', function() {
|
|
142
|
-
let count = 0;
|
|
143
|
-
myp5.touchEnded = function() {
|
|
144
|
-
count += 1;
|
|
145
|
-
};
|
|
146
|
-
window.dispatchEvent(new TouchEvent('touchend'));
|
|
147
|
-
assert.strictEqual(count, 1);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
test('should be fired when a touch starts over the element', function() {
|
|
151
|
-
let count = 0;
|
|
152
|
-
let div = myp5.createDiv();
|
|
153
|
-
let divTouchEnded = function() {
|
|
154
|
-
count += 1;
|
|
155
|
-
};
|
|
156
|
-
div.touchEnded(divTouchEnded);
|
|
157
|
-
div.elt.dispatchEvent(new TouchEvent('touchend'));
|
|
158
|
-
assert.strictEqual(count, 1);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
test('touchEnded functions on multiple instances must run once', async function() {
|
|
162
|
-
let sketchFn = function(sketch, resolve, reject) {
|
|
163
|
-
let count = 0;
|
|
164
|
-
sketch.touchEnded = function() {
|
|
165
|
-
count += 1;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
sketch.finish = function() {
|
|
169
|
-
resolve(count);
|
|
170
|
-
};
|
|
171
|
-
};
|
|
172
|
-
let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches
|
|
173
|
-
await sketches.setup; //wait for all sketches to setup
|
|
174
|
-
window.dispatchEvent(new TouchEvent('touchend'));
|
|
175
|
-
sketches.end(); //resolve all sketches by calling their finish functions
|
|
176
|
-
let counts = await sketches.result;
|
|
177
|
-
assert.deepEqual(counts, [1, 1]);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
});
|