瀏覽代碼

框选item优化

haojianlong 4 年之前
父節點
當前提交
e4893f2661
共有 1 個文件被更改,包括 22 次插入2 次删除
  1. 22 2
      persagy-web-big/src/items/SRectSelectItem.ts

+ 22 - 2
persagy-web-big/src/items/SRectSelectItem.ts

@@ -60,7 +60,27 @@ export class SRectSelectItem extends SGraphItem {
      * @return 边界区域
      */
     boundingRect(): SRect {
-        return new SRect(this.startPoint, this.endPoint);
+        let left, top, w, h;
+        // 起始点在结束点左侧
+        if (this.startPoint.x < this.endPoint.x) {
+            left = this.startPoint.x;
+            w = this.endPoint.x - this.startPoint.x;
+        } else {
+            // 否则
+            left = this.endPoint.x;
+            w = this.startPoint.x - this.endPoint.x;
+        }
+
+        // 起始点在结束点上侧
+        if (this.startPoint.y < this.endPoint.y) {
+            top = this.startPoint.y;
+            h = this.endPoint.y - this.startPoint.y;
+        } else {
+            // 否则
+            top = this.endPoint.y;
+            h = this.startPoint.y - this.endPoint.y;
+        }
+        return new SRect(left, top, w, h);
     }
 
     /**
@@ -85,6 +105,6 @@ export class SRectSelectItem extends SGraphItem {
         painter.pen.lineWidth = painter.toPx(2);
         painter.pen.color = ItemColor.rectSelectOutColor;
         painter.brush.color = ItemColor.rectSelectInColor;
-        painter.drawRect(this.startPoint, this.endPoint);
+        painter.drawRect(this.boundingRect());
     }
 }