transformation notUndoable => undoable
The `undoable` transformation property is not preserved when the element is "stringified". So transformations cannot be undone, once the element is loaded from JSON.
This commit is contained in:
parent
ccf928c048
commit
236e4db236
27
area.js
27
area.js
|
|
@ -537,20 +537,17 @@ var DrawingArea = new Lang.Class({
|
||||||
this.grabbedElement = copy;
|
this.grabbedElement = copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let undoable = !duplicate;
|
||||||
|
|
||||||
if (this.currentTool == Manipulations.MOVE)
|
if (this.currentTool == Manipulations.MOVE)
|
||||||
this.grabbedElement.startTransformation(startX, startY, controlPressed ? Transformations.ROTATION : Transformations.TRANSLATION);
|
this.grabbedElement.startTransformation(startX, startY, controlPressed ? Transformations.ROTATION : Transformations.TRANSLATION, undoable);
|
||||||
else if (this.currentTool == Manipulations.RESIZE)
|
else if (this.currentTool == Manipulations.RESIZE)
|
||||||
this.grabbedElement.startTransformation(startX, startY, controlPressed ? Transformations.STRETCH : Transformations.SCALE_PRESERVE);
|
this.grabbedElement.startTransformation(startX, startY, controlPressed ? Transformations.STRETCH : Transformations.SCALE_PRESERVE, undoable);
|
||||||
else if (this.currentTool == Manipulations.MIRROR) {
|
else if (this.currentTool == Manipulations.MIRROR) {
|
||||||
this.grabbedElement.startTransformation(startX, startY, controlPressed ? Transformations.INVERSION : Transformations.REFLECTION);
|
this.grabbedElement.startTransformation(startX, startY, controlPressed ? Transformations.INVERSION : Transformations.REFLECTION, undoable);
|
||||||
this._redisplay();
|
this._redisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (duplicate)
|
|
||||||
// For undo, ignore both the transformations inherited from the duplicated element
|
|
||||||
// and the current transformation.
|
|
||||||
this.grabbedElement.makeAllTransformationsNotUndoable();
|
|
||||||
|
|
||||||
this.motionHandler = this.connect('motion-event', (actor, event) => {
|
this.motionHandler = this.connect('motion-event', (actor, event) => {
|
||||||
if (this.spaceKeyPressed)
|
if (this.spaceKeyPressed)
|
||||||
return;
|
return;
|
||||||
|
|
@ -565,28 +562,30 @@ var DrawingArea = new Lang.Class({
|
||||||
},
|
},
|
||||||
|
|
||||||
_updateTransforming: function(x, y, controlPressed) {
|
_updateTransforming: function(x, y, controlPressed) {
|
||||||
|
let undoable = this.grabbedElement.lastTransformation.undoable || false;
|
||||||
|
|
||||||
if (controlPressed && this.grabbedElement.lastTransformation.type == Transformations.TRANSLATION) {
|
if (controlPressed && this.grabbedElement.lastTransformation.type == Transformations.TRANSLATION) {
|
||||||
this.grabbedElement.stopTransformation();
|
this.grabbedElement.stopTransformation();
|
||||||
this.grabbedElement.startTransformation(x, y, Transformations.ROTATION);
|
this.grabbedElement.startTransformation(x, y, Transformations.ROTATION, undoable);
|
||||||
} else if (!controlPressed && this.grabbedElement.lastTransformation.type == Transformations.ROTATION) {
|
} else if (!controlPressed && this.grabbedElement.lastTransformation.type == Transformations.ROTATION) {
|
||||||
this.grabbedElement.stopTransformation();
|
this.grabbedElement.stopTransformation();
|
||||||
this.grabbedElement.startTransformation(x, y, Transformations.TRANSLATION);
|
this.grabbedElement.startTransformation(x, y, Transformations.TRANSLATION, undoable);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controlPressed && this.grabbedElement.lastTransformation.type == Transformations.SCALE_PRESERVE) {
|
if (controlPressed && this.grabbedElement.lastTransformation.type == Transformations.SCALE_PRESERVE) {
|
||||||
this.grabbedElement.stopTransformation();
|
this.grabbedElement.stopTransformation();
|
||||||
this.grabbedElement.startTransformation(x, y, Transformations.STRETCH);
|
this.grabbedElement.startTransformation(x, y, Transformations.STRETCH, undoable);
|
||||||
} else if (!controlPressed && this.grabbedElement.lastTransformation.type == Transformations.STRETCH) {
|
} else if (!controlPressed && this.grabbedElement.lastTransformation.type == Transformations.STRETCH) {
|
||||||
this.grabbedElement.stopTransformation();
|
this.grabbedElement.stopTransformation();
|
||||||
this.grabbedElement.startTransformation(x, y, Transformations.SCALE_PRESERVE);
|
this.grabbedElement.startTransformation(x, y, Transformations.SCALE_PRESERVE, undoable);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controlPressed && this.grabbedElement.lastTransformation.type == Transformations.REFLECTION) {
|
if (controlPressed && this.grabbedElement.lastTransformation.type == Transformations.REFLECTION) {
|
||||||
this.grabbedElement.transformations.pop();
|
this.grabbedElement.transformations.pop();
|
||||||
this.grabbedElement.startTransformation(x, y, Transformations.INVERSION);
|
this.grabbedElement.startTransformation(x, y, Transformations.INVERSION, undoable);
|
||||||
} else if (!controlPressed && this.grabbedElement.lastTransformation.type == Transformations.INVERSION) {
|
} else if (!controlPressed && this.grabbedElement.lastTransformation.type == Transformations.INVERSION) {
|
||||||
this.grabbedElement.transformations.pop();
|
this.grabbedElement.transformations.pop();
|
||||||
this.grabbedElement.startTransformation(x, y, Transformations.REFLECTION);
|
this.grabbedElement.startTransformation(x, y, Transformations.REFLECTION, undoable);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.grabbedElement.updateTransformation(x, y);
|
this.grabbedElement.updateTransformation(x, y);
|
||||||
|
|
|
||||||
27
elements.js
27
elements.js
|
|
@ -123,7 +123,8 @@ const _DrawingElement = new Lang.Class({
|
||||||
fill: this.fill,
|
fill: this.fill,
|
||||||
fillRule: this.fillRule,
|
fillRule: this.fillRule,
|
||||||
eraser: this.eraser,
|
eraser: this.eraser,
|
||||||
transformations: this.transformations.filter(transformation => transformation.type != Transformations.SMOOTH),
|
transformations: this.transformations.filter(transformation => transformation.type != Transformations.SMOOTH)
|
||||||
|
.map(transformation => Object.assign({}, transformation, { undoable: undefined })),
|
||||||
points: this.points.map((point) => [Math.round(point[0]*100)/100, Math.round(point[1]*100)/100])
|
points: this.points.map((point) => [Math.round(point[0]*100)/100, Math.round(point[1]*100)/100])
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
@ -409,7 +410,7 @@ const _DrawingElement = new Lang.Class({
|
||||||
|
|
||||||
let newPoints = this.points.slice();
|
let newPoints = this.points.slice();
|
||||||
|
|
||||||
this.transformations.push({ type: Transformations.SMOOTH,
|
this.transformations.push({ type: Transformations.SMOOTH, undoable: true,
|
||||||
undo: () => this.points = oldPoints,
|
undo: () => this.points = oldPoints,
|
||||||
redo: () => this.points = newPoints });
|
redo: () => this.points = newPoints });
|
||||||
},
|
},
|
||||||
|
|
@ -465,7 +466,7 @@ const _DrawingElement = new Lang.Class({
|
||||||
return;
|
return;
|
||||||
|
|
||||||
let center = this._getOriginalCenter();
|
let center = this._getOriginalCenter();
|
||||||
this.transformations[0] = { type: Transformations.ROTATION, notUndoable: true,
|
this.transformations[0] = { type: Transformations.ROTATION,
|
||||||
angle: getAngle(center[0], center[1], points[points.length - 1][0], points[points.length - 1][1], x, y) };
|
angle: getAngle(center[0], center[1], points[points.length - 1][0], points[points.length - 1][1], x, y) };
|
||||||
|
|
||||||
} else if (this.shape == Shapes.ELLIPSE && transform) {
|
} else if (this.shape == Shapes.ELLIPSE && transform) {
|
||||||
|
|
@ -474,7 +475,7 @@ const _DrawingElement = new Lang.Class({
|
||||||
|
|
||||||
points[2] = [x, y];
|
points[2] = [x, y];
|
||||||
let center = this._getOriginalCenter();
|
let center = this._getOriginalCenter();
|
||||||
this.transformations[0] = { type: Transformations.ROTATION, notUndoable: true,
|
this.transformations[0] = { type: Transformations.ROTATION,
|
||||||
angle: getAngle(center[0], center[1], center[0] + 1, center[1], x, y) };
|
angle: getAngle(center[0], center[1], center[0] + 1, center[1], x, y) };
|
||||||
|
|
||||||
} else if (this.shape == Shapes.POLYGON || this.shape == Shapes.POLYLINE) {
|
} else if (this.shape == Shapes.POLYGON || this.shape == Shapes.POLYLINE) {
|
||||||
|
|
@ -500,18 +501,18 @@ const _DrawingElement = new Lang.Class({
|
||||||
this.transformations.shift();
|
this.transformations.shift();
|
||||||
},
|
},
|
||||||
|
|
||||||
startTransformation: function(startX, startY, type) {
|
startTransformation: function(startX, startY, type, undoable) {
|
||||||
if (type == Transformations.TRANSLATION)
|
if (type == Transformations.TRANSLATION)
|
||||||
this.transformations.push({ startX: startX, startY: startY, type: type, slideX: 0, slideY: 0 });
|
this.transformations.push({ startX, startY, type, undoable, slideX: 0, slideY: 0 });
|
||||||
else if (type == Transformations.ROTATION)
|
else if (type == Transformations.ROTATION)
|
||||||
this.transformations.push({ startX: startX, startY: startY, type: type, angle: 0 });
|
this.transformations.push({ startX, startY, type, undoable, angle: 0 });
|
||||||
else if (type == Transformations.SCALE_PRESERVE || type == Transformations.STRETCH)
|
else if (type == Transformations.SCALE_PRESERVE || type == Transformations.STRETCH)
|
||||||
this.transformations.push({ startX: startX, startY: startY, type: type, scaleX: 1, scaleY: 1, angle: 0 });
|
this.transformations.push({ startX, startY, type, undoable, scaleX: 1, scaleY: 1, angle: 0 });
|
||||||
else if (type == Transformations.REFLECTION)
|
else if (type == Transformations.REFLECTION)
|
||||||
this.transformations.push({ startX: startX, startY: startY, endX: startX, endY: startY, type: type,
|
this.transformations.push({ startX, startY, endX: startX, endY: startY, type, undoable,
|
||||||
scaleX: 1, scaleY: 1, slideX: 0, slideY: 0, angle: 0 });
|
scaleX: 1, scaleY: 1, slideX: 0, slideY: 0, angle: 0 });
|
||||||
else if (type == Transformations.INVERSION)
|
else if (type == Transformations.INVERSION)
|
||||||
this.transformations.push({ startX: startX, startY: startY, endX: startX, endY: startY, type: type,
|
this.transformations.push({ startX, startY, endX: startX, endY: startY, type, undoable,
|
||||||
scaleX: -1, scaleY: -1, slideX: startX, slideY: startY,
|
scaleX: -1, scaleY: -1, slideX: startX, slideY: startY,
|
||||||
angle: Math.PI + Math.atan(startY / (startX || 1)) });
|
angle: Math.PI + Math.atan(startY / (startX || 1)) });
|
||||||
|
|
||||||
|
|
@ -596,7 +597,7 @@ const _DrawingElement = new Lang.Class({
|
||||||
undoTransformation: function() {
|
undoTransformation: function() {
|
||||||
if (this.transformations && this.transformations.length) {
|
if (this.transformations && this.transformations.length) {
|
||||||
// Do not undo initial transformations (transformations made during the drawing step).
|
// Do not undo initial transformations (transformations made during the drawing step).
|
||||||
if (this.lastTransformation.notUndoable)
|
if (!this.lastTransformation.undoable)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!this._undoneTransformations)
|
if (!this._undoneTransformations)
|
||||||
|
|
@ -635,10 +636,6 @@ const _DrawingElement = new Lang.Class({
|
||||||
delete this._undoneTransformations;
|
delete this._undoneTransformations;
|
||||||
},
|
},
|
||||||
|
|
||||||
makeAllTransformationsNotUndoable: function() {
|
|
||||||
this.transformations.forEach(transformation => transformation.notUndoable = true);
|
|
||||||
},
|
|
||||||
|
|
||||||
// The figure rotation center before transformations (original).
|
// The figure rotation center before transformations (original).
|
||||||
// this.textWidth is computed during Cairo building.
|
// this.textWidth is computed during Cairo building.
|
||||||
_getOriginalCenter: function() {
|
_getOriginalCenter: function() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue