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);
|
|
|
|
}
|
2023-02-25 17:33:18 +00:00
|
|
|
body.meter #img,
|
|
|
|
body.meter #can {
|
2023-02-25 21:32:08 +00:00
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
body.image #can{
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
body.image #img {
|
|
|
|
display: block;
|
2023-02-25 17:33:18 +00:00
|
|
|
}
|
2019-02-08 18:16:42 +00:00
|
|
|
#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%;
|
2019-08-25 19:54:50 +00:00
|
|
|
top: 50%;
|
|
|
|
transform: translate(-50%,-50%);
|
2019-02-08 18:16:42 +00:00
|
|
|
}
|
|
|
|
#can.show{
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="img">
|
|
|
|
</div>
|
|
|
|
<canvas id="can">
|
|
|
|
</canvas>
|
|
|
|
<script>
|
|
|
|
'use strict';
|
2023-02-25 17:33:18 +00:00
|
|
|
const { ipcRenderer } = require('electron')
|
|
|
|
const remote = require('@electron/remote')
|
2020-02-21 07:28:26 +00:00
|
|
|
let imgTmp;
|
2024-01-19 11:49:03 +00:00
|
|
|
function delay (ms) {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
return setTimeout(resolve, ms)
|
|
|
|
})
|
|
|
|
}
|
2019-02-08 18:16:42 +00:00
|
|
|
async function setImage (src) {
|
|
|
|
return new Promise(async (resolve, reject) => {
|
2020-02-21 07:28:26 +00:00
|
|
|
imgTmp = new Image()
|
2019-02-08 18:16:42 +00:00
|
|
|
let img = document.getElementById('img')
|
|
|
|
let body = document.querySelector('body')
|
2023-02-25 17:33:18 +00:00
|
|
|
body.className = ''
|
2023-02-25 21:32:08 +00:00
|
|
|
body.classList.add('image')
|
2020-02-21 07:28:26 +00:00
|
|
|
imgTmp.onload = function () {
|
2024-01-19 11:49:03 +00:00
|
|
|
img.style.backgroundImage = `url('${src}')`
|
|
|
|
return resolve(src)
|
|
|
|
}
|
|
|
|
imgTmp.src = src
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function setBlank () {
|
|
|
|
let img = document.getElementById('img')
|
|
|
|
img.style.background = ''
|
|
|
|
img.style.backgroundUrl = ''
|
|
|
|
img.style.backgroundColor = 'black'
|
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')
|
2023-02-25 17:33:18 +00:00
|
|
|
body.className = ''
|
|
|
|
body.classList.add('meter')
|
2019-02-08 18:16:42 +00:00
|
|
|
}
|
2019-06-25 16:13:15 +00:00
|
|
|
async function onFocus () {
|
|
|
|
console.log('focus')
|
|
|
|
const can = document.getElementById('can')
|
|
|
|
const dpr = window.devicePixelRatio || 1
|
2023-02-25 17:33:18 +00:00
|
|
|
const body = document.querySelector('body')
|
2019-06-25 16:13:15 +00:00
|
|
|
let ctx;
|
2023-02-25 17:33:18 +00:00
|
|
|
body.className = ''
|
2019-06-25 16:13:15 +00:00
|
|
|
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++) {
|
2020-02-21 07:28:26 +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-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
|
2019-08-25 19:54:50 +00:00
|
|
|
const screen = window.outerWidth / window.outerHeight
|
2023-02-25 17:33:18 +00:00
|
|
|
const body = document.querySelector('body')
|
2024-01-19 11:49:03 +00:00
|
|
|
let ctx
|
2023-02-25 17:33:18 +00:00
|
|
|
body.className = ''
|
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) {
|
2019-08-25 19:54:50 +00:00
|
|
|
if (arg.ratio < screen) {
|
|
|
|
can.width = (window.innerHeight * arg.ratio) * dpr
|
|
|
|
can.height = window.innerHeight * dpr
|
|
|
|
} else {
|
2024-01-19 11:49:03 +00:00
|
|
|
can.width = window.innerWidth * dpr
|
2019-08-25 19:54:50 +00:00
|
|
|
can.height = (window.innerWidth / arg.ratio) * dpr
|
|
|
|
}
|
2019-08-25 19:26:43 +00:00
|
|
|
} else {
|
|
|
|
can.width = window.innerWidth * dpr
|
2019-08-25 19:54:50 +00:00
|
|
|
can.height = window.innerHeight * dpr
|
2019-08-25 19:26:43 +00:00
|
|
|
}
|
2019-08-25 19:54:50 +00:00
|
|
|
|
2019-06-25 16:13:15 +00:00
|
|
|
|
2019-08-25 19:26:43 +00:00
|
|
|
if (arg.ratio) {
|
2019-08-25 19:54:50 +00:00
|
|
|
if (arg.ratio < screen) {
|
|
|
|
can.style.width = `${window.innerHeight * arg.ratio}px`
|
|
|
|
can.style.height = `${window.innerHeight}px`
|
|
|
|
} else {
|
2023-02-25 07:08:05 +00:00
|
|
|
can.style.width = `${window.innerWidth}px`
|
2019-08-25 19:54:50 +00:00
|
|
|
can.style.height = `${window.innerWidth / arg.ratio}px`
|
|
|
|
}
|
2019-08-25 19:26:43 +00:00
|
|
|
} else {
|
|
|
|
can.style.width = `${window.innerWidth}px`
|
2019-08-25 19:54:50 +00:00
|
|
|
can.style.height = `${window.innerHeight}px`
|
2019-08-25 19:26:43 +00:00
|
|
|
}
|
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
|
2019-08-25 19:54:50 +00:00
|
|
|
const fontSize = 18
|
|
|
|
|
|
|
|
ctx.lineWidth = 2
|
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-08-25 19:54:50 +00:00
|
|
|
|
|
|
|
ctx.lineWidth = 1
|
|
|
|
|
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-08-25 19:54:50 +00:00
|
|
|
//left count
|
2019-06-25 16:13:15 +00:00
|
|
|
ctx.fillText(`${(half - i)}`, (wsec * i) + spacer, (h / 2) - spacer)
|
2019-08-25 19:54:50 +00:00
|
|
|
//right count
|
|
|
|
ctx.fillText(`${(half - i)}`, (w - (wsec * i)) - (spacer * 2), (h / 2) + (spacer * 2))
|
|
|
|
//up count
|
2019-06-25 16:13:15 +00:00
|
|
|
ctx.fillText(`${(half - i)}`, (w / 2) + spacer, (hsec * i) + spacer + (fontSize / 2) )
|
2019-08-25 19:54:50 +00:00
|
|
|
//down count
|
|
|
|
ctx.fillText(`${(half - i)}`, (w / 2) - (spacer * 2), (h - (hsec * i)) - spacer)
|
2019-02-08 18:16:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
async function onDigital (event, arg) {
|
|
|
|
if (arg.src) {
|
2024-01-19 11:49:03 +00:00
|
|
|
if (arg.exposure) {
|
|
|
|
setBlank()
|
|
|
|
await delay(10)
|
|
|
|
}
|
2019-02-08 18:16:42 +00:00
|
|
|
try {
|
2023-02-25 07:08:05 +00:00
|
|
|
await setImage(arg.src)
|
2019-02-08 18:16:42 +00:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2024-01-19 11:49:03 +00:00
|
|
|
if (arg.exposure) {
|
|
|
|
await delay(arg.exposure)
|
|
|
|
setBlank()
|
|
|
|
}
|
|
|
|
ipcRenderer.send('display_load', { src : arg.src })
|
2019-02-08 18:16:42 +00:00
|
|
|
}
|
|
|
|
return event.returnValue = true
|
|
|
|
}
|
2023-02-25 17:33:18 +00:00
|
|
|
|
2019-02-08 18:16:42 +00:00
|
|
|
async function onEscape (evt) {
|
|
|
|
let isEscape = false
|
|
|
|
let win
|
2023-02-25 17:33:18 +00:00
|
|
|
|
2019-02-08 18:16:42 +00:00
|
|
|
evt = evt || window.event
|
|
|
|
|
|
|
|
if ('key' in evt) {
|
|
|
|
isEscape = (evt.key == 'Escape' || evt.key == 'Esc')
|
|
|
|
} else {
|
|
|
|
isEscape = (evt.keyCode == 27)
|
|
|
|
}
|
2023-02-25 17:33:18 +00:00
|
|
|
|
2019-02-08 18:16:42 +00:00
|
|
|
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>
|