rework zoom to zoom into mouse location
Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
This commit is contained in:
parent
44e760f37d
commit
7e6df6819f
1 changed files with 16 additions and 5 deletions
|
@ -285,19 +285,30 @@ mouse.registerContext(
|
|||
mouse.listen.camera.onwheel.on((evn) => {
|
||||
evn.evn.preventDefault();
|
||||
|
||||
// Get cursor world position
|
||||
const cursorPosition = viewport.viewToCanvas(evn.x, evn.y);
|
||||
console.debug(cursorPosition);
|
||||
|
||||
// Get viewport center
|
||||
const pcx = viewport.cx;
|
||||
const pcy = viewport.cy;
|
||||
if (evn.delta < 0) {
|
||||
viewport.zoom *= 1 + Math.abs(evn.delta * 0.0002);
|
||||
} else {
|
||||
viewport.zoom *= 1 - Math.abs(evn.delta * 0.0002);
|
||||
}
|
||||
|
||||
// Apply zoom
|
||||
viewport.zoom *= 1 - evn.delta * 0.0002;
|
||||
|
||||
// Apply normal zoom (center of viewport)
|
||||
viewport.cx = pcx;
|
||||
viewport.cy = pcy;
|
||||
|
||||
viewport.transform(imageCollection.element);
|
||||
|
||||
// Calculate new viewport center and move
|
||||
const newCursorPosition = viewport.viewToCanvas(evn.x, evn.y);
|
||||
viewport.cx = pcx - (newCursorPosition.x - cursorPosition.x);
|
||||
viewport.cy = pcy - (newCursorPosition.y - cursorPosition.y);
|
||||
|
||||
viewport.transform(imageCollection.element);
|
||||
|
||||
toolbar.currentTool.redraw();
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue