123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- /*
- * ********************************************************************************************************************
- *
- * :*$@@%$*: ;: ;; ;;
- * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
- * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
- * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
- * =@* %! @ $= % %@= =%@! %=
- * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
- * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
- * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
- * $@* ;@@@%=!: *@*
- * =@$ ;;;!=%@@@@=! =@!
- * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2019. 北京上格云技术有限公司
- * ;%@@$=$@@%* *@@@$=%@@%;
- * ::;:: ::;:: All rights reserved.
- *
- * ********************************************************************************************************************
- */
- import { SGraphyItem, SMouseEvent } from "@sybotan-web/graphy/lib";
- import {
- SColor,
- SPainter,
- SPath2D,
- SPoint,
- SRect
- } from "@sybotan-web/draw/lib";
- /**
- * 蒙版item
- *
- * @author 郝建龙
- */
- export class SceneMarkItem extends SGraphyItem {
- /** 轮廓线坐标 */
- outLine: SPoint[] = [];
- /** 是否闭合 */
- closeFlag = false;
- /** 鼠标移动点 */
- private lastPoint = new SPoint();
- /** 蒙版 */
- private mask = new SPath2D();
- /**
- * 构造函数
- *
- * @param parent 指向父对象
- * @param data 蒙版起点数据
- */
- constructor(parent: SGraphyItem | null, data: SPoint) {
- super(parent);
- this.outLine.push(data);
- this.lastPoint = data;
- this.zOrder = Number.MAX_SAFE_INTEGER;
- } // Constructor
- /**
- * 鼠标按下事件
- *
- * @param event 事件参数
- * @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;
- this.lastPoint.y = p.y;
- this.outLine.push(p);
- }
- return true;
- } // Function onMouseDown()
- /**
- * 鼠标移动事件
- *
- * @param event 事件参数
- * @return boolean
- */
- onMouseMove(event: SMouseEvent): boolean {
- if (!this.closeFlag) {
- this.lastPoint = new SPoint(event.x, event.y);
- }
- return true;
- } // Function onMouseMove()
- /***
- * 键盘按键弹起事件
- *
- * @param event 事件参数
- */
- onKeyUp(event: KeyboardEvent): void {
- if (event.keyCode == 13 && this.outLine.length >= 3) {
- this.createMask();
- }
- } // Function onKeyUp()
- /**
- * 创建蒙版
- *
- */
- createMask(): void {
- this.closeFlag = true;
- this.mask = new SPath2D();
- this.mask.moveTo(Number.MIN_SAFE_INTEGER, Number.MIN_SAFE_INTEGER);
- this.mask.lineTo(Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER);
- this.mask.lineTo(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
- 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();
- }
- 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对象
- * @param rect 绘制区域
- */
- onDraw(painter: SPainter, rect?: SRect): void {
- if (this.closeFlag) {
- painter.pen.color = SColor.Transparent;
- painter.brush.color = new SColor("#FFFF0080");
- painter.drawPath(this.mask);
- } else {
- painter.pen.color = new SColor("#ff0000");
- painter.drawPolyline(this.outLine);
- painter.drawLine(
- this.outLine[this.outLine.length - 1],
- this.lastPoint
- );
- }
- } // Function onDraw()
- } // Class SceneMarkItem
|