zhangyu 5 lat temu
rodzic
commit
6b1136d758

+ 16 - 6
saga-web-big/src/items/SPolygonItem.ts

@@ -1,5 +1,5 @@
 import { SGraphItem, SGraphPointListInsert, SGraphPointListDelete, SGraphPointListUpdate } from "@saga-web/graph/lib";
-import { SMouseEvent, SUndoStack } from "@saga-web/base/";;
+import { SMouseEvent, SUndoStack, SKeyCode } from "@saga-web/base/";;
 import {
     SColor,
     SLineCapStyle,
@@ -154,6 +154,8 @@ export class SPolygonItem extends SGraphItem {
                 point = null
             }
         }
+        this.curIndex = -1;
+        this.curPoint = null;
         this.update()
         return point
     }
@@ -273,6 +275,10 @@ export class SPolygonItem extends SGraphItem {
         painter.pen.color = SColor.Black;
         painter.brush.color = SColor.White;
         pointList.forEach((item, index) => {
+            painter.brush.color = SColor.White;
+            if (index == this.curIndex) {
+                painter.brush.color = new SColor(this.fillColor);
+            }
             painter.drawCircle(item.x, item.y, painter.toPx(this.len / 2))
         })
     }
@@ -489,6 +495,8 @@ export class SPolygonItem extends SGraphItem {
         if (this.status == SItemStatus.Edit) {
             if (event.key == 'Alt') {
                 this.isAlt = false;
+            } else if (event.keyCode == SKeyCode.Delete) {
+                this.deletePoint(this.curIndex);
             }
         }
         this.update()
@@ -567,9 +575,11 @@ export class SPolygonItem extends SGraphItem {
             this.lastPoint.y = event.y;
             this.update();
         } else if (this.status == SItemStatus.Edit) {
-            if (-1 != this.curIndex) {
-                this.pointList[this.curIndex].x = event.x;
-                this.pointList[this.curIndex].y = event.y;
+            if (event.buttons == 1) {
+                if (-1 != this.curIndex) {
+                    this.pointList[this.curIndex].x = event.x;
+                    this.pointList[this.curIndex].y = event.y;
+                }
             }
             this.update()
         } else {
@@ -592,8 +602,8 @@ export class SPolygonItem extends SGraphItem {
                 const pos = new SPoint(this.pointList[this.curIndex].x, this.pointList[this.curIndex].y)
                 this.recordAction(SGraphPointListUpdate, [this.pointList, this.curPoint, pos, this.curIndex])
             }
-            this.curIndex = -1;
-            this.curPoint = null;
+            // this.curIndex = -1;
+            // this.curPoint = null;
         } else {
             // return super.onMouseUp(event)
         }

+ 6 - 4
saga-web-big/src/items/SPolylineItem.ts

@@ -166,7 +166,7 @@ export class SPolylineItem extends SGraphItem {
      * @return  boolean 是否处理事件
      * */
     onMouseDown(event: SMouseEvent): boolean {
-        // this.curIndex = -1;
+        this.curIndex = -1;
         this.curPoint = null;
         if (event.buttons == 1) {
             if (this.status == SItemStatus.Create) {
@@ -209,9 +209,11 @@ export class SPolylineItem extends SGraphItem {
             this.update();
             return true;
         } else if (this.status == SItemStatus.Edit) {
-            if (this.canHandle(this.curIndex)) {
-                this.pointList[this.curIndex].x = event.x;
-                this.pointList[this.curIndex].y = event.y;
+            if (event.buttons == 1) {
+                if (this.canHandle(this.curIndex)) {
+                    this.pointList[this.curIndex].x = event.x;
+                    this.pointList[this.curIndex].y = event.y;
+                }
             }
             this.update();
             return true;

+ 35 - 20
saga-web-graph/src/items/STextItem.ts

@@ -13,6 +13,9 @@ import { SGraphItem } from "../SGraphItem";
  * @author  张宇(taohuzy@163.com)
  */
 export class STextItem extends SObjectItem {
+    /** 记录painter */
+    private _painter: SPainter | null = null;
+
     /** 文本内容 */
     private _text: string = "";
     get text(): string {
@@ -20,9 +23,14 @@ export class STextItem extends SObjectItem {
     }
     set text(v: string) {
         this._text = v;
+        this._textArr = this.text.split(/\n/g);
+        this.drawFormatText();
         this.update();
     }
 
+    /** 切割后的文本数组 */
+    private _textArr: string[] = [];
+
     /** 文本颜色 */
     private _color: string = "#333333";
     get color(): string {
@@ -40,6 +48,7 @@ export class STextItem extends SObjectItem {
     }
     set font(v: SFont) {
         this._font = v;
+        this.drawFormatText();
         this.update();
     }
 
@@ -116,7 +125,14 @@ export class STextItem extends SObjectItem {
         //绘制文本
         painter.brush.color = new SColor(this.color);
         painter.font = this.font;
-        this.drawFormatText(painter);
+        this._textArr.forEach((text: string, index: number) => {
+            painter.drawText(
+                text,
+                2,
+                index * (this.font.size + 2) + 2,
+                this.maxWidth
+            );
+        });
     } // Function drawShowText()
 
     /**
@@ -124,25 +140,20 @@ export class STextItem extends SObjectItem {
      *
      * @param painter    绘制类
      */
-    protected drawFormatText(painter: SPainter): void {
-        let textArr: string[] = this.text.split(/\n/g);
-        let textMaxWidth = 0;
-        let textHeight: number = this.font.size;
-        textArr.forEach((text: string, index: number) => {
-            painter.drawText(
-                text,
-                0,
-                index * (textHeight + 2) + 2,
-                this.maxWidth
-            );
-            let textWidth: number = painter.textWidth(text);
-            if (textWidth > textMaxWidth) {
-                textMaxWidth = textWidth;
-            }
-        });
-        // 在绘制文本后计算文本的宽高
-        this.width = textMaxWidth;
-        this.height = (textHeight + 2) * textArr.length;
+    protected drawFormatText(): void {
+        if (this._painter instanceof SPainter) {
+            let textMaxWidth = 0;
+            let textHeight: number = this.font.size;
+            this._textArr.forEach((text: string, index: number) => {
+                let textWidth: number = this._painter?this._painter.textWidth(text)+4:4;
+                if (textWidth > textMaxWidth) {
+                    textMaxWidth = textWidth;
+                }
+            });
+            // 在绘制文本后计算文本的宽高
+            this.width = textMaxWidth;
+            this.height = (textHeight + 2) * this._textArr.length;
+        }
     } // Function drawFormatText()
 
     /**
@@ -151,6 +162,10 @@ export class STextItem extends SObjectItem {
      * @param   painter      绘画类
      */
     onDraw(painter: SPainter): void {
+        if (!(this._painter instanceof SPainter)) {
+            this._painter = painter;
+            this.drawFormatText();
+        }
         this.drawShowText(painter);
     } // Function onDraw()
 } // Class STextItem