moved dashArray attr to Shape level and hooked into native setLineDash method now that it's in the spec. This enables dashed lines for any type of stroke, not just straight lines

This commit is contained in:
Eric Rowell
2012-12-08 10:21:52 -08:00
parent c316edb418
commit 9be03d6eab
3 changed files with 45 additions and 90 deletions

View File

@@ -183,9 +183,18 @@
}
},
_stroke: function(shape, skipShadow) {
var context = this.context, stroke = shape.getStroke(), strokeWidth = shape.getStrokeWidth(), shadow = shape.getShadow();
var context = this.context, stroke = shape.getStroke(), strokeWidth = shape.getStrokeWidth(), shadow = shape.getShadow(), dashArray = shape.getDashArray();
if(stroke || strokeWidth) {
context.save();
this._applyLineCap(shape);
if(dashArray) {
if(context.setLineDash) {
context.setLineDash(dashArray);
}
else {
Kinetic.Global.warn('Could not apply dash array because your browser does not support it.');
}
}
if(!skipShadow && shadow) {
this._applyShadow(shape);
}
@@ -219,6 +228,12 @@
context.shadowOffsetX = offset.x;
context.shadowOffsetY = offset.y;
}
},
_applyLineCap: function(shape) {
var lineCap = shape.getLineCap();
if(lineCap) {
this.context.lineCap = lineCap;
}
}
};
@@ -237,12 +252,19 @@
_stroke: function(shape) {
var context = this.context, stroke = shape.getStroke(), strokeWidth = shape.getStrokeWidth();
if(stroke || strokeWidth) {
this._applyLineCap(shape);
context.save();
context.lineWidth = strokeWidth || 2;
context.strokeStyle = '#' + shape.colorKey;
context.stroke(context);
context.restore();
}
},
_applyLineCap: function(shape) {
var lineCap = shape.getLineCap();
if(lineCap) {
this.context.lineCap = lineCap;
}
}
};
})();