2018-02-02 18:48:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
namespace pxsim.visuals {
|
|
|
|
enum InfraredRemoteButton {
|
|
|
|
CenterBeacon = 0x01,
|
|
|
|
TopLeft = 0x02,
|
|
|
|
BottomLeft = 0x04,
|
|
|
|
TopRight = 0x08,
|
|
|
|
BottomRight = 0x10,
|
|
|
|
}
|
|
|
|
|
|
|
|
export class RemoteBeaconButtonsControl extends ControlView<InfraredSensorNode> {
|
|
|
|
private group: SVGGElement;
|
2018-02-02 22:38:54 +01:00
|
|
|
private id = Math.random().toString();
|
|
|
|
|
2018-02-02 18:48:27 +01:00
|
|
|
getInnerView() {
|
|
|
|
this.group = svg.elt("g") as SVGGElement;
|
2018-02-07 18:53:58 +01:00
|
|
|
this.group.setAttribute("transform", `scale(0.9, 0.9)`)
|
2018-02-02 22:38:54 +01:00
|
|
|
|
|
|
|
const xml = pxsim.visuals.normalizeXml(this.id, pxsim.visuals.REMOVE_SVG);
|
|
|
|
const content = svg.parseString(xml);
|
|
|
|
this.group.appendChild(content);
|
|
|
|
|
|
|
|
const btns: Map<InfraredRemoteButton> = {
|
2018-02-07 18:53:58 +01:00
|
|
|
"centerbeacon": InfraredRemoteButton.CenterBeacon,
|
2018-02-02 22:38:54 +01:00
|
|
|
"topleft": InfraredRemoteButton.TopLeft,
|
|
|
|
"topright": InfraredRemoteButton.TopRight,
|
|
|
|
"bottomleft": InfraredRemoteButton.BottomLeft,
|
|
|
|
"bottomright": InfraredRemoteButton.BottomRight
|
|
|
|
}
|
2018-02-05 22:57:24 +01:00
|
|
|
|
2018-02-02 22:38:54 +01:00
|
|
|
Object.keys(btns).forEach(bid => {
|
|
|
|
const cid = btns[bid];
|
|
|
|
const bel = content.getElementById(pxsim.visuals.normalizeId(this.id, bid));
|
2018-02-05 22:57:24 +01:00
|
|
|
bel.setAttribute("class", "sim-button");
|
2018-02-02 22:38:54 +01:00
|
|
|
pointerEvents.down.forEach(evid => bel.addEventListener(evid, ev => {
|
|
|
|
ev3board().remoteState.setPressed(cid, true);
|
|
|
|
}));
|
|
|
|
bel.addEventListener(pointerEvents.leave, ev => {
|
|
|
|
ev3board().remoteState.setPressed(cid, false);
|
|
|
|
});
|
|
|
|
bel.addEventListener(pointerEvents.up, ev => {
|
|
|
|
ev3board().remoteState.setPressed(cid, false);
|
|
|
|
});
|
|
|
|
});
|
2018-02-02 18:48:27 +01:00
|
|
|
return this.group;
|
|
|
|
}
|
|
|
|
|
|
|
|
getInnerWidth() {
|
2018-02-07 18:53:58 +01:00
|
|
|
return 80;
|
2018-02-02 18:48:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getInnerHeight() {
|
2018-02-07 18:53:58 +01:00
|
|
|
return 123.773;
|
2018-02-02 18:48:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|