push_event_to_buffer(esp, event_size, 0x06, [ window.innerWidth, window.innerHeight ]);
+ document.getElementsByTagName("canvas")[0].addEventListener("drop", function (ev) {
+ ev.preventDefault();
+
+ // ROBUSTNESS: Currently, this only gives the first file, which for a lot of purposes, will be enough.
+ // But if multiple files are dropped, the application will only know about the first one.
+ ev.dataTransfer.items[0].getAsFile().arrayBuffer()
+ .then(response => {
+ // 0 is assumed to be reserved in request_file.onyx.
+ requested_file_data[0] = response;
+ push_event_to_buffer(esp, event_size, 0x08, [0x01, 0, response.byteLength]);
+ })
+ .catch(error => {
+ push_event_to_buffer(esp, event_size, 0x08, [0x02, 0, 0]);
+ });
+
+ return false;
+ });
+
+ document.getElementsByTagName("canvas")[0].addEventListener("dragover", function(ev) {
+ ev.preventDefault();
+ return false;
+ });
+
document.oncontextmenu = (e) => {
e.preventDefault = true;
return false;
#private_file gfx :: package immediate_mode
#private_file ui :: package ui
#private_file config :: package config
+#private_file wasm :: package wasm_utils
search_buffer: string.String_Buffer;
-
background_tile_texture : gfx.Texture;
-
on_file_load_callbacks : map.Map(u32, (file_event: ^events.Event) -> void);
+wasm_data : [] u8;
+
main :: (args: [] cstr) {
init();
}
case .FileRequest {
- @Bug // When debugging I tried to do this
- //
- printf("{}\n", event.file);
- //
- // And it looked like it was printing correctly. However, it destroyed the data in the event,
- // which made the below code fail. Without printing this, everything works just fine. This
- // probably has to do with the "any" type for printf.
- //
- // Actually, I tried this:
- //
- // println(event.file.file_id);
- //
- // And it also breaks it... Hmm
- //
- // Another wrinkle: When I copied this case-body to a different function, it worked perfectly.
- // Definitely something wrong with the stack allocation when in case statements.
- //
- // events.consume() was returning a pointer to a local variable on the stack.... UGH
- // Some kind of shadowing warning would be nice
-
if f := map.get(^on_file_load_callbacks, event.file.file_id); f != null_proc {
f(event);
printf("Warning: No callback set for file id {}.\n", event.file.file_id);
}
}
+
+ case .FileDropped {
+ printf("File with size {} and status {} was dropped.\n", event.file.size, event.file.status);
+
+ if wasm_data.count > 0 do memory.free_slice(^wasm_data);
+
+ wasm_data = memory.make_slice(u8, event.file.size);
+ events.get_requested_file_data(event.file.file_id, wasm_data);
+
+ wasm_module := wasm.load(wasm_data);
+ defer wasm.free(^wasm_module);
+
+ for ^entry: wasm_module.sections.entries {
+ printf("Section: {}\nOffset: {}\n", entry.key, entry.value);
+ }
+ }
}
}
t += dt;
if ui.is_key_just_down(~~#char "L") {
- color_file := events.request_file("/res/colors_light.json");
+ color_file := events.request_file("/res/colors_dark.json");
map.put(^on_file_load_callbacks, color_file, load_colors);
}
}
defer if color_data.count > 0 do cfree(color_data.data);
events.get_requested_file_data(event.file.file_id, color_data);
- @DynamicLoading // Currently, this file is just baked into the binary. When a mechanism
- // is added to easily ask JS to make a fetch request for a file, that can be used here.
- // colors_json := #file_contents "res/colors_light.json";
-
arena := alloc.arena.make(context.allocator, 4096);
defer alloc.arena.free(^arena);
colors := json.decode(color_data, alloc.arena.make_allocator(^arena));