Implement View#autoUpdate to control automatic updates.

Closes #921
This commit is contained in:
Jürg Lehni 2016-01-27 13:10:04 +01:00
parent b56d18d6a4
commit e7c4e3c990
2 changed files with 27 additions and 3 deletions

View file

@ -93,7 +93,7 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
// (via view.requestUpdate()), which handles the smooth updates. // (via view.requestUpdate()), which handles the smooth updates.
this._needsUpdate = true; this._needsUpdate = true;
var view = this._view; var view = this._view;
if (view && !view._requested) if (view && !view._requested && view._autoUpdate)
view.requestUpdate(); view.requestUpdate();
} }
// Have project keep track of changed items so they can be iterated. // Have project keep track of changed items so they can be iterated.

View file

@ -107,6 +107,8 @@ var View = Base.extend(Emitter, /** @lends View# */{
// Count the installed native and virtual item events, // Count the installed native and virtual item events,
// see #_countItemEvent(): // see #_countItemEvent():
this._itemEvents = { native: {}, virtual: {} }; this._itemEvents = { native: {}, virtual: {} };
// Do not set _autoUpdate on Node.js by default:
this._autoUpdate = !paper.agent.node;
}, },
/** /**
@ -161,6 +163,26 @@ var View = Base.extend(Emitter, /** @lends View# */{
_time: 0, _time: 0,
_count: 0, _count: 0,
/**
* Controls whether the view is automatically updated in the next animation
* frame on changes, or whether you prefer to manually call
* {@link #update()} or {@link #requestUpdate()} after changes.
* Note that this is `true` by default, except for Node.js, where manual
* updates make more sense.
*
* @bean
* @type Boolean
*/
getAutoUpdate: function() {
return this._autoUpdate;
},
setAutoUpdate: function(autoUpdate) {
this._autoUpdate = autoUpdate;
if (autoUpdate)
this.requestUpdate();
},
/** /**
* Updates the view if there are changes. Note that when using built-in * Updates the view if there are changes. Note that when using built-in
* event hanlders for interaction, animation and load events, this method is * event hanlders for interaction, animation and load events, this method is
@ -205,7 +227,8 @@ var View = Base.extend(Emitter, /** @lends View# */{
} }
// Even if we're not animating, update the view now since this // Even if we're not animating, update the view now since this
// might have been a request for a single redraw after a change // might have been a request for a single redraw after a change
that.update(); if (that._autoUpdate)
that.update();
}, this._element); }, this._element);
this._requested = true; this._requested = true;
} }
@ -354,7 +377,8 @@ var View = Base.extend(Emitter, /** @lends View# */{
delta: delta delta: delta
}); });
this._changed(); this._changed();
this.requestUpdate(); if (this._autoUpdate)
this.requestUpdate();
}, },
/** /**