Fix resizing of screen canvas to ensure it fits within the area in the ev3 svg (#365)

This commit is contained in:
Sam El-Husseini 2018-03-08 14:34:27 -08:00 committed by GitHub
parent 994e57c395
commit 49dc3b0a75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -504,12 +504,12 @@ namespace pxsim.visuals {
const bBox = this.layoutView.getBrick().getScreenBBox(); const bBox = this.layoutView.getBrick().getScreenBBox();
if (!bBox || bBox.width == 0) return; if (!bBox || bBox.width == 0) return;
const scale = (bBox.width - 4) / SCREEN_WIDTH; const scale = (bBox.height - 2) / SCREEN_HEIGHT;
this.screenScaledWidth = (bBox.width - 4); this.screenScaledHeight = (bBox.height - 2);
this.screenScaledHeight = this.screenScaledWidth / SCREEN_WIDTH * SCREEN_HEIGHT; this.screenScaledWidth = this.screenScaledHeight / SCREEN_HEIGHT * SCREEN_WIDTH;
this.screenCanvas.style.top = `${bBox.top + 2}px`; this.screenCanvas.style.top = `${bBox.top + 1}px`;
this.screenCanvas.style.left = `${bBox.left + 2}px`; this.screenCanvas.style.left = `${bBox.left + ((bBox.width - this.screenScaledWidth) * 0.5)}px`;
this.screenCanvas.width = this.screenScaledWidth; this.screenCanvas.width = this.screenScaledWidth;
this.screenCanvas.height = this.screenScaledHeight; this.screenCanvas.height = this.screenScaledHeight;