diff --git a/src/Canvas.js b/src/Canvas.js index 4b8a856b..91f4f04e 100644 --- a/src/Canvas.js +++ b/src/Canvas.js @@ -118,8 +118,6 @@ if(!skipShadow && shadow) { this._applyShadow(shape); } - var s = fill.start; - var e = fill.end; // color fill switch(fillType) { @@ -128,18 +126,25 @@ context.fill(context); break; case 'PATTERN': - var repeat = !fill.repeat ? 'repeat' : fill.repeat; + if(fill.x || fill.y) { + context.translate(fill.x || 0, fill.y || 0); + } + if(fill.rotation) { + context.rotate(fill.rotation); + } if(fill.scale) { context.scale(fill.scale.x, fill.scale.y); } if(fill.offset) { - context.translate(fill.offset.x, fill.offset.y); - } file:///C:/Users/Eric/Documents/Eric/workspaces/KineticJS/dist/kinetic-current.js + context.translate(-1 * fill.offset.x, -1 * fill.offset.y); + } - context.fillStyle = context.createPattern(fill.image, repeat); + context.fillStyle = context.createPattern(fill.image, fill.repeat || 'repeat'); context.fill(context); break; case 'LINEAR_GRADIENT': + var s = fill.start; + var e = fill.end; var grd = context.createLinearGradient(s.x, s.y, e.x, e.y); var colorStops = fill.colorStops; @@ -152,6 +157,8 @@ break; case 'RADIAL_GRADIENT': + var s = fill.start; + var e = fill.end; var grd = context.createRadialGradient(s.x, s.y, s.radius, e.x, e.y, e.radius); var colorStops = fill.colorStops; diff --git a/tests/js/unit/shapeTests.js b/tests/js/unit/shapeTests.js index e6c7fa9e..9600e740 100644 --- a/tests/js/unit/shapeTests.js +++ b/tests/js/unit/shapeTests.js @@ -178,5 +178,47 @@ Test.Modules.SHAPE = { var dataUrl = layer.toDataURL(); test(dataUrls['change custom shape draw func'] === dataUrl, 'problem with setDrawFunc'); + }, + 'add star with translated, scaled, rotated fill': function(containerId) { + var imageObj = new Image(); + imageObj.onload = function() { + var stage = new Kinetic.Stage({ + container: containerId, + width: 578, + height: 200 + }); + var layer = new Kinetic.Layer(); + + var star = new Kinetic.Star({ + x: 200, + y: 100, + numPoints: 5, + innerRadius: 40, + outerRadius: 70, + fill: { + image: imageObj, + x: -20, + y: -20, + //scale: {x: 0.5, y: 0.5}, + offset: {x: 219, y: 150}, + rotation: Math.PI * 0.5, + repeat: 'no-repeat' + }, + stroke: 'blue', + strokeWidth: 5, + draggable: true + }); + + layer.add(star); + stage.add(layer); + + /* + var anim = new Kinetic.Animation(function() { + star.attrs.fill.rotation += 0.02; + }, layer); + anim.start(); + */ + }; + imageObj.src = '../assets/darth-vader.jpg'; } };