mirror of
https://github.com/konvajs/konva.git
synced 2025-11-18 17:21:36 +08:00
setup support for pattern fills
This commit is contained in:
51
dist/kinetic-core.js
vendored
51
dist/kinetic-core.js
vendored
@@ -2536,33 +2536,40 @@ Kinetic.Shape.prototype = {
|
||||
var context = this.getContext();
|
||||
var fill = this.attrs.fill;
|
||||
if(!!fill) {
|
||||
var s = fill.start;
|
||||
var e = fill.end;
|
||||
var f = null;
|
||||
|
||||
// color fill
|
||||
if( typeof fill == 'string') {
|
||||
f = this.attrs.fill;
|
||||
}
|
||||
else {
|
||||
var s = fill.start;
|
||||
var e = fill.end;
|
||||
// pattern fill
|
||||
else if(fill.image !== undefined) {
|
||||
var o = Kinetic.GlobalObject._getPoint(fill.offset);
|
||||
|
||||
|
||||
// linear gradient
|
||||
if(s.x !== undefined && s.y !== undefined && e.x !== undefined && e.y !== undefined) {
|
||||
var context = this.getContext();
|
||||
var grd = context.createLinearGradient(s.x, s.y, e.x, e.y);
|
||||
grd.addColorStop(0, s.color);
|
||||
grd.addColorStop(1, e.color);
|
||||
f = grd;
|
||||
}
|
||||
// radial gradient
|
||||
else if(s.radius !== undefined && e.radius !== undefined) {
|
||||
var context = this.getContext();
|
||||
var grd = context.createRadialGradient(s.x, s.y, s.radius, s.x, s.y, e.radius);
|
||||
grd.addColorStop(0, s.color);
|
||||
grd.addColorStop(1, e.color);
|
||||
f = grd;
|
||||
}
|
||||
else {
|
||||
f = 'black';
|
||||
}
|
||||
var repeat = fill.repeat === undefined ? 'repeat' : fill.repeat;
|
||||
f = context.createPattern(fill.image, repeat);
|
||||
}
|
||||
// gradient fill
|
||||
else if(s.x !== undefined && s.y !== undefined && e.x !== undefined && e.y !== undefined) {
|
||||
var context = this.getContext();
|
||||
var grd = context.createLinearGradient(s.x, s.y, e.x, e.y);
|
||||
grd.addColorStop(0, s.color);
|
||||
grd.addColorStop(1, e.color);
|
||||
f = grd;
|
||||
}
|
||||
// radial gradient
|
||||
else if(s.radius !== undefined && e.radius !== undefined) {
|
||||
var context = this.getContext();
|
||||
var grd = context.createRadialGradient(s.x, s.y, s.radius, s.x, s.y, e.radius);
|
||||
grd.addColorStop(0, s.color);
|
||||
grd.addColorStop(1, e.color);
|
||||
f = grd;
|
||||
}
|
||||
else {
|
||||
f = 'black';
|
||||
}
|
||||
|
||||
context.fillStyle = f;
|
||||
|
||||
4
dist/kinetic-core.min.js
vendored
4
dist/kinetic-core.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user