Procházet zdrojové kódy

比例尺item添加

haojianlong před 4 roky
rodič
revize
2361260e13
3 změnil soubory, kde provedl 28 přidání a 52 odebrání
  1. 2 0
      src/DivideFloorScene.ts
  2. 3 1
      src/index.ts
  3. 23 51
      src/items/EditLineItem.ts

+ 2 - 0
src/DivideFloorScene.ts

@@ -306,6 +306,8 @@ export class DivideFloorScene extends ZoneScene {
             }
             this.removeItem(this.rectSelectItem);
             this.rectSelectItem = null;
+        } else {
+            super.onMouseUp(event);
         }
         return false;
     } // Function onMouseUp()

+ 3 - 1
src/index.ts

@@ -21,6 +21,7 @@ import { Opt } from "./types/Opt";
 import { SImageShowType } from "./enums/SImageShowType";
 import { STextOrigin } from "./enums/STextOrigin";
 import { EditLineItem } from "./items/EditLineItem";
+import { SItemStatus } from "./enums/SItemStatus";
 
 export {
     FloorScene,
@@ -48,5 +49,6 @@ export {
     LikeSpaceItem,
     SImageShowType,
     STextOrigin,
-    EditLineItem
+    EditLineItem,
+    SItemStatus
 };

+ 23 - 51
src/items/EditLineItem.ts

@@ -98,10 +98,10 @@ export class EditLineItem extends SGraphItem {
     }
 
     /** 拖动灵敏度 */
-    dis: number = 5;
+    dis: number = 8;
 
     /** 拖动灵敏度 */
-    private sceneDis: number = 5;
+    private sceneDis: number = 8;
 
     /** 当前点索引 */
     curIndex: number = -1;
@@ -183,7 +183,12 @@ export class EditLineItem extends SGraphItem {
      */
     protected pointChange(): void {
         if (this.line.length > 1) {
-            const line = new SLine(this.line[0], this.line[1]);
+            const line = new SLine(
+                this.line[0].x,
+                this.line[0].y,
+                this.line[1].x,
+                this.line[1].y
+            );
             const dis = SMathUtil.pointDistance(
                 this.line[0].x,
                 this.line[0].y,
@@ -220,32 +225,12 @@ export class EditLineItem extends SGraphItem {
             // 坐标集合长度不大于2时
             this.line[1] = p;
             // this.recordAction(SGraphPointListInsert, [this.line, p, 1]);
-            this.status = SItemStatus.Normal;
-            this.releaseItem();
-            this.$emit("finishCreated");
-            this.pointChange();
-        }
-        this.update();
-    }
-
-    /**
-     * 鼠标双击事件
-     *
-     * @param event     事件参数
-     * @return 是否处理事件
-     */
-    onDoubleClick(event: SMouseEvent): boolean {
-        // 如果为show状态 双击改对象则需改为编辑状态
-        if (this.status == SItemStatus.Normal) {
             this.status = SItemStatus.Edit;
-            this.grabItem(this);
-        } else if (this.status == SItemStatus.Edit) {
-            // 处于编辑状态时
-            this.status = SItemStatus.Normal;
             this.releaseItem();
+            // this.$emit("finishCreated");
+            this.pointChange();
         }
         this.update();
-        return true;
     }
 
     /**
@@ -263,13 +248,17 @@ export class EditLineItem extends SGraphItem {
         }
         // 按下鼠标左键
         if (event.buttons == SMouseButton.LeftButton) {
-            if (this.status == SItemStatus.Normal) {
-                //标准状态时
-                return super.onMouseDown(event);
-            } else if (this.status == SItemStatus.Edit) {
+            if (this.status == SItemStatus.Edit) {
                 // 编辑状态时
                 // 判断是否点击到端点上(获取端点索引值)
                 this.findNearestPoint(new SPoint(event.x, event.y));
+                if (this.curIndex > -1) {
+                    this.grabItem(this);
+                } else {
+                    this.$emit("onmousedown");
+                    super.onMouseDown(event);
+                    return true;
+                }
             } else if (this.status == SItemStatus.Create) {
                 // 创建状态时
                 this.addPoint(new SPoint(event.x, event.y));
@@ -291,16 +280,9 @@ export class EditLineItem extends SGraphItem {
         if (this.status == SItemStatus.Edit) {
             // 当前点索引大于 -1 时
             if (this.curIndex > -1) {
-                const p = new SPoint(
-                    this.line[this.curIndex].x,
-                    this.line[this.curIndex].y
-                );
-                // this.recordAction(SGraphPointListUpdate, [
-                //     this.line,
-                //     this.curPoint,
-                //     p,
-                //     this.curIndex
-                // ]);
+                this.releaseItem();
+            } else {
+                return super.onMouseUp(event);
             }
         } else if (this.status == SItemStatus.Normal) {
             // 标准状态时
@@ -338,6 +320,8 @@ export class EditLineItem extends SGraphItem {
                 this.line[this.curIndex].x = event.x;
                 this.line[this.curIndex].y = event.y;
                 this.pointChange();
+            } else {
+                super.onMouseMove(event);
             }
         } else {
             return super.onMouseMove(event);
@@ -373,18 +357,6 @@ export class EditLineItem extends SGraphItem {
     }
 
     /**
-     * 记录相关动作并推入栈中
-     *
-     * @param SGraphCommand 相关命令类
-     * @param any           对应传入参数
-     */
-    // protected recordAction(SGraphCommand: any, any: any[]): void {
-    //     // 记录相关命令并推入堆栈中 todo
-    //     const command = new SGraphCommand(this.scene, this, ...any);
-    //     this.undoStack.push(command);
-    // }
-
-    /**
      * 移动后处理所有坐标,并肩原点置为场景原点
      *
      * @param x     x 坐标