|
@@ -26,7 +26,8 @@ import {
|
|
|
SPainter,
|
|
|
SPath2D,
|
|
|
SPoint,
|
|
|
- SPolygonUtil
|
|
|
+ SPolygonUtil,
|
|
|
+ SRect
|
|
|
} from "@saga-web/draw/lib";
|
|
|
import { SMouseEvent } from "@saga-web/base/lib";
|
|
|
import { ItemOrder } from "../types/ItemOrder";
|
|
@@ -42,6 +43,14 @@ export class SceneMarkItem extends SGraphyItem {
|
|
|
outLine: SPoint[] = [];
|
|
|
/** 是否闭合 */
|
|
|
closeFlag = false;
|
|
|
+ /** X坐标最小值 */
|
|
|
+ private minX = Number.MAX_SAFE_INTEGER;
|
|
|
+ /** X坐标最大值 */
|
|
|
+ private maxX = Number.MIN_SAFE_INTEGER;
|
|
|
+ /** Y坐标最小值 */
|
|
|
+ private minY = Number.MAX_SAFE_INTEGER;
|
|
|
+ /** Y坐标最大值 */
|
|
|
+ private maxY = Number.MIN_SAFE_INTEGER;
|
|
|
/** 鼠标移动点 */
|
|
|
private lastPoint = new SPoint();
|
|
|
/** 蒙版 */
|
|
@@ -74,9 +83,29 @@ export class SceneMarkItem extends SGraphyItem {
|
|
|
if (data instanceof Array) {
|
|
|
this.outLine = data;
|
|
|
this.createMask();
|
|
|
+ this.outLine.forEach(it => {
|
|
|
+ let x = it.x,
|
|
|
+ y = it.y;
|
|
|
+ if (x < this.minX) {
|
|
|
+ this.minX = x;
|
|
|
+ }
|
|
|
+ if (y < this.minY) {
|
|
|
+ this.minY = y;
|
|
|
+ }
|
|
|
+ if (x > this.maxX) {
|
|
|
+ this.maxX = x;
|
|
|
+ }
|
|
|
+ if (y > this.maxY) {
|
|
|
+ this.maxY = y;
|
|
|
+ }
|
|
|
+ });
|
|
|
} else {
|
|
|
this.outLine.push(data);
|
|
|
this.lastPoint = data;
|
|
|
+ this.minY = data.y;
|
|
|
+ this.maxY = data.y;
|
|
|
+ this.minX = data.x;
|
|
|
+ this.maxX = data.x;
|
|
|
}
|
|
|
this.zOrder = ItemOrder.sceneMarkOrder;
|
|
|
} // Constructor
|
|
@@ -98,9 +127,23 @@ export class SceneMarkItem extends SGraphyItem {
|
|
|
return true;
|
|
|
}
|
|
|
let p = new SPoint(event.x, event.y);
|
|
|
- this.lastPoint.x = p.x;
|
|
|
- this.lastPoint.y = p.y;
|
|
|
+ let x = p.x,
|
|
|
+ y = p.y;
|
|
|
+ this.lastPoint.x = x;
|
|
|
+ this.lastPoint.y = y;
|
|
|
this.outLine.push(p);
|
|
|
+ if (x < this.minX) {
|
|
|
+ this.minX = x;
|
|
|
+ }
|
|
|
+ if (y < this.minY) {
|
|
|
+ this.minY = y;
|
|
|
+ }
|
|
|
+ if (x > this.maxX) {
|
|
|
+ this.maxX = x;
|
|
|
+ }
|
|
|
+ if (y > this.maxY) {
|
|
|
+ this.maxY = y;
|
|
|
+ }
|
|
|
}
|
|
|
this.update();
|
|
|
return true;
|
|
@@ -153,6 +196,8 @@ export class SceneMarkItem extends SGraphyItem {
|
|
|
this.closeFlag = true;
|
|
|
if (this.scene) {
|
|
|
this.scene.grabItem = null;
|
|
|
+ // @ts-ignore
|
|
|
+ this.scene.isMarking = false;
|
|
|
}
|
|
|
this.mask = new SPath2D();
|
|
|
this.mask.moveTo(Number.MIN_SAFE_INTEGER, Number.MIN_SAFE_INTEGER);
|
|
@@ -171,6 +216,18 @@ export class SceneMarkItem extends SGraphyItem {
|
|
|
} // Function createMask()
|
|
|
|
|
|
/**
|
|
|
+ * 外接矩阵
|
|
|
+ */
|
|
|
+ boundingRect(): SRect {
|
|
|
+ return new SRect(
|
|
|
+ this.minX,
|
|
|
+ this.minY,
|
|
|
+ this.maxX - this.minX,
|
|
|
+ this.maxY - this.minY
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 判断点是否在区域内
|
|
|
*
|
|
|
* @param x
|