添加旋转角度提示

添加父元素变换时子元素包围盒等辅助元素显隐控制
This commit is contained in:
walker 2023-06-20 13:57:26 +08:00
parent 33ac26a825
commit 5f7052ba9b

View File

@ -14,7 +14,7 @@ import {
} from '.'; } from '.';
import { GraphicApp } from '../app'; import { GraphicApp } from '../app';
import { JlGraphic } from '../core'; import { JlGraphic } from '../core';
import { AbsorbablePosition } from '../graphic'; import { AbsorbablePosition, VectorText } from '../graphic';
import { DraggablePoint } from '../graphic/DraggablePoint'; import { DraggablePoint } from '../graphic/DraggablePoint';
import { import {
angleToAxisx, angleToAxisx,
@ -447,6 +447,10 @@ export class TransformPoints extends Container {
* *
*/ */
startAngle = 0; startAngle = 0;
/**
*
*/
angleAssistantText: VectorText;
/** /**
* *
*/ */
@ -461,6 +465,10 @@ export class TransformPoints extends Container {
this.obj = obj; this.obj = obj;
this.name = TransformPoints.Name; this.name = TransformPoints.Name;
this.angleAssistantText = new VectorText('');
this.angleAssistantText.setVectorFontSize(16);
this.angleAssistantText.anchor.set(0.5);
// 创建缩放拖拽点 // 创建缩放拖拽点
this.ltScalePoint = new DraggablePoint(new Point()); this.ltScalePoint = new DraggablePoint(new Point());
this.ltScalePoint.name = TransformPoints.LeftTopName; this.ltScalePoint.name = TransformPoints.LeftTopName;
@ -495,6 +503,11 @@ export class TransformPoints extends Container {
child.on('transformend', this.onObjTransformEnd, this); child.on('transformend', this.onObjTransformEnd, this);
}); });
} }
const pg = this.obj.getGraphic();
if (pg != null) {
pg.on('transformstart', this.onObjTransformStart, this);
pg.on('transformend', this.onObjTransformEnd, this);
}
this.obj.on('repaint', this.onGraphicRepaint, this); this.obj.on('repaint', this.onGraphicRepaint, this);
this.children.forEach((dp) => { this.children.forEach((dp) => {
@ -556,6 +569,19 @@ export class TransformPoints extends Container {
); );
this.obj.emit('transformstart', GraphicTransformEvent.rotate(this.obj)); this.obj.emit('transformstart', GraphicTransformEvent.rotate(this.obj));
// app.emit('transformstart', app.selectedGraphics); // app.emit('transformstart', app.selectedGraphics);
this.obj.getCanvas().addAssistantAppends(this.angleAssistantText);
this.updateAngleAssistantText(de);
}
updateAngleAssistantText(de: GraphicTransformEvent) {
this.angleAssistantText.text = this.obj.angle + '°';
let cursorPoint = de.data?.startPosition;
if (de.data?.currentPosition) {
cursorPoint = de.data?.currentPosition;
}
if (cursorPoint) {
this.angleAssistantText.position.x = cursorPoint.x;
this.angleAssistantText.position.y = cursorPoint.y - 10;
}
} }
/** /**
* *
@ -571,6 +597,7 @@ export class TransformPoints extends Container {
angle = angle - 360; angle = angle - 360;
} }
this.obj.angle = angle; this.obj.angle = angle;
this.updateAngleAssistantText(de);
// this.obj.emit('rotatemove', this.obj); // this.obj.emit('rotatemove', this.obj);
} }
/** /**
@ -579,6 +606,7 @@ export class TransformPoints extends Container {
*/ */
onRotateEnd() { onRotateEnd() {
this.showAll(); this.showAll();
this.obj.getCanvas().removeAssistantAppends(this.angleAssistantText);
this.rotateAngleStepKeyListeners.forEach((listener) => this.rotateAngleStepKeyListeners.forEach((listener) =>
this.obj.getGraphicApp().removeKeyboardListener(listener) this.obj.getGraphicApp().removeKeyboardListener(listener)
); );
@ -832,6 +860,11 @@ export class BoundsGraphic extends Graphics {
child.on('transformend', this.onObjTransformEnd, this); child.on('transformend', this.onObjTransformEnd, this);
}); });
} }
const pg = this.obj.getGraphic();
if (pg != null) {
pg.on('transformstart', this.onObjTransformStart, this);
pg.on('transformend', this.onObjTransformEnd, this);
}
this.obj.on('repaint', this.onGraphicRepaint, this); this.obj.on('repaint', this.onGraphicRepaint, this);
graphic.addAssistantAppend(this); graphic.addAssistantAppend(this);
} }