Selaa lähdekoodia

edit:feat>添加宽度是否像素属性

zhangyu 4 vuotta sitten
vanhempi
commit
89b8b78f95

+ 4 - 0
persagy-web-big-edit/src/SBaseEditScene.ts

@@ -165,6 +165,10 @@ export class SBaseEditScene extends SGraphEditScene {
         item.connect("finishCreated", this, this.finishCreated);
         item.connect("onContextMenu", this, this.getItem);
         if (this.view) {
+            // 视图存在缩放比例,箭头宽度随缩放比例改变
+            if (this.view?.scale)
+            item.arrowWidth = item.arrowWidth / this.view.scale;
+
             this.view.update();
         }
     }

+ 20 - 7
persagy-web-big-edit/src/items/SBaseArrowPolyEdit.ts

@@ -61,7 +61,11 @@ export class SBaseArrowPolyEdit extends SBaseLineEdit {
 	 * @param data      坐标集合|第一个点坐标
 	 */
 	constructor(parent: SGraphItem | null, data: Marker): void {
-		super(parent, data);
+        super(parent, data);
+        // 箭头宽度
+        if (data?.style?.default?.arrowWidth) {
+            this.arrowWidth = data.style.default.arrowWidth;
+        }
 		this.pointChange();
 	}
 
@@ -109,7 +113,18 @@ export class SBaseArrowPolyEdit extends SBaseLineEdit {
 				];
 			}
 		}
-	}
+    }
+    
+    /**
+     * 返回对象储存的相关数据
+     *
+     * @return	对象数据
+     */
+    toData() {
+        const data = super.toData();
+        data.style.default.arrowWidth = this.arrowWidth;
+        return data
+    }
 
 	/**
 	 * 绘制
@@ -140,12 +155,10 @@ export class SBaseArrowPolyEdit extends SBaseLineEdit {
 			painter.drawPolygon(this.pointList);
 			painter.restore();
 
-			if (
-				this.status == SItemStatus.Edit ||
-				this.status == SItemStatus.Create
-			) {
+			if (this.status == SItemStatus.Edit) {
+                painter.pen.lineWidth = lw;
 				this.line.forEach((p, i) => {
-					painter.brush.color = this.fillColor;
+					painter.brush.color = SColor.White;
 					if (i == this.curIndex) {
 						painter.brush.color = this.activeFillColor;
 					}

+ 4 - 0
persagy-web-edit/src/SGraphEdit.ts

@@ -36,6 +36,10 @@ import { SMouseEvent } from "@persagy-web/base/";
 export class SGraphEdit extends SGraphItem {
     //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     //属性
+
+    /** 宽度是否像素 */
+    widthIsPx: boolean = false;
+
     /** 编辑状态 */
     protected _status: SItemStatus = SItemStatus.Normal;
     get status(): SItemStatus {

+ 8 - 1
persagy-web-edit/src/items/SBaseCircleEdit.ts

@@ -131,6 +131,7 @@ export class SBaseCircleEdit extends SGraphEdit {
   */
   constructor(parent: SGraphItem | null, data: Marker) {
     super(parent);
+    this.widthIsPx = true;
     this.data = data;
     if (data.style) {
       // 关于顶点
@@ -385,7 +386,13 @@ export class SBaseCircleEdit extends SGraphEdit {
       this.calRect()
       painter.pen.color = this.strokeColor;
       painter.brush.color = this.fillColor;
-      painter.pen.lineWidth = this.lineWidth;
+
+      // 使用像素值
+      if(this.widthIsPx) {
+        painter.pen.lineWidth = painter.toPx(this.lineWidth);
+      } else { //否则
+        painter.pen.lineWidth = this.lineWidth;
+      }
       if (this.lineStyle == SLineStyle.Dashed) {
         painter.pen.lineDash = [
           painter.toPx(this.lineWidth * 3),

+ 8 - 1
persagy-web-edit/src/items/SBaseRectEdit.ts

@@ -138,6 +138,7 @@ export class SBaseRectEdit extends SGraphEdit {
      */
     constructor(parent: SGraphItem | null, data: Marker) {
         super(parent);
+        this.widthIsPx = true;
         this.data = data;
         if (data.style && data.style.default) {
             // 关于顶点
@@ -387,7 +388,13 @@ export class SBaseRectEdit extends SGraphEdit {
             // this.calRect();
             painter.pen.color = this.strokeColor;
             painter.brush.color = this.fillColor;
-            painter.pen.lineWidth = this.lineWidth;
+
+            // 使用像素值
+            if (this.widthIsPx) {
+                painter.pen.lineWidth = painter.toPx(this.lineWidth);
+            } else { // 否则
+                painter.pen.lineWidth = this.lineWidth;
+            }
             if (this.lineStyle == SLineStyle.Dashed) {
                 painter.pen.lineDash = [
                     painter.toPx(this.lineWidth * 3),