Fix drawing of selected items in zoomed views.

This commit is contained in:
Jürg Lehni 2011-12-27 16:40:49 +01:00
parent 6e3cef6eb4
commit 2280c0cb94
2 changed files with 12 additions and 12 deletions

View file

@ -259,7 +259,7 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
draw: function(ctx, matrix) { draw: function(ctx, matrix) {
ctx.save(); ctx.save();
if (matrix) if (!matrix.isIdentity())
matrix.applyToContext(ctx); matrix.applyToContext(ctx);
var param = { offset: new Point(0, 0) }; var param = { offset: new Point(0, 0) };
for (var i = 0, l = this.layers.length; i < l; i++) for (var i = 0, l = this.layers.length; i < l; i++)
@ -277,37 +277,37 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
// concatenation of parent's matrices through caching. // concatenation of parent's matrices through caching.
var matrices = {}; var matrices = {};
// Descriptionf of the paramters to getGlobalMatrix(): // Descriptionf of the paramters to getGlobalMatrix():
// matrix is the container for the final concatenated matrix, passed // mx is the container for the final concatenated matrix, passed
// to getGlobalMatrix() on the initial call. // to getGlobalMatrix() on the initial call.
// cached defines wether the result of the concatenation should be // cached defines wether the result of the concatenation should be
// cached, only used for parents of items that this is called for. // cached, only used for parents of items that this is called for.
function getGlobalMatrix(item, matrix, cached) { function getGlobalMatrix(item, mx, cached) {
var cache = cached && matrices[item._id]; var cache = cached && matrices[item._id];
if (cache) { if (cache) {
// Found a cached version, copy over the values and return // Found a cached version, copy over the values and return
matrix.initialize(cache); mx.concatenate(cache);
return matrix; return mx;
} }
if (item._parent) { if (item._parent) {
// Get concatenated matrix from all the parents, using // Get concatenated matrix from all the parents, using
// local caching (passing true for cached): // local caching (passing true for cached):
getGlobalMatrix(item._parent, matrix, true); getGlobalMatrix(item._parent, mx, true);
// No need to concatenate if it's the identity matrix // No need to concatenate if it's the identity matrix
if (!item._matrix.isIdentity()) if (!item._matrix.isIdentity())
matrix.concatenate(item._matrix); mx.concatenate(item._matrix);
} else { } else {
// Simply copy over the item's matrix, since it's the root // Simply copy over the item's matrix, since it's the root
matrix.initialize(item._matrix); mx.initialize(item._matrix);
} }
// If the result needs to be cached, create a copy since matrix // If the result needs to be cached, create a copy since matrix
// might be further modified through recursive calls // might be further modified through recursive calls
if (cached) if (cached)
matrices[item._id] = matrix.clone(); matrices[item._id] = mx.clone();
return matrix; return mx;
} }
for (var id in this._selectedItems) { for (var id in this._selectedItems) {
var item = this._selectedItems[id]; var item = this._selectedItems[id];
item.drawSelected(ctx, getGlobalMatrix(item, new Matrix())); item.drawSelected(ctx, getGlobalMatrix(item, matrix.clone()));
} }
ctx.restore(); ctx.restore();
} }

View file

@ -56,7 +56,7 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
var ctx = this._context, var ctx = this._context,
size = this._viewSize; size = this._viewSize;
ctx.clearRect(0, 0, size._width + 1, size._height + 1); ctx.clearRect(0, 0, size._width + 1, size._height + 1);
this._project.draw(ctx, this._matrix.isIdentity() ? null : this._matrix); this._project.draw(ctx, this._matrix);
this._redrawNeeded = false; this._redrawNeeded = false;
return true; return true;
} }