feat(ui): move resetScale to transformer

This commit is contained in:
psychedelicious 2024-08-05 20:52:16 +10:00
parent 8e2b7845e1
commit ab16976084
2 changed files with 21 additions and 13 deletions

View File

@ -145,17 +145,6 @@ export class CanvasLayer {
this.konva.objectGroup.opacity(opacity);
};
resetScale = () => {
const attrs = {
scaleX: 1,
scaleY: 1,
rotation: 0,
};
this.konva.objectGroup.setAttrs(attrs);
this.transformer.konva.bboxOutline.setAttrs(attrs);
this.transformer.konva.proxyRect.setAttrs(attrs);
};
rasterize = async () => {
this.log.debug('Rasterizing layer');
@ -169,7 +158,6 @@ export class CanvasLayer {
const imageDTO = await uploadImage(blob, `${this.id}_rasterized.png`, 'other', true);
const imageObject = imageDTOToImageObject(imageDTO);
await this.renderer.renderObject(imageObject, true);
this.resetScale();
this.manager.stateApi.rasterizeEntity(
{ id: this.id, imageObject, position: { x: Math.round(rect.x), y: Math.round(rect.y) } },
this.type

View File

@ -512,12 +512,32 @@ export class CanvasTransformer {
this.isTransforming = false;
this.setInteractionMode('off');
this.parent.resetScale();
// Reset the scale of the the entity. We've either replaced the transformed objects with a rasterized image, or
// canceled a transformation. In either case, the scale should be reset.
this.resetScale();
this.parent.updatePosition();
this.updateBbox();
this.syncInteractionState();
};
/**
* Resets the scale of the transformer and the entity.
* When the entity is transformed, it's scale and rotation are modified by the transformer. After canceling or applying
* a transformation, the scale and rotation should be reset to the original values.
*/
resetScale = () => {
const attrs = {
scaleX: 1,
scaleY: 1,
rotation: 0,
};
this.parent.konva.objectGroup.setAttrs(attrs);
this.konva.bboxOutline.setAttrs(attrs);
this.konva.proxyRect.setAttrs(attrs);
};
/**
* Sets the transformer to a specific interaction mode.
* @param interactionMode The mode to set the transformer to. The transformer can be in one of three modes: