Skip to content

Commit

Permalink
make Modifier keys customizable (#2925)
Browse files Browse the repository at this point in the history
Make the keys used for modifying transformations and multiselect customizable within shiftKey, altKey and ctrlKey
  • Loading branch information
asturur committed May 2, 2016
1 parent 6fd1f8a commit fab0c05
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
44 changes: 40 additions & 4 deletions src/canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@
*/
uniScaleTransform: false,

/**
* Indicates which key enable unproportional scaling
* values: altKey, shiftKey, ctrlKey
* @since 1.6.2
* @type String
* @default
*/
uniScaleKey: 'shiftKey',

/**
* When true, objects use center point as the origin of scale transformation.
* <b>Backwards incompatibility note:</b> This property replaces "centerTransform" (Boolean).
Expand All @@ -74,6 +83,24 @@
*/
centeredRotation: false,

/**
* Indicates which key enable centered Transfrom
* values: altKey, shiftKey, ctrlKey
* @since 1.6.2
* @type String
* @default
*/
centeredKey: 'altKey',

/**
* Indicates which key enable alternate action on corner
* values: altKey, shiftKey, ctrlKey
* @since 1.6.2
* @type String
* @default
*/
altActionKey: 'shiftKey',

/**
* Indicates that canvas is interactive. This property should not be changed.
* @type Boolean
Expand All @@ -88,6 +115,15 @@
*/
selection: true,

/**
* Indicates which key enable multiple click selection
* values: altKey, shiftKey, ctrlKey
* @since 1.6.2
* @type String
* @default
*/
selectionKey: 'shiftKey',

/**
* Color of selection
* @type String
Expand Down Expand Up @@ -345,7 +381,7 @@
activeGroup &&
!activeGroup.contains(target) &&
activeGroup !== target &&
!e.shiftKey)
!e[this.selectionKey])
||
(target && !target.evented)
||
Expand Down Expand Up @@ -417,10 +453,10 @@
return 'rotate';
case 'ml':
case 'mr':
return e.shiftKey ? 'skewY' : 'scaleX';
return e[this.altActionKey] ? 'skewY' : 'scaleX';
case 'mt':
case 'mb':
return e.shiftKey ? 'skewX' : 'scaleY';
return e[this.altActionKey] ? 'skewX' : 'scaleY';
default:
return 'scale';
}
Expand Down Expand Up @@ -464,7 +500,7 @@
mouseXSign: 1,
mouseYSign: 1,
shiftKey: e.shiftKey,
altKey: e.altKey
altKey: e[this.centeredKey]
};

this._currentTransform.original = {
Expand Down
4 changes: 2 additions & 2 deletions src/mixins/canvas_events.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@
_onScale: function(e, transform, x, y) {
// rotate object only if shift key is not pressed
// and if it is not a group we are transforming
if ((e.shiftKey || this.uniScaleTransform) && !transform.target.get('lockUniScaling')) {
if ((e[this.uniScaleKey] || this.uniScaleTransform) && !transform.target.get('lockUniScaling')) {
transform.currentAction = 'scale';
return this._scaleObject(x, y);
}
Expand Down Expand Up @@ -748,7 +748,7 @@
n += 8; // full circle ahead
}
n += cursorOffset[corner];
if (e.shiftKey && cursorOffset[corner] % 2 === 0) {
if (e[this.altActionKey] && cursorOffset[corner] % 2 === 0) {
//if we are holding shift and we are on a mx corner...
n += 2;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mixins/canvas_grouping.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
_shouldGroup: function(e, target) {
var activeObject = this.getActiveObject();
return e.shiftKey && target && target.selectable &&
return e[this.selectionKey] && target && target.selectable &&
(this.getActiveGroup() || (activeObject && activeObject !== target))
&& this.selection;
},
Expand Down

0 comments on commit fab0c05

Please sign in to comment.