Skip to content

Commit

Permalink
- lockUniScaling now can't be overridden with shiftKey or uniScaleTra…
Browse files Browse the repository at this point in the history
…nsform property

- Pass event to object 'rotating'
- some refactoring
  • Loading branch information
Kienz committed Apr 20, 2013
1 parent 2c662d3 commit d03da23
Showing 1 changed file with 33 additions and 52 deletions.
85 changes: 33 additions & 52 deletions src/canvas_events.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@
var groupSelector = this._groupSelector;

// We initially clicked in an empty area, so we draw a box for multiple selection.
if (groupSelector !== null) {
if (groupSelector) {
pointer = getPointer(e, this.upperCanvasEl);

groupSelector.left = pointer.x - this._offset.left - groupSelector.ex;
Expand Down Expand Up @@ -322,85 +322,66 @@
pointer = getPointer(e, this.upperCanvasEl);

var x = pointer.x,
y = pointer.y;

this._currentTransform.target.isMoving = true;

var t = this._currentTransform, reset = false;
if (
(t.action === 'scale' || t.action === 'scaleX' || t.action === 'scaleY')
&&
(
// Switch from a normal resize to center-based
(e.altKey && (t.originX !== 'center' || t.originY !== 'center'))
||
// Switch from center-based resize to normal one
(!e.altKey && t.originX === 'center' && t.originY === 'center')
)
) {
y = pointer.y,
reset = false,
transform = this._currentTransform;

target = transform.target;
target.isMoving = true;

if ((transform.action === 'scale' || transform.action === 'scaleX' || transform.action === 'scaleY') &&
// Switch from a normal resize to center-based
((e.altKey && (transform.originX !== 'center' || transform.originY !== 'center')) ||
// Switch from center-based resize to normal one
(!e.altKey && transform.originX === 'center' && transform.originY === 'center'))
) {
this._resetCurrentTransform(e);
reset = true;
}

if (this._currentTransform.action === 'rotate') {
if (transform.action === 'rotate') {
this._rotateObject(x, y);

this.fire('object:rotating', {
target: this._currentTransform.target,
e: e
});
this._currentTransform.target.fire('rotating');
this.fire('object:rotating', { target: target, e: e });
target.fire('rotating', { e: e });
}
else if (this._currentTransform.action === 'scale') {
else if (transform.action === 'scale') {
// rotate object only if shift key is not pressed
// and if it is not a group we are transforming

if (e.shiftKey || this.uniScaleTransform) {
this._currentTransform.currentAction = 'scale';
if ((e.shiftKey || this.uniScaleTransform) && !target.get('lockUniScaling')) {
transform.currentAction = 'scale';
this._scaleObject(x, y);
}
else {
if (!reset && t.currentAction === 'scale') {
// Switch from a normal resize to proportional
// Switch from a normal resize to proportional
if (!reset && transform.currentAction === 'scale') {
this._resetCurrentTransform(e);
}

this._currentTransform.currentAction = 'scaleEqually';
transform.currentAction = 'scaleEqually';
this._scaleObject(x, y, 'equally');
}

this.fire('object:scaling', {
target: this._currentTransform.target,
e: e
});
this._currentTransform.target.fire('scaling', { e: e });
this.fire('object:scaling', { target: target, e: e });
target.fire('scaling', { e: e });
}
else if (this._currentTransform.action === 'scaleX') {
else if (transform.action === 'scaleX') {
this._scaleObject(x, y, 'x');

this.fire('object:scaling', {
target: this._currentTransform.target,
e: e
});
this._currentTransform.target.fire('scaling', { e: e });
this.fire('object:scaling', { target: target, e: e});
target.fire('scaling', { e: e });
}
else if (this._currentTransform.action === 'scaleY') {
else if (transform.action === 'scaleY') {
this._scaleObject(x, y, 'y');

this.fire('object:scaling', {
target: this._currentTransform.target,
e: e
});
this._currentTransform.target.fire('scaling', { e: e });
this.fire('object:scaling', { target: target, e: e});
target.fire('scaling', { e: e });
}
else {
this._translateObject(x, y);

this.fire('object:moving', {
target: this._currentTransform.target,
e: e
});
this._currentTransform.target.fire('moving', { e: e });
this.fire('object:moving', { target: target, e: e});
target.fire('moving', { e: e });
this._setCursor(this.moveCursor);
}

Expand Down

0 comments on commit d03da23

Please sign in to comment.