-
Notifications
You must be signed in to change notification settings - Fork 1
/
emscripten_shell.html
177 lines (154 loc) · 6.15 KB
/
emscripten_shell.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
#body {
margin: 0px !important;
border: 0px none !important;
padding: 0px !important;
background: black;
}
#canvas-parent {
margin: 0px !important;
border: 0px none !important;
padding: 0px !important;
position: absolute;
}
#canvas {
border: 0px none !important;
padding: 0px !important;
background-color: black;
user-select: none;
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
-o-user-select: none;
width: 100% !important;
height: 100% !important;
}
#loading {
width: 100px;
height: 100px;
position: relative;
top: 300px;
left: 50%;
translate: -50% -50%;
z-index: 100;
}
#loading p {
translate: 5% -50%;
font-family: 'Anonymous Pro',Lato,LatoExtended,sans-serif; /* matching for itch.io page theme*/
font-size: x-large;
color: rgb(215, 46, 46);
}
#spinner {
position: relative;
left: 10%;
height: 30px;
width: 30px;
margin: 0;
margin-top: 20px;
margin-left: 20px;
display: inline-block;
vertical-align: top;
-webkit-animation: rotation .8s linear infinite;
-moz-animation: rotation .8s linear infinite;
-o-animation: rotation .8s linear infinite;
animation: rotation 0.8s linear infinite;
border-left: 5px solid rgb(235, 235, 235);
border-right: 5px solid rgb(235, 235, 235);
border-bottom: 5px solid rgb(235, 235, 235);
border-top: 5px solid rgb(120, 120, 120);
border-radius: 100%;
background-color: rgb(215, 46, 46);
}
@-webkit-keyframes rotation {
from {-webkit-transform: rotate(0deg);}
to {-webkit-transform: rotate(360deg);}
}
@-moz-keyframes rotation {
from {-moz-transform: rotate(0deg);}
to {-moz-transform: rotate(360deg);}
}
@-o-keyframes rotation {
from {-o-transform: rotate(0deg);}
to {-o-transform: rotate(360deg);}
}
@keyframes rotation {
from {transform: rotate(0deg);}
to {transform: rotate(360deg);}
}
</style>
</head>
<body id="body">
<div id="loading">
<div id="spinner"></div>
<p>Loading...</p>
</div>
<div id="canvas_parent">
<canvas id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas>
</div>
<script type='text/javascript'>
let canvas_parent = document.getElementById("canvas_parent");
let body = document.getElementById("body");
let resize_canvas = function(){
let new_height = window.innerHeight;
let new_width = (window.innerHeight / 3) * 4;
if (new_width > window.innerWidth){
new_width = window.innerWidth;
new_height = (window.innerWidth / 4) * 3;
}
let remaining_width = window.innerWidth - new_width;
if (remaining_width > 0) {
canvas_parent.style.position = "absolute";
canvas_parent.style.left = Math.floor(remaining_width / 2) + "px";
}
canvas_parent.style.height = new_height + "px";
canvas_parent.style.width = new_width + "px";
};
new ResizeObserver(() => { resize_canvas(); }).observe(body);
addEventListener('resize', (event) => { resize_canvas(); });
let canvas = document.getElementById('canvas');
let loading = document.getElementById('loading');
var Module = {
canvas: (function() {
canvas.addEventListener("webglcontextlost", function(e) {
alert('WebGL context lost. You will need to reload the page.');
e.preventDefault();
}, false);
return canvas;
})(),
monitorRunDependencies: function(how_many_left) {
if (how_many_left === 0) {
loading.style.display = 'none';
}
}
};
let scrolling_key_codes = [ 32, 37, 38, 39, 40 ];
let last_target;
window.onload = function() {
body.addEventListener('keydown', function (event) {
if (last_target != canvas) {
return false;
}
if (scrolling_key_codes.includes(event.keyCode)) {
event.preventDefault();
}
}, false);
body.addEventListener('click', function (event) {
last_target = event.target;
window.focus();
}, false);
canvas.addEventListener('mousedown', function (event) {
window.focus();
event.preventDefault();
event.stopPropagation();
}, false);
};
</script>
{{{ SCRIPT }}}
</body>
</html>