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-02 22:38:54 +01:00
|
|
|
this.group.setAttribute("transform", `scale(0.25, 0.25)`)
|
|
|
|
|
|
|
|
const xml = pxsim.visuals.normalizeXml(this.id, pxsim.visuals.REMOVE_SVG);
|
|
|
|
const content = svg.parseString(xml);
|
|
|
|
this.group.appendChild(content);
|
|
|
|
|
|
|
|
const btns: Map<InfraredRemoteButton> = {
|
|
|
|
"center": InfraredRemoteButton.CenterBeacon,
|
|
|
|
"topleft": InfraredRemoteButton.TopLeft,
|
|
|
|
"topright": InfraredRemoteButton.TopRight,
|
|
|
|
"bottomleft": InfraredRemoteButton.BottomLeft,
|
|
|
|
"bottomright": InfraredRemoteButton.BottomRight
|
|
|
|
}
|
|
|
|
|
|
|
|
Object.keys(btns).forEach(bid => {
|
|
|
|
const cid = btns[bid];
|
|
|
|
const bel = content.getElementById(pxsim.visuals.normalizeId(this.id, bid));
|
|
|
|
bel.className += " sim-button";
|
|
|
|
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-02 22:38:54 +01:00
|
|
|
return 98.3;
|
2018-02-02 18:48:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getInnerHeight() {
|
2018-02-02 22:38:54 +01:00
|
|
|
return 110.8;
|
2018-02-02 18:48:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|