2019-02-08 18:16:42 +00:00
|
|
|
<!doctype html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>display</title>
|
|
|
|
<style>
|
|
|
|
body{
|
|
|
|
background: #000;
|
|
|
|
padding: 0;
|
|
|
|
margin: 0;
|
|
|
|
max-width: 100%;
|
|
|
|
max-height: 100vh;
|
|
|
|
}
|
|
|
|
body.meter {
|
|
|
|
background: rgb(117, 117, 117);
|
|
|
|
}
|
|
|
|
#img {
|
|
|
|
position: absolute;
|
|
|
|
/*background-image: url(".../img/background.jpg");*/
|
|
|
|
background-repeat:no-repeat;
|
|
|
|
background-size: contain;
|
|
|
|
background-position: center;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
bottom: 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
#can{
|
|
|
|
margin: 0;
|
|
|
|
background: #fff;
|
|
|
|
display: none;
|
|
|
|
position: fixed;
|
2019-08-25 19:26:43 +00:00
|
|
|
left: 50%;
|
|
|
|
transform: translateX(-50%);
|
2019-02-08 18:16:42 +00:00
|
|
|
top: 0;
|
|
|
|
}
|
|
|
|
#can.show{
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="img">
|
|
|
|
</div>
|
|
|
|
<canvas id="can">
|
|
|
|
</canvas>
|
|
|
|
<script>
|
|
|
|
'use strict';
|
|
|
|
const { remote, ipcRenderer } = require('electron')
|
|
|
|
|
|
|
|
async function setImage (src) {
|
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
|
//let img = new Image()
|
|
|
|
let img = document.getElementById('img')
|
|
|
|
let body = document.querySelector('body')
|
|
|
|
if (body.classList.contains('meter')) {
|
|
|
|
body.classList.remove('meter')
|
|
|
|
}
|
|
|
|
|
|
|
|
img.style.backgroundImage = `url('${src}')`;
|
2019-06-25 16:13:15 +00:00
|
|
|
});
|
2019-02-08 18:16:42 +00:00
|
|
|
}
|
2019-06-18 19:47:17 +00:00
|
|
|
async function onMeter () {
|
2019-06-25 16:13:15 +00:00
|
|
|
console.log('meter')
|
2019-06-18 19:47:17 +00:00
|
|
|
const body = document.querySelector('body')
|
2019-02-08 18:16:42 +00:00
|
|
|
if (!body.classList.contains('meter')) {
|
|
|
|
body.classList.add('meter')
|
|
|
|
}
|
|
|
|
}
|
2019-06-25 16:13:15 +00:00
|
|
|
async function onFocus () {
|
|
|
|
console.log('focus')
|
|
|
|
const can = document.getElementById('can')
|
|
|
|
const dpr = window.devicePixelRatio || 1
|
|
|
|
let ctx;
|
|
|
|
if (!can.classList.contains('show')) {
|
|
|
|
can.classList.add('show')
|
|
|
|
}
|
|
|
|
can.width = window.innerWidth * dpr
|
|
|
|
can.height = window.innerHeight * dpr
|
|
|
|
|
|
|
|
can.style.width = `${window.innerWidth}px`
|
|
|
|
can.style.height = `${window.innerHeight}px`
|
|
|
|
|
|
|
|
ctx = can.getContext('2d')
|
|
|
|
ctx.scale(dpr, dpr)
|
|
|
|
|
|
|
|
try{
|
|
|
|
await drawFocus(can, ctx)
|
|
|
|
} catch (err) {
|
|
|
|
alert(JSON.stringify(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
async function drawFocus (can, ctx) {
|
|
|
|
const count = 20
|
|
|
|
const half = Math.round(count / 2)
|
|
|
|
const dpr = window.devicePixelRatio || 1
|
|
|
|
const w = can.width / dpr
|
|
|
|
const h = can.height / dpr
|
2019-06-26 20:07:00 +00:00
|
|
|
const longest = w >= h ? w * 1.5 : h * 1.5
|
|
|
|
const opp = Math.tan(360 / (count * 32)) * longest / 10
|
|
|
|
|
|
|
|
//console.log(`l: ${longest}`)
|
|
|
|
//console.log(`${360 / (count * 8)}deg`)
|
|
|
|
//console.log(`o: ${opp}`)
|
|
|
|
|
2019-06-25 16:13:15 +00:00
|
|
|
for (let i = 0; i < count; i++) {
|
2019-06-26 20:07:00 +00:00
|
|
|
ctx.beginPath()
|
2019-06-25 16:13:15 +00:00
|
|
|
ctx.moveTo(w / 2, h / 2)
|
2019-06-26 20:07:00 +00:00
|
|
|
ctx.lineTo((w / 2) + opp, longest)
|
|
|
|
ctx.lineTo((w / 2) - opp, longest)
|
2019-06-25 16:13:15 +00:00
|
|
|
ctx.fill()
|
|
|
|
ctx.translate(w / 2, h / 2);
|
|
|
|
ctx.rotate((360 / count) * Math.PI / 180)
|
|
|
|
ctx.translate(- w / 2, -h / 2)
|
|
|
|
}
|
|
|
|
}
|
2019-08-25 19:26:43 +00:00
|
|
|
async function onField (evt, arg) {
|
2019-06-25 16:13:15 +00:00
|
|
|
console.log('field guide')
|
2019-08-25 19:26:43 +00:00
|
|
|
console.dir(arg)
|
2019-02-08 18:16:42 +00:00
|
|
|
const can = document.getElementById('can')
|
2019-06-25 16:13:15 +00:00
|
|
|
const dpr = window.devicePixelRatio || 1
|
|
|
|
let ctx;
|
2019-02-08 18:16:42 +00:00
|
|
|
if (!can.classList.contains('show')) {
|
|
|
|
can.classList.add('show')
|
|
|
|
}
|
2019-08-25 19:26:43 +00:00
|
|
|
if (arg.ratio) {
|
|
|
|
can.width = (window.innerHeight * arg.ratio) * dpr
|
|
|
|
} else {
|
|
|
|
can.width = window.innerWidth * dpr
|
|
|
|
}
|
|
|
|
can.height = window.innerHeight * dpr
|
2019-06-25 16:13:15 +00:00
|
|
|
|
2019-08-25 19:26:43 +00:00
|
|
|
if (arg.ratio) {
|
|
|
|
can.style.width = `${window.innerHeight * arg.ratio}px`
|
|
|
|
} else {
|
|
|
|
can.style.width = `${window.innerWidth}px`
|
|
|
|
}
|
2019-02-08 18:16:42 +00:00
|
|
|
can.style.height = `${window.innerHeight}px`
|
2019-06-25 16:13:15 +00:00
|
|
|
|
|
|
|
ctx = can.getContext('2d')
|
|
|
|
ctx.scale(dpr, dpr)
|
|
|
|
|
2019-02-08 18:16:42 +00:00
|
|
|
try{
|
2019-06-18 19:47:17 +00:00
|
|
|
await drawField(can, ctx)
|
2019-02-08 18:16:42 +00:00
|
|
|
} catch (err) {
|
|
|
|
alert(JSON.stringify(err))
|
|
|
|
}
|
|
|
|
}
|
2019-06-18 19:47:17 +00:00
|
|
|
// draw a field guide
|
|
|
|
async function drawField (can, ctx) {
|
2019-02-08 18:16:42 +00:00
|
|
|
const count = 20
|
|
|
|
const half = Math.round(count / 2)
|
2019-06-25 16:13:15 +00:00
|
|
|
const dpr = window.devicePixelRatio || 1
|
|
|
|
const w = can.width / dpr
|
|
|
|
const h = can.height / dpr
|
2019-02-08 18:16:42 +00:00
|
|
|
const wsec = w / count
|
2019-06-25 16:13:15 +00:00
|
|
|
const hsec = h / count
|
|
|
|
const spacer = 12
|
|
|
|
const fontSize = 18;
|
2019-06-18 19:47:17 +00:00
|
|
|
|
2019-02-08 18:16:42 +00:00
|
|
|
ctx.moveTo(w / 2, 0)
|
|
|
|
ctx.lineTo(w / 2, h)
|
|
|
|
ctx.stroke()
|
|
|
|
ctx.moveTo(0, h / 2)
|
|
|
|
ctx.lineTo(w, h / 2)
|
|
|
|
ctx.stroke()
|
2019-06-18 19:47:17 +00:00
|
|
|
|
2019-02-08 18:16:42 +00:00
|
|
|
for (let i = 0; i < count; i++) {
|
|
|
|
ctx.moveTo(wsec * i, hsec * i)
|
|
|
|
ctx.lineTo(wsec * i, h - (hsec * i))
|
|
|
|
ctx.stroke()
|
|
|
|
ctx.moveTo(wsec * i, hsec * i)
|
|
|
|
ctx.lineTo(w - (wsec * i), hsec * i)
|
|
|
|
ctx.stroke()
|
|
|
|
}
|
2019-06-25 16:13:15 +00:00
|
|
|
ctx.font = `${fontSize}px Arial`
|
2019-02-08 18:16:42 +00:00
|
|
|
for (let i = 0; i < half; i++) {
|
2019-06-25 16:13:15 +00:00
|
|
|
ctx.fillText(`${(half - i)}`, (wsec * i) + spacer, (h / 2) - spacer)
|
|
|
|
//ctx.fillText(`${(half - i)}`, (w - (wsec * i)) - spacer, (h / 2) - spacer)
|
|
|
|
ctx.fillText(`${(half - i)}`, (w / 2) + spacer, (hsec * i) + spacer + (fontSize / 2) )
|
|
|
|
//ctx.fillText(`${(half - i)}`, (w / 2) + spacer, (h - (hsec * i)) - spacer)
|
2019-02-08 18:16:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
async function onDigital (event, arg) {
|
|
|
|
if (arg.src) {
|
|
|
|
try {
|
|
|
|
await setImage(arg.src)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return event.returnValue = true
|
|
|
|
}
|
|
|
|
async function onEscape (evt) {
|
|
|
|
let isEscape = false
|
|
|
|
let win
|
|
|
|
evt = evt || window.event
|
|
|
|
|
|
|
|
if ('key' in evt) {
|
|
|
|
isEscape = (evt.key == 'Escape' || evt.key == 'Esc')
|
|
|
|
} else {
|
|
|
|
isEscape = (evt.keyCode == 27)
|
|
|
|
}
|
|
|
|
if (isEscape) {
|
|
|
|
win = remote.getCurrentWindow()
|
|
|
|
win.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ipcRenderer.on('display', onDigital)
|
2019-06-18 19:47:17 +00:00
|
|
|
ipcRenderer.on('field', onField)
|
|
|
|
ipcRenderer.on('meter', onMeter)
|
2019-06-25 16:13:15 +00:00
|
|
|
ipcRenderer.on('focus', onFocus)
|
2019-02-08 18:16:42 +00:00
|
|
|
document.onkeydown = onEscape
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|