drawImage coordinates made optional

This commit is contained in:
Luis Leiva 2015-06-21 11:35:22 +02:00
parent 0c5ce077af
commit 030763919a
2 changed files with 5 additions and 7 deletions

View File

@ -402,12 +402,14 @@
/**
* Draws an image.
* @param {Number} src - Image source path.
* @param {Number} x - Horizontal coordinate.
* @param {Number} y - Vertical coordinate.
* @param {Number} [x] - Horizontal coordinate.
* @param {Number} [y] - Vertical coordinate.
* @return jSketch
* @memberof jSketch
*/
drawImage: function(src, x,y) {
if (typeof x === 'undefined') x = 0;
if (typeof y === 'undefined') y = 0;
var self = this, img = new Image();
img.src = src;
img.onload = function() {

6
jsketch.min.js vendored
View File

@ -1,5 +1 @@
/*!
* jSketch 0.8 | Luis A. Leiva | MIT license
* A simple JavaScript library for drawing facilities on HTML5 canvas.
*/
(function(a){var c=function(e,d){return new b(e,d)};var b=function(e,d){if(!e){return}if(typeof d==="undefined"){d={}}this.context(e);this.stageWidth=e.getAttribute("width");this.stageHeight=e.getAttribute("height");this.graphics.fillStyle=typeof d.fillStyle!=="undefined"?d.fillStyle:"#F00";this.graphics.strokeStyle=typeof d.strokeStyle!=="undefined"?d.strokeStyle:"#F0F";this.graphics.lineWidth=typeof d.lineWidth!=="undefined"?d.lineWidth:2;this.graphics.lineCap=typeof d.lineCap!=="undefined"?d.lineCap:"round";this.graphics.lineJoin=typeof d.lineJoin!=="undefined"?d.lineJoin:"round";this.graphics.mitterLimit=typeof d.mitterLimit!=="undefined"?d.mitterLimit:10;this.graphics.options=Object.keys(d);this.data={};return this};c.fn=b.prototype={context:function(d){if(d==null){throw ("No canvas element specified.")}this.canvas=d;this.graphics=d.getContext("2d");return this},size:function(e,d){this.stageWidth=e;this.stageHeight=d;this.canvas.width=e;this.canvas.height=d;return this},background:function(d){var e=this.graphics.fillStyle;this.beginFill(d);this.graphics.fillRect(0,0,this.stageWidth,this.stageHeight);this.beginFill(e);return this},stage:function(f,d,e){this.size(f,d).background(e);return this},beginFill:function(d){this.saveGraphics();this.graphics.fillStyle=d;return this},endFill:function(){this.graphics.fillStyle=this.data.fillStyle;return this},lineStyle:function(d,e,f,h,g){this.graphics.strokeStyle=d||this.graphics.strokeStyle;this.graphics.lineWidth=e||this.graphics.lineWidth;this.graphics.lineCap=f||this.graphics.lineCap;this.graphics.lineJoin=h||this.graphics.lineJoin;this.graphics.mitterLimit=g||this.graphics.mitterLimit;return this},moveTo:function(d,e){this.graphics.moveTo(d,e);return this},lineTo:function(d,e){this.graphics.lineTo(d,e);return this},line:function(e,g,d,f){this.graphics.moveTo(e,g);this.lineTo(d,f);return this},curveTo:function(d,g,f,e){this.graphics.quadraticCurveTo(f,e,d,g);return this},curve:function(f,i,d,h,g,e){this.graphics.moveTo(f,i);this.curveTo(d,h,g,e);return this},stroke:function(){this.graphics.stroke();return this},strokeRect:function(e,g,f,d){this.graphics.beginPath();this.graphics.strokeRect(e,g,f,d);this.graphics.closePath();return this},fillRect:function(e,g,f,d){this.graphics.beginPath();this.graphics.fillRect(e,g,f,d);this.graphics.closePath();return this},strokeCircle:function(e,f,d){this.graphics.beginPath();this.graphics.arc(e,f,d,0,Math.PI*2,false);this.graphics.stroke();this.graphics.closePath();return this},fillCircle:function(e,f,d){this.graphics.beginPath();this.graphics.arc(e,f,d,0,Math.PI*2,false);this.graphics.fill();this.graphics.closePath();return this},radialCircle:function(e,j,d,f,h){var i=this.graphics.createRadialGradient(e,j,d,e,j,h);i.addColorStop(0,f);i.addColorStop(1,"rgba(0,0,0,0)");this.graphics.fillStyle=i;this.fillCircle(e,j,d);return this},beginPath:function(){this.saveGraphics();this.graphics.beginPath();return this},closePath:function(){this.graphics.closePath();this.restoreGraphics();return this},eraser:function(d){if(typeof d==="undefined"){d=15}this.graphics.globalCompositeOperation="destination-out";this.graphics.lineWidth=d;return this},pencil:function(d){if(typeof d!=="undefined"){this.graphics.lineWidth=d}this.graphics.globalCompositeOperation="source-over";return this},clear:function(){this.graphics.clearRect(0,0,this.stageWidth,this.stageHeight);this.data={};return this},save:function(){this.graphics.save();return this},restore:function(){this.graphics.restore();return this},saveGraphics:function(d){if(typeof d==="undefined"){d=this.graphics.options}if(typeof d==="string"){d=d.split(" ")}for(var e=0;e<d.length;e++){var f=d[e];this.data[f]=this.graphics[f]}return this},restoreGraphics:function(d){if(typeof d==="undefined"){d=this.graphics.options}if(typeof d==="string"){d=d.split(" ")}for(var e=0;e<d.length;e++){var f=d[e];this.graphics[f]=this.data[f]}return this},drawImage:function(g,d,h){var f=this,e=new Image();e.src=g;e.onload=function(){f.graphics.drawImage(e,d,h)};return this}};a.jSketch=c})(this);
!function(i){var t=function(i,t){return new s(i,t)},s=function(i,t){return i?("undefined"==typeof t&&(t={}),this.context(i),this.stageWidth=i.getAttribute("width"),this.stageHeight=i.getAttribute("height"),this.graphics.fillStyle="undefined"!=typeof t.fillStyle?t.fillStyle:"#F00",this.graphics.strokeStyle="undefined"!=typeof t.strokeStyle?t.strokeStyle:"#F0F",this.graphics.lineWidth="undefined"!=typeof t.lineWidth?t.lineWidth:2,this.graphics.lineCap="undefined"!=typeof t.lineCap?t.lineCap:"round",this.graphics.lineJoin="undefined"!=typeof t.lineJoin?t.lineJoin:"round",this.graphics.mitterLimit="undefined"!=typeof t.mitterLimit?t.mitterLimit:10,this.graphics.options=Object.keys(t),this.data={},this):void 0};t.fn=s.prototype={context:function(i){if(null==i)throw"No canvas element specified.";return this.canvas=i,this.graphics=i.getContext("2d"),this},size:function(i,t){return this.stageWidth=i,this.stageHeight=t,this.canvas.width=i,this.canvas.height=t,this},background:function(i){var t=this.graphics.fillStyle;return this.beginFill(i),this.graphics.fillRect(0,0,this.stageWidth,this.stageHeight),this.beginFill(t),this},stage:function(i,t,s){return this.size(i,t).background(s),this},beginFill:function(i){return this.saveGraphics(),this.graphics.fillStyle=i,this},endFill:function(){return this.graphics.fillStyle=this.data.fillStyle,this},lineStyle:function(i,t,s,e,h){return this.graphics.strokeStyle=i||this.graphics.strokeStyle,this.graphics.lineWidth=t||this.graphics.lineWidth,this.graphics.lineCap=s||this.graphics.lineCap,this.graphics.lineJoin=e||this.graphics.lineJoin,this.graphics.mitterLimit=h||this.graphics.mitterLimit,this},moveTo:function(i,t){return this.graphics.moveTo(i,t),this},lineTo:function(i,t){return this.graphics.lineTo(i,t),this},line:function(i,t,s,e){return this.graphics.moveTo(i,t),this.lineTo(s,e),this},curveTo:function(i,t,s,e){return this.graphics.quadraticCurveTo(s,e,i,t),this},curve:function(i,t,s,e,h,r){return this.graphics.moveTo(i,t),this.curveTo(s,e,h,r),this},stroke:function(){return this.graphics.stroke(),this},strokeRect:function(i,t,s,e){return this.graphics.beginPath(),this.graphics.strokeRect(i,t,s,e),this.graphics.closePath(),this},fillRect:function(i,t,s,e){return this.graphics.beginPath(),this.graphics.fillRect(i,t,s,e),this.graphics.closePath(),this},strokeCircle:function(i,t,s){return this.graphics.beginPath(),this.graphics.arc(i,t,s,0,2*Math.PI,!1),this.graphics.stroke(),this.graphics.closePath(),this},fillCircle:function(i,t,s){return this.graphics.beginPath(),this.graphics.arc(i,t,s,0,2*Math.PI,!1),this.graphics.fill(),this.graphics.closePath(),this},radialCircle:function(i,t,s,e,h){var r=this.graphics.createRadialGradient(i,t,s,i,t,h);return r.addColorStop(0,e),r.addColorStop(1,"rgba(0,0,0,0)"),this.graphics.fillStyle=r,this.fillCircle(i,t,s),this},beginPath:function(){return this.saveGraphics(),this.graphics.beginPath(),this},closePath:function(){return this.graphics.closePath(),this.restoreGraphics(),this},eraser:function(i){return"undefined"==typeof i&&(i=15),this.graphics.globalCompositeOperation="destination-out",this.graphics.lineWidth=i,this},pencil:function(i){return"undefined"!=typeof i&&(this.graphics.lineWidth=i),this.graphics.globalCompositeOperation="source-over",this},clear:function(){return this.graphics.clearRect(0,0,this.stageWidth,this.stageHeight),this.data={},this},save:function(){return this.graphics.save(),this},restore:function(){return this.graphics.restore(),this},saveGraphics:function(i){"undefined"==typeof i&&(i=this.graphics.options),"string"==typeof i&&(i=i.split(" "));for(var t=0;t<i.length;t++){var s=i[t];this.data[s]=this.graphics[s]}return this},restoreGraphics:function(i){"undefined"==typeof i&&(i=this.graphics.options),"string"==typeof i&&(i=i.split(" "));for(var t=0;t<i.length;t++){var s=i[t];this.graphics[s]=this.data[s]}return this},drawImage:function(i,t,s){"undefined"==typeof t&&(t=0),"undefined"==typeof s&&(s=0);var e=this,h=new Image;return h.src=i,h.onload=function(){e.graphics.drawImage(h,t,s)},this}},i.jSketch=t}(this);