Quellcode durchsuchen

add new items of typescript

haojianlong vor 6 Jahren
Ursprung
Commit
d5ab686b6f

+ 58 - 0
src/assets/graphy/SGraphy/newItems/SGraphyCircleItem.ts

@@ -0,0 +1,58 @@
+
+import { SGraphyItem } from '@sybotan-web/graphy';
+import { SRect, SSize } from "@sybotan-web/base";
+import { SPen, SPainter, SColor } from "@sybotan-web/draw";
+
+/**
+ * 圆Item类
+ *
+ */
+export class SGraphyCircleItem extends SGraphyItem {
+    r: number;
+    color: SColor = SColor.Black;
+    width: number = 1;
+
+    /**
+     * 构造函数
+     *
+     * @param r    圆半径
+     * @param width   圆线的宽度
+     *
+     * @param color  圆线的颜色
+     * @param parent    
+     */
+    constructor(
+        parent: SGraphyItem | null,
+        r: number,
+        color: SColor = SColor.Black,
+        width: number = 1
+    ) {
+        super(parent);
+        this.r = r;
+    } // Constructor()
+
+    /**
+     * Item对象边界区域
+     * 
+     * @return SRect
+     */
+    boundingRect(): SRect {
+        return new SRect(
+            -this.r,
+            -this.r,
+            2 * this.r,
+            2 * this.r
+        );
+    } // Function boundingRect()
+
+    /**
+     * Item绘制操作
+     *
+     * @param   painter       painter对象
+     * @param   rect          绘制区域
+     */
+    onDraw(painter: SPainter, rect: SRect): void {
+        painter.pen = new SPen(this.color, this.width);
+        painter.drawCircle(0, 0, this.r);
+    }
+} // Class SGraphyCircleItem

+ 115 - 0
src/assets/graphy/SGraphy/newItems/SGraphyPolygonItem.ts

@@ -0,0 +1,115 @@
+
+import { SGraphyItem } from '@sybotan-web/graphy'
+import { SRect, SSize, SPoint } from "@sybotan-web/base";
+import { SPen, SPainter, SColor } from "@sybotan-web/draw";
+
+/**
+ * 不规则多边形Item类
+ *
+ */
+export class SGraphyPolygonItem extends SGraphyItem {
+	pointArr: SPoint[];
+	color: SColor = SColor.Black;
+	width: number = 1;
+
+	/**
+	 * 构造函数
+	 *
+	 * @param pointArr  点坐标list
+	 * @param width   线的宽度
+	 *
+	 * @param color  线的颜色
+	 * @param parent    
+	 */
+	constructor(
+		parent: SGraphyItem | null,
+		pointArr: SPoint[],
+		color: SColor = SColor.Black,
+		width: number = 1
+	) {
+		super(parent);
+		this.pointArr = pointArr;
+		this.color = color;
+		this.width = width;
+	} // Constructor()
+
+	/**
+	 * Item对象边界区域
+	 * 
+	 * @return SRect
+	 */
+	boundingRect(): SRect {
+		let minX = this.pointArr[0].x;
+		let maxX = minX;
+		let minY = this.pointArr[0].y;
+		let maxY = minY;
+		for (let i = 1; i < this.pointArr.length; i++) {
+			if (this.pointArr[i].x < minX) {
+				minX = this.pointArr[i].x
+			}
+			if (this.pointArr[i].y < minY) {
+				minY = this.pointArr[i].y
+			}
+			if (this.pointArr[i].x > maxX) {
+				maxX = this.pointArr[i].x
+			}
+			if (this.pointArr[i].y > maxY) {
+				maxY = this.pointArr[i].y
+			}
+		}
+
+		return new SRect(
+			minX,
+			minY,
+			maxX - minX,
+			maxY - minY
+		);
+	} // Function boundingRect()
+
+	/**
+	 * 判断点是否在区域内
+	 * 
+	 * @param x 
+	 * @param y 
+	 */
+	contains(x: number, y: number): boolean {
+		let nCross = 0,
+			point = [x, y],
+			APoints = this.pointArr,
+			length = APoints.length,
+			p1, p2, i, xinters;
+		p1 = APoints[0];
+		for (i = 1; i <= length; i++) {
+			p2 = APoints[i % length];
+			if (
+				point[0] > Math.min(p1.x, p2.x) &&
+				point[0] <= Math.max(p1.x, p2.x)
+			) {
+				if (point[1] <= Math.max(p1.y, p2.y)) {
+					if (p1.x != p2.x) {
+						//计算位置信息
+						xinters = (point[0] - p1.x) * (p2.y - p1.y) / (p2.x - p1.x) + p1.y;
+						if (p1.y == p2.y || point[1] <= xinters) {
+							nCross++
+						}
+					}
+				}
+			}
+			p1 = p2;
+		}
+		console.log(nCross % 2 === 1)
+		return nCross % 2 === 1
+	}
+	/**
+	 * Item绘制操作
+	 *
+	 * @param   painter       painter对象
+	 * @param   rect          绘制区域
+	 */
+	onDraw(painter: SPainter, rect: SRect): void {
+		if (this.pointArr.length) {
+			painter.pen = new SPen(this.color, this.width);
+			painter.drawPolygon(this.pointArr)
+		}
+	}
+} // Class SGraphyPolygonItem

+ 70 - 0
src/assets/graphy/SGraphy/newItems/SGraphyRectItem.ts

@@ -0,0 +1,70 @@
+
+import { SGraphyItem } from '@sybotan-web/graphy'
+import { SRect, SSize, SPoint } from "@sybotan-web/base";
+import { SPen, SPainter, SColor } from "@sybotan-web/draw";
+
+/**
+ * 矩形Item类
+ *
+ */
+export class SGraphyRectItem extends SGraphyItem {
+  startX: number;
+  startY: number;
+  width: number;
+  height: number;
+  color: SColor = SColor.Black;
+  isVirtual: boolean = false;
+	/**
+	 * 构造函数
+	 *
+	 * @param startX  线的起始x坐标
+   * @param startY  线的起始y坐标
+   * @param width   矩形的宽度
+   * @param height  矩形的宽度
+	 * @param color   矩形填充的颜色 
+	 * @param parent    
+   * @param isVirtual    是否为虚线
+	 */
+  constructor(
+    parent: SGraphyItem | null,
+    startX: number,
+    startY: number,
+    width: number,
+    height: number,
+    color: SColor = SColor.Black,
+    isVirtual: boolean = false
+  ) {
+    super(parent);
+    this.startX = startX
+    this.startY = startY
+    this.width = width;
+    this.height = height
+    this.color = color;
+    this.isVirtual = isVirtual;
+  } // Constructor()
+
+	/**
+	 * Item对象边界区域
+	 * 
+	 * @return SRect
+	 */
+  boundingRect(): SRect {
+    return new SRect(
+      this.startX,
+      this.startY,
+      this.width,
+      this.height
+    );
+  } // Function boundingRect()
+
+	/**
+	 * Item绘制操作
+	 *
+	 * @param   painter       painter对象
+	 * @param   rect          绘制区域
+	 */
+  onDraw(painter: SPainter, rect: SRect): void {
+    painter.pen = new SPen(this.color, this.width);
+    painter.drawRect(this.startX,this.startY,this.width,this.height)
+  }
+} // Class SGraphyRectItem

+ 83 - 0
src/assets/graphy/SGraphy/newItems/SGraphyWallItem.ts

@@ -0,0 +1,83 @@
+
+import { SGraphyItem } from '@sybotan-web/graphy'
+import { SRect, SSize, SPoint } from "@sybotan-web/base";
+import { SPen, SPainter, SColor } from "@sybotan-web/draw";
+
+/**
+ * 墙Item类
+ *
+ */
+export class SGraphyWallItem extends SGraphyItem {
+	pointArr: SPoint[];
+	isVirtual: boolean = false;
+	color: SColor = SColor.Black;
+	width: number = 1;
+	/**
+	 * 构造函数
+	 *
+	 * @param pointArr  点坐标list
+	 * @param isVirtual 墙类型(实体墙-虚拟墙)
+	 * @param color  墙的颜色
+	 * @param width   墙的宽度
+	 * @param parent    
+	 */
+	constructor(
+		parent: SGraphyItem | null,
+		pointArr: SPoint[],
+		isVirtual: boolean = false,
+		color: SColor = SColor.Black,
+		width: number = 1,
+	) {
+		super(parent);
+		this.isVirtual = isVirtual;
+		this.pointArr = pointArr;
+		this.color = color;
+		this.width = width;
+	} // Constructor()
+
+	/**
+	 * Item对象边界区域
+	 * 
+	 * @return SRect
+	 */
+	boundingRect(): SRect {
+		let minX = this.pointArr[0].x;
+		let maxX = minX;
+		let minY = this.pointArr[0].y;
+		let maxY = minY;
+		for (let i = 1; i < this.pointArr.length; i++) {
+			if (this.pointArr[i].x < minX) {
+				minX = this.pointArr[i].x
+			}
+			if (this.pointArr[i].y < minY) {
+				minY = this.pointArr[i].y
+			}
+			if (this.pointArr[i].x > maxX) {
+				maxX = this.pointArr[i].x
+			}
+			if (this.pointArr[i].y > maxY) {
+				maxY = this.pointArr[i].y
+			}
+		}
+
+		return new SRect(
+			minX,
+			minY,
+			maxX - minX,
+			maxY - minY
+		);
+	} // Function boundingRect()
+
+	/**
+	 * Item绘制操作
+	 *
+	 * @param   painter       painter对象
+	 * @param   rect          绘制区域
+	 */
+	onDraw(painter: SPainter, rect: SRect): void {
+		if (this.pointArr.length) {
+			painter.pen = new SPen(this.color, this.width);
+			painter.drawPolyline(this.pointArr)
+		}
+	}
+} // Class SGraphyPolygonItem