Skip to content

Commit f79c533

Browse files
authored
Merge pull request #148 from dasher-project/wasm-dashercore
Wasm dashercore
2 parents e3c8a4f + bfb7a67 commit f79c533

1 file changed

Lines changed: 22 additions & 19 deletions

File tree

wasm-build/demo.html

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
canvas {
2424
border: 2px solid #ddd; border-radius: 4px; display: block;
2525
margin: 0 auto; cursor: crosshair; touch-action: none;
26+
width: 100%; height: auto; aspect-ratio: 4 / 3;
2627
}
2728
.controls {
2829
width: 280px; background: white; border-radius: 8px; padding: 20px;
@@ -74,23 +75,6 @@
7475
</style>
7576
</head>
7677
<body>
77-
<div class="header">
78-
<h1>DasherCore WebAssembly Demo</h1>
79-
<p>Native DasherCore performance in your browser &mdash; Built with C++ and WebAssembly</p>
80-
</div>
81-
82-
<div class="instructions">
83-
<h3>How to use Dasher:</h3>
84-
<p>1. Move your mouse over the canvas to steer &mdash; the letters zoom toward you</p>
85-
<p>2. The crosshair (vertical line) is where text gets entered &mdash; move up/down to choose letters</p>
86-
<p>3. Move further right to dash faster; move left to slow down / reverse</p>
87-
<p>4. Typed text appears in the output box below</p>
88-
</div>
89-
90-
<div class="status loading" id="status-container">
91-
<p class="status-text" id="status">Loading DasherCore WebAssembly...</p>
92-
</div>
93-
9478
<div class="container">
9579
<div class="canvas-container">
9680
<canvas id="dasher-canvas" width="800" height="600"></canvas>
@@ -153,8 +137,8 @@ <h2>Output Text</h2>
153137
let lastFpsTime = performance.now();
154138

155139
function updateStatus(message, type) {
156-
statusText.textContent = message;
157-
statusContainer.className = 'status ' + (type || 'loading');
140+
if (statusText) statusText.textContent = message;
141+
if (statusContainer) statusContainer.className = 'status ' + (type || 'loading');
158142
}
159143

160144
function enableControls() {
@@ -348,6 +332,25 @@ <h2>Output Text</h2>
348332
ctx.textAlign = 'center';
349333
ctx.fillText('Loading DasherCore...', canvas.width / 2, canvas.height / 2);
350334

335+
// Responsive canvas: sync resolution to display size
336+
function resizeCanvas() {
337+
const rect = canvas.getBoundingClientRect();
338+
const w = Math.round(rect.width);
339+
const h = Math.round(rect.height);
340+
if (w > 0 && h > 0 && (w !== canvas.width || h !== canvas.height)) {
341+
canvas.width = w;
342+
canvas.height = h;
343+
if (dasher && isRunning) {
344+
dasher.setScreenSize(w, h);
345+
}
346+
}
347+
}
348+
349+
window.addEventListener('resize', resizeCanvas);
350+
const resizeObserver = new ResizeObserver(resizeCanvas);
351+
resizeObserver.observe(canvas);
352+
resizeCanvas();
353+
351354
window.addEventListener('beforeunload', () => {
352355
if (dasher) dasher.destroy();
353356
});

0 commit comments

Comments
 (0)