From 56146c07dde86ecd45410a7687922cd35c98738b Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Thu, 30 Dec 2021 14:40:33 +0100 Subject: [PATCH] Improve UV editor zooming behavior --- js/texturing/uv.js | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/js/texturing/uv.js b/js/texturing/uv.js index 8110637e..b0c02886 100644 --- a/js/texturing/uv.js +++ b/js/texturing/uv.js @@ -1811,17 +1811,27 @@ Interface.definePanels(function() { this.zoom = number; - let {viewport} = this.$refs; - let offset = $(this.$refs.viewport).offset() - let offsetX = event.clientX - offset.left; - let offsetY = event.clientY - offset.top; - - let zoom_diff = this.zoom - old_zoom; - viewport.scrollLeft += ((viewport.scrollLeft + offsetX) * zoom_diff) / old_zoom - viewport.scrollTop += ((viewport.scrollTop + offsetY) * zoom_diff) / old_zoom - - this.updateMouseCoords(event) - if (Painter.selection.overlay) UVEditor.updatePastingOverlay() + let updateScroll = () => { + let {viewport} = this.$refs; + let offset = $(this.$refs.viewport).offset() + let offsetX = event.clientX - offset.left; + let offsetY = event.clientY - offset.top; + // Make it a bit easier to scroll into corners + offsetX = (offsetX - this.width/2) * 1.1 + this.width/2; + offsetY = (offsetY - this.height/2) * 1.1 + this.height/2; + let zoom_diff = this.zoom - old_zoom; + + viewport.scrollLeft += ((viewport.scrollLeft + offsetX) * zoom_diff) / old_zoom + viewport.scrollTop += ((viewport.scrollTop + offsetY) * zoom_diff) / old_zoom + + this.updateMouseCoords(event) + if (Painter.selection.overlay) UVEditor.updatePastingOverlay() + } + if (n > 0) { + Vue.nextTick(updateScroll); + } else { + updateScroll(); + } return false; }