mirror of https://github.com/luileito/jsketch.git
Fixed save/restore graphic options
This commit is contained in:
parent
738e1a7bfb
commit
baaa5c100a
38
jsketch.js
38
jsketch.js
|
|
@ -41,7 +41,7 @@
|
||||||
// Scene defaults.
|
// Scene defaults.
|
||||||
this.stageWidth = elem.width;
|
this.stageWidth = elem.width;
|
||||||
this.stageHeight = elem.height;
|
this.stageHeight = elem.height;
|
||||||
// Drawing defaults.
|
// Set drawing defaults.
|
||||||
this.drawingDefaults(options);
|
this.drawingDefaults(options);
|
||||||
// Make room for storing some data such as brush type, colors, etc.
|
// Make room for storing some data such as brush type, colors, etc.
|
||||||
this.data = {};
|
this.data = {};
|
||||||
|
|
@ -90,7 +90,14 @@
|
||||||
this.graphics.lineJoin = typeof options.lineJoin !== 'undefined' ? options.lineJoin : 'round';
|
this.graphics.lineJoin = typeof options.lineJoin !== 'undefined' ? options.lineJoin : 'round';
|
||||||
this.graphics.miterLimit = typeof options.miterLimit !== 'undefined' ? options.miterLimit : 10;
|
this.graphics.miterLimit = typeof options.miterLimit !== 'undefined' ? options.miterLimit : 10;
|
||||||
// Remember graphic options for later saveing/restoring drawing status.
|
// Remember graphic options for later saveing/restoring drawing status.
|
||||||
this.graphics.options = Object.keys(options);
|
this.graphics.options = {
|
||||||
|
fillStyle: this.graphics.fillStyle,
|
||||||
|
strokeStyle: this.graphics.strokeStyle,
|
||||||
|
lineWidth: this.graphics.lineWidth,
|
||||||
|
lineCap: this.graphics.lineCap,
|
||||||
|
lineJoin: this.graphics.lineJoin,
|
||||||
|
miterLimit: this.graphics.miterLimit
|
||||||
|
};
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|
@ -106,7 +113,7 @@
|
||||||
this.canvas.width = width;
|
this.canvas.width = width;
|
||||||
this.canvas.height = height;
|
this.canvas.height = height;
|
||||||
// On resizing we lost drawing options, so reset.
|
// On resizing we lost drawing options, so reset.
|
||||||
this.drawingDefaults();
|
this.restoreGraphics();
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|
@ -150,7 +157,7 @@
|
||||||
* @memberof jSketch
|
* @memberof jSketch
|
||||||
*/
|
*/
|
||||||
endFill: function() {
|
endFill: function() {
|
||||||
this.graphics.fillStyle = this.data.fillStyle;
|
this.restoreGraphics();
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|
@ -366,7 +373,6 @@
|
||||||
clear: function() {
|
clear: function() {
|
||||||
// Note: using 'this.canvas.width = this.canvas.width' resets _all_ styles, so better use clearRect.
|
// Note: using 'this.canvas.width = this.canvas.width' resets _all_ styles, so better use clearRect.
|
||||||
this.graphics.clearRect(0,0, this.stageWidth,this.stageHeight);
|
this.graphics.clearRect(0,0, this.stageWidth,this.stageHeight);
|
||||||
this.data = {};
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|
@ -393,12 +399,11 @@
|
||||||
* @return jSketch
|
* @return jSketch
|
||||||
* @memberof jSketch
|
* @memberof jSketch
|
||||||
*/
|
*/
|
||||||
saveGraphics: function(propList) {
|
saveGraphics: function(options) {
|
||||||
if (typeof propList === 'undefined') propList = this.graphics.options;
|
if (typeof options === 'undefined') options = this.graphics.options;
|
||||||
if (typeof propList === 'string') propList = propList.split(" ");
|
else this.graphics.options = options;
|
||||||
for (var p = 0; p < propList.length; p++) {
|
for (var opt in options) {
|
||||||
var prop = propList[p];
|
this.data[opt] = options[opt];
|
||||||
this.data[prop] = this.graphics[prop];
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
@ -408,12 +413,11 @@
|
||||||
* @return jSketch
|
* @return jSketch
|
||||||
* @memberof jSketch
|
* @memberof jSketch
|
||||||
*/
|
*/
|
||||||
restoreGraphics: function(propList) {
|
restoreGraphics: function(options) {
|
||||||
if (typeof propList === 'undefined') propList = this.graphics.options;
|
if (typeof options === 'undefined') options = this.graphics.options;
|
||||||
if (typeof propList === 'string') propList = propList.split(" ");
|
else this.graphics.options = options;
|
||||||
for (var p = 0; p < propList.length; p++) {
|
for (var opt in options) {
|
||||||
var prop = propList[p];
|
this.graphics[opt] = options[opt];
|
||||||
this.graphics[prop] = this.data[prop];
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue