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) {
ctx.save();
if (matrix)
if (!matrix.isIdentity())
matrix.applyToContext(ctx);
var param = { offset: new Point(0, 0) };
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.
var matrices = {};
// 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.
// cached defines wether the result of the concatenation should be
// 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];
if (cache) {
// Found a cached version, copy over the values and return
matrix.initialize(cache);
return matrix;
mx.concatenate(cache);
return mx;
}
if (item._parent) {
// Get concatenated matrix from all the parents, using
// 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
if (!item._matrix.isIdentity())
matrix.concatenate(item._matrix);
mx.concatenate(item._matrix);
} else {
// 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
// might be further modified through recursive calls
if (cached)
matrices[item._id] = matrix.clone();
return matrix;
matrices[item._id] = mx.clone();
return mx;
}
for (var id in this._selectedItems) {
var item = this._selectedItems[id];
item.drawSelected(ctx, getGlobalMatrix(item, new Matrix()));
item.drawSelected(ctx, getGlobalMatrix(item, matrix.clone()));
}
ctx.restore();
}

View file

@ -56,7 +56,7 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
var ctx = this._context,
size = this._viewSize;
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;
return true;
}