소스 검색

'添加图标移动图片时锚点跟随移动'

zhangyu 5 년 전
부모
커밋
84832e5298
1개의 변경된 파일10개의 추가작업 그리고 23개의 파일을 삭제
  1. 10 23
      saga-web-big/src/items/SIconTextItem.ts

+ 10 - 23
saga-web-big/src/items/SIconTextItem.ts

@@ -142,12 +142,12 @@ export class SIconTextItem extends SObjectItem {
       this.img.url = `http://adm.sagacloud.cn:8080/doc/assets/img/logo.png`;
       this.img.width = 24;
       this.img.height = 24;
-      this.img.connect("onMove", this, this.moveAhchorPoint.bind(this));
+      this.img.connect("onMove", this, this.changeAhchorPoint.bind(this));
       let anchorPoint = [
-        { x: this.img.x, y: this.img.height / 2 }, 
-        { x: this.img.x, y: -this.img.height / 2 }, 
-        { x: -this.img.width / 2, y: this.img.y }, 
-        { x: this.img.width / 2, y: this.img.y }
+        { x: this.img.x, y: this.img.y + (this.img.height / 2) }, 
+        { x: this.img.x, y: this.img.y - (this.img.height / 2) }, 
+        { x: this.img.x - (this.img.width / 2), y: this.img.y }, 
+        { x: this.img.x + (this.img.width / 2), y: this.img.y }
       ];
       this.anchorList = anchorPoint.map(t => {
         let item = new SAnchorItem(this);
@@ -166,30 +166,17 @@ export class SIconTextItem extends SObjectItem {
     }
 
     /**
-     * 图片移动计算并移动锚点的位置
-     *
-     * */
-    private moveAhchorPoint(): void {
-      // 判断是否有锚点
-      if (this.anchorList.length) {
-        this.anchorList.forEach(item => {
-          item.moveTo(item.x + this.img.x, item.y + this.img.y);
-        })
-      }
-    } // Function moveAhchorPoint()
-
-    /**
-     * 图片大小改变计算并移动锚点的位置
+     * 计算并移动锚点的位置
      *
      * */
     private changeAhchorPoint(): void {
       // 判断是否有锚点
       if (this.anchorList.length) {
         let anchorPoint = [
-          { x: this.img.x, y: this.img.height / 2 }, 
-          { x: this.img.x, y: -this.img.height / 2 }, 
-          { x: -this.img.width / 2, y: this.img.y }, 
-          { x: this.img.width / 2, y: this.img.y }
+          { x: this.img.x, y: this.img.y + (this.img.height / 2) }, 
+          { x: this.img.x, y: this.img.y - (this.img.height / 2) }, 
+          { x: this.img.x - (this.img.width / 2), y: this.img.y }, 
+          { x: this.img.x + (this.img.width / 2), y: this.img.y }
         ]; 
         this.anchorList.forEach((item, index) => {
           item.moveTo(anchorPoint[index].x, anchorPoint[index].y);