pxt-calliope/sim/visuals/genericpart.ts

40 lines
1.4 KiB
TypeScript
Raw Normal View History

namespace pxsim.visuals {
export function mkGenericPartSVG(partVisual: PartVisualDefinition): SVGAndSize<SVGImageElement> {
let imgAndSize = mkImageSVG({
image: partVisual.image,
width: partVisual.width,
height: partVisual.height,
imageUnitDist: partVisual.pinDist,
targetUnitDist: PIN_DIST
});
return imgAndSize;
}
2016-09-01 04:01:59 +02:00
export class GenericPart implements IBoardComponent<any> {
public style: string = "";
public element: SVGElement;
2016-09-01 04:01:59 +02:00
defs: SVGElement[] = [];
constructor(partVisual: PartVisualDefinition) {
let imgAndSize = mkGenericPartSVG(partVisual);
2016-09-01 04:01:59 +02:00
let img = imgAndSize.el;
let scaleFn = mkScaleFn(partVisual.pinDist, PIN_DIST);
let [pinX, pinY] = partVisual.firstPin;
let left = -scaleFn(pinX);
let top = -scaleFn(pinY);
translateEl(img, [left, top]); // So that 0,0 is on the first pin
this.element = svg.elt("g");
this.element.appendChild(img);
}
2016-09-01 04:01:59 +02:00
moveToCoord(xy: Coord): void {
2016-09-01 04:01:59 +02:00
translateEl(this.element, xy);
}
2016-09-01 04:01:59 +02:00
//unused
init(bus: EventBus, state: any, svgEl: SVGSVGElement, gpioPins: string[], otherArgs: string[]): void { }
updateState(): void { }
updateTheme(): void { }
}
}