mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-08-28 22:08:54 -04:00
Rename View#draw() -> View#update() and remove checkRedraw argument.
We always check for changes, since change propagation should work reliably.
This commit is contained in:
parent
c75d48cf98
commit
6e5d8939d5
12 changed files with 46 additions and 39 deletions
|
@ -323,8 +323,8 @@ paper.PaperScope.prototype.PaperScript = (function(root) {
|
|||
});
|
||||
if (onFrame)
|
||||
view.setOnFrame(onFrame);
|
||||
// Automatically draw view at the end.
|
||||
view.draw();
|
||||
// Automatically update view at the end.
|
||||
view.update();
|
||||
}
|
||||
}).call(scope);
|
||||
}
|
||||
|
|
|
@ -231,7 +231,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
}
|
||||
if (project) {
|
||||
if (flags & /*#=*/ ChangeFlag.APPEARANCE) {
|
||||
project._needsRedraw = true;
|
||||
project._needsUpdate = true;
|
||||
}
|
||||
// Have project keep track of changed items so they can be iterated.
|
||||
// This can be used for example to update the SVG tree. Needs to be
|
||||
|
|
|
@ -88,7 +88,7 @@ var Layer = Group.extend(/** @lends Layer# */{
|
|||
Base.splice(this._project.layers, null, this._index, 1);
|
||||
// Tell project we need a redraw. This is similar to _changed()
|
||||
// mechanism.
|
||||
this._project._needsRedraw = true;
|
||||
this._project._needsUpdate = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -301,7 +301,7 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
that.setImage(image);
|
||||
that.fire('load');
|
||||
if (view)
|
||||
view.draw(true);
|
||||
view.update();
|
||||
}
|
||||
|
||||
/*#*/ if (__options.environment == 'browser') {
|
||||
|
|
|
@ -530,7 +530,7 @@ new function() {
|
|||
view = scope.project && scope.project.view;
|
||||
if (onLoad)
|
||||
onLoad.call(this, item);
|
||||
view.draw(true);
|
||||
view.update();
|
||||
}
|
||||
|
||||
if (isRoot) {
|
||||
|
|
|
@ -78,12 +78,12 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
|
|||
},
|
||||
|
||||
/**
|
||||
* Draws the view.
|
||||
* Updates the view if there are changes.
|
||||
*
|
||||
* @function
|
||||
*/
|
||||
draw: function(checkRedraw) {
|
||||
if (checkRedraw && !this._project._needsRedraw)
|
||||
update: function() {
|
||||
if (!this._project._needsUpdate)
|
||||
return false;
|
||||
// Initial tests conclude that clearing the canvas using clearRect
|
||||
// is always faster than setting canvas.width = canvas.width
|
||||
|
@ -92,7 +92,7 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
|
|||
size = this._viewSize;
|
||||
ctx.clearRect(0, 0, size.width + 1, size.height + 1);
|
||||
this._project.draw(ctx, this._matrix, this._ratio);
|
||||
this._project._needsRedraw = false;
|
||||
this._project._needsUpdate = false;
|
||||
return true;
|
||||
}
|
||||
}, new function() { // Item based mouse handling:
|
||||
|
|
|
@ -97,7 +97,7 @@ var Key = new function() {
|
|||
// Call the onKeyDown or onKeyUp handler if present
|
||||
tool.fire(type, new KeyEvent(down, key, character, event));
|
||||
if (view)
|
||||
view.draw(true);
|
||||
view.update();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -205,8 +205,8 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
if (this._stats)
|
||||
this._stats.update();
|
||||
this._handlingFrame = false;
|
||||
// Automatically draw view on each frame.
|
||||
this.draw(true);
|
||||
// Automatically update view on each frame.
|
||||
this.update();
|
||||
},
|
||||
|
||||
_animateItem: function(item, animate) {
|
||||
|
@ -241,8 +241,8 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
}
|
||||
},
|
||||
|
||||
_redraw: function() {
|
||||
this._project._needsRedraw = true;
|
||||
_update: function() {
|
||||
this._project._needsUpdate = true;
|
||||
if (this._handlingFrame)
|
||||
return;
|
||||
if (this._animate) {
|
||||
|
@ -250,8 +250,8 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
// requesting another animation frame.
|
||||
this._handleFrame();
|
||||
} else {
|
||||
// Otherwise simply redraw the view now
|
||||
this.draw();
|
||||
// Otherwise simply update the view now
|
||||
this.update();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -263,14 +263,14 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
*/
|
||||
_changed: function(flags) {
|
||||
if (flags & /*#=*/ ChangeFlag.APPEARANCE)
|
||||
this._project._needsRedraw = true;
|
||||
this._project._needsUpdate = true;
|
||||
},
|
||||
|
||||
_transform: function(matrix) {
|
||||
this._matrix.concatenate(matrix);
|
||||
// Force recalculation of these values next time they are requested.
|
||||
this._bounds = null;
|
||||
this._redraw();
|
||||
this._update();
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -308,7 +308,7 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
size: size,
|
||||
delta: delta
|
||||
});
|
||||
this._redraw();
|
||||
this._update();
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -397,15 +397,22 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
},
|
||||
|
||||
/**
|
||||
* Draws the view.
|
||||
* Updates the view if there are changes.
|
||||
*
|
||||
* @name View#draw
|
||||
* @name View#update
|
||||
* @function
|
||||
*/
|
||||
/*
|
||||
draw: function(checkRedraw) {
|
||||
// update: function(checkUpdate) {
|
||||
// },
|
||||
|
||||
/**
|
||||
* Updates the view if there are changes.
|
||||
*
|
||||
* @deprecated use {@link #update()} instead.
|
||||
*/
|
||||
draw: function() {
|
||||
this.update();
|
||||
},
|
||||
*/
|
||||
|
||||
// TODO: getInvalidBounds
|
||||
// TODO: invalidate(rect)
|
||||
|
@ -640,9 +647,9 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
view._handleEvent('mousedown', point, event);
|
||||
if (tool = view._scope._tool)
|
||||
tool._handleEvent('mousedown', point, event);
|
||||
// In the end we always call draw(), but pass checkRedraw = true, so we
|
||||
// only redraw the view if anything has changed in the above calls.
|
||||
view.draw(true);
|
||||
// In the end we always call update(), which only updates the view if
|
||||
// anything has changed in the above calls.
|
||||
view.update();
|
||||
}
|
||||
|
||||
function mousemove(event) {
|
||||
|
@ -673,7 +680,7 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
tool._handleEvent(dragging && tool.responds('mousedrag')
|
||||
? 'mousedrag' : 'mousemove', point, event);
|
||||
}
|
||||
view.draw(true);
|
||||
view.update();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -687,7 +694,7 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
view._handleEvent('mouseup', point, event);
|
||||
if (tool)
|
||||
tool._handleEvent('mouseup', point, event);
|
||||
view.draw(true);
|
||||
view.update();
|
||||
}
|
||||
|
||||
function selectstart(event) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue