66 lines
2.5 KiB
JavaScript
66 lines
2.5 KiB
JavaScript
|
import { Graphics } from 'pixi.js';
|
||
|
import { JlGraphic, VectorText } from 'jl-graphic';
|
||
|
|
||
|
const spksSwitchConsts = {
|
||
|
codeFontSize: 12,
|
||
|
codeColor: 0xffffff,
|
||
|
bodyLineColor: 0xffffff,
|
||
|
bodyLineWidth: 4,
|
||
|
bodyRectLineColor: 0xffffff,
|
||
|
bodyRectLineWidth: 2,
|
||
|
bodyRectWidth: 20,
|
||
|
bodyRectHeight: 20,
|
||
|
bodyColor: 0x000000,
|
||
|
};
|
||
|
class SpksSwitch extends JlGraphic {
|
||
|
static Type = 'spksSwitch';
|
||
|
datas;
|
||
|
codeGraph = new VectorText('');
|
||
|
rectBody = new Graphics();
|
||
|
lineBody = new Graphics();
|
||
|
textGraph = new VectorText('S');
|
||
|
constructor(datas) {
|
||
|
super(SpksSwitch.Type);
|
||
|
this.datas = datas;
|
||
|
this.addChild(this.codeGraph);
|
||
|
this.addChild(this.rectBody);
|
||
|
this.addChild(this.lineBody);
|
||
|
this.addChild(this.textGraph);
|
||
|
this.textGraph.name = 'spks_switch_code';
|
||
|
}
|
||
|
doRepaint() {
|
||
|
const codeGraph = this.codeGraph;
|
||
|
codeGraph.text = this.datas.code;
|
||
|
codeGraph.style.fill = spksSwitchConsts.codeColor;
|
||
|
codeGraph.setVectorFontSize(spksSwitchConsts.codeFontSize);
|
||
|
const codeTransform = this.datas?.childTransforms?.find((item) => item.name === 'spks_switch_code');
|
||
|
if (codeTransform) {
|
||
|
const position = codeTransform?.transform.position;
|
||
|
const rotation = codeTransform?.transform?.rotation;
|
||
|
codeGraph.position.set(position?.x, position?.y);
|
||
|
codeGraph.rotation = rotation || 0;
|
||
|
}
|
||
|
else {
|
||
|
codeGraph.position.set(20, 0);
|
||
|
}
|
||
|
codeGraph.anchor.set(0.5);
|
||
|
this.textGraph.style.fill = spksSwitchConsts.codeColor;
|
||
|
this.textGraph.setVectorFontSize(spksSwitchConsts.codeFontSize);
|
||
|
this.textGraph.anchor.set(0.5);
|
||
|
this.rectBody.clear();
|
||
|
this.rectBody.beginFill(spksSwitchConsts.bodyColor, 0);
|
||
|
this.rectBody.lineStyle(spksSwitchConsts.bodyRectLineWidth, spksSwitchConsts.bodyRectLineColor);
|
||
|
this.rectBody.drawRect(-spksSwitchConsts.bodyRectWidth / 2, -spksSwitchConsts.bodyRectHeight / 2, spksSwitchConsts.bodyRectWidth, spksSwitchConsts.bodyRectHeight);
|
||
|
this.rectBody.endFill();
|
||
|
this.lineBody.clear();
|
||
|
const lineY = this.datas.flip
|
||
|
? spksSwitchConsts.bodyRectHeight / 2
|
||
|
: -spksSwitchConsts.bodyRectHeight / 2;
|
||
|
this.lineBody.lineStyle(spksSwitchConsts.bodyLineWidth, spksSwitchConsts.bodyLineColor);
|
||
|
this.lineBody.moveTo(-spksSwitchConsts.bodyRectWidth / 2, lineY);
|
||
|
this.lineBody.lineTo(spksSwitchConsts.bodyRectWidth / 2, lineY);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export { SpksSwitch };
|