فهرست منبع

比例尺修改文本

haojianlong 4 سال پیش
والد
کامیت
c3a280485c
1فایلهای تغییر یافته به همراه13 افزوده شده و 3 حذف شده
  1. 13 3
      src/items/EditLineItem.ts

+ 13 - 3
src/items/EditLineItem.ts

@@ -47,6 +47,9 @@ export class EditLineItem extends SGraphItem {
         this.update();
     }
 
+    /** 是否更改文字 */
+    isChangeText: boolean = true;
+
     /** 线条颜色 */
     private _strokeColor: SColor = SColor.Black;
     get strokeColor(): SColor {
@@ -242,6 +245,7 @@ export class EditLineItem extends SGraphItem {
     onMouseDown(event: SMouseEvent): boolean {
         this.curIndex = -1;
         this.curPoint = null;
+        this.isChangeText = true;
         // 按下 shiftKey 键
         if (event.shiftKey) {
             event = this.compare(event);
@@ -282,7 +286,11 @@ export class EditLineItem extends SGraphItem {
             if (this.curIndex > -1) {
                 this.releaseItem();
             } else {
-                return super.onMouseUp(event);
+                if (this.isChangeText) {
+                    this.$emit("changText", event);
+                } else {
+                    return super.onMouseUp(event);
+                }
             }
         } else if (this.status == SItemStatus.Normal) {
             // 标准状态时
@@ -321,6 +329,7 @@ export class EditLineItem extends SGraphItem {
                 this.line[this.curIndex].y = event.y;
                 this.pointChange();
             } else {
+                this.isChangeText = false;
                 super.onMouseMove(event);
             }
         } else {
@@ -528,8 +537,9 @@ export class EditLineItem extends SGraphItem {
     onDraw(painter: SPainter): void {
         // 如果线段存在
         if (this.line.length) {
+            const lw = painter.toPx(this.lineWidth);
             painter.save();
-            painter.pen.lineWidth = painter.toPx(this.lineWidth);
+            painter.pen.lineWidth = lw;
             painter.translate(this.line[0].x, this.line[0].y);
             painter.rotate((this._ang * 180) / Math.PI);
             painter.pen.color = this.strokeColor;
@@ -541,7 +551,7 @@ export class EditLineItem extends SGraphItem {
                 painter.font.textAlign = STextAlign.Center;
                 painter.brush.color = SColor.Black;
                 painter.pen.color = SColor.White;
-                painter.pen.lineWidth = painter.toPx(8);
+                painter.pen.lineWidth = 8 * lw;
                 painter.drawText(this.text, this.textPos.x, this.textPos.y);
             }
             painter.restore();