mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Do not factor in view matrix into Item#globalMatrix.
Instead concatenate it when drawing selections.
This commit is contained in:
parent
48c8946f9e
commit
7c28c7e9e3
3 changed files with 10 additions and 9 deletions
|
@ -1106,7 +1106,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
if (!matrix) {
|
if (!matrix) {
|
||||||
matrix = this._globalMatrix = this._matrix.clone();
|
matrix = this._globalMatrix = this._matrix.clone();
|
||||||
if (this._parent)
|
if (this._parent)
|
||||||
matrix.concatenate(this._parent.getGlobalMatrix());
|
matrix.preConcatenate(this._parent.getGlobalMatrix());
|
||||||
matrix._updateVersion = updateVersion;
|
matrix._updateVersion = updateVersion;
|
||||||
}
|
}
|
||||||
return matrix;
|
return matrix;
|
||||||
|
@ -3391,9 +3391,11 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
// Keep calculating the current global matrix, by keeping a history
|
// Keep calculating the current global matrix, by keeping a history
|
||||||
// and pushing / popping as we go along.
|
// and pushing / popping as we go along.
|
||||||
var trackTransforms = param.trackTransforms,
|
var trackTransforms = param.trackTransforms,
|
||||||
transforms = param.transforms,
|
// If transforms does not exist, set it up with the identity matrix
|
||||||
|
transforms = param.transforms = param.transforms || [new Matrix()],
|
||||||
|
matrix = this._matrix,
|
||||||
parentMatrix = transforms[transforms.length - 1],
|
parentMatrix = transforms[transforms.length - 1],
|
||||||
globalMatrix = parentMatrix.clone().concatenate(this._matrix);
|
globalMatrix = parentMatrix.clone().concatenate(matrix);
|
||||||
// If this item is not invertible, do not draw it, since it would cause
|
// If this item is not invertible, do not draw it, since it would cause
|
||||||
// empty ctx.currentPath and mess up caching. It appears to also be a
|
// empty ctx.currentPath and mess up caching. It appears to also be a
|
||||||
// good idea generally to not draw in such cirucmstances, e.g. SVG
|
// good idea generally to not draw in such cirucmstances, e.g. SVG
|
||||||
|
@ -3402,6 +3404,8 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
return;
|
return;
|
||||||
// Only keep track of transformation if told so. See Project#draw()
|
// Only keep track of transformation if told so. See Project#draw()
|
||||||
if (trackTransforms) {
|
if (trackTransforms) {
|
||||||
|
if (!transforms)
|
||||||
|
transforms = param.transforms = [];
|
||||||
transforms.push(this._globalMatrix = globalMatrix);
|
transforms.push(this._globalMatrix = globalMatrix);
|
||||||
// We also keep the cached _globalMatrix versioned.
|
// We also keep the cached _globalMatrix versioned.
|
||||||
globalMatrix._updateVersion = updateVersion;
|
globalMatrix._updateVersion = updateVersion;
|
||||||
|
@ -3457,7 +3461,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
ctx.translate(-itemOffset.x, -itemOffset.y);
|
ctx.translate(-itemOffset.x, -itemOffset.y);
|
||||||
}
|
}
|
||||||
// Apply globalMatrix when drawing into temporary canvas.
|
// Apply globalMatrix when drawing into temporary canvas.
|
||||||
(direct ? this._matrix : globalMatrix).applyToContext(ctx);
|
(direct ? matrix : globalMatrix).applyToContext(ctx);
|
||||||
// If we're drawing into a separate canvas and a clipItem is defined for
|
// If we're drawing into a separate canvas and a clipItem is defined for
|
||||||
// the current rendering loop, we need to draw the clip item again.
|
// the current rendering loop, we need to draw the clip item again.
|
||||||
if (!direct && param.clipItem)
|
if (!direct && param.clipItem)
|
||||||
|
|
|
@ -196,7 +196,7 @@ var PathItem = Item.extend(/** @lends PathItem# */{
|
||||||
// To compare with native canvas approach:
|
// To compare with native canvas approach:
|
||||||
var ctx = CanvasProvider.getContext(1, 1);
|
var ctx = CanvasProvider.getContext(1, 1);
|
||||||
// Abuse clip = true to get a shape for ctx.isPointInPath().
|
// Abuse clip = true to get a shape for ctx.isPointInPath().
|
||||||
this._draw(ctx, new Base({ clip: true, transforms: [new Matrix()] }));
|
this._draw(ctx, new Base({ clip: true }));
|
||||||
var res = ctx.isPointInPath(point.x, point.y, this.getWindingRule());
|
var res = ctx.isPointInPath(point.x, point.y, this.getWindingRule());
|
||||||
CanvasProvider.release(ctx);
|
CanvasProvider.release(ctx);
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -431,9 +431,6 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
|
||||||
var param = new Base({
|
var param = new Base({
|
||||||
offset: new Point(0, 0),
|
offset: new Point(0, 0),
|
||||||
ratio: ratio,
|
ratio: ratio,
|
||||||
// A stack of concatenated matrices, to keep track of the current
|
|
||||||
// global matrix, since Canvas is not able tell us (yet).
|
|
||||||
transforms: [matrix],
|
|
||||||
// Tell the drawing routine that we want to track nested matrices
|
// Tell the drawing routine that we want to track nested matrices
|
||||||
// in param.transforms, and that we want it to set _globalMatrix
|
// in param.transforms, and that we want it to set _globalMatrix
|
||||||
// as used below. Item#rasterize() and Raster#getAverageColor() do
|
// as used below. Item#rasterize() and Raster#getAverageColor() do
|
||||||
|
@ -458,7 +455,7 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
|
||||||
|| item.getLayer().getSelectedColor();
|
|| item.getLayer().getSelectedColor();
|
||||||
ctx.strokeStyle = ctx.fillStyle = color
|
ctx.strokeStyle = ctx.fillStyle = color
|
||||||
? color.toCanvasStyle(ctx) : '#009dec';
|
? color.toCanvasStyle(ctx) : '#009dec';
|
||||||
var mx = item._globalMatrix;
|
var mx = item._globalMatrix.clone().preConcatenate(matrix);
|
||||||
if (item._drawSelected)
|
if (item._drawSelected)
|
||||||
item._drawSelected(ctx, mx);
|
item._drawSelected(ctx, mx);
|
||||||
if (item._boundsSelected) {
|
if (item._boundsSelected) {
|
||||||
|
|
Loading…
Reference in a new issue