From a74ea1e697df6fb21102aa54f9d02256dba6299d Mon Sep 17 00:00:00 2001 From: Asturur Date: Sun, 11 Sep 2016 11:30:10 +0200 Subject: [PATCH] move backgroundColor to all classes --- src/shapes/object.class.js | 28 ++++++++++++++++++++++++++-- src/shapes/text.class.js | 24 +----------------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index 2413f46bb77..3c6c68d3628 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -1097,13 +1097,14 @@ 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(); @@ -1111,6 +1112,29 @@ 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 diff --git a/src/shapes/text.class.js b/src/shapes/text.class.js index 6575bae1cec..6a9690c9346 100644 --- a/src/shapes/text.class.js +++ b/src/shapes/text.class.js @@ -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