Skip to content

PS2 games in the browser: static recompilation to WebAssembly with a native runtime

C++

Touch controls scale with the screen and the bar scrolls instead of widening the page

Samir Nuric89f518afc48
diff --git a/web/shell.html b/web/shell.html
index be2b0e2..0f21c4c 100644
--- a/web/shell.html
+++ b/web/shell.html
@@ -6,11 +6,11 @@
<title>ps2-web-recomp</title>
<style>
:root { color-scheme: dark; }
- html, body { margin: 0; height: 100%; background: #0b0b0d; color: #d8d8dc; font: 13px system-ui, sans-serif; }
+ html, body { margin: 0; height: 100%; overflow: hidden; background: #0b0b0d; color: #d8d8dc; font: 13px system-ui, sans-serif; }
body { display: flex; flex-direction: column; }
#stage { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; }
canvas { width: 100%; height: 100%; display: block; background: #000; }
- #bar { display: flex; gap: 16px; align-items: center; padding: 6px 12px; background: #141418; border-top: 1px solid #222; }
+ #bar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 6px 12px; background: #141418; border-top: 1px solid #222; }
#status { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#stats { font-variant-numeric: tabular-nums; color: #9ad; }
select { background: #2a3a55; color: #fff; border: 0; padding: 5px 8px; border-radius: 4px; }
@@ -21,6 +21,11 @@
#help { margin: 0; line-height: 1.5; color: #e8c37a; }
.controls { display: none; }
body.touch { overscroll-behavior: none; touch-action: none; -webkit-user-select: none; user-select: none; }
+ body.touch #bar { flex-wrap: nowrap; overflow-x: auto; gap: 8px; padding: 4px 8px calc(4px + env(safe-area-inset-bottom)); touch-action: pan-x; scrollbar-width: none; }
+ body.touch #bar::-webkit-scrollbar { display: none; }
+ body.touch #bar > * { flex: none; }
+ body.touch #status { max-width: 45vw; }
+ body.touch #bar button, body.touch #bar select { padding: 5px 10px; font-size: 12px; }
body.touch #stage { flex: none; width: 100%; aspect-ratio: 4 / 3; max-height: 60vh; }
body.touch.wide #stage { aspect-ratio: 16 / 9; }
body.touch .controls {
@@ -28,33 +33,35 @@
gap: 10px 8px; align-content: center; padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
touch-action: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
--ctl: #1d2433; --ctl-on: #4a6aa5; --ctl-line: #34405a; --ctl-text: #dfe6f3;
+ --cell: clamp(30px, min(11vw, 5.2vh), 64px);
}
+ .controls { --face: calc(var(--cell) * 1.25); }
.cluster { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.cluster.left { grid-area: left; } .cluster.right { grid-area: right; }
.cluster.mid { grid-area: mid; flex-direction: row; gap: 10px; justify-self: center; }
- .shoulders { display: flex; gap: 8px; width: 100%; max-width: 160px; }
+ .shoulders { display: flex; gap: 8px; width: 100%; max-width: calc(var(--cell) * 4); }
.ctl {
display: flex; align-items: center; justify-content: center; color: var(--ctl-text);
background: var(--ctl); border: 1px solid var(--ctl-line); font-weight: 600;
}
.ctl.on, .dpad span.on { background: var(--ctl-on); }
- .shoulder { flex: 1; height: 38px; border-radius: 12px 12px 6px 6px; }
- .small { padding: 0 12px; height: 30px; border-radius: 15px; font-size: 12px; font-weight: 500; }
- .face { display: grid; grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(3, 50px); }
- .face .ctl { border-radius: 50%; font-size: 20px; }
+ .shoulder { flex: 1; height: calc(var(--cell) * 0.95); border-radius: 12px 12px 6px 6px; }
+ .small { padding: 0 calc(var(--cell) * 0.3); height: calc(var(--cell) * 0.75); border-radius: calc(var(--cell) * 0.375); font-size: calc(var(--cell) * 0.3); font-weight: 500; }
+ .face { display: grid; grid-template-columns: repeat(3, var(--face)); grid-template-rows: repeat(3, var(--face)); }
+ .face .ctl { border-radius: 50%; font-size: calc(var(--face) * 0.4); }
.face .tri { grid-area: 1 / 2; } .face .sq { grid-area: 2 / 1; }
.face .ci { grid-area: 2 / 3; } .face .cr { grid-area: 3 / 2; }
- .dpad { width: 120px; height: 120px; display: grid; grid-template-columns: repeat(3, 40px); grid-template-rows: repeat(3, 40px); }
+ .dpad { width: calc(var(--cell) * 3); height: calc(var(--cell) * 3); display: grid; grid-template-columns: repeat(3, var(--cell)); grid-template-rows: repeat(3, var(--cell)); }
.dpad span {
- display: flex; align-items: center; justify-content: center; font-size: 14px;
+ display: flex; align-items: center; justify-content: center; font-size: calc(var(--cell) * 0.35);
color: var(--ctl-text); background: var(--ctl); border: 1px solid var(--ctl-line);
}
.dpad .up { grid-area: 1 / 2; border-radius: 8px 8px 0 0; } .dpad .down { grid-area: 3 / 2; border-radius: 0 0 8px 8px; }
.dpad .left { grid-area: 2 / 1; border-radius: 8px 0 0 8px; } .dpad .right { grid-area: 2 / 3; border-radius: 0 8px 8px 0; }
.dpad .hub { grid-area: 2 / 2; }
- .stick { position: relative; width: 120px; height: 120px; border-radius: 50%; background: var(--ctl); border: 1px solid var(--ctl-line); }
+ .stick { position: relative; width: calc(var(--cell) * 3); height: calc(var(--cell) * 3); border-radius: 50%; background: var(--ctl); border: 1px solid var(--ctl-line); }
.knob {
- position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px;
+ position: absolute; left: 50%; top: 50%; width: 43%; height: 43%; margin: -21.5% 0 0 -21.5%;
border-radius: 50%; background: var(--ctl-on); border: 1px solid var(--ctl-line);
}
body.touch.hide-controls .controls { display: none; }
@@ -69,14 +76,12 @@
@media (orientation: landscape) {
body.touch #stage { flex: 1; aspect-ratio: auto; max-height: none; }
body.touch .controls { position: fixed; inset: 0; display: block; padding: 0; pointer-events: none; z-index: 1;
- --ctl: rgba(255, 255, 255, 0.12); --ctl-on: rgba(255, 255, 255, 0.45); --ctl-line: rgba(255, 255, 255, 0.28); --ctl-text: #fff; }
+ --ctl: rgba(255, 255, 255, 0.12); --ctl-on: rgba(255, 255, 255, 0.45); --ctl-line: rgba(255, 255, 255, 0.28); --ctl-text: #fff;
+ --cell: clamp(26px, min(9vh, 7vw), 60px); }
body.touch .cluster { position: absolute; top: 8px; bottom: 40px; justify-content: space-between; pointer-events: auto; opacity: 0.75; }
body.touch .cluster.left { left: calc(10px + env(safe-area-inset-left)); }
body.touch .cluster.right { right: calc(10px + env(safe-area-inset-right)); }
body.touch .cluster.mid { top: auto; bottom: 40px; left: 50%; transform: translateX(-50%); }
- body.touch .dpad { width: 105px; height: 105px; grid-template-columns: repeat(3, 35px); grid-template-rows: repeat(3, 35px); }
- body.touch .stick { width: 105px; height: 105px; }
- body.touch .face { grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(3, 44px); }
body.fullscreen.touch .cluster { bottom: calc(8px + env(safe-area-inset-bottom)); }
body.fullscreen.touch .cluster.mid { bottom: calc(8px + env(safe-area-inset-bottom)); }
}