Have all visual changes include ChangeFlags.APPEARANCE.

This commit is contained in:
Jürg Lehni 2011-06-19 22:20:28 +01:00
parent bfe229ae14
commit f0bc3f115b
7 changed files with 40 additions and 24 deletions

View file

@ -15,10 +15,26 @@
*/
var ChangeFlags = {
GEOMETRY: 1, // Item geometry (path, bounds)
STROKE: 2, // Stroke geometry (excluding color)
STYLE: 4, // Fill style or stroke color / dash,
APPEARANCE: 8, // Visible item attributes: visible, blendMode, opacity ...
ATTRIBUTE: 16, // Any attributes, also inviislbe ones: locked, name, ...
HIERARCHY: 32 // Change in item hierarchy
// Anything affecting the appearance of an item, including GEOMETRY,
// STROKE, STYLE and ATTRIBUTE (except for the invisible ones: locked, name)
APPEARANCE: 1,
// Change in item hierarchy
HIERARCHY: 2,
// Item geometry (path, bounds)
GEOMETRY: 4,
// Stroke geometry (excluding color)
STROKE: 8,
// Fill style or stroke color / dash
STYLE: 16,
// Item attributes: visible, blendMode, locked, name, opacity, clipMask ...
ATTRIBUTE: 32
};
// Shortcuts to the ChangeFlags to send to #_changed(), all including appearance
var Change = {
HIERARCHY: ChangeFlags.HIERARCHY | ChangeFlags.APPEARANCE,
GEOMETRY: ChangeFlags.GEOMETRY | ChangeFlags.APPEARANCE,
STROKE: ChangeFlags.STROKE | ChangeFlags.APPEARANCE,
STYLE: ChangeFlags.STYLE | ChangeFlags.APPEARANCE,
ATTRIBUTE: ChangeFlags.ATTRIBUTE | ChangeFlags.APPEARANCE
};

View file

@ -75,7 +75,7 @@ var Group = this.Group = Item.extend({
},
_getClipMask: function() {
// TODO: Use caching once ChangeFlags.HIERARCHY is implemented
// TODO: Use caching once Change.HIERARCHY is implemented
for (var i = 0, l = this._children.length; i < l; i++) {
var child = this._children[i];
if (child._clipMask)

View file

@ -209,8 +209,8 @@ var Item = this.Item = Base.extend({
if (value != this[name]) {
this[name] = value;
// #locked does not change appearance, all others do:
this._changed(ChangeFlags.ATTRIBUTE
| (name !== '_locked' ? ChangeFlags.APPEARANCE : 0));
this._changed(name === '_locked'
? ChangeFlags.ATTRIBUTE : Change.ATTRIBUTE);
}
};
}, {});
@ -340,7 +340,7 @@ var Item = this.Item = Base.extend({
} else if ((selected = !!selected) != this._selected) {
this._selected = selected;
this._project._updateSelection(this);
this._changed(ChangeFlags.ATTRIBUTE | ChangeFlags.APPEARANCE);
this._changed(Change.ATTRIBUTE);
}
},
@ -367,7 +367,7 @@ var Item = this.Item = Base.extend({
this.setFillColor(null);
this.setStrokeColor(null);
}
this._changed(ChangeFlags.ATTRIBUTE | ChangeFlags.APPEARANCE);
this._changed(Change.ATTRIBUTE);
},
_clipMask: false,
@ -671,7 +671,7 @@ var Item = this.Item = Base.extend({
item._setProject(this._project);
if (item._name)
item.setName(item._name);
this._changed(ChangeFlags.HIERARCHY);
this._changed(Change.HIERARCHY);
return true;
}
return false;
@ -810,7 +810,7 @@ var Item = this.Item = Base.extend({
Base.splice(this._parent._children, null, this._index, 1);
// Notify parent of changed hierarchy
if (notify)
this._parent._changed(ChangeFlags.HIERARCHY);
this._parent._changed(Change.HIERARCHY);
this._parent = null;
return true;
}
@ -856,7 +856,7 @@ var Item = this.Item = Base.extend({
for (var i = removed.length - 1; i >= 0; i--)
removed[i]._remove(true, false);
if (removed.length > 0)
this._changed(ChangeFlags.HIERARCHY);
this._changed(Change.HIERARCHY);
return removed;
},
@ -869,7 +869,7 @@ var Item = this.Item = Base.extend({
// Adjust inidces
for (var i = 0, l = this._children.length; i < l; i++)
this._children[i]._index = i;
this._changed(ChangeFlags.HIERARCHY);
this._changed(Change.HIERARCHY);
}
},
@ -1435,7 +1435,7 @@ var Item = this.Item = Base.extend({
// and transform the cached _bounds and _position without
// recalculating each time.
this._transform(matrix, flags);
this._changed(ChangeFlags.GEOMETRY);
this._changed(Change.GEOMETRY);
}
// Transform position as well. Do not modify _position directly,
// since it's a LinkedPoint and would cause recursion!

View file

@ -58,7 +58,7 @@ var Layer = this.Layer = Group.extend({
if (deselect)
this.setSelected(false);
Base.splice(this._project.layers, null, this._index, 1);
this._project._changed(ChangeFlags.HIERARCHY);
this._project._changed(Change.HIERARCHY);
return true;
}
return false;

View file

@ -105,8 +105,8 @@ var PathStyle = this.PathStyle = Base.extend(new function() {
if (old != value && !(old && old.equals && old.equals(value))) {
this['_' + key] = value;
if (this._item) {
this._item._changed(ChangeFlags.STYLE
| (strokeFlags[key] ? ChangeFlags.STROKE : 0));
this._item._changed(Change.STYLE
| (strokeFlags[key] ? Change.STROKE : 0));
}
}
}

View file

@ -196,7 +196,7 @@ var Path = this.Path = PathItem.extend({
this._curves[i = length - 1] = Curve.create(this,
this._segments[i], this._segments[0]);
}
this._changed(ChangeFlags.GEOMETRY);
this._changed(Change.GEOMETRY);
}
},
@ -276,7 +276,7 @@ var Path = this.Path = PathItem.extend({
curve._segment1 = segments[index + amount];
}
}
this._changed(ChangeFlags.GEOMETRY);
this._changed(Change.GEOMETRY);
return segs;
},
@ -559,7 +559,7 @@ var Path = this.Path = PathItem.extend({
if (last && this._closed && (curve = curves[curves.length - 1]))
curve._segment2 = segments[0];
}
this._changed(ChangeFlags.GEOMETRY);
this._changed(Change.GEOMETRY);
return removed;
},
@ -885,7 +885,7 @@ var Path = this.Path = PathItem.extend({
last1.remove();
this.setClosed(true);
}
this._changed(ChangeFlags.GEOMETRY);
this._changed(Change.GEOMETRY);
return true;
}
return false;

View file

@ -102,7 +102,7 @@ var Segment = this.Segment = Base.extend({
other._changed();
}
}
this._path._changed(ChangeFlags.GEOMETRY);
this._path._changed(Change.GEOMETRY);
},
/**