Added new methods

This commit is contained in:
--global 2014-05-30 18:50:39 +02:00
parent a73369aa36
commit a604021b40
1 changed files with 43 additions and 16 deletions

View File

@ -15,7 +15,7 @@
* var canvas1 = document.getElementById('foo');
* var canvas2 = document.getElementById('bar');
* // instantiate once, reuse everywhere
* var brush = new jSketch(canvas1).lineStyle('red').moveTo(50,50).lineTo(10,10);
* var brush = new jSketch(canvas1).lineStyle('red').moveTo(50,50).lineTo(10,10).stroke();
* brush.context(canvas2).beginFill('#5F7').fillCircle(30,30,8).endFill();
*/
(function(window){
@ -140,7 +140,7 @@
* Sets the line style.
* @param {Number|String} color an HTML color
* @param {Number} thickness line thickness
* @param {String} thickness style of line cap
* @param {String} capStyle style of line cap
* @param {String} joinStyle style of line join
* @param {String} mitter style of mitter
* @return jSketch
@ -177,7 +177,6 @@
*/
lineTo: function(x,y) {
this.graphics.lineTo(x,y);
this.graphics.stroke();
return this;
},
/**
@ -207,7 +206,6 @@
*/
curveTo: function(x,y,cpx,cpy) {
this.graphics.quadraticCurveTo(cpx,cpy,x,y);
this.graphics.stroke();
return this;
},
/**
@ -227,6 +225,16 @@
this.curveTo(x2,y2,cpx,cpy);
return this;
},
/**
* Strokes a given path.
* @return jSketch
* @name stroke
* @methodOf jSketch
*/
stroke: function() {
this.graphics.stroke();
return this;
},
/**
* Draws a stroke-only rectangle.
* @param {Number} x
@ -331,6 +339,7 @@
this.data.strokeStyle = this.graphics.strokeStyle;
this.graphics.globalCompositeOperation = "copy";
this.graphics.strokeStyle = "rgba(0,0,0,0)";
return this;
},
/**
* Sets brush to pencil mode.
@ -341,6 +350,7 @@
pencil: function() {
this.graphics.globalCompositeOperation = "source-over";
this.graphics.strokeStyle = this.data.strokeStyle;
return this;
},
/**
* Clears stage.
@ -374,6 +384,23 @@
restore: function() {
this.graphics.restore();
return this;
},
/**
* Draws an image.
* @param {Number} img
* @param {Number} x
* @param {Number} y
* @return jSketch
* @name drawImage
* @methodOf jSketch
*/
drawImage: function(src, x,y) {
var self = this, img = new Image();
img.src = src;
img.onload = function() {
self.graphics.drawImage(img, x,y);
}
return this;
}
};