Browse Source

'修改图标原点'

zhangyu 5 years ago
parent
commit
749232c31e

+ 4 - 2
saga-web-big/src/items/SIconTextItem.ts

@@ -7,7 +7,7 @@ import {
 } from "@saga-web/graph/lib";
 import { SItemStatus } from "..";
 import { SMouseEvent } from "@saga-web/base";
-import { SSize, SRect, SPainter, SColor, SFont } from "@saga-web/draw";
+import { SSize, SRect, SPainter, SColor, SFont, SPoint } from "@saga-web/draw";
 import { Anchor } from "../types/topology/Anchor";
 
 /**
@@ -210,7 +210,7 @@ export class SIconTextItem extends SObjectItem {
         this.textItem.text = "";
         this.textItem.font.size = 12;
         // 偏移二分之一文本高度
-        this.textItem.moveTo(20, -(this.textItem.height * 0.5));
+        this.textItem.moveTo((this.img.width * 0.5) + 4, -(this.textItem.height * 0.5));
         this.moveable = true;
         this.selectable = true;
     }
@@ -254,6 +254,8 @@ export class SIconTextItem extends SObjectItem {
      * @param   newSize 改之后大小
      * */
     onResize(oldSize: SSize, newSize: SSize) {
+        this.img.origin = new SPoint(this.img.width * 0.5, this.img.height * 0.5);
+        this.update();
         console.log(arguments);
     } // Function onResize()
 

+ 2 - 3
saga-web-graph/src/items/SImageItem.ts

@@ -1,5 +1,5 @@
 import { SObjectItem } from "./SObjectItem";
-import { SPainter, SRect, SSize, SColor, SPoint } from "@saga-web/draw/lib";
+import { SPainter, SRect, SSize, SColor } from "@saga-web/draw/lib";
 import { SImageShowType } from "../enums/SImageShowType";
 import { SGraphItem } from "../SGraphItem";
 
@@ -128,7 +128,6 @@ export class SImageItem extends SObjectItem {
         }
         this.imgWidth = width;
         this.imgHeight = height;
-        this.origin = new SPoint(this.width / 2, this.height / 2);
     } // Function computeImgSize()
 
     /**
@@ -173,6 +172,6 @@ export class SImageItem extends SObjectItem {
         painter.pen.lineWidth = this.lineWidth;
         painter.pen.color = this.strokeColor;
         painter.brush.color = SColor.Transparent;
-        painter.drawRect(this.boundingRect());
+        painter.drawRect(0, 0, this.width, this.height);
     } // Function onDraw()
 } // Class SImageItem

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

@@ -1,5 +1,5 @@
 import { SObjectItem } from "./SObjectItem";
-import { SPainter, SRect, SColor, SFont, SPoint } from "@saga-web/draw/lib";
+import { SPainter, SRect, SColor, SFont } from "@saga-web/draw/lib";
 import { SGraphItem } from "../SGraphItem";
 import { SLineStyle } from "../enums/SLineStyle";
 
@@ -129,6 +129,7 @@ export class STextItem extends SObjectItem {
      * @param painter    绘制类
      */
     protected drawShowText(painter: SPainter): void {
+        painter.translate(-this.origin.x, -this.origin.y);
         //绘制矩形轮廓
         if (this.selected) {
             painter.shadow.shadowBlur = 10;
@@ -141,7 +142,7 @@ export class STextItem extends SObjectItem {
         painter.brush.color = this.backgroundColor;
         painter.pen.lineWidth = this.lineWidth;
         painter.pen.color = this.strokeColor;
-        painter.drawRect(this.boundingRect());
+        painter.drawRect(0, 0, this.width, this.height);
 
         //绘制文本
         painter.brush.color = new SColor(this.color);
@@ -178,7 +179,6 @@ 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()
@@ -189,7 +189,6 @@ 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();