Skip to content

Commit c4dd52c

Browse files
author
lauren mccarthy
committed
adding doc for mouse
1 parent 5b85378 commit c4dd52c

File tree

2 files changed

+168
-4
lines changed

2 files changed

+168
-4
lines changed

src/input/mouse.js

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ define(function (require) {
145145
/**
146146
* The mouseMoved() function is called every time the mouse moves and a mouse
147147
* button is not pressed.
148+
* Browsers may have different default
149+
* behaviors attached to various mouse events. To prevent any default
150+
* behavior for this event, add `return false` to the end of the method.
148151
*
149152
* @method mouseMoved
150153
* @example
@@ -166,12 +169,25 @@ define(function (require) {
166169
* }
167170
* </code>
168171
* </div>
172+
*
173+
* <div class="norender">
174+
* <code>
175+
* function mouseMoved() {
176+
* ellipse(mouseX, mouseY, 5, 5);
177+
* // prevent default
178+
* return false;
179+
* }
180+
* </code>
181+
* </div>
169182
*/
170183

171184
/**
172185
* The mouseDragged() function is called once every time the mouse moves and
173186
* a mouse button is pressed. If no mouseDragged() function is defined, the
174187
* touchMoved() function will be called instead if it is defined.
188+
* Browsers may have different default
189+
* behaviors attached to various mouse events. To prevent any default
190+
* behavior for this event, add `return false` to the end of the method.
175191
*
176192
* @method mouseDragged
177193
* @example
@@ -193,6 +209,16 @@ define(function (require) {
193209
* }
194210
* </code>
195211
* </div>
212+
*
213+
* <div class="norender">
214+
* <code>
215+
* function mouseDragged() {
216+
* ellipse(mouseX, mouseY, 5, 5);
217+
* // prevent default
218+
* return false;
219+
* }
220+
* </code>
221+
* </div>
196222
*/
197223
p5.prototype.onmousemove = function(e){
198224
var context = this._isGlobal ? window : this;
@@ -228,14 +254,16 @@ define(function (require) {
228254
* can be used to determine which button has been pressed. If no
229255
* mousePressed() function is defined, the touchStarted() function will be
230256
* called instead if it is defined.
257+
* Browsers may have different default
258+
* behaviors attached to various mouse events. To prevent any default
259+
* behavior for this event, add `return false` to the end of the method.
231260
*
232261
* @method mousePressed
233262
* @example
234263
* <div>
235264
* <code>
236265
* // Click within the image to change
237266
* // the value of the rectangle
238-
* // after the mouse has been clicked
239267
*
240268
* var value = 0;
241269
* function draw() {
@@ -251,6 +279,16 @@ define(function (require) {
251279
* }
252280
* </code>
253281
* </div>
282+
*
283+
* <div class="norender">
284+
* <code>
285+
* function mousePressed() {
286+
* ellipse(mouseX, mouseY, 5, 5);
287+
* // prevent default
288+
* return false;
289+
* }
290+
* </code>
291+
* </div>
254292
*/
255293
p5.prototype.onmousedown = function(e) {
256294
var context = this._isGlobal ? window : this;
@@ -276,6 +314,10 @@ define(function (require) {
276314
* The mouseReleased() function is called every time a mouse button is
277315
* released. If no mouseReleased() function is defined, the touchEnded()
278316
* function will be called instead if it is defined.
317+
* Browsers may have different default
318+
* behaviors attached to various mouse events. To prevent any default
319+
* behavior for this event, add `return false` to the end of the method.
320+
*
279321
*
280322
* @method mouseReleased
281323
* @example
@@ -299,6 +341,16 @@ define(function (require) {
299341
* }
300342
* </code>
301343
* </div>
344+
*
345+
* <div class="norender">
346+
* <code>
347+
* function mouseReleased() {
348+
* ellipse(mouseX, mouseY, 5, 5);
349+
* // prevent default
350+
* return false;
351+
* }
352+
* </code>
353+
* </div>
302354
*/
303355
p5.prototype.onmouseup = function(e) {
304356
var context = this._isGlobal ? window : this;
@@ -322,6 +374,9 @@ define(function (require) {
322374
/**
323375
* The mouseClicked() function is called once after a mouse button has been
324376
* pressed and then released.
377+
* Browsers may have different default
378+
* behaviors attached to various mouse events. To prevent any default
379+
* behavior for this event, add `return false` to the end of the method.
325380
*
326381
* @method mouseClicked
327382
* @example
@@ -345,6 +400,16 @@ define(function (require) {
345400
* }
346401
* </code>
347402
* </div>
403+
*
404+
* <div class="norender">
405+
* <code>
406+
* function mouseClicked() {
407+
* ellipse(mouseX, mouseY, 5, 5);
408+
* // prevent default
409+
* return false;
410+
* }
411+
* </code>
412+
* </div>
348413
*/
349414
p5.prototype.onclick = function(e) {
350415
var context = this._isGlobal ? window : this;
@@ -361,6 +426,9 @@ define(function (require) {
361426
* the mouse wheel if rotated up or away from the user and positive in the
362427
* other direction. On OS X with "natural" scrolling enabled, the values are
363428
* opposite.
429+
* Browsers may have different default
430+
* behaviors attached to various mouse events. To prevent any default
431+
* behavior for this event, add `return false` to the end of the method.
364432
*
365433
* See <a href="http://www.javascriptkit.com/javatutors/onmousewheel.shtml">
366434
* mouse wheel event in JS</a>.

src/input/touch.js

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,42 @@ define(function (require) {
8585
/**
8686
* The touchStarted() function is called once after every time a touch is
8787
* registered. If no touchStarted() function is defined, the mousePressed()
88-
* function will be called instead if it is defined.
88+
* function will be called instead if it is defined. Browsers may have
89+
* different default
90+
* behaviors attached to various touch events. To prevent any default
91+
* behavior for this event, add `return false` to the end of the method.
8992
*
9093
* @method touchStarted
94+
* @example
95+
* <div>
96+
* <code>
97+
* // Touch within the image to change
98+
* // the value of the rectangle
99+
*
100+
* var value = 0;
101+
* function draw() {
102+
* fill(value);
103+
* rect(25, 25, 50, 50);
104+
* }
105+
* function touchStarted() {
106+
* if (value == 0) {
107+
* value = 255;
108+
* } else {
109+
* value = 0;
110+
* }
111+
* }
112+
* </code>
113+
* </div>
114+
*
115+
* <div class="norender">
116+
* <code>
117+
* function touchStarted() {
118+
* ellipse(touchX, touchY, 5, 5);
119+
* // prevent default
120+
* return false;
121+
* }
122+
* </code>
123+
* </div>
91124
*/
92125
p5.prototype.ontouchstart = function(e) {
93126
var context = this._isGlobal ? window : this;
@@ -110,9 +143,40 @@ define(function (require) {
110143
/**
111144
* The touchMoved() function is called every time a touch move is registered.
112145
* If no touchStarted() function is defined, the mouseDragged() function will
113-
* be called instead if it is defined.
146+
* be called instead if it is defined. Browsers may have different default
147+
* behaviors attached to various touch events. To prevent any default
148+
* behavior for this event, add `return false` to the end of the method.
114149
*
115150
* @method touchMoved
151+
* @example
152+
* <div>
153+
* <code>
154+
* // Move your finger across the page
155+
* // to change its value
156+
*
157+
* var value = 0;
158+
* function draw() {
159+
* fill(value);
160+
* rect(25, 25, 50, 50);
161+
* }
162+
* function touchMoved() {
163+
* value = value + 5;
164+
* if (value > 255) {
165+
* value = 0;
166+
* }
167+
* }
168+
* </code>
169+
* </div>
170+
*
171+
* <div class="norender">
172+
* <code>
173+
* function touchMoved() {
174+
* ellipse(touchX, touchY, 5, 5);
175+
* // prevent default
176+
* return false;
177+
* }
178+
* </code>
179+
* </div>
116180
*/
117181
p5.prototype.ontouchmove = function(e) {
118182
var context = this._isGlobal ? window : this;
@@ -135,9 +199,41 @@ define(function (require) {
135199
/**
136200
* The touchEnded() function is called every time a touch ends. If no
137201
* touchStarted() function is defined, the mouseReleased() function will be
138-
* called instead if it is defined.
202+
* called instead if it is defined. Browsers may have different default
203+
* behaviors attached to various touch events. To prevent any default
204+
* behavior for this event, add `return false` to the end of the method.
139205
*
140206
* @method touchEnded
207+
* @example
208+
* <div>
209+
* <code>
210+
* // Release touch within the image to
211+
* // change the value of the rectangle
212+
*
213+
* var value = 0;
214+
* function draw() {
215+
* fill(value);
216+
* rect(25, 25, 50, 50);
217+
* }
218+
* function touchEnded() {
219+
* if (value == 0) {
220+
* value = 255;
221+
* } else {
222+
* value = 0;
223+
* }
224+
* }
225+
* </code>
226+
* </div>
227+
*
228+
* <div class="norender">
229+
* <code>
230+
* function touchEnded() {
231+
* ellipse(touchX, touchY, 5, 5);
232+
* // prevent default
233+
* return false;
234+
* }
235+
* </code>
236+
* </div>
141237
*/
142238
p5.prototype.ontouchend = function(e) {
143239
var context = this._isGlobal ? window : this;

0 commit comments

Comments
 (0)