Browse Source

'文本原点调整'

zhangyu 5 years ago
parent
commit
98e82fe54f

+ 1 - 1
saga-web-big/src/items/SIconTextItem.ts

@@ -210,7 +210,7 @@ export class SIconTextItem extends SObjectItem {
         this.textItem.text = "";
         this.textItem.font.size = 12;
         // 偏移二分之一文本高度
-        this.textItem.moveTo(26, -(this.textItem.height * 0.5));
+        this.textItem.moveTo(20, -(this.textItem.height * 0.5));
         this.moveable = true;
         this.selectable = true;
     }

+ 5 - 8
saga-web-graph/src/items/SImageItem.ts

@@ -1,5 +1,5 @@
 import { SObjectItem } from "./SObjectItem";
-import { SPainter, SRect, SSize, SColor } from "@saga-web/draw/lib";
+import { SPainter, SRect, SSize, SColor, SPoint } from "@saga-web/draw/lib";
 import { SImageShowType } from "../enums/SImageShowType";
 import { SGraphItem } from "../SGraphItem";
 
@@ -128,6 +128,7 @@ export class SImageItem extends SObjectItem {
         }
         this.imgWidth = width;
         this.imgHeight = height;
+        this.origin = new SPoint(this.width / 2, this.height / 2);
     } // Function computeImgSize()
 
     /**
@@ -136,12 +137,7 @@ export class SImageItem extends SObjectItem {
      * @return	SRect
      */
     boundingRect(): SRect {
-        return new SRect(
-            -this.width / 2,
-            -this.height / 2,
-            this.width,
-            this.height
-        );
+        return new SRect(-this.origin.x, -this.origin.y, this.width, this.height);
     } // Function boundingRect()
 
     /**
@@ -161,9 +157,10 @@ export class SImageItem extends SObjectItem {
      * @param   painter      绘画类
      */
     onDraw(painter: SPainter): void {
+        painter.translate(-this.origin.x, -this.origin.y);
         if (this.isLoadOver) {
             // @ts-ignore
-            painter.drawImage(this.img, -this.imgWidth / 2, -this.imgHeight / 2, this.imgWidth, this.imgHeight);
+            painter.drawImage(this.img, 0, 0, this.imgWidth, this.imgHeight);
         }
         if (this.selected) {
             painter.shadow.shadowBlur = 10;

+ 4 - 2
saga-web-graph/src/items/STextItem.ts

@@ -1,5 +1,5 @@
 import { SObjectItem } from "./SObjectItem";
-import { SPainter, SRect, SColor, SFont } from "@saga-web/draw/lib";
+import { SPainter, SRect, SColor, SFont, SPoint } from "@saga-web/draw/lib";
 import { SGraphItem } from "../SGraphItem";
 import { SLineStyle } from "../enums/SLineStyle";
 
@@ -110,7 +110,7 @@ export class STextItem extends SObjectItem {
      * @return  边界区域
      */
     boundingRect(): SRect {
-        return new SRect(0, 0, this.width, this.height);
+        return new SRect(-this.origin.x, -this.origin.y, this.width, this.height);
     } // Function boundingRect()
 
     /**
@@ -178,6 +178,7 @@ export class STextItem extends SObjectItem {
             // 在绘制文本后计算文本的宽高
             this.width = textMaxWidth;
             this.height = (fontSize * 1.25) * this._textArr.length + (fontSize / 8);
+            this.origin = new SPoint(this.width / 2, this.height / 2);
             this._painter.restore();
         }
     } // Function drawFormatText()
@@ -188,6 +189,7 @@ export class STextItem extends SObjectItem {
      * @param   painter      绘画类
      */
     onDraw(painter: SPainter): void {
+        painter.translate(-this.origin.x, -this.origin.y);
         if (!(this._painter instanceof SPainter)) {
             this._painter = painter;
             this.drawFormatText();