|
@@ -1,6 +1,7 @@
|
|
|
import { SGraphyItem } from "@saga-web/graphy/lib";
|
|
|
import { SLine, SPainter, SPoint } from "@saga-web/draw/lib";
|
|
|
import { SMouseEvent } from "@saga-web/base";
|
|
|
+import { SMathUtil } from "../utils/SMathUtil";
|
|
|
|
|
|
/**
|
|
|
* 直线item
|
|
@@ -12,6 +13,42 @@ export class SLineItem extends SGraphyItem {
|
|
|
p1: SPoint | undefined;
|
|
|
/** 线段终止点 */
|
|
|
p2: SPoint | undefined;
|
|
|
+ /** 是否完成绘制 */
|
|
|
+ private isFinish: boolean = true;
|
|
|
+ /** 拖动灵敏度 */
|
|
|
+ dis: number = 5;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param parent 父级
|
|
|
+ * @param line 线段
|
|
|
+ * */
|
|
|
+ constructor(parent: SGraphyItem | null, line: SLine);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param parent 父级
|
|
|
+ * @param point 线段起点
|
|
|
+ * */
|
|
|
+ constructor(parent: SGraphyItem | null, point: SPoint);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param parent 父级
|
|
|
+ * @param l 线段or线段起点
|
|
|
+ * */
|
|
|
+ constructor(parent: SGraphyItem | null, l: SPoint | SLine) {
|
|
|
+ super(parent);
|
|
|
+ if (l instanceof SPoint) {
|
|
|
+ this.p1 = l;
|
|
|
+ } else {
|
|
|
+ this.p1 = l.p1;
|
|
|
+ this.p2 = l.p2;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 鼠标按下事件
|
|
@@ -30,7 +67,17 @@ export class SLineItem extends SGraphyItem {
|
|
|
* @return 是否处理事件
|
|
|
* */
|
|
|
onMouseMove(event: SMouseEvent): boolean {
|
|
|
- return false;
|
|
|
+ if (this.isFinish) {
|
|
|
+ if (!this.p2) {
|
|
|
+ this.p2 = new SPoint(event.x, event.y);
|
|
|
+ } else {
|
|
|
+ this.p2.x = event.x;
|
|
|
+ this.p2.y = event.y;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return super.onMouseMove(event);
|
|
|
+ }
|
|
|
} // Function onMouseMove()
|
|
|
|
|
|
/**
|
|
@@ -40,7 +87,12 @@ export class SLineItem extends SGraphyItem {
|
|
|
* @return 是否处理事件
|
|
|
* */
|
|
|
onMouseUp(event: SMouseEvent): boolean {
|
|
|
- return false;
|
|
|
+ if (!this.isFinish) {
|
|
|
+ this.isFinish = true;
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return super.onMouseUp(event);
|
|
|
+ }
|
|
|
} // Function onMouseUp()
|
|
|
|
|
|
/**
|
|
@@ -51,7 +103,15 @@ export class SLineItem extends SGraphyItem {
|
|
|
* @return true-是
|
|
|
*/
|
|
|
contains(x: number, y: number): boolean {
|
|
|
-
|
|
|
+ if (this.p1 instanceof SPoint && this.p2 instanceof SPoint) {
|
|
|
+ let p = new SPoint(x, y);
|
|
|
+ if (
|
|
|
+ SMathUtil.pointToLine(p, new SLine(this.p1, this.p2)).MinDis <
|
|
|
+ this.dis
|
|
|
+ ) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
return false;
|
|
|
} // Function contains()
|
|
|
|