Skip to content

Commit 2daccf5

Browse files
committed
fix iframe dimensions, restore natural sketch size
1 parent 2833e1b commit 2daccf5

163 files changed

Lines changed: 381 additions & 162 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

editor/index.html

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Editor — C++ Mode for Processing</title>
7+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/codemirror.min.css">
8+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/theme/dracula.min.css">
9+
<style>
10+
* { margin: 0; padding: 0; box-sizing: border-box; }
11+
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #1a1a1a; color: #eee; height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
12+
13+
#site-nav { border-bottom: 1px solid #333; padding: 0 2rem; display: flex; align-items: center; justify-content: space-between; height: 52px; background: #111; flex-shrink: 0; }
14+
#site-nav a { color: #eee; text-decoration: none; font-size: 14px; }
15+
#site-nav .logo { font-weight: 600; font-size: 15px; }
16+
17+
.editor-layout { display: flex; flex: 1; overflow: hidden; }
18+
19+
/* Editor pane */
20+
.editor-pane { display: flex; flex-direction: column; width: 50%; border-right: 2px solid #222; }
21+
.pane-toolbar { display: flex; align-items: center; gap: 0.75rem; padding: 0.5rem 0.75rem; background: #111; border-bottom: 1px solid #2a2a2a; flex-shrink: 0; }
22+
.pane-label { font-size: 12px; color: #666; flex: 1; font-family: monospace; }
23+
#status { font-size: 12px; color: #666; }
24+
#status.compiling { color: #e8b400; }
25+
#status.error { color: #f77; }
26+
#status.ok { color: #5f5; }
27+
.btn-run { background: #e8b400; color: #111; border: none; padding: 0.4rem 1.1rem; border-radius: 5px; font-size: 13px; font-weight: 700; cursor: pointer; letter-spacing: 0.01em; }
28+
.btn-run:hover { background: #f5c400; }
29+
.btn-run:disabled { background: #444; color: #777; cursor: not-allowed; }
30+
.CodeMirror { flex: 1; height: 100%; font-size: 13px; line-height: 1.55; font-family: 'JetBrains Mono', 'Fira Code', monospace; }
31+
.CodeMirror-scroll { height: 100% !important; }
32+
.editor-pane { flex: 1; }
33+
34+
/* Preview pane */
35+
.preview-pane { display: flex; flex-direction: column; width: 50%; background: #000; }
36+
.preview-pane .pane-toolbar { background: #111; }
37+
.btn-stop { background: #2a2a2a; color: #aaa; border: 1px solid #333; padding: 0.4rem 0.9rem; border-radius: 5px; font-size: 12px; cursor: pointer; }
38+
.btn-stop:hover { background: #333; color: #eee; }
39+
40+
#preview-area { flex: 1; background: #000; display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; }
41+
#preview-area canvas { display: block !important; }
42+
#preview-placeholder { color: #333; font-size: 13px; text-align: center; line-height: 2; pointer-events: none; }
43+
#preview-placeholder kbd { background: #222; border: 1px solid #333; padding: 2px 6px; border-radius: 3px; font-size: 12px; color: #888; }
44+
45+
#error-panel { display: none; background: #1c0808; border-top: 1px solid #4a1010; padding: 0.6rem 1rem; font-family: 'JetBrains Mono', monospace; font-size: 11.5px; color: #f88; max-height: 130px; overflow-y: auto; white-space: pre; flex-shrink: 0; }
46+
</style>
47+
</head>
48+
<body>
49+
50+
<nav id="site-nav">
51+
<a class="logo" href="/">C++ Mode for Processing</a>
52+
<a href="/reference" style="color:#888;font-size:13px;">Reference</a>
53+
</nav>
54+
55+
<div class="editor-layout">
56+
<div class="editor-pane">
57+
<div class="pane-toolbar">
58+
<span class="pane-label">sketch.cpp</span>
59+
<span id="status"></span>
60+
<button class="btn-run" id="btn-run" onclick="runSketch()">▶ Run</button>
61+
</div>
62+
<textarea id="code-editor"></textarea>
63+
<div id="error-panel"></div>
64+
</div>
65+
66+
<div class="preview-pane">
67+
<div class="pane-toolbar">
68+
<span class="pane-label">Output</span>
69+
<button class="btn-stop" onclick="stopSketch()">■ Stop</button>
70+
</div>
71+
<div id="preview-area">
72+
<div id="preview-placeholder">
73+
Press <kbd>▶ Run</kbd> or <kbd>Ctrl+Enter</kbd>
74+
</div>
75+
</div>
76+
</div>
77+
</div>
78+
79+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/codemirror.min.js"></script>
80+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/mode/clike/clike.min.js"></script>
81+
<script>
82+
const API = 'https://bench-volumes-pontiac-riders.trycloudflare.com';
83+
84+
const DEFAULT = `class _PSketch : public PApplet {
85+
float angle = 0;
86+
public:
87+
void setup() override {
88+
size(500, 400, P3D);
89+
}
90+
void draw() override {
91+
background(20);
92+
lights();
93+
translate(width/2, height/2);
94+
rotateX(angle * 0.7f);
95+
rotateY(angle);
96+
fill(232, 180, 0);
97+
box(130);
98+
angle += 0.02f;
99+
}
100+
};`;
101+
102+
const editor = CodeMirror.fromTextArea(document.getElementById('code-editor'), {
103+
mode: 'text/x-c++src',
104+
theme: 'dracula',
105+
lineNumbers: true,
106+
indentUnit: 2,
107+
tabSize: 2,
108+
indentWithTabs: false,
109+
autofocus: true,
110+
});
111+
editor.setValue(DEFAULT);
112+
editor.setSize('100%', '100%');
113+
114+
function setStatus(msg, cls) {
115+
const el = document.getElementById('status');
116+
el.textContent = msg;
117+
el.className = cls || '';
118+
}
119+
120+
function stopSketch() {
121+
const area = document.getElementById('preview-area');
122+
// Remove old canvas and scripts
123+
area.innerHTML = '<div id="preview-placeholder">Press <kbd>▶ Run</kbd> or <kbd>Ctrl+Enter</kbd></div>';
124+
// Clean up old module
125+
if (window.Module && window.Module._emscripten_cancel_main_loop) {
126+
try { window.Module._emscripten_cancel_main_loop(); } catch(e) {}
127+
}
128+
window.Module = undefined;
129+
setStatus('');
130+
}
131+
132+
async function runSketch() {
133+
const btn = document.getElementById('btn-run');
134+
const errorPanel = document.getElementById('error-panel');
135+
errorPanel.style.display = 'none';
136+
errorPanel.textContent = '';
137+
btn.disabled = true;
138+
setStatus('Compiling...', 'compiling');
139+
140+
let resp, data;
141+
try {
142+
resp = await fetch(API + '/compile', {
143+
method: 'POST',
144+
headers: { 'Content-Type': 'application/json' },
145+
body: JSON.stringify({ code: editor.getValue() }),
146+
});
147+
data = await resp.json();
148+
} catch(e) {
149+
setStatus('Server unreachable', 'error');
150+
errorPanel.textContent = 'Could not reach compile server:\n' + e.message;
151+
errorPanel.style.display = 'block';
152+
btn.disabled = false;
153+
return;
154+
}
155+
156+
if (!resp.ok || data.error) {
157+
setStatus('Error', 'error');
158+
errorPanel.textContent = data.error || 'Unknown error';
159+
errorPanel.style.display = 'block';
160+
btn.disabled = false;
161+
return;
162+
}
163+
164+
setStatus('Loading...', 'compiling');
165+
btn.disabled = false;
166+
167+
// Stop previous sketch
168+
stopSketch();
169+
170+
const area = document.getElementById('preview-area');
171+
172+
// Create canvas
173+
const canvas = document.createElement('canvas');
174+
canvas.id = 'canvas';
175+
area.appendChild(canvas);
176+
177+
// Decode wasm and data
178+
const wasmBinary = Uint8Array.from(atob(data.wasm), c => c.charCodeAt(0));
179+
const dataBytes = data.data ? Uint8Array.from(atob(data.data), c => c.charCodeAt(0)) : null;
180+
181+
// Set Module before the script runs
182+
window.Module = {
183+
canvas: canvas,
184+
wasmBinary: wasmBinary,
185+
onRuntimeInitialized: function() {
186+
setStatus('Running', 'ok');
187+
},
188+
print: t => console.log('[sketch]', t),
189+
printErr: t => console.warn('[sketch]', t),
190+
};
191+
192+
if (dataBytes) {
193+
// Inject preloaded data package
194+
window.Module.getPreloadedPackage = function(name, size) {
195+
return dataBytes.buffer;
196+
};
197+
}
198+
199+
// Load the emscripten JS glue
200+
const blob = new Blob([data.js], { type: 'application/javascript' });
201+
const blobUrl = URL.createObjectURL(blob);
202+
const script = document.createElement('script');
203+
script.src = blobUrl;
204+
script.onload = () => URL.revokeObjectURL(blobUrl);
205+
script.onerror = e => {
206+
setStatus('Load error', 'error');
207+
errorPanel.textContent = 'Failed to load compiled sketch.';
208+
errorPanel.style.display = 'block';
209+
};
210+
document.head.appendChild(script);
211+
}
212+
213+
document.addEventListener('keydown', e => {
214+
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') { e.preventDefault(); runSketch(); }
215+
});
216+
</script>
217+
<script src="../assets/nav.js"></script>
218+
</body>
219+
</html>

examples/acceleration-with-vectors.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</div>
6868
<div class="content">
6969
<h1>Acceleration With Vectors</h1>
70-
<div class="preview-wrap" style="aspect-ratio:640/360;max-width:640px;"><iframe id="sketch-frame" width="640" height="360" style="width:100%;height:100%;"></iframe></div>
70+
<div class="preview-wrap" style="aspect-ratio:640/360;max-width:640px;"><iframe id="sketch-frame" width="640" height="360" style="display:block;border:none;"></iframe></div>
7171
<script>(function(){const iframe=document.getElementById('sketch-frame');const doc=iframe.contentDocument||iframe.contentWindow.document;doc.open();doc.write(`<!DOCTYPE html><html><head><style>*{margin:0;padding:0;}body{overflow:hidden;}</style><script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.0/p5.min.js"><\/script></head><body><script>class Mover {
7272
constructor() {
7373
this.location = new p5.Vector(width/2, height/2);

examples/additive-wave.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</div>
6868
<div class="content">
6969
<h1>Additive Wave</h1>
70-
<div class="preview-wrap" style="aspect-ratio:640/360;max-width:640px;"><iframe id="sketch-frame" width="640" height="360" style="width:100%;height:100%;"></iframe></div>
70+
<div class="preview-wrap" style="aspect-ratio:640/360;max-width:640px;"><iframe id="sketch-frame" width="640" height="360" style="display:block;border:none;"></iframe></div>
7171
<script>(function(){const iframe=document.getElementById('sketch-frame');const doc=iframe.contentDocument||iframe.contentWindow.document;doc.open();doc.write(`<!DOCTYPE html><html><head><style>*{margin:0;padding:0;}body{overflow:hidden;}</style><script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.0/p5.min.js"><\/script></head><body><script>let xspacing = 8;
7272
let w;
7373
let maxwaves = 4;

examples/alpha-mask.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</div>
6868
<div class="content">
6969
<h1>Alpha Mask</h1>
70-
<div class="preview-wrap" style="aspect-ratio:640/360;max-width:640px;"><iframe id="sketch-frame" width="640" height="360" style="width:100%;height:100%;"></iframe></div>
70+
<div class="preview-wrap" style="aspect-ratio:640/360;max-width:640px;"><iframe id="sketch-frame" width="640" height="360" style="display:block;border:none;"></iframe></div>
7171
<script>(function(){const iframe=document.getElementById('sketch-frame');const doc=iframe.contentDocument||iframe.contentWindow.document;doc.open();doc.write(`<!DOCTYPE html><html><head><style>*{margin:0;padding:0;}body{overflow:hidden;}</style><script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.0/p5.min.js"><\/script></head><body><script>let img;
7272
let imgMask;
7373

examples/animated-sprite.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</div>
6868
<div class="content">
6969
<h1>Animated Sprite</h1>
70-
<div class="preview-wrap" style="aspect-ratio:640/360;max-width:640px;"><iframe id="sketch-frame" width="640" height="360" style="width:100%;height:100%;"></iframe></div>
70+
<div class="preview-wrap" style="aspect-ratio:640/360;max-width:640px;"><iframe id="sketch-frame" width="640" height="360" style="display:block;border:none;"></iframe></div>
7171
<script>(function(){const iframe=document.getElementById('sketch-frame');const doc=iframe.contentDocument||iframe.contentWindow.document;doc.open();doc.write(`<!DOCTYPE html><html><head><style>*{margin:0;padding:0;}body{overflow:hidden;}</style><script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.0/p5.min.js"><\/script></head><body><script>let animation1 = null;
7272
let animation2 = null;
7373
let xpos;

examples/arctangent.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</div>
6868
<div class="content">
6969
<h1>Arctangent</h1>
70-
<div class="preview-wrap" style="aspect-ratio:640/360;max-width:640px;"><iframe id="sketch-frame" width="640" height="360" style="width:100%;height:100%;"></iframe></div>
70+
<div class="preview-wrap" style="aspect-ratio:640/360;max-width:640px;"><iframe id="sketch-frame" width="640" height="360" style="display:block;border:none;"></iframe></div>
7171
<script>(function(){const iframe=document.getElementById('sketch-frame');const doc=iframe.contentDocument||iframe.contentWindow.document;doc.open();doc.write(`<!DOCTYPE html><html><head><style>*{margin:0;padding:0;}body{overflow:hidden;}</style><script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.0/p5.min.js"><\/script></head><body><script>class Eye {
7272
constructor(x, y, size) {
7373
this.x = x;

examples/arm.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</div>
6868
<div class="content">
6969
<h1>Arm</h1>
70-
<div class="preview-wrap" style="aspect-ratio:640/360;max-width:640px;"><iframe id="sketch-frame" width="640" height="360" style="width:100%;height:100%;"></iframe></div>
70+
<div class="preview-wrap" style="aspect-ratio:640/360;max-width:640px;"><iframe id="sketch-frame" width="640" height="360" style="display:block;border:none;"></iframe></div>
7171
<script>(function(){const iframe=document.getElementById('sketch-frame');const doc=iframe.contentDocument||iframe.contentWindow.document;doc.open();doc.write(`<!DOCTYPE html><html><head><style>*{margin:0;padding:0;}body{overflow:hidden;}</style><script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.0/p5.min.js"><\/script></head><body><script>let x, y;
7272
let angle1 = 0.0;
7373
let angle2 = 0.0;

examples/array-2d.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</div>
6868
<div class="content">
6969
<h1>Array 2D</h1>
70-
<div class="preview-wrap" style="aspect-ratio:640/360;max-width:640px;"><iframe id="sketch-frame" width="640" height="360" style="width:100%;height:100%;"></iframe></div>
70+
<div class="preview-wrap" style="aspect-ratio:640/360;max-width:640px;"><iframe id="sketch-frame" width="640" height="360" style="display:block;border:none;"></iframe></div>
7171
<script>(function(){const iframe=document.getElementById('sketch-frame');const doc=iframe.contentDocument||iframe.contentWindow.document;doc.open();doc.write(`<!DOCTYPE html><html><head><style>*{margin:0;padding:0;}body{overflow:hidden;}</style><script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.0/p5.min.js"><\/script></head><body><script>let distances;
7272
let maxDistance;
7373
let spacer;

examples/array-objects.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</div>
6868
<div class="content">
6969
<h1>Array Objects</h1>
70-
<div class="preview-wrap" style="aspect-ratio:640/360;max-width:640px;"><iframe id="sketch-frame" width="640" height="360" style="width:100%;height:100%;"></iframe></div>
70+
<div class="preview-wrap" style="aspect-ratio:640/360;max-width:640px;"><iframe id="sketch-frame" width="640" height="360" style="display:block;border:none;"></iframe></div>
7171
<script>(function(){const iframe=document.getElementById('sketch-frame');const doc=iframe.contentDocument||iframe.contentWindow.document;doc.open();doc.write(`<!DOCTYPE html><html><head><style>*{margin:0;padding:0;}body{overflow:hidden;}</style><script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.0/p5.min.js"><\/script></head><body><script>class Module {
7272
constructor(xOffset, yOffset, x, y, speed, unit) {
7373
this.xOffset = xOffset;

examples/array.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</div>
6868
<div class="content">
6969
<h1>Array</h1>
70-
<div class="preview-wrap" style="aspect-ratio:640/360;max-width:640px;"><iframe id="sketch-frame" width="640" height="360" style="width:100%;height:100%;"></iframe></div>
70+
<div class="preview-wrap" style="aspect-ratio:640/360;max-width:640px;"><iframe id="sketch-frame" width="640" height="360" style="display:block;border:none;"></iframe></div>
7171
<script>(function(){const iframe=document.getElementById('sketch-frame');const doc=iframe.contentDocument||iframe.contentWindow.document;doc.open();doc.write(`<!DOCTYPE html><html><head><style>*{margin:0;padding:0;}body{overflow:hidden;}</style><script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.0/p5.min.js"><\/script></head><body><script>let coswave = [];
7272
7373
function setup() {

0 commit comments

Comments
 (0)