From 96fb6d8f164621a933354d64ccd661a660acc163 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Sun, 14 Nov 2010 17:21:43 -0500 Subject: [PATCH] Improve the algorithm for proportional mouse tracking Change the proportional algorithm so stop moving the zoom region when cursor is in a "padding region" at the edge of the screen. (The padding region is a 10th of the screen at 2x zoom, and smaller for higher zooms.) Based on earlier versions from Jon McCann and Florian Muellner. https://bugzilla.gnome.org/show_bug.cgi?id=629950 --- js/ui/magnifier.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/js/ui/magnifier.js b/js/ui/magnifier.js index 86a3f294b..edc3d00c2 100644 --- a/js/ui/magnifier.js +++ b/js/ui/magnifier.js @@ -1093,10 +1093,15 @@ ZoomRegion.prototype = { let [xRoi, yRoi, widthRoi, heightRoi] = this.getROI(); let halfScreenWidth = global.screen_width / 2; let halfScreenHeight = global.screen_height / 2; - let xProportion = (halfScreenWidth - xMouse) / halfScreenWidth; - let yProportion = (halfScreenHeight - yMouse) / halfScreenHeight; - let xPos = xMouse + xProportion * widthRoi / 2; - let yPos = yMouse + yProportion * heightRoi / 2; + // We want to pad with a constant distance after zooming, so divide + // by the magnification factor. + let unscaledPadding = Math.min(this._viewPortWidth, this._viewPortHeight) / 5; + let xPadding = unscaledPadding / this._xMagFactor; + let yPadding = unscaledPadding / this._yMagFactor; + let xProportion = (xMouse - halfScreenWidth) / halfScreenWidth; // -1 ... 1 + let yProportion = (yMouse - halfScreenHeight) / halfScreenHeight; // -1 ... 1 + let xPos = xMouse - xProportion * (widthRoi / 2 - xPadding); + let yPos = yMouse - yProportion * (heightRoi /2 - yPadding); return [xPos, yPos]; },