-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for drag and drop in emscripten
- Loading branch information
Chris Greening
committed
Dec 10, 2024
1 parent
e0d1e41
commit 52f4b37
Showing
6 changed files
with
178 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<!doctype html> | ||
<html lang="en-us"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||
<title>ZX Spectrum Emulator</title> | ||
<style> | ||
body { | ||
margin: 0; | ||
background-color: black; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
} | ||
.emscripten { | ||
padding-right: 0; | ||
margin-left: auto; | ||
margin-right: auto; | ||
display: block; | ||
} | ||
#canvas { | ||
border: 0px none; | ||
background-color: black; | ||
} | ||
#drop-zone { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
display: none; | ||
background: rgba(0,0,0,0.7); | ||
align-items: center; | ||
justify-content: center; | ||
color: white; | ||
font-family: Arial, sans-serif; | ||
font-size: 24px; | ||
} | ||
.active { | ||
display: flex !important; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas> | ||
<div id="drop-zone">Drop TAP, TZX, or Z80 file here</div> | ||
<script> | ||
var Module = { | ||
canvas: (function() { | ||
var canvas = document.getElementById('canvas'); | ||
return canvas; | ||
})() | ||
}; | ||
|
||
// Drag and drop handling | ||
const dropZone = document.getElementById('drop-zone'); | ||
|
||
document.body.addEventListener('dragenter', (e) => { | ||
e.preventDefault(); | ||
dropZone.classList.add('active'); | ||
}); | ||
|
||
dropZone.addEventListener('dragleave', (e) => { | ||
e.preventDefault(); | ||
dropZone.classList.remove('active'); | ||
}); | ||
|
||
dropZone.addEventListener('dragover', (e) => { | ||
e.preventDefault(); | ||
}); | ||
|
||
dropZone.addEventListener('drop', async (e) => { | ||
e.preventDefault(); | ||
dropZone.classList.remove('active'); | ||
|
||
const file = e.dataTransfer.files[0]; | ||
const arrayBuffer = await file.arrayBuffer(); | ||
Module.loadDroppedFile(file.name, arrayBuffer); | ||
}); | ||
</script> | ||
{{{ SCRIPT }}} | ||
</body> | ||
</html> |
Binary file not shown.