Skip to content

Commit 48b3268

Browse files
author
lauren mccarthy
committed
moving update pcoords calls back into updatecoords from draw issue #367
2 parents ab8ae50 + ba3fb29 commit 48b3268

File tree

8 files changed

+36
-18
lines changed

8 files changed

+36
-18
lines changed

examples/p5.Image/saving-images.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function setup() {
88

99
setTimeout(function(){
1010
console.log("Save image")
11-
save(img, "unicorn.png");
11+
save(img, "unicorn.jpeg");
1212
}, 1000);
1313

1414
});

lib/p5.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ var core = function (require, shim, constants) {
199199
f.call(this);
200200
});
201201
userDraw();
202-
this._updatePMouseCoords();
203-
this._updatePTouchCoords();
204202
this._registeredMethods.post.forEach(function (f) {
205203
f.call(this);
206204
});
@@ -2956,6 +2954,7 @@ var inputmouse = function (require, core, constants) {
29562954
p5.prototype.mouseIsPressed = false;
29572955
p5.prototype.isMousePressed = false;
29582956
p5.prototype._updateMouseCoords = function (e) {
2957+
this._updatePMouseCoords();
29592958
if (e.type === 'touchstart' || e.type === 'touchmove') {
29602959
this._setProperty('mouseX', this.touchX);
29612960
this._setProperty('mouseY', this.touchY);
@@ -3111,6 +3110,7 @@ var inputtouch = function (require, core) {
31113110
p5.prototype.ptouchY = 0;
31123111
p5.prototype.touches = [];
31133112
p5.prototype._updateTouchCoords = function (e) {
3113+
this._updatePTouchCoords();
31143114
if (e.type === 'mousedown' || e.type === 'mousemove') {
31153115
this._setProperty('touchX', this.mouseX);
31163116
this._setProperty('touchY', this.mouseY);
@@ -3587,7 +3587,7 @@ var outputfiles = function (require, core) {
35873587
} else if (args[0] instanceof p5.Table) {
35883588
p5.prototype.saveTable(args[0], args[1], args[2], args[3]);
35893589
} else if (args[0] instanceof p5.Image) {
3590-
p5.prototype.saveCanvas(args[0].canvas, args[1], args[2]);
3590+
p5.prototype.saveCanvas(args[0].canvas, args[1]);
35913591
} else if (args[0] instanceof p5.SoundFile) {
35923592
p5.prototype.saveSound(args[0], args[1], args[2], args[3]);
35933593
} else if (args[0] instanceof Object) {
@@ -3726,11 +3726,12 @@ var outputfiles = function (require, core) {
37263726
if (!extension) {
37273727
extension = '';
37283728
}
3729+
if (!filename) {
3730+
filename = 'untitled';
3731+
}
37293732
var ext = '';
3730-
if (filename) {
3733+
if (filename && filename.indexOf('.') > -1) {
37313734
ext = filename.split('.').pop();
3732-
} else {
3733-
filename = 'untitled';
37343735
}
37353736
if (extension) {
37363737
if (ext !== extension) {
@@ -3743,6 +3744,7 @@ var outputfiles = function (require, core) {
37433744
ext
37443745
];
37453746
}
3747+
p5.prototype._checkFileExtension = _checkFileExtension;
37463748
p5.prototype._isSafari = function () {
37473749
var x = Object.prototype.toString.call(window.HTMLElement);
37483750
return x.indexOf('Constructor') > 0;
@@ -3757,6 +3759,12 @@ var outputimage = function (require, core) {
37573759
var p5 = core;
37583760
var frames = [];
37593761
p5.prototype.saveCanvas = function (_cnv, filename, extension) {
3762+
if (!extension) {
3763+
extension = p5.prototype._checkFileExtension(filename, extension)[1];
3764+
if (extension === '') {
3765+
extension = 'png';
3766+
}
3767+
}
37603768
var cnv;
37613769
if (_cnv) {
37623770
cnv = _cnv;
@@ -3772,7 +3780,7 @@ var outputimage = function (require, core) {
37723780
window.location.href = cnv.toDataURL();
37733781
} else {
37743782
var mimeType;
3775-
if (!extension) {
3783+
if (typeof extension === 'undefined') {
37763784
extension = 'png';
37773785
mimeType = 'image/png';
37783786
} else {

lib/p5.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/core.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ define(function (require) {
280280
f.call(this);
281281
});
282282
userDraw();
283-
this._updatePMouseCoords();
284-
this._updatePTouchCoords();
283+
// this._updatePMouseCoords();
284+
// this._updatePTouchCoords();
285285
// call any registered post functions
286286
this._registeredMethods.post.forEach(function(f) {
287287
f.call(this);

src/input/mouse.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ define(function (require) {
101101
p5.prototype.isMousePressed = false; // both are supported
102102

103103
p5.prototype._updateMouseCoords = function(e) {
104+
this._updatePMouseCoords();
104105
if(e.type === 'touchstart' || e.type === 'touchmove') {
105106
this._setProperty('mouseX', this.touchX);
106107
this._setProperty('mouseY', this.touchY);

src/input/touch.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ define(function (require) {
6161
p5.prototype.touches = [];
6262

6363
p5.prototype._updateTouchCoords = function(e) {
64+
this._updatePTouchCoords();
6465
if(e.type === 'mousedown' || e.type === 'mousemove'){
6566
this._setProperty('touchX', this.mouseX);
6667
this._setProperty('touchY', this.mouseY);

src/output/files.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ define(function (require) {
215215
p5.prototype.saveTable(args[0], args[1], args[2], args[3]);
216216
}
217217
else if (args[0] instanceof p5.Image) {
218-
p5.prototype.saveCanvas(args[0].canvas, args[1], args[2]);
218+
p5.prototype.saveCanvas(args[0].canvas, args[1]);
219219
}
220220
else if (args[0] instanceof p5.SoundFile) {
221221
p5.prototype.saveSound(args[0], args[1], args[2], args[3]);
@@ -520,12 +520,13 @@ define(function (require) {
520520
if (!extension) {
521521
extension = '';
522522
}
523+
if (!filename) {
524+
filename = 'untitled';
525+
}
523526
var ext = '';
524527
// make sure the file will have a name, see if filename needs extension
525-
if (filename) {
528+
if (filename && filename.indexOf('.') > -1) {
526529
ext = filename.split('.').pop();
527-
} else {
528-
filename = 'untitled';
529530
}
530531
// append extension if it doesn't exist
531532
if (extension) {
@@ -536,6 +537,7 @@ define(function (require) {
536537
}
537538
return [filename, ext];
538539
}
540+
p5.prototype._checkFileExtension = _checkFileExtension;
539541

540542
/**
541543
* Returns true if the browser is Safari, false if not.

src/output/image.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ define(function (require) {
1717
* specific html5 canvas (optional).
1818
*/
1919
p5.prototype.saveCanvas = function(_cnv, filename, extension) {
20+
if (!extension) {
21+
extension = p5.prototype._checkFileExtension(filename, extension)[1];
22+
if (extension === '') {
23+
extension = 'png';
24+
}
25+
}
2026
var cnv;
2127
if (_cnv) {
2228
cnv = _cnv;
@@ -33,7 +39,7 @@ define(function (require) {
3339
window.location.href = cnv.toDataURL();
3440
} else {
3541
var mimeType;
36-
if (!extension) {
42+
if (typeof(extension) === 'undefined') {
3743
extension = 'png';
3844
mimeType = 'image/png';
3945
}

0 commit comments

Comments
 (0)