From fd5aa299695181634f7eb835f7549277c3a5df33 Mon Sep 17 00:00:00 2001 From: Daniel Becker Date: Wed, 1 Apr 2020 14:35:41 -0500 Subject: [PATCH] Added scaling of shotfeed --- .idea/workspace.xml | 96 ++++++++++++++++----------------- src/components/ShotFeed.js | 14 +++-- src/util/TargetScreenManager.js | 20 +++---- 3 files changed, 63 insertions(+), 67 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index f5eff12..17b703d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,11 +2,8 @@ - - - - - + + @@ -37,7 +34,7 @@ - + @@ -47,13 +44,10 @@ - + - - - - - + + @@ -70,10 +64,10 @@ - + - + @@ -86,7 +80,7 @@ - + @@ -109,11 +103,11 @@ - + - - + + @@ -172,7 +166,6 @@ @@ -304,12 +298,12 @@ - + - @@ -391,13 +385,6 @@ - - - - - - - @@ -466,20 +453,10 @@ - - - - - - - - - - - + @@ -507,16 +484,6 @@ - - - - - - - - - - @@ -539,7 +506,7 @@ - + @@ -547,5 +514,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/components/ShotFeed.js b/src/components/ShotFeed.js index 39fcc5e..377817f 100644 --- a/src/components/ShotFeed.js +++ b/src/components/ShotFeed.js @@ -11,6 +11,7 @@ class ShotFeed extends React.Component { } this.canvasRef = React.createRef(); + this.canvasParentRef = React.createRef(); } updateNoise(e) { @@ -41,8 +42,15 @@ class ShotFeed extends React.Component { outputDimensions, 200); } - const scaleRows = .75 - const scaleColumns = .75 + const parentWidth = this.canvasParentRef.current.offsetWidth * .9; + const windowHeight = window.innerHeight * .6; + let scaleColumns = parentWidth / outputDimensions.columns + let scaleRows = windowHeight / outputDimensions.rows + if (scaleRows < scaleColumns) { + scaleColumns = scaleRows + } else { + scaleRows = scaleColumns + } const canvas = this.canvasRef.current; canvas.width = outputDimensions.columns * scaleColumns; canvas.height = outputDimensions.rows * scaleRows; @@ -61,7 +69,7 @@ class ShotFeed extends React.Component { render() { return ( -
+
diff --git a/src/util/TargetScreenManager.js b/src/util/TargetScreenManager.js index 4228ab4..3f28cce 100644 --- a/src/util/TargetScreenManager.js +++ b/src/util/TargetScreenManager.js @@ -12,6 +12,8 @@ class TargetScreenManager { this.maxWidth = canvas.width; this.ctx = canvas.getContext('2d'); console.log("Target canvas attached"); + + this.wipeScreen(); } detachCanvas() { @@ -19,37 +21,29 @@ class TargetScreenManager { console.log("Target canvas detached") } - // showCalibrationScreen() { - // let image = new Image(); - // image.onload = () => { - // this.ctx.drawImage(image, 0, 0, this.maxWidth, this.maxHeight); - // } - // image.src = "/assets/checkerboard.svg"; - // } - showCalibrationScreen(cornerNumber) { let textCoordinates = {x: null, y: null}; - const textWidth = 125; + const textWidth = 190; switch(cornerNumber) { case 1: - textCoordinates = {x: 20, y: 30} + textCoordinates = {x: 10, y: 30} break; case 2: textCoordinates = {x: this.maxWidth - 30 - textWidth, y: 30} break; case 3: - textCoordinates = {x: this.maxWidth - 30 - textWidth, y: this.maxHeight - 30} + textCoordinates = {x: this.maxWidth - 30 - textWidth, y: this.maxHeight - 10} break; case 4: - textCoordinates = {x: 20, y: this.maxHeight - 30} + textCoordinates = {x: 10, y: this.maxHeight - 10} break; } this.wipeScreen(); - this.ctx.font = "20px Times" + this.ctx.font = "30px Times" this.ctx.fillStyle = "black" this.ctx.fillText("Click this corner!", textCoordinates.x, textCoordinates.y); }