// 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]);
- });
+ var response = ev.dataTransfer.items[0].getAsFile();
+ response.arrayBuffer().then(data => {
+ // 0 is assumed to be reserved in request_file.onyx.
+ requested_file_data[0] = {
+ name: response.name,
+ data: data,
+ };
+ push_event_to_buffer(esp, event_size, 0x08, [0x01, 0, data.byteLength, response.name.length ]);
+ })
+ .catch(error => {
+ push_event_to_buffer(esp, event_size, 0x08, [0x02, 0, 0, 0]);
+ });
return false;
});
fetch(path)
.then(response => response.arrayBuffer())
.then(array_buffer => {
- requested_file_data[fileid] = array_buffer;
+ requested_file_data[fileid] = {
+ name: path,
+ data: array_buffer,
+ };
- push_event_to_buffer(esp, event_size, 0x09, [ 0x01, fileid, array_buffer.byteLength ]);
+ push_event_to_buffer(esp, event_size, 0x09, [ 0x01, fileid, array_buffer.byteLength, path.length ]);
})
.catch((error) => {
- push_event_to_buffer(esp, event_size, 0x09, [ 0x02, fileid, 0 ]);
+ push_event_to_buffer(esp, event_size, 0x09, [ 0x02, fileid, 0, 0 ]);
});
},
- get_requested_file_data(fileid, bufferptr, bufferlen) {
+ get_requested_file_data(fileid, bufferptr, bufferlen, nameptr, namelen) {
var file_data = requested_file_data[fileid];
if (file_data == null) return 0;
- if (bufferlen < file_data.byteLength) return 0;
+ if (bufferlen < file_data.data.byteLength) return 0;
let WASM_U8 = new Uint8Array(ONYX_MEMORY.buffer);
- var u8_data = new Uint8Array(file_data);
+ var u8_data = new Uint8Array(file_data.data);
WASM_U8.set(u8_data, bufferptr);
+ if (namelen >= file_data.name.length) {
+ var name_data = new TextEncoder().encode(file_data.name);
+ WASM_U8.set(name_data, nameptr);
+ }
+
requested_file_data[fileid] = null;
delete requested_file_data[fileid];
gl.enable(gl.BLEND);
gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
- analyzer_state->init();
+ __initialize(^analyzer_state);
load_background_tile_texture :: () {
background_tile_texture = gfx.load_texture(32, 32, #file_contents "res/images/background_tile.data", gl.RGB, gl.RGB);
};
}
- analyzer_state->init();
-
debug_log(.Info, "Successfully loaded colorscheme.", null);
}
}
case .FileDropped {
- debug_log(.Info, "File with size {} and status {} was dropped.\n", event.file.size, event.file.status);
-
wasm_data := memory.make_slice(u8, event.file.size);
- events.get_requested_file_data(event.file.file_id, wasm_data);
+ name := memory.make_slice(u8, event.file.name_length, context.temp_allocator);
+ events.get_requested_file_data(event.file.file_id, wasm_data, name);
+
+ debug_log(.Info, "File with size {} and name {} was dropped.\n", event.file.size, name);
+
+ if !string.ends_with(name, ".wasm") {
+ debug_log(.Warning, "A non-WASM file was dropped. Ignoring.", null);
+ break;
+ }
// This transfers ownership of wasm_data to the analyzer_state
load_wasm_binary(^analyzer_state, wasm_data);
use package core.intrinsics.onyx { __initialize }
+
+// I'm honestly not entirely sure what should go in this structure.
+// I want this framework/UI to be fairly portable to other binary file
+// types (ELF, PE), so I want this to be fairly independent from the
+// specifics about how it is being displayed. However, I think it would
+// also be nice to have a single (or couple) structures that can be serialied
+// and saved to store the project session state. I think for the time being I
+// will let this get as gross as possible while adding new features and I'll
+// clean this up later when I have a better idea.
+// - brendanfh 2021/07/15
Wasm_Analyzer_State :: struct {
allocator := context.allocator;
wasm_binary : wasm.WasmBinary;
wasm_sections : wasm.WasmSections;
- windows : map.Map(u32, ui.Window_State);
+ window_states : map.Map(u32, ui.Window_State);
- sidebar_window := ui.Window_State.{ .{0,0}, .{400,400} };
- sidebar_expansion := 0.0f;
sidebar_expansion_target := 0.0f;
-
- init :: (use state: ^Wasm_Analyzer_State) {
- __initialize(state);
-
- sidebar_window.border_width = 0;
- sidebar_window.border_color = .{ 0, 0, 0 };
- sidebar_window.background_color = config.Colors.dark_background;
- sidebar_window.active_color = config.Colors.background;
- }
}
load_wasm_binary :: (use state: ^Wasm_Analyzer_State, @transfers_ownership data: [] u8) {
window_width, window_height := gfx.get_window_size();
sidebar_window.position = .{ (sidebar_expansion - 1) * sidebar_window.size.x, y_offset };
sidebar_window.size.y = ~~window_height - y_offset;
+ sidebar_window.active_color = config.Colors.background;
+ sidebar_window.background_color = config.Colors.dark_background;
+ sidebar_window.border_width = 0;
sidebar_rectangle := ui.Rectangle.{ 0, 0, sidebar_window.size.x, sidebar_window.size.y };
ui.window_start(^sidebar_window);
defer ui.window_end();
+ // since there is only one sidebar, these can be persistant.
+ // Should all the sidebar state just be persistant variables tho??
#persist x_scroll := 0.0f;
#persist y_scroll := 0.0f;
+ #persist sidebar_window := ui.Window_State.{ gfx.Vector2.{0,0}, gfx.Vector2.{400,400} };
+ #persist sidebar_expansion := 0.0f;
+
ui.scrollable_region_start(sidebar_rectangle, ^x_scroll, ^y_scroll);
defer ui.scrollable_region_stop();
}
}
+draw_windows :: (use state: ^Wasm_Analyzer_State) {
+}