mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Implement setters for Matrix#translation, #rotation and #scaling.
Propagating the changes down to the owning Item too.
This commit is contained in:
parent
b96f9ff57b
commit
f3832e0780
1 changed files with 22 additions and 0 deletions
|
@ -605,6 +605,13 @@ var Matrix = Base.extend(/** @lends Matrix# */{
|
|||
return new Point(this._tx, this._ty);
|
||||
},
|
||||
|
||||
setTranslation: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
this._tx = point.x;
|
||||
this._ty = point.y;
|
||||
this._changed();
|
||||
},
|
||||
|
||||
/**
|
||||
* The scaling values of the matrix, if it can be decomposed.
|
||||
*
|
||||
|
@ -616,6 +623,15 @@ var Matrix = Base.extend(/** @lends Matrix# */{
|
|||
return (this.decompose() || {}).scaling;
|
||||
},
|
||||
|
||||
setScaling: function(/* scale */) {
|
||||
var scaling = this.getScaling();
|
||||
if (scaling != null) {
|
||||
var scale = Point.read(arguments);
|
||||
(this._owner || this).scale(
|
||||
scale.x / scaling.x, scale.y / scaling.y);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* The rotation angle of the matrix, if it can be decomposed.
|
||||
*
|
||||
|
@ -627,6 +643,12 @@ var Matrix = Base.extend(/** @lends Matrix# */{
|
|||
return (this.decompose() || {}).rotation;
|
||||
},
|
||||
|
||||
setRotation: function(angle) {
|
||||
var rotation = this.getRotation();
|
||||
if (rotation != null)
|
||||
(this._owner || this).rotate(angle - rotation);
|
||||
},
|
||||
|
||||
/**
|
||||
* Inverts the transformation of the matrix. If the matrix is not invertible
|
||||
* (in which case {@link #isSingular()} returns true), {@code null } is
|
||||
|
|
Loading…
Reference in a new issue