|
23 | 23 | canvas { |
24 | 24 | border: 2px solid #ddd; border-radius: 4px; display: block; |
25 | 25 | margin: 0 auto; cursor: crosshair; touch-action: none; |
| 26 | + width: 100%; height: auto; aspect-ratio: 4 / 3; |
26 | 27 | } |
27 | 28 | .controls { |
28 | 29 | width: 280px; background: white; border-radius: 8px; padding: 20px; |
|
74 | 75 | </style> |
75 | 76 | </head> |
76 | 77 | <body> |
77 | | - <div class="header"> |
78 | | - <h1>DasherCore WebAssembly Demo</h1> |
79 | | - <p>Native DasherCore performance in your browser — 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 — the letters zoom toward you</p> |
85 | | - <p>2. The crosshair (vertical line) is where text gets entered — 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 | | - |
94 | 78 | <div class="container"> |
95 | 79 | <div class="canvas-container"> |
96 | 80 | <canvas id="dasher-canvas" width="800" height="600"></canvas> |
@@ -153,8 +137,8 @@ <h2>Output Text</h2> |
153 | 137 | let lastFpsTime = performance.now(); |
154 | 138 |
|
155 | 139 | 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'); |
158 | 142 | } |
159 | 143 |
|
160 | 144 | function enableControls() { |
@@ -348,6 +332,25 @@ <h2>Output Text</h2> |
348 | 332 | ctx.textAlign = 'center'; |
349 | 333 | ctx.fillText('Loading DasherCore...', canvas.width / 2, canvas.height / 2); |
350 | 334 |
|
| 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 | + |
351 | 354 | window.addEventListener('beforeunload', () => { |
352 | 355 | if (dasher) dasher.destroy(); |
353 | 356 | }); |
|
0 commit comments