couple commits
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<title>Hello traveller!</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -60,6 +60,20 @@ class stream_t {
|
||||
}
|
||||
}
|
||||
|
||||
function unsecuredCopyToClipboard(text) {
|
||||
const textArea = document.createElement("textarea");
|
||||
textArea.value = text;
|
||||
document.body.appendChild(textArea);
|
||||
textArea.focus();
|
||||
textArea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
} catch (err) {
|
||||
console.error('Unable to copy to clipboard', err);
|
||||
}
|
||||
document.body.removeChild(textArea);
|
||||
}
|
||||
|
||||
class memory_t {
|
||||
exports = null; // this is set after wasm module created
|
||||
constructor(wasm_memory) {
|
||||
@@ -108,6 +122,9 @@ const wasm_app_imports = {
|
||||
wasm_trap: () => { throw new Error(); },
|
||||
wasm_write_to_console: (str, len) => { console.log(mem.read_cstr(str, len)); },
|
||||
|
||||
wasm_open_link: (str, len) => { window.open(mem.read_cstr(str, len)); },
|
||||
wasm_set_clipboard: (str, len) => { unsecuredCopyToClipboard(mem.read_cstr(str, len)); },
|
||||
|
||||
// gfx
|
||||
wasm_draw_text: (str, len, x, y, font_str, font_len, font_size, r, g, b, a) => {
|
||||
ctx2d.font = `${font_size}px ${mem.read_cstr(font_str, font_len)}`;
|
||||
@@ -137,8 +154,14 @@ const wasm_app_imports = {
|
||||
ctx2d.rect(x, y, w, h);
|
||||
ctx2d.clip();
|
||||
},
|
||||
wasm_open_link: (str, len) => {
|
||||
window.open(mem.read_cstr(str, len));
|
||||
wasm_set_cursor: (cursor_num) => {
|
||||
let cursor = 'auto';
|
||||
if (cursor_num == 0) {
|
||||
cursor = 'text';
|
||||
} else if (cursor_num == 1) {
|
||||
cursor = 'pointer';
|
||||
}
|
||||
document.getElementById("canvas").style.cursor = cursor;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -201,14 +224,20 @@ const wasm_app_imports = {
|
||||
}
|
||||
});
|
||||
|
||||
addEventListener("contextmenu", (event) => { event.preventDefault(); return false; })
|
||||
|
||||
addEventListener("resize", (event) => { wake_up(); });
|
||||
addEventListener("keydown", (event) => {
|
||||
if (["F1", "F2", "F3", "p"].includes(event.key)) event.preventDefault();
|
||||
wasm_exports["wasm_key_down"](mem.write_string_to_cglobal("wasm_temp_buff1", event.key), event.ctrlKey, event.shiftKey, event.altKey, event.metaKey);
|
||||
let memory = wasm_exports["wasm_temp_alloc"](64);
|
||||
mem.write_string_into_cmemory(memory, 64, event.key);
|
||||
wasm_exports["wasm_key_down"](memory, event.ctrlKey, event.shiftKey, event.altKey, event.metaKey);
|
||||
wake_up();
|
||||
});
|
||||
addEventListener("keyup", (event) => {
|
||||
wasm_exports["wasm_key_up"](mem.write_string_to_cglobal("wasm_temp_buff1", event.key), event.ctrlKey, event.shiftKey, event.altKey, event.metaKey);
|
||||
let memory = wasm_exports["wasm_temp_alloc"](64);
|
||||
mem.write_string_into_cmemory(memory, 64, event.key);
|
||||
wasm_exports["wasm_key_up"](memory, event.ctrlKey, event.shiftKey, event.altKey, event.metaKey);
|
||||
wake_up();
|
||||
});
|
||||
addEventListener("mousemove", (event) => {
|
||||
@@ -216,7 +245,7 @@ const wasm_app_imports = {
|
||||
wake_up();
|
||||
});
|
||||
addEventListener("mousedown", (event) => {
|
||||
wasm_exports["wasm_mouse_down"](event.clientX, event.clientY, event.button, event.ctrlKey, event.shiftKey, event.altKey, event.metaKey);
|
||||
wasm_exports["wasm_mouse_down"](event.clientX, event.clientY, event.button, event.ctrlKey, event.shiftKey, event.altKey, event.metaKey, event.detail);
|
||||
wake_up();
|
||||
});
|
||||
addEventListener("mouseup", (event) => {
|
||||
|
||||
Reference in New Issue
Block a user