mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Only rely on _drawCount for drawing related things, and caching where it allows.
Project#selectedItems was out of sync until the next draw loop.
This commit is contained in:
parent
5db6db3b76
commit
0b7e128426
2 changed files with 16 additions and 18 deletions
|
@ -198,6 +198,8 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
var parent = this._parent,
|
||||
project = this._project,
|
||||
symbol = this._parentSymbol;
|
||||
// Reset _drawCount on each change.
|
||||
this._drawCount = null;
|
||||
if (flags & /*#=*/ ChangeFlag.GEOMETRY) {
|
||||
// Clear cached bounds and position whenever geometry changes
|
||||
delete this._bounds;
|
||||
|
@ -783,9 +785,8 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
* @bean
|
||||
*/
|
||||
getGlobalMatrix: function() {
|
||||
// TODO: This only works correctly if Item#draw() is in use. For other
|
||||
// possible future backends and items that aren't drawn, we need have to
|
||||
// implement another approach.
|
||||
// TODO: if drawCount is out of sync, we still need to walk up the chain
|
||||
// and concatenate the matrices.
|
||||
return this._drawCount === this._project._drawCount
|
||||
&& this._globalMatrix || null;
|
||||
},
|
||||
|
@ -3078,8 +3079,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
return;
|
||||
// Each time the project gets drawn, it's _drawCount is increased.
|
||||
// Keep the _drawCount of drawn items in sync, so we have an easy
|
||||
// way to filter out selected items that are not being drawn, e.g.
|
||||
// because they are currently not part of the DOM.
|
||||
// way to know for which selected items we need to draw selection info.
|
||||
this._drawCount = this._project._drawCount;
|
||||
// Keep calculating the current global matrix, by keeping a history
|
||||
// and pushing / popping as we go along.
|
||||
|
|
|
@ -168,7 +168,7 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
|
|||
var items = [];
|
||||
for (var id in this._selectedItems) {
|
||||
var item = this._selectedItems[id];
|
||||
if (item._drawCount === this._drawCount)
|
||||
if (item.isInserted())
|
||||
items.push(item);
|
||||
}
|
||||
return items;
|
||||
|
@ -184,19 +184,17 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
|
|||
*/
|
||||
|
||||
// TODO: Implement setSelectedItems?
|
||||
|
||||
_updateSelection: function(item) {
|
||||
var id = item._id,
|
||||
selectedItems = this._selectedItems;
|
||||
if (item._selected) {
|
||||
this._selectedItemCount++;
|
||||
this._selectedItems[item._id] = item;
|
||||
// Make sure the item is considered selected right away if it is
|
||||
// part of the DOM, even before it's getting drawn for the first
|
||||
// time.
|
||||
if (item.isInserted())
|
||||
item._drawCount = this._drawCount;
|
||||
} else {
|
||||
if (selectedItems[id] !== item) {
|
||||
this._selectedItemCount++;
|
||||
selectedItems[id] = item;
|
||||
}
|
||||
} else if (selectedItems[id] === item) {
|
||||
this._selectedItemCount--;
|
||||
delete this._selectedItems[item._id];
|
||||
delete selectedItems[id];
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -205,7 +203,7 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
|
|||
*/
|
||||
selectAll: function() {
|
||||
for (var i = 0, l = this.layers.length; i < l; i++)
|
||||
this.layers[i].setSelected(true);
|
||||
this.layers[i].setFullySelected(true);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -213,7 +211,7 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
|
|||
*/
|
||||
deselectAll: function() {
|
||||
for (var i in this._selectedItems)
|
||||
this._selectedItems[i].setSelected(false);
|
||||
this._selectedItems[i].setFullySelected(false);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue