diff --git a/app/src/components/SVGContent.vue b/app/src/components/SVGContent.vue index c974e77..79764ca 100644 --- a/app/src/components/SVGContent.vue +++ b/app/src/components/SVGContent.vue @@ -319,6 +319,8 @@ export default defineComponent({ mousePosition.y = (mouse.clientY - transform.y) / currentRatio; }); + let gamePadZoomSpeed = 10; + function animate() { if (stats) { stats.begin(); @@ -374,6 +376,38 @@ export default defineComponent({ } } + if (navigator.getGamepads) { + var gamepads = navigator.getGamepads(); + var gp = gamepads[0]; + + if (gp) { + if (gp.buttons[7].pressed) { + gamePadZoomSpeed += .1; + } + if (gp.buttons[5].pressed) { + gamePadZoomSpeed -= .1; + } + if (gamePadZoomSpeed < 1) { + gamePadZoomSpeed = 1; + } + if (gamePadZoomSpeed > 30) { + gamePadZoomSpeed = 30; + } + + const transform = pz.getTransform(); + + const horizontalShift = gp.axes[0] * -1 * gamePadZoomSpeed; + const verticalShift = gp.axes[1] * -1 * gamePadZoomSpeed; + + if (horizontalShift || verticalShift) { + pz.moveTo( + transform!.x + horizontalShift, + transform!.y + verticalShift + ); + } + } + } + if (stats) { stats.end(); }