This commit is contained in:
fan 2023-08-07 10:32:52 +08:00
commit 4d82d8d4f2
3 changed files with 6 additions and 38 deletions

View File

@ -4,7 +4,7 @@ import {
GraphicInteractionPlugin, GraphicInteractionPlugin,
JlDrawApp, JlDrawApp,
JlGraphic, JlGraphic,
linePoint, pointBox,
} from 'src/jl-graphic'; } from 'src/jl-graphic';
import { IRectData, Rect, RectTemplate } from './Rect'; import { IRectData, Rect, RectTemplate } from './Rect';
@ -78,18 +78,10 @@ export class RectGraphicHitArea implements IHitArea {
this.rect = rect; this.rect = rect;
} }
contains(x: number, y: number): boolean { contains(x: number, y: number): boolean {
const boxRect = this.rect.getLocalBounds();
let contains = false; let contains = false;
const datas = this.rect.datas;
const tolerance = datas.lineWidth;
const p1 = new Point(0, 0);
const p2 = new Point(p1.x + datas.width, p1.y);
const p3 = new Point(p1.x + datas.width, p1.y + datas.height);
const p4 = new Point(p1.x, p1.y + datas.height);
const p = new Point(x, y); const p = new Point(x, y);
contains = contains || linePoint(p1, p2, p, tolerance); contains = contains || pointBox(p, boxRect);
contains = contains || linePoint(p2, p3, p, tolerance);
contains = contains || linePoint(p3, p4, p, tolerance);
contains = contains || linePoint(p4, p1, p, tolerance);
return contains; return contains;
} }
} }

View File

@ -58,7 +58,9 @@ export class TrainWindow extends JlGraphic {
TrainWindowConsts.lineWidth, TrainWindowConsts.lineWidth,
new Color(TrainWindowConsts.lineColor) new Color(TrainWindowConsts.lineColor)
); );
rectGraphic.beginFill(TrainWindowConsts.lineColor, 0.00001);
rectGraphic.drawRect(0, 0, width, TrainWindowConsts.height); rectGraphic.drawRect(0, 0, width, TrainWindowConsts.height);
rectGraphic.endFill;
const rectP = new Rectangle(0, 0, width, TrainWindowConsts.height); const rectP = new Rectangle(0, 0, width, TrainWindowConsts.height);
rectGraphic.pivot = getRectangleCenter(rectP); rectGraphic.pivot = getRectangleCenter(rectP);
} }

View File

@ -1,4 +1,4 @@
import { FederatedPointerEvent, IHitArea, Point } from 'pixi.js'; import { FederatedPointerEvent, Point } from 'pixi.js';
import { import {
AbsorbableLine, AbsorbableLine,
AbsorbablePosition, AbsorbablePosition,
@ -7,7 +7,6 @@ import {
GraphicInteractionPlugin, GraphicInteractionPlugin,
JlDrawApp, JlDrawApp,
JlGraphic, JlGraphic,
linePoint,
} from 'src/jl-graphic'; } from 'src/jl-graphic';
import { import {
@ -218,30 +217,6 @@ export class TrainWindowDraw extends GraphicDrawAssistant<
} }
} }
//碰撞检测
export class RectGraphicHitArea implements IHitArea {
rect: TrainWindow;
constructor(rect: TrainWindow) {
this.rect = rect;
}
contains(x: number, y: number): boolean {
const width = TrainWindowConsts.width;
let contains = false;
const tolerance = TrainWindowConsts.lineWidth;
const p1 = new Point(0, 0);
const p2 = new Point(width, 0);
const p3 = new Point(width, TrainWindowConsts.height);
const p4 = new Point(0, TrainWindowConsts.height);
const p = new Point(x, y);
contains = contains || linePoint(p1, p2, p, tolerance);
contains = contains || linePoint(p2, p3, p, tolerance);
contains = contains || linePoint(p3, p4, p, tolerance);
contains = contains || linePoint(p4, p1, p, tolerance);
return contains;
}
}
/** /**
* *
* @param polygon * @param polygon
@ -284,7 +259,6 @@ export class TrainWindowInteraction extends GraphicInteractionPlugin<TrainWindow
g.cursor = 'pointer'; g.cursor = 'pointer';
g.scalable = true; g.scalable = true;
g.rotatable = true; g.rotatable = true;
g.rectGraphic.hitArea = new RectGraphicHitArea(g);
g.on('transformstart', this.move, this); g.on('transformstart', this.move, this);
} }
unbind(g: TrainWindow): void { unbind(g: TrainWindow): void {