Fix fabric.Line to update width/height when changing x1,y1,x2,y2 coordinates.

This commit is contained in:
kangax 2011-09-19 17:48:16 -04:00
parent b8036e848e
commit 475578276e
5 changed files with 34 additions and 6 deletions

View file

@ -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;

18
dist/all.js vendored
View file

@ -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

View file

@ -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 <kangax@gmail.com>",
"keywords": ["canvas", "graphic", "graphics", "SVG", "node-canvas", "parser", "HTML5", "object model"],
"repository": "git://github.com/kangax/fabric.js",

2
site

@ -1 +1 @@
Subproject commit fe08e6aa3b0737d958e800b5ac3872bff4172aa1
Subproject commit 968ea5040ec0d69e0e270de81b5bfefcada1a3a7

View file

@ -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