mirror of
https://github.com/konvajs/konva.git
synced 2025-09-18 09:50:05 +08:00
Text shape now depends on Rect for rect drawing func
This commit is contained in:
@@ -24,24 +24,24 @@ Kinetic.Rect.prototype = {
|
||||
},
|
||||
drawFunc: function(context) {
|
||||
context.beginPath();
|
||||
if(this.attrs.cornerRadius === 0) {
|
||||
var cornerRadius = this.getCornerRadius(), width = this.getWidth(), height = this.getHeight();
|
||||
if(cornerRadius === 0) {
|
||||
// simple rect - don't bother doing all that complicated maths stuff.
|
||||
context.rect(0, 0, this.attrs.width, this.attrs.height);
|
||||
context.rect(0, 0, width, height);
|
||||
}
|
||||
else {
|
||||
// arcTo would be nicer, but browser support is patchy (Opera)
|
||||
context.moveTo(this.attrs.cornerRadius, 0);
|
||||
context.lineTo(this.attrs.width - this.attrs.cornerRadius, 0);
|
||||
context.arc(this.attrs.width - this.attrs.cornerRadius, this.attrs.cornerRadius, this.attrs.cornerRadius, Math.PI * 3 / 2, 0, false);
|
||||
context.lineTo(this.attrs.width, this.attrs.height - this.attrs.cornerRadius);
|
||||
context.arc(this.attrs.width - this.attrs.cornerRadius, this.attrs.height - this.attrs.cornerRadius, this.attrs.cornerRadius, 0, Math.PI / 2, false);
|
||||
context.lineTo(this.attrs.cornerRadius, this.attrs.height);
|
||||
context.arc(this.attrs.cornerRadius, this.attrs.height - this.attrs.cornerRadius, this.attrs.cornerRadius, Math.PI / 2, Math.PI, false);
|
||||
context.lineTo(0, this.attrs.cornerRadius);
|
||||
context.arc(this.attrs.cornerRadius, this.attrs.cornerRadius, this.attrs.cornerRadius, Math.PI, Math.PI * 3 / 2, false);
|
||||
context.moveTo(cornerRadius, 0);
|
||||
context.lineTo(width - cornerRadius, 0);
|
||||
context.arc(width - cornerRadius, cornerRadius, cornerRadius, Math.PI * 3 / 2, 0, false);
|
||||
context.lineTo(width, height - cornerRadius);
|
||||
context.arc(width - cornerRadius, height - cornerRadius, cornerRadius, 0, Math.PI / 2, false);
|
||||
context.lineTo(cornerRadius, height);
|
||||
context.arc(cornerRadius, height - cornerRadius, cornerRadius, Math.PI / 2, Math.PI, false);
|
||||
context.lineTo(0, cornerRadius);
|
||||
context.arc(cornerRadius, cornerRadius, cornerRadius, Math.PI, Math.PI * 3 / 2, false);
|
||||
}
|
||||
context.closePath();
|
||||
|
||||
this.fillStroke(context);
|
||||
}
|
||||
};
|
||||
|
@@ -46,32 +46,9 @@ Kinetic.Text.prototype = {
|
||||
},
|
||||
drawFunc: function(context) {
|
||||
// draw rect
|
||||
context.beginPath();
|
||||
var boxWidth = this.getWidth();
|
||||
var boxHeight = this.getHeight();
|
||||
Kinetic.Rect.prototype.drawFunc.call(this, context);
|
||||
|
||||
if(this.attrs.cornerRadius === 0) {
|
||||
// simple rect - don't bother doing all that complicated maths stuff.
|
||||
context.rect(0, 0, boxWidth, boxHeight);
|
||||
}
|
||||
else {
|
||||
// arcTo would be nicer, but browser support is patchy (Opera)
|
||||
context.moveTo(this.attrs.cornerRadius, 0);
|
||||
context.lineTo(boxWidth - this.attrs.cornerRadius, 0);
|
||||
context.arc(boxWidth - this.attrs.cornerRadius, this.attrs.cornerRadius, this.attrs.cornerRadius, Math.PI * 3 / 2, 0, false);
|
||||
context.lineTo(boxWidth, boxHeight - this.attrs.cornerRadius);
|
||||
context.arc(boxWidth - this.attrs.cornerRadius, boxHeight - this.attrs.cornerRadius, this.attrs.cornerRadius, 0, Math.PI / 2, false);
|
||||
context.lineTo(this.attrs.cornerRadius, boxHeight);
|
||||
context.arc(this.attrs.cornerRadius, boxHeight - this.attrs.cornerRadius, this.attrs.cornerRadius, Math.PI / 2, Math.PI, false);
|
||||
context.lineTo(0, this.attrs.cornerRadius);
|
||||
context.arc(this.attrs.cornerRadius, this.attrs.cornerRadius, this.attrs.cornerRadius, Math.PI, Math.PI * 3 / 2, false);
|
||||
}
|
||||
context.closePath();
|
||||
|
||||
this.fillStroke(context);
|
||||
/*
|
||||
* draw text
|
||||
*/
|
||||
// draw text
|
||||
var p = this.attrs.padding;
|
||||
var lineHeightPx = this.attrs.lineHeight * this.getTextHeight();
|
||||
var textArr = this.textArr;
|
||||
@@ -102,32 +79,7 @@ Kinetic.Text.prototype = {
|
||||
}
|
||||
context.restore();
|
||||
},
|
||||
drawHitFunc: function(context) {
|
||||
// draw rect
|
||||
context.beginPath();
|
||||
var boxWidth = this.getWidth();
|
||||
var boxHeight = this.getHeight();
|
||||
|
||||
if(this.attrs.cornerRadius === 0) {
|
||||
// simple rect - don't bother doing all that complicated maths stuff.
|
||||
context.rect(0, 0, boxWidth, boxHeight);
|
||||
}
|
||||
else {
|
||||
// arcTo would be nicer, but browser support is patchy (Opera)
|
||||
context.moveTo(this.attrs.cornerRadius, 0);
|
||||
context.lineTo(boxWidth - this.attrs.cornerRadius, 0);
|
||||
context.arc(boxWidth - this.attrs.cornerRadius, this.attrs.cornerRadius, this.attrs.cornerRadius, Math.PI * 3 / 2, 0, false);
|
||||
context.lineTo(boxWidth, boxHeight - this.attrs.cornerRadius);
|
||||
context.arc(boxWidth - this.attrs.cornerRadius, boxHeight - this.attrs.cornerRadius, this.attrs.cornerRadius, 0, Math.PI / 2, false);
|
||||
context.lineTo(this.attrs.cornerRadius, boxHeight);
|
||||
context.arc(this.attrs.cornerRadius, boxHeight - this.attrs.cornerRadius, this.attrs.cornerRadius, Math.PI / 2, Math.PI, false);
|
||||
context.lineTo(0, this.attrs.cornerRadius);
|
||||
context.arc(this.attrs.cornerRadius, this.attrs.cornerRadius, this.attrs.cornerRadius, Math.PI, Math.PI * 3 / 2, false);
|
||||
}
|
||||
context.closePath();
|
||||
|
||||
this.fillStroke(context);
|
||||
},
|
||||
drawHitFunc: Kinetic.Rect.prototype.drawFunc,
|
||||
/**
|
||||
* set text
|
||||
* @name setText
|
||||
|
Reference in New Issue
Block a user