Return correct values for #rotation and #scaling on items with #applyMatrix = true

While preserving caching for #applyMatrix = false

Relates to #1004, #1177
This commit is contained in:
Jürg Lehni 2017-01-03 13:39:35 +01:00
parent aa75374406
commit 4d81a292a2

View file

@ -1065,16 +1065,16 @@ new function() { // Injection scope for various item event handlers
/** /**
* The current rotation angle of the item, as described by its * The current rotation angle of the item, as described by its
* {@link #matrix}. * {@link #matrix}.
* Please note that this only works for items with {@link #applyMatrix} set * Please note that this only returns meaningful values for items with
* to `false`, meaning they do not directly bake transformations into their * {@link #applyMatrix} set to `false`, meaning they do not directly bake
* content. * transformations into their content.
* *
* @bean * @bean
* @type Number * @type Number
*/ */
getRotation: function() { getRotation: function() {
var decomposed = this._decompose(); var decomposed = this._decompose();
return decomposed && decomposed.rotation; return decomposed ? decomposed.rotation : 0;
}, },
setRotation: function(rotation) { setRotation: function(rotation) {
@ -1084,27 +1084,27 @@ new function() { // Injection scope for various item event handlers
// update the rotation property on it. // update the rotation property on it.
var decomposed = this._decomposed; var decomposed = this._decomposed;
this.rotate(rotation - current); this.rotate(rotation - current);
decomposed.rotation = rotation; if (decomposed) {
this._decomposed = decomposed; decomposed.rotation = rotation;
this._decomposed = decomposed;
}
} }
}, },
/** /**
* The current scale factor of the item, as described by its * The current scale factor of the item, as described by its
* {@link #matrix}. * {@link #matrix}.
* Please note that this only works for items with {@link #applyMatrix} set * Please note that this only returns meaningful values for items with
* to `false`, meaning they do not directly bake transformations into their * {@link #applyMatrix} set to `false`, meaning they do not directly bake
* content. * transformations into their content.
* *
* @bean * @bean
* @type Point * @type Point
*/ */
getScaling: function() { getScaling: function() {
var decomposed = this._decompose(), var decomposed = this._decompose(),
scaling = decomposed && decomposed.scaling; s = decomposed && decomposed.scaling;
return scaling return new LinkedPoint(s ? s.x : 1, s ? s.y : 1, this, 'setScaling');
? new LinkedPoint(scaling.x, scaling.y, this, 'setScaling')
: undefined;
}, },
setScaling: function(/* scaling */) { setScaling: function(/* scaling */) {
@ -1115,8 +1115,10 @@ new function() { // Injection scope for various item event handlers
// See #setRotation() for preservation of _decomposed. // See #setRotation() for preservation of _decomposed.
var decomposed = this._decomposed; var decomposed = this._decomposed;
this.scale(scaling.x / current.x, scaling.y / current.y); this.scale(scaling.x / current.x, scaling.y / current.y);
decomposed.scaling = scaling; if (decomposed) {
this._decomposed = decomposed; decomposed.scaling = scaling;
this._decomposed = decomposed;
}
} }
}, },