72 lines
2.0 KiB
JavaScript
72 lines
2.0 KiB
JavaScript
|
import { Point } from 'pixi.js';
|
||
|
import { GraphicDrawAssistant, pointBox, GraphicInteractionPlugin } from 'jl-graphic';
|
||
|
import { Separator } from './Separator.js';
|
||
|
|
||
|
class SeparatorDraw extends GraphicDrawAssistant {
|
||
|
SeparatorGraph;
|
||
|
constructor(app, template, data) {
|
||
|
super(app, template, 'sym_o_square', '分隔符Separator');
|
||
|
this.SeparatorGraph = this.graphicTemplate.new(data);
|
||
|
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 };
|