|
|
|
@ -8,7 +8,7 @@ import styles from "./MiddlePane.module.css";
|
|
|
|
|
const ZOOM_STRENGTH = -0.005;
|
|
|
|
|
|
|
|
|
|
export default function MiddlePane(props) {
|
|
|
|
|
let {settings, setSettings, world} = props;
|
|
|
|
|
let {settings, setSettings, world, blit} = props;
|
|
|
|
|
let mounted = true;
|
|
|
|
|
|
|
|
|
|
let [canvas, setCanvas] = createStore({
|
|
|
|
@ -273,11 +273,12 @@ export default function MiddlePane(props) {
|
|
|
|
|
return [x, y];
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let _canvas;
|
|
|
|
|
let _canvas, container;
|
|
|
|
|
return (<div
|
|
|
|
|
class={styles.MiddlePane}
|
|
|
|
|
onMount={set_resize()}
|
|
|
|
|
onCleanup={remove_resize()}
|
|
|
|
|
ref={container}
|
|
|
|
|
>
|
|
|
|
|
<canvas
|
|
|
|
|
ref={(el) => {
|
|
|
|
@ -290,8 +291,8 @@ export default function MiddlePane(props) {
|
|
|
|
|
onMount={() => {mounted = true}}
|
|
|
|
|
onCleanup={() => {mounted = false}}
|
|
|
|
|
onMouseDown={(evt) => {
|
|
|
|
|
let mouse_x = evt.clientX - canvas.element.offsetLeft;
|
|
|
|
|
let mouse_y = evt.clientY - canvas.element.offsetTop;
|
|
|
|
|
let mouse_x = evt.clientX - container.offsetLeft;
|
|
|
|
|
let mouse_y = evt.clientY - container.offsetTop;
|
|
|
|
|
setMouse((mouse) => {
|
|
|
|
|
return {
|
|
|
|
|
...mouse,
|
|
|
|
@ -309,17 +310,17 @@ export default function MiddlePane(props) {
|
|
|
|
|
|
|
|
|
|
if (mouse.down) {
|
|
|
|
|
// TODO: numerically stable solution
|
|
|
|
|
setView("cx", view.cx + (evt.clientX - canvas.element.offsetLeft) - mouse.x);
|
|
|
|
|
setView("cy", view.cy + (evt.clientY - canvas.element.offsetTop) - mouse.y);
|
|
|
|
|
setView("cx", view.cx + (evt.clientX - container.offsetLeft) - mouse.x);
|
|
|
|
|
setView("cy", view.cy + (evt.clientY - container.offsetTop) - mouse.y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setMouse("x", evt.clientX - canvas.element.offsetLeft);
|
|
|
|
|
setMouse("y", evt.clientY - canvas.element.offsetTop);
|
|
|
|
|
setMouse("x", evt.clientX - container.offsetLeft);
|
|
|
|
|
setMouse("y", evt.clientY - container.offsetTop);
|
|
|
|
|
}}
|
|
|
|
|
onMouseUp={(evt) => {
|
|
|
|
|
setMouse("down", false);
|
|
|
|
|
setMouse("x", evt.clientX - canvas.element.offsetLeft);
|
|
|
|
|
setMouse("y", evt.clientY - canvas.element.offsetTop);
|
|
|
|
|
setMouse("x", evt.clientX - container.offsetLeft);
|
|
|
|
|
setMouse("y", evt.clientY - container.offsetTop);
|
|
|
|
|
|
|
|
|
|
let dist = Math.sqrt((mouse.x - mouse.click_x) ** 2 + (mouse.y - mouse.click_y) ** 2);
|
|
|
|
|
if (dist < 10) {
|
|
|
|
@ -344,6 +345,28 @@ export default function MiddlePane(props) {
|
|
|
|
|
setView("cx", view.cx * delta);
|
|
|
|
|
setView("cy", view.cy * delta);
|
|
|
|
|
}}
|
|
|
|
|
onDrop={(evt) => {
|
|
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
|
|
container.classList.remove(styles.dragging);
|
|
|
|
|
let data = JSON.parse(evt.dataTransfer.getData("application/json"));
|
|
|
|
|
|
|
|
|
|
blit(data, ...getHovered());
|
|
|
|
|
|
|
|
|
|
setSettings("selected", getHovered());
|
|
|
|
|
}}
|
|
|
|
|
onDragOver={(evt) => {
|
|
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
|
|
container.classList.add(styles.dragging);
|
|
|
|
|
setMouse("hovering", true);
|
|
|
|
|
setMouse("x", evt.clientX - container.offsetLeft);
|
|
|
|
|
setMouse("y", evt.clientY - container.offsetTop);
|
|
|
|
|
}}
|
|
|
|
|
onDragLeave={(evt) => {
|
|
|
|
|
setMouse("hovering", false);
|
|
|
|
|
container.classList.remove(styles.dragging);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Sowwy, your browser does not support canvases.
|
|
|
|
|
</canvas>
|
|
|
|
|