Skip to content

Commit

Permalink
move backgroundColor to all classes (#3248)
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur committed Sep 11, 2016
1 parent 876c9ca commit d7157d1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
28 changes: 26 additions & 2 deletions src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1097,20 +1097,44 @@
if (!noTransform) {
this.transform(ctx);
}
this._setOpacity(ctx);
this._setShadow(ctx);
this._renderBackground(ctx);
this._setStrokeStyles(ctx);
this._setFillStyles(ctx);
if (this.transformMatrix) {
ctx.transform.apply(ctx, this.transformMatrix);
}
this._setOpacity(ctx);
this._setShadow(ctx);
this.clipTo && fabric.util.clipContext(this, ctx);
this._render(ctx, noTransform);
this.clipTo && ctx.restore();

ctx.restore();
},

/**
* Draws a background for the object big as its width and height;
* @private
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_renderBackground: function(ctx) {
if (!this.backgroundColor) {
return;
}

ctx.fillStyle = this.backgroundColor;

ctx.fillRect(
-this.width / 2,
-this.height / 2,
this.width,
this.height
);
// if there is background color no other shadows
// should be casted
this._removeShadow(ctx);
},

/**
* @private
* @param {CanvasRenderingContext2D} ctx Context to render on
Expand Down
24 changes: 1 addition & 23 deletions src/shapes/text.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,32 +634,10 @@
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_renderTextBackground: function(ctx) {
this._renderTextBoxBackground(ctx);
this._renderBackground(ctx);
this._renderTextLinesBackground(ctx);
},

/**
* @private
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_renderTextBoxBackground: function(ctx) {
if (!this.backgroundColor) {
return;
}

ctx.fillStyle = this.backgroundColor;

ctx.fillRect(
this._getLeftOffset(),
this._getTopOffset(),
this.width,
this.height
);
// if there is background color no other shadows
// should be casted
this._removeShadow(ctx);
},

/**
* @private
* @param {CanvasRenderingContext2D} ctx Context to render on
Expand Down

0 comments on commit d7157d1

Please sign in to comment.