From 46b878421783893efd297953968da59bf2dd0771 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Wed, 9 Aug 2017 15:40:32 -0400 Subject: [PATCH] Correctly convert input coords into scratch coords --- src/RenderWebGL.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/RenderWebGL.js b/src/RenderWebGL.js index e642d24..7118d37 100644 --- a/src/RenderWebGL.js +++ b/src/RenderWebGL.js @@ -623,15 +623,19 @@ class RenderWebGL extends EventEmitter { const drawable = this._allDrawables[drawableID]; if (!drawable) return null; + // Convert client coordinates into absolute scratch units + const scratchX = this._nativeSize[0] * ((x / this._gl.canvas.clientWidth) - 0.5); + const scratchY = this._nativeSize[1] * ((y / this._gl.canvas.clientHeight) - 0.5); + const gl = this._gl; twgl.bindFramebufferInfo(gl, this._queryBufferInfo); const bounds = drawable.getFastBounds(); bounds.snapToInt(); - // Translate input x and y to coordinates relative to the drawable - const pickX = x - ((this._nativeSize[0] / 2) + bounds.left); - const pickY = y - ((this._nativeSize[1] / 2) - bounds.top); + // Translate to scratch units relative to the drawable + const pickX = scratchX - bounds.left; + const pickY = scratchY + bounds.top; // Limit size of viewport to the bounds around the target Drawable, // and create the projection matrix for the draw. @@ -672,8 +676,8 @@ class RenderWebGL extends EventEmitter { width: bounds.width, height: bounds.height, scratchOffset: [ - (this._nativeSize[0] / 2) - x + drawable._position[0], - (this._nativeSize[1] / 2) - y - drawable._position[1] + -scratchX + drawable._position[0], + -scratchY - drawable._position[1] ], x: pickX, y: pickY