From 475578276e354d44beb9ce5469da5edc28e50a52 Mon Sep 17 00:00:00 2001 From: kangax Date: Mon, 19 Sep 2011 17:48:16 -0400 Subject: [PATCH] Fix `fabric.Line` to update width/height when changing x1,y1,x2,y2 coordinates. --- HEADER.js | 2 +- dist/all.js | 18 ++++++++++++++++-- package.json | 2 +- site | 2 +- src/line.class.js | 16 +++++++++++++++- 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/HEADER.js b/HEADER.js index 71c06689..f32638c9 100644 --- a/HEADER.js +++ b/HEADER.js @@ -1,6 +1,6 @@ /*! Fabric.js Copyright 2008-2011, Bitsonnet (Juriy Zaytsev, Maxim Chernyak) */ -var fabric = fabric || { version: "0.5.10" }; +var fabric = fabric || { version: "0.5.11" }; if (typeof exports != 'undefined') { exports.fabric = fabric; diff --git a/dist/all.js b/dist/all.js index 81b41bbd..0d931836 100644 --- a/dist/all.js +++ b/dist/all.js @@ -1,6 +1,6 @@ /*! Fabric.js Copyright 2008-2011, Bitsonnet (Juriy Zaytsev, Maxim Chernyak) */ -var fabric = fabric || { version: "0.5.10" }; +var fabric = fabric || { version: "0.5.11" }; if (typeof exports != 'undefined') { exports.fabric = fabric; @@ -7967,7 +7967,9 @@ fabric.util.object.extend(fabric.Canvas.prototype, { "use strict"; var fabric = global.fabric || (global.fabric = { }), - extend = fabric.util.object.extend; + extend = fabric.util.object.extend, + parentSet = fabric.Object.prototype.set, + coordProps = { 'x1': 1, 'x2': 1, 'y1': 1, 'y2': 1 }; if (fabric.Line) { fabric.warn('fabric.Line is already defined'); @@ -8005,12 +8007,24 @@ fabric.util.object.extend(fabric.Canvas.prototype, { this.set('x2', points[2]); this.set('y2', points[3]); + this._setWidthHeight(); + }, + + _setWidthHeight: function() { this.set('width', (this.x2 - this.x1) || 1); this.set('height', (this.y2 - this.y1) || 1); this.set('left', this.x1 + this.width / 2); this.set('top', this.y1 + this.height / 2); }, + set: function(name, value) { + parentSet.call(this, name, value); + if (name in coordProps) { + this._setWidthHeight(); + } + return this; + }, + /** * @private * @method _render diff --git a/package.json b/package.json index b159765d..26454ec7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fabric", "description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.", - "version": "0.5.10", + "version": "0.5.11", "author": "Juriy Zaytsev ", "keywords": ["canvas", "graphic", "graphics", "SVG", "node-canvas", "parser", "HTML5", "object model"], "repository": "git://github.com/kangax/fabric.js", diff --git a/site b/site index fe08e6aa..968ea504 160000 --- a/site +++ b/site @@ -1 +1 @@ -Subproject commit fe08e6aa3b0737d958e800b5ac3872bff4172aa1 +Subproject commit 968ea5040ec0d69e0e270de81b5bfefcada1a3a7 diff --git a/src/line.class.js b/src/line.class.js index 1e1bbe0a..a4e9c40f 100644 --- a/src/line.class.js +++ b/src/line.class.js @@ -5,7 +5,9 @@ "use strict"; var fabric = global.fabric || (global.fabric = { }), - extend = fabric.util.object.extend; + extend = fabric.util.object.extend, + parentSet = fabric.Object.prototype.set, + coordProps = { 'x1': 1, 'x2': 1, 'y1': 1, 'y2': 1 }; if (fabric.Line) { fabric.warn('fabric.Line is already defined'); @@ -43,12 +45,24 @@ this.set('x2', points[2]); this.set('y2', points[3]); + this._setWidthHeight(); + }, + + _setWidthHeight: function() { this.set('width', (this.x2 - this.x1) || 1); this.set('height', (this.y2 - this.y1) || 1); this.set('left', this.x1 + this.width / 2); this.set('top', this.y1 + this.height / 2); }, + set: function(name, value) { + parentSet.call(this, name, value); + if (name in coordProps) { + this._setWidthHeight(); + } + return this; + }, + /** * @private * @method _render