-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvas.js
38 lines (34 loc) · 1.45 KB
/
canvas.js
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
window.addEventListener("load", function() {
Scheme.load_main("canvas.wasm", {}, {
document: {
body() { return document.body; },
getElementById: Document.prototype.getElementById.bind(document),
createElement: Document.prototype.createElement.bind(document),
createTextNode: Document.prototype.createTextNode.bind(document),
},
element: {
value(elem) { return elem.value; },
setValue(elem, value) { elem.value = value; },
checked(elem) { return elem.checked; },
setChecked(elem, checked) { elem.checked = (checked == 1); },
setAttribute(elem, name, value) { elem.setAttribute(name, value); },
removeAttribute(elem, name) { elem.removeAttribute(name); },
appendChild(parent, child) { return parent.appendChild(child); },
remove(elem) { elem.remove(); },
replaceWith(oldElem, newElem) { oldElem.replaceWith(newElem); },
addEventListener(elem, name, f) { elem.addEventListener(name, f); },
removeEventListener(elem, name, f) { elem.removeEventListener(name, f); }
},
event: {
target(event) { return event.target; }
},
canvas: {
getContext(canvas) {return canvas.getContext("2d"); },
fillRect(context, x, y, width, height) {
context.fillRect(x, y, width, height);
},
fillStyle(context, style) {context.fillStyle = style; },
getCursorPosition(canvas, event) { return [event.offsetX, event.offsetY]; }
}
});
});