-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
158 lines (147 loc) ยท 5.06 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Live Mind</title>
<style>
* {
box-sizing: border-box;
}
html, body {
margin: 0;
padding: 0;
overflow: hidden;
}
body > .wrapper {
position: relative;
}
#canvas {
/* margin-top: 29px; */
position: relative;
/* padding: 5px; */
}
html, body, body > .wrapper, #canvas {
height: 100%;
width: 100%;
}
#electron-titlebar {
z-index: 1;
}
#electron-titlebar .title {
width: 100%;
height: 100%;
line-height: 29px;
/* padding-left: 0.2rem; */
font-size: 0.8rem;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
color: #181E1C;
display: inline-block;
position: absolute;
}
#electron-titlebar .icon {
width: 29px;
height: 100%;
line-height: 29px;
padding-left: 0.2rem;
padding-bottom: 0.1rem;
display: inline-block;
}
.icon > img {
width: 100%;
height: 100%;
padding: 0.23rem;
}
body > .wrapper, #electron-titlebar {
background-color: #181E1C; /* #6B95C4; */
}
.overlay {
display: none;
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
background-color: rgb(24, 30, 28, .5);
z-index: 1;
}
body[data-blurred="true"] > .overlay {
display: block;
}
</style>
</head>
<body data-blurred="false">
<div id="electron-titlebar" class="drag">
<div class="icon">
<img src="build/icon.svg" />
<!-- <img src="build/icon.inverse.svg" /> -->
</div>
<!-- <div class="title">
<span>Live Mind</span>
</div> -->
</div>
<div class="overlay"></div>
<div class="wrapper">
<canvas id="canvas"></canvas>
</div>
<script>
const {
titlebarHeight,
windowConfig: {
width: w,
height: h,
frame,
},
} = require('./config');
try {
const win = require('electron').remote.getCurrentWindow();
win.on('blur', () => document.body.setAttribute('data-blurred', 'true'));
win.on('focus', () => document.body.setAttribute('data-blurred', 'false'));
if (!frame) {
require('electron-titlebar');
document.getElementById('electron-titlebar').style.height = `${titlebarHeight}px`;
}
} catch(e) {
console.log('Running without electron.')
}
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
let mouseDown = false;
document.onmousedown = _ => mouseDown = true;
document.onmouseup = _ => mouseDown = false;
const rect = canvas.getBoundingClientRect();
const getMousePos = (e) => ({
x: e.clientX - rect.left,
y: e.clientY - rect.top + titlebarHeight
});
canvas.width = canvas.offsetWidth - 10;
canvas.height = canvas.offsetHeight - 10;
ctx.fillStyle = '#fff';
ctx.fillRect(0, 0, w, h);
const fontSize = 24;
ctx.font = `${fontSize}px "Times`;
let pos = [];
let word = '';
canvas.onmousemove = (e) => {
word = '';
pos = getMousePos(e);
if (mouseDown) erase();
};
document.addEventListener('keydown', (event) => {
if (event.key.length === 1) word += event.key;
if (word) writeWord();
});
function writeWord() {
ctx.fillStyle = '#000';
ctx.fillText(word, pos.x, pos.y);
}
function erase() {
ctx.beginPath();
ctx.arc(pos.x, pos.y, fontSize, 0, 6.3);
ctx.fillStyle = '#fff';
ctx.fill();
}
</script>
</body>
</html>