2024-01-02 17:03:15 +08:00
|
|
|
import { Point } from 'pixi.js';
|
|
|
|
import { GraphicDrawAssistant, pointBox, GraphicInteractionPlugin } from 'jl-graphic';
|
|
|
|
import { Separator } from './Separator.js';
|
|
|
|
|
|
|
|
class SeparatorDraw extends GraphicDrawAssistant {
|
|
|
|
SeparatorGraph;
|
2024-01-03 16:43:48 +08:00
|
|
|
constructor(app, template) {
|
2024-01-02 17:03:15 +08:00
|
|
|
super(app, template, 'sym_o_square', '分隔符Separator');
|
2024-01-03 16:43:48 +08:00
|
|
|
this.SeparatorGraph = this.graphicTemplate.new();
|
2024-01-02 17:03:15 +08:00
|
|
|
this.container.addChild(this.SeparatorGraph);
|
|
|
|
SeparatorInteraction.init(app);
|
|
|
|
}
|
|
|
|
bind() {
|
|
|
|
super.bind();
|
|
|
|
this.SeparatorGraph.loadData(this.graphicTemplate.datas);
|
|
|
|
this.SeparatorGraph.doRepaint();
|
|
|
|
}
|
|
|
|
onLeftDown(e) {
|
|
|
|
this.container.position.copyFrom(this.toCanvasCoordinates(e.global));
|
|
|
|
this.createAndStore(true);
|
|
|
|
}
|
|
|
|
redraw(p) {
|
|
|
|
this.container.position.copyFrom(p);
|
|
|
|
}
|
|
|
|
prepareData(data) {
|
|
|
|
data.transform = this.container.saveTransform();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//碰撞检测
|
|
|
|
class SeparatorGraphicHitArea {
|
|
|
|
separator;
|
|
|
|
constructor(separator) {
|
|
|
|
this.separator = separator;
|
|
|
|
}
|
|
|
|
contains(x, y) {
|
|
|
|
let contains = false;
|
|
|
|
const p = new Point(x, y);
|
|
|
|
const r = this.separator.getLocalBounds();
|
|
|
|
contains = pointBox(p, r);
|
|
|
|
return contains;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class SeparatorInteraction extends GraphicInteractionPlugin {
|
|
|
|
static Name = 'Separator_transform';
|
|
|
|
constructor(app) {
|
|
|
|
super(SeparatorInteraction.Name, app);
|
|
|
|
}
|
|
|
|
static init(app) {
|
|
|
|
return new SeparatorInteraction(app);
|
|
|
|
}
|
|
|
|
filter(...grahpics) {
|
|
|
|
return grahpics
|
|
|
|
.filter((g) => g.type === Separator.Type)
|
|
|
|
.map((g) => g);
|
|
|
|
}
|
|
|
|
bind(g) {
|
|
|
|
g.eventMode = 'static';
|
|
|
|
g.cursor = 'pointer';
|
|
|
|
g.scalable = true;
|
|
|
|
g.rotatable = true;
|
|
|
|
g.rectGraphic.hitArea = new SeparatorGraphicHitArea(g);
|
|
|
|
}
|
|
|
|
unbind(g) {
|
|
|
|
g.eventMode = 'none';
|
|
|
|
g.scalable = false;
|
|
|
|
g.rotatable = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export { SeparatorDraw, SeparatorGraphicHitArea, SeparatorInteraction };
|