Merge pull request #154 from paulkaplan/fix-pick-sizing
Fix picking when input size is different from native size
This commit is contained in:
commit
ace5d934f8
@ -623,15 +623,19 @@ class RenderWebGL extends EventEmitter {
|
|||||||
const drawable = this._allDrawables[drawableID];
|
const drawable = this._allDrawables[drawableID];
|
||||||
if (!drawable) return null;
|
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;
|
const gl = this._gl;
|
||||||
twgl.bindFramebufferInfo(gl, this._queryBufferInfo);
|
twgl.bindFramebufferInfo(gl, this._queryBufferInfo);
|
||||||
|
|
||||||
const bounds = drawable.getFastBounds();
|
const bounds = drawable.getFastBounds();
|
||||||
bounds.snapToInt();
|
bounds.snapToInt();
|
||||||
|
|
||||||
// Translate input x and y to coordinates relative to the drawable
|
// Translate to scratch units relative to the drawable
|
||||||
const pickX = x - ((this._nativeSize[0] / 2) + bounds.left);
|
const pickX = scratchX - bounds.left;
|
||||||
const pickY = y - ((this._nativeSize[1] / 2) - bounds.top);
|
const pickY = scratchY + bounds.top;
|
||||||
|
|
||||||
// Limit size of viewport to the bounds around the target Drawable,
|
// Limit size of viewport to the bounds around the target Drawable,
|
||||||
// and create the projection matrix for the draw.
|
// and create the projection matrix for the draw.
|
||||||
@ -672,8 +676,8 @@ class RenderWebGL extends EventEmitter {
|
|||||||
width: bounds.width,
|
width: bounds.width,
|
||||||
height: bounds.height,
|
height: bounds.height,
|
||||||
scratchOffset: [
|
scratchOffset: [
|
||||||
(this._nativeSize[0] / 2) - x + drawable._position[0],
|
-scratchX + drawable._position[0],
|
||||||
(this._nativeSize[1] / 2) - y - drawable._position[1]
|
-scratchY - drawable._position[1]
|
||||||
],
|
],
|
||||||
x: pickX,
|
x: pickX,
|
||||||
y: pickY
|
y: pickY
|
||||||
|
Loading…
x
Reference in New Issue
Block a user