|
@@ -24,8 +24,10 @@ import {
|
|
|
SPainter,
|
|
|
SPath2D,
|
|
|
SPoint,
|
|
|
+ SPolygonUtil,
|
|
|
SRect
|
|
|
} from "@sybotan-web/draw/lib";
|
|
|
+import { Opt } from "../types/Opt";
|
|
|
|
|
|
/**
|
|
|
* 蒙版item
|
|
@@ -48,10 +50,31 @@ export class SceneMarkItem extends SGraphyItem {
|
|
|
* @param parent 指向父对象
|
|
|
* @param data 蒙版起点数据
|
|
|
*/
|
|
|
- constructor(parent: SGraphyItem | null, data: SPoint) {
|
|
|
+ constructor(parent: SGraphyItem | null, data: SPoint); // Constructor
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param parent 指向父对象
|
|
|
+ * @param data 蒙版轮廓线数据
|
|
|
+ */
|
|
|
+ constructor(parent: SGraphyItem | null, data: SPoint[]); // Constructor
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param parent 指向父对象
|
|
|
+ * @param data 蒙版起点数据 | 蒙版轮廓线数据
|
|
|
+ */
|
|
|
+ constructor(parent: SGraphyItem | null, data: SPoint[] | SPoint) {
|
|
|
super(parent);
|
|
|
- this.outLine.push(data);
|
|
|
- this.lastPoint = data;
|
|
|
+ if (data instanceof Array) {
|
|
|
+ this.outLine = data;
|
|
|
+ this.createMask();
|
|
|
+ } else {
|
|
|
+ this.outLine.push(data);
|
|
|
+ this.lastPoint = data;
|
|
|
+ }
|
|
|
this.zOrder = Number.MAX_SAFE_INTEGER;
|
|
|
} // Constructor
|
|
|
|
|
@@ -62,7 +85,6 @@ export class SceneMarkItem extends SGraphyItem {
|
|
|
* @return boolean
|
|
|
*/
|
|
|
onMouseDown(event: SMouseEvent): boolean {
|
|
|
- console.log(arguments);
|
|
|
if (!this.closeFlag && event.buttons == 1) {
|
|
|
let p = new SPoint(event.x, event.y);
|
|
|
this.lastPoint.x = p.x;
|
|
@@ -81,6 +103,7 @@ export class SceneMarkItem extends SGraphyItem {
|
|
|
onMouseMove(event: SMouseEvent): boolean {
|
|
|
if (!this.closeFlag) {
|
|
|
this.lastPoint = new SPoint(event.x, event.y);
|
|
|
+ console.log(this.lastPoint);
|
|
|
}
|
|
|
return true;
|
|
|
} // Function onMouseMove()
|
|
@@ -109,34 +132,15 @@ export class SceneMarkItem extends SGraphyItem {
|
|
|
this.mask.lineTo(Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
|
|
|
this.mask.lineTo(Number.MIN_SAFE_INTEGER, Number.MIN_SAFE_INTEGER);
|
|
|
|
|
|
- let antiArr = this.outLine;
|
|
|
- if (this.isAntiClockWise(this.outLine)) {
|
|
|
- antiArr = this.outLine.reverse();
|
|
|
+ let antiArr = this.outLine.concat([]);
|
|
|
+ // (计算基于数学坐标系统,在绘图坐标系由于y轴方向相反结果也要取反)
|
|
|
+ if (SPolygonUtil.clockDir(antiArr) > 0) {
|
|
|
+ antiArr = antiArr.reverse();
|
|
|
}
|
|
|
this.mask.polygon(antiArr);
|
|
|
} // Function createMask()
|
|
|
|
|
|
/**
|
|
|
- * 判断多边形点是否逆时针排列
|
|
|
- *
|
|
|
- * @param pArr 点数组
|
|
|
- * @return boolean 是-true 否-false
|
|
|
- */
|
|
|
- private isAntiClockWise(pArr: SPoint[]): boolean {
|
|
|
- let newArr = pArr.concat([]);
|
|
|
- let rightPoint = newArr[0],
|
|
|
- index = 0;
|
|
|
- for (let i = 1; i < newArr.length; i++) {
|
|
|
- if (newArr[i].x > rightPoint.x) {
|
|
|
- index = i;
|
|
|
- rightPoint = newArr[i];
|
|
|
- }
|
|
|
- }
|
|
|
- index = index == 0 ? newArr.length - 1 : index - 1;
|
|
|
- return rightPoint.y > newArr[index].y;
|
|
|
- } // Function isAntiClockWise
|
|
|
-
|
|
|
- /**
|
|
|
* Item绘制操作
|
|
|
*
|
|
|
* @param painter painter对象
|
|
@@ -145,10 +149,11 @@ export class SceneMarkItem extends SGraphyItem {
|
|
|
onDraw(painter: SPainter, rect?: SRect): void {
|
|
|
if (this.closeFlag) {
|
|
|
painter.pen.color = SColor.Transparent;
|
|
|
- painter.brush.color = new SColor("#FFFF0080");
|
|
|
+ painter.brush.color = Opt.sceneMarkColor;
|
|
|
painter.drawPath(this.mask);
|
|
|
} else {
|
|
|
painter.pen.color = new SColor("#ff0000");
|
|
|
+ painter.pen.lineWidth = painter.toPx(5);
|
|
|
painter.drawPolyline(this.outLine);
|
|
|
painter.drawLine(
|
|
|
this.outLine[this.outLine.length - 1],
|