new centeredScaling for Konva.Transformer

This commit is contained in:
Anton Lavrenov
2018-09-19 14:59:01 +03:00
parent f7ed3f7d52
commit 4ac38ddc1f
6 changed files with 218 additions and 112 deletions

View File

@@ -125,6 +125,7 @@
* @param {Number} [config.anchorStrokeWidth] Anchor stroke size
* @param {Number} [config.anchorSize] Default is 10
* @param {Boolean} [config.keepRatio] Should we keep ratio when we are moving edges? Default is true
* @param {Boolean} [config.centeredScaling] Should we resize relative to node's center? Default is false
* @param {Array} [config.enabledAnchors] Array of names of enabled handles
* @param {Function} [config.boundBoxFunc] Bounding box function
* @example
@@ -575,7 +576,8 @@
this.getParent()
);
if (e.altKey) {
var centeredScaling = this.getCenteredScaling() || e.altKey;
if (centeredScaling) {
var topLeft = this.findOne('.top-left');
var bottomRight = this.findOne('.bottom-right');
var topOffsetX = topLeft.x();
@@ -1088,6 +1090,22 @@
*/
Konva.Factory.addGetterSetter(Konva.Transformer, 'keepRatio', true);
/**
* get/set should we resize relative to node's center?
* @name centeredScaling
* @method
* @memberof Konva.Transformer.prototype
* @param {Boolean} centeredScaling
* @returns {Boolean}
* @example
* // get
* var centeredScaling = transformer.centeredScaling();
*
* // set
* transformer.centeredScaling(true);
*/
Konva.Factory.addGetterSetter(Konva.Transformer, 'centeredScaling', false);
/**
* get/set padding
* @name padding