From fe66782c145ac9d8c66fe920ef163f825c8bcaf1 Mon Sep 17 00:00:00 2001 From: Daniel Garcia Briseno <94071409+dgarciabriseno@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:44:20 -0500 Subject: [PATCH] Adhere zoom to settings --- .../js/Viewport/Helper/HelioviewerZoomer.js | 59 ++++++++++++++++++- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/resources/js/Viewport/Helper/HelioviewerZoomer.js b/resources/js/Viewport/Helper/HelioviewerZoomer.js index 5fe26b397..b35a6f02c 100644 --- a/resources/js/Viewport/Helper/HelioviewerZoomer.js +++ b/resources/js/Viewport/Helper/HelioviewerZoomer.js @@ -27,6 +27,10 @@ const MAX_THRESHOLD = 1.5; this._maxImageScale = zoomLevels[0]; this._minImageScale = zoomLevels[zoomLevels.length - 1]; this._slider = new ZoomControls(this._maxImageScale, zoomLevels.length - 1, this._targetCenter.bind(this), this.jumpToZoomLevel.bind(this)); + this._step = { + lock: false, + lastVal: 0 + }; Helioviewer.userSettings.set('mobileZoomScale', 1); // Make sure the sun is centered when the user requests centering the viewport @@ -253,14 +257,26 @@ const MAX_THRESHOLD = 1.5; * Fired when 2 fingers touch the screen */ pinchStart(center) { - this.setAnchorForCenter(center); + if (Helioviewer.userSettings.get('zoom.focus') == 'center') { + // If setting is set to focus on the center of the screen, always do that. + this._targetCenter(); + } else { + // Focus on the target that was given by the pinch/cursor. + this.setAnchorForCenter(center); + } this._last_size = 0; + this._step.lastVal = 0; } /** * Fires as a user pinches/stretches */ pinchUpdate(size) { + // Don't do anything if the user has step zoom enabled. + if (Helioviewer.userSettings.get('zoom.type') == 'step') { + this._stepZoom(size) + return; + } let change = (size - this._last_size) / 200; this.setScale(this._scale + change); this._last_size = size; @@ -269,6 +285,29 @@ const MAX_THRESHOLD = 1.5; pinchEnd() { } + /** + * Handle step zooming if user has enabled it. + */ + _stepZoom(size) { + // Debounce the step zoom. A lot of step events can come in at once. + if (this._step.lock) { + return; + } + + if (size > this._step.lastVal) { + this._zoomHelioviewer(2, true); + } else if (size < this._step.lastVal) { + this._zoomHelioviewer(0.5, false); + } else { + // zoom didn't change, don't enable the scroll lock, just do nothing. + // this happens on some high resolution touchpads (mac) + return; + } + this._step.lastVal = size; + this._step.lock = true; + setTimeout(() => {this._step.lock = false;}, 500); + } + onUpdateViewport() { // Set anchor to center screen let center = { @@ -332,14 +371,28 @@ const MAX_THRESHOLD = 1.5; * Executed when the zoom in button is clicked. */ _smoothZoomIn() { - this._animateZoom(2, 0.2); + this._targetCenter(); + // Non step zoom will use zoom animation. + if (Helioviewer.userSettings.get('zoom.type') != 'step') { + this._animateZoom(2, 0.2); + } else { + // Step zoom just jumps forward + this._zoomHelioviewer(2, true); + } } /** * Executed when the zoom out button is clicked. */ _smoothZoomOut() { - this._animateZoom(0.5, 0.2); + this._targetCenter(); + // Non step zoom will use zoom animation. + if (Helioviewer.userSettings.get('zoom.type') != 'step') { + this._animateZoom(0.5, 0.2); + } else { + // step zoom will just jump out. + this._zoomHelioviewer(0.5, false); + } } /**