MCPcopy Index your code
hub / github.com/processing/p5.js / pointer

Function pointer

src/events/pointer.js:7–1924  ·  view source on GitHub ↗

* @module Events * @submodule Pointer * @for p5

(p5, fn, lifecycles)

Source from the content-addressed store, hash-verified

5 */
6
7function pointer(p5, fn, lifecycles){
8 lifecycles.presetup = function(){
9 const events = [
10 'pointerdown',
11 'pointerup',
12 'pointermove',
13 'dragend',
14 'dragover',
15 'click',
16 'dblclick',
17 'wheel'
18 ];
19 for(const event of events){
20 window.addEventListener(event, this[`_on${event}`].bind(this), {
21 passive: false,
22 signal: this._removeSignal
23 });
24 }
25
26 window.addEventListener('blur', () => {
27 this.mouseIsPressed = false;
28 }, { signal: this._removeSignal });
29 };
30
31 /**
32 * A `Number` system variable that tracks the mouse's horizontal movement.
33 *
34 * `movedX` tracks how many pixels the mouse moves left or right between
35 * frames. `movedX` will have a negative value if the mouse moves left between
36 * frames and a positive value if it moves right. `movedX` can be calculated
37 * as `mouseX - pmouseX`.
38 *
39 * Note: `movedX` continues updating even when
40 * <a href="#/p5/requestPointerLock">requestPointerLock()</a> is active.
41 *
42 * @property {Number} movedX
43 * @readOnly
44 *
45 * @example
46 * function setup() {
47 * createCanvas(100, 100);
48 *
49 * describe(
50 * 'A gray square. The text ">>" appears when the user moves the mouse to the right. The text "<<" appears when the user moves the mouse to the left.'
51 * );
52 * }
53 *
54 * function draw() {
55 * background(200);
56 *
57 * // Style the text.
58 * textAlign(CENTER);
59 * textSize(16);
60 *
61 * // Display >> when movedX is positive and
62 * // << when it's negative.
63 * if (movedX > 0) {
64 * text('>>', 50, 50);

Callers 1

pointer.jsFile · 0.85

Calls 13

getTouchInfoFunction · 0.85
getMouseInfoFunction · 0.85
mouseMovedMethod · 0.80
preventDefaultMethod · 0.80
mousePressedMethod · 0.80
deleteMethod · 0.80
mouseReleasedMethod · 0.80
mouseClickedMethod · 0.80
doubleClickedMethod · 0.80
mouseWheelMethod · 0.80
pushMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected