mirror of https://github.com/lgc-4/DataTools3.git
zooming-ish
This commit is contained in:
parent
d30cfc2c59
commit
eb0bc9d9b9
|
@ -4,7 +4,8 @@ Modular data conversion tools (for developers)
|
||||||
|
|
||||||
## TODO:
|
## TODO:
|
||||||
|
|
||||||
- [ ] zooming
|
- [X] zooming
|
||||||
|
- [ ] fix zooming font size
|
||||||
- [ ] controls explanation
|
- [ ] controls explanation
|
||||||
- [ ] typed values
|
- [ ] typed values
|
||||||
- [ ] implicit type conversion
|
- [ ] implicit type conversion
|
||||||
|
|
|
@ -57,6 +57,8 @@ document.addEventListener("mousemove", (e) => {
|
||||||
Mouse.updatePosition(e.clientX, e.clientY);
|
Mouse.updatePosition(e.clientX, e.clientY);
|
||||||
|
|
||||||
let delta = Mouse.getDelta();
|
let delta = Mouse.getDelta();
|
||||||
|
delta.x *= 1/Camera.zoom;
|
||||||
|
delta.y *= 1/Camera.zoom;
|
||||||
|
|
||||||
if (draggingBox != null) {
|
if (draggingBox != null) {
|
||||||
draggingBox.x += delta.x;
|
draggingBox.x += delta.x;
|
||||||
|
@ -66,18 +68,24 @@ document.addEventListener("mousemove", (e) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (draggingCamera) {
|
if (draggingCamera) {
|
||||||
Camera.x -= delta.x;
|
Camera.movePosition(-delta.x, -delta.y);
|
||||||
Camera.y -= delta.y;
|
|
||||||
|
|
||||||
Box.updateAllPositions();
|
|
||||||
|
|
||||||
document.getElementById("canvas").style.backgroundPosition = (-Camera.x) + "px " + (-Camera.y) + "px";
|
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.addEventListener("wheel", (e) => {
|
||||||
|
let lastZoom = Camera.zoom;
|
||||||
|
Camera.zoom = Math.min(1, Math.max(0.25, Camera.zoom - e.deltaY / 2000));
|
||||||
|
|
||||||
|
document.body.style.setProperty("--zoom", Camera.zoom);
|
||||||
|
|
||||||
|
Camera.movePosition(
|
||||||
|
(Mouse.position.x / lastZoom - Mouse.position.x / Camera.zoom),
|
||||||
|
(Mouse.position.y / lastZoom - Mouse.position.y / Camera.zoom),
|
||||||
|
);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
function isPointInRect(px, py, rx, ry, rw, rh) {
|
function isPointInRect(px, py, rx, ry, rw, rh) {
|
||||||
return px >= rx && px <= rx + rw && py >= ry && py <= ry + rh;
|
return px >= rx && px <= rx + rw && py >= ry && py <= ry + rh;
|
||||||
}
|
}
|
|
@ -1,4 +1,17 @@
|
||||||
class Camera {
|
class Camera {
|
||||||
static x = 0;
|
static x = 0;
|
||||||
static y = 0;
|
static y = 0;
|
||||||
|
static zoom = 1;
|
||||||
|
|
||||||
|
static setPosition(x, y) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
Box.updateAllPositions();
|
||||||
|
|
||||||
|
document.getElementById("canvas").style.backgroundPosition = (-Camera.x) + "px " + (-Camera.y) + "px";
|
||||||
|
}
|
||||||
|
|
||||||
|
static movePosition(x, y) {
|
||||||
|
this.setPosition(this.x + x, this.y + y);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -27,6 +27,7 @@ body {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
|
--zoom: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#canvas {
|
#canvas {
|
||||||
|
@ -38,6 +39,7 @@ body {
|
||||||
background-image: url("icons/background.svg");
|
background-image: url("icons/background.svg");
|
||||||
background-size: 80px 80px;
|
background-size: 80px 80px;
|
||||||
z-index: 0;
|
z-index: 0;
|
||||||
|
zoom: var(--zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
#playground {
|
#playground {
|
||||||
|
@ -48,6 +50,8 @@ body {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow: none;
|
overflow: none;
|
||||||
|
zoom: var(--zoom);
|
||||||
|
font-size: calc(1em * var(--zoom));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -110,6 +114,7 @@ input, textarea, select, button {
|
||||||
background-color: #25252577;
|
background-color: #25252577;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
border: 1px solid #111;
|
border: 1px solid #111;
|
||||||
|
font-size: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
button:hover, select:hover {
|
button:hover, select:hover {
|
||||||
|
|
Loading…
Reference in New Issue