Rename Item#transformContent to the more correct Item#applyMatrix

This commit is contained in:
Jürg Lehni 2014-03-02 16:04:17 +01:00
parent fb1420eee0
commit 80a725d08a
11 changed files with 47 additions and 36 deletions

View file

@ -29,7 +29,7 @@
path.smooth(); path.smooth();
layer.insertChild(0, new Group({ layer.insertChild(0, new Group({
children: [path], children: [path],
transformContent: false applyMatrix: false
})); }));
} }

View file

@ -42,7 +42,7 @@
this.item = new Group({ this.item = new Group({
children: [ball], children: [ball],
transformContent: false, applyMatrix: false,
position: this.point position: this.point
}); });
} }

View file

@ -11,11 +11,11 @@
var yesGroup = words.children.yes; var yesGroup = words.children.yes;
var noGroup = words.children.no; var noGroup = words.children.no;
// Imported SVG Groups have their transformContent flag turned off by // Imported SVG Groups have their applyMatrix flag turned off by
// default. This is required for SVG importing to work correctly. Turn // default. This is required for SVG importing to work correctly. Turn
// it on now, so we don't have to deal with nested coordinate spaces. // it on now, so we don't have to deal with nested coordinate spaces.
yesGroup.transformContent = true; yesGroup.applyMatrix = true;
noGroup.transformContent = true; noGroup.applyMatrix = true;
// Resize the words to fit snugly inside the view: // Resize the words to fit snugly inside the view:
project.activeLayer.fitBounds(view.bounds); project.activeLayer.fitBounds(view.bounds);

View file

@ -27,7 +27,7 @@
var group = new Group({ var group = new Group({
children: [leftPath, rightPath], children: [leftPath, rightPath],
transformContent: false, applyMatrix: false,
strokeWidth: 30, strokeWidth: 30,
strokeJoin: 'round', strokeJoin: 'round',
strokeCap: 'butt', strokeCap: 'butt',

View file

@ -53,8 +53,8 @@ var Item = Base.extend(Callback, /** @lends Item# */{
_class: 'Item', _class: 'Item',
// All items apply their matrix by default. // All items apply their matrix by default.
// Exceptions are Raster, PlacedSymbol, Clip and Shape. // Exceptions are Raster, PlacedSymbol, Clip and Shape.
_transformContent: true, _applyMatrix: true,
_canTransformContent: true, _canApplyMatrix: true,
_boundsSelected: false, _boundsSelected: false,
_selectChildren: false, _selectChildren: false,
// Provide information about fields to be serialized, with their defaults // Provide information about fields to be serialized, with their defaults
@ -70,7 +70,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
guide: false, guide: false,
selected: false, selected: false,
clipMask: false, clipMask: false,
transformContent: null, applyMatrix: null,
data: {} data: {}
}, },
@ -1134,7 +1134,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
setMatrix: function(matrix) { setMatrix: function(matrix) {
// Use Matrix#initialize to easily copy over values. // Use Matrix#initialize to easily copy over values.
this._matrix.initialize(matrix); this._matrix.initialize(matrix);
if (this._transformContent) { if (this._applyMatrix) {
// Directly apply the internal matrix. This will also call // Directly apply the internal matrix. This will also call
// _changed() for us. // _changed() for us.
this.transform(null, true); this.transform(null, true);
@ -1173,17 +1173,24 @@ var Item = Base.extend(Callback, /** @lends Item# */{
* @default true * @default true
* @bean * @bean
*/ */
getTransformContent: function() { getApplyMatrix: function() {
return this._transformContent; return this._applyMatrix;
}, },
setTransformContent: function(transform) { setApplyMatrix: function(transform) {
// Tell #transform() to apply the internal matrix if _transformContent // Tell #transform() to apply the internal matrix if _applyMatrix
// can be set to true. // can be set to true.
if (this._transformContent = this._canTransformContent && !!transform) if (this._applyMatrix = this._canApplyMatrix && !!transform)
this.transform(null, true); this.transform(null, true);
}, },
/**
* @bean
* @deprecated use {@link #getApplyMatrix()} instead.
*/
getTransformContent: '#getApplyMatrix',
setTransformContent: '#setApplyMatrix',
/** /**
* {@grouptitle Project Hierarchy} * {@grouptitle Project Hierarchy}
* The project that this item belongs to. * The project that this item belongs to.
@ -1492,7 +1499,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
// meaning the default value has been overwritten (default is on // meaning the default value has been overwritten (default is on
// prototype). // prototype).
var keys = ['_locked', '_visible', '_blendMode', '_opacity', var keys = ['_locked', '_visible', '_blendMode', '_opacity',
'_clipMask', '_guide', '_transformContent']; '_clipMask', '_guide', '_applyMatrix'];
for (var i = 0, l = keys.length; i < l; i++) { for (var i = 0, l = keys.length; i < l; i++) {
var key = keys[i]; var key = keys[i];
if (this.hasOwnProperty(key)) if (this.hasOwnProperty(key))
@ -1984,16 +1991,16 @@ var Item = Base.extend(Callback, /** @lends Item# */{
} }
} }
Base.splice(children, items, index, 0); Base.splice(children, items, index, 0);
var transformContent = this._transformContent; var applyMatrix = this._applyMatrix;
for (var i = 0, l = items.length; i < l; i++) { for (var i = 0, l = items.length; i < l; i++) {
var item = items[i]; var item = items[i];
item._parent = this; item._parent = this;
item._setProject(this._project, true); item._setProject(this._project, true);
// Only pass on the transformContent setting if it's different // Only pass on the applyMatrix setting if it's different
// and the child has not its onw setting already. // and the child has not its onw setting already.
if (item._transformContent ^ transformContent if (item._applyMatrix ^ applyMatrix
&& !item.hasOwnProperty('_transformContent')) && !item.hasOwnProperty('_applyMatrix'))
item.setTransformContent(transformContent); item.setApplyMatrix(applyMatrix);
// Setting the name again makes sure all name lookup structures // Setting the name again makes sure all name lookup structures
// are kept in sync. // are kept in sync.
if (item._name) if (item._name)
@ -2059,6 +2066,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
* the list of children and moving it above all other children. You can * the list of children and moving it above all other children. You can
* use this function for groups, compound paths and layers. * use this function for groups, compound paths and layers.
* *
* @function
* @param {Item} item The item to be appended as a child * @param {Item} item The item to be appended as a child
* @deprecated use {@link #addChild(item)} instead. * @deprecated use {@link #addChild(item)} instead.
*/ */
@ -2079,6 +2087,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
/** /**
* Moves this item above the specified item. * Moves this item above the specified item.
* *
* @function
* @param {Item} item The item above which it should be moved * @param {Item} item The item above which it should be moved
* @return {Boolean} {@true if it was moved} * @return {Boolean} {@true if it was moved}
* @deprecated use {@link #insertAbove(item)} instead. * @deprecated use {@link #insertAbove(item)} instead.
@ -2088,6 +2097,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
/** /**
* Moves the item below the specified item. * Moves the item below the specified item.
* *
* @function
* @param {Item} item the item below which it should be moved * @param {Item} item the item below which it should be moved
* @return {Boolean} {@true if it was moved} * @return {Boolean} {@true if it was moved}
* @deprecated use {@link #insertBelow(item)} instead. * @deprecated use {@link #insertBelow(item)} instead.
@ -2767,11 +2777,11 @@ var Item = Base.extend(Callback, /** @lends Item# */{
// 'lines'. Default: ['objects', 'children'] // 'lines'. Default: ['objects', 'children']
transform: function(matrix, _applyMatrix) { transform: function(matrix, _applyMatrix) {
// If no matrix is provided, or the matrix is the identity, we might // If no matrix is provided, or the matrix is the identity, we might
// still have some work to do in case _transformContent is true // still have some work to do in case _applyMatrix is true
if (matrix && matrix.isIdentity()) if (matrix && matrix.isIdentity())
matrix = null; matrix = null;
var _matrix = this._matrix, var _matrix = this._matrix,
applyMatrix = (_applyMatrix || this._transformContent) applyMatrix = (_applyMatrix || this._applyMatrix)
// Don't apply _matrix if the result of concatenating with // Don't apply _matrix if the result of concatenating with
// matrix would be identity. // matrix would be identity.
&& (!_matrix.isIdentity() || matrix); && (!_matrix.isIdentity() || matrix);
@ -2781,11 +2791,11 @@ var Item = Base.extend(Callback, /** @lends Item# */{
// Simply preconcatenate the internal matrix with the passed one: // Simply preconcatenate the internal matrix with the passed one:
if (matrix) if (matrix)
_matrix.preConcatenate(matrix); _matrix.preConcatenate(matrix);
// Call #_applyMatrix() now, if we need to directly apply the internal // Call #_transformContent() now, if we need to directly apply the
// _matrix transformations to the item's content. // internal _matrix transformations to the item's content.
// Application is not possible on Raster, PointText, PlacedSymbol, since // Application is not possible on Raster, PointText, PlacedSymbol, since
// the matrix is where the actual transformation state is stored. // the matrix is where the actual transformation state is stored.
if (applyMatrix = applyMatrix && this._applyMatrix(_matrix)) { if (applyMatrix = applyMatrix && this._transformContent(_matrix)) {
// When the _matrix could be applied, we also need to transform // When the _matrix could be applied, we also need to transform
// color styles (only gradients so far) and pivot point: // color styles (only gradients so far) and pivot point:
var pivot = this._pivot, var pivot = this._pivot,
@ -2841,7 +2851,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
return this; return this;
}, },
_applyMatrix: function(matrix) { _transformContent: function(matrix) {
var children = this._children; var children = this._children;
if (children) { if (children) {
for (var i = 0, l = children.length; i < l; i++) for (var i = 0, l = children.length; i < l; i++)

View file

@ -20,8 +20,8 @@
*/ */
var PlacedSymbol = Item.extend(/** @lends PlacedSymbol# */{ var PlacedSymbol = Item.extend(/** @lends PlacedSymbol# */{
_class: 'PlacedSymbol', _class: 'PlacedSymbol',
_transformContent: false, _applyMatrix: false,
_canTransformContent: false, _canApplyMatrix: false,
// PlacedSymbol uses strokeBounds for bounds // PlacedSymbol uses strokeBounds for bounds
_boundsGetter: { getBounds: 'getStrokeBounds' }, _boundsGetter: { getBounds: 'getStrokeBounds' },
_boundsSelected: true, _boundsSelected: true,

View file

@ -19,8 +19,8 @@
*/ */
var Raster = Item.extend(/** @lends Raster# */{ var Raster = Item.extend(/** @lends Raster# */{
_class: 'Raster', _class: 'Raster',
_transformContent: false, _applyMatrix: false,
_canTransformContent: false, _canApplyMatrix: false,
// Raster doesn't make the distinction between the different bounds, // Raster doesn't make the distinction between the different bounds,
// so use the same name for all of them // so use the same name for all of them
_boundsGetter: 'getBounds', _boundsGetter: 'getBounds',

View file

@ -19,8 +19,8 @@
*/ */
var Shape = Item.extend(/** @lends Shape# */{ var Shape = Item.extend(/** @lends Shape# */{
_class: 'Shape', _class: 'Shape',
_transformContent: false, _applyMatrix: false,
_canTransformContent: false, _canApplyMatrix: false,
_boundsSelected: true, _boundsSelected: true,
_serializeFields: { _serializeFields: {
shape: null, shape: null,

View file

@ -347,7 +347,7 @@ var Path = PathItem.extend(/** @lends Path# */{
return true; return true;
}, },
_applyMatrix: function(matrix) { _transformContent: function(matrix) {
var coords = new Array(6); var coords = new Array(6);
for (var i = 0, l = this._segments.length; i < l; i++) for (var i = 0, l = this._segments.length; i < l; i++)
this._segments[i]._transformCoordinates(matrix, coords, true); this._segments[i]._transformCoordinates(matrix, coords, true);

View file

@ -81,7 +81,7 @@ new function() {
if (!isClip) { if (!isClip) {
// Have the group not pass on all transformations to its children, // Have the group not pass on all transformations to its children,
// as this is how SVG works too. // as this is how SVG works too.
item._transformContent = false; item._applyMatrix = false;
item = applyAttributes(item, node, isRoot); item = applyAttributes(item, node, isRoot);
// Style on items needs to be handled differently than all other // Style on items needs to be handled differently than all other
// items: We first apply the style to the item, then use it as the // items: We first apply the style to the item, then use it as the

View file

@ -24,7 +24,8 @@
var TextItem = Item.extend(/** @lends TextItem# */{ var TextItem = Item.extend(/** @lends TextItem# */{
_class: 'TextItem', _class: 'TextItem',
_boundsSelected: true, _boundsSelected: true,
_transformContent: false, _applyMatrix: false,
_canApplyMatrix: false,
_serializeFields: { _serializeFields: {
content: null content: null
}, },