Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply viewport transform when calculating isTargetTransparent() #2980

Merged
merged 1 commit into from
Jul 2, 2016
Merged

Apply viewport transform when calculating isTargetTransparent() #2980

merged 1 commit into from
Jul 2, 2016

Conversation

kherock
Copy link
Contributor

@kherock kherock commented May 18, 2016

This fixes a bug with how an interactive canvas with perPixelTargetFind behaves after being panned/zoomed.

Version

1.6.2

Test Case

http://jsfiddle.net/d10y74q7/5/

Steps to reproduce

  1. Turn perPixelTargetFind on for a Canvas instance
  2. Modify the viewport of the canvas (pan or zoom)
  3. Attempt to select objects of the interactive canvas

Expected Behavior

Cursor should change to the move cursor when over opaque pixels, and clicking & dragging should move items.

Actual Behavior

Objects can only be interacted with when the XY coordinates of the pointer are coincidentally over opaque pixels in the canvas with an unmodified viewport.

@kherock kherock changed the title Apply viewport transform when calculating isTargetTransparent Apply viewport transform when calculating isTargetTransparent() May 18, 2016
@kherock
Copy link
Contributor Author

kherock commented May 18, 2016

Ok, I just discovered that the fix is still incomplete with my commit as the resize handles are still not selectable after panning/zooming. I'll see if I can figure out what's wrong.

EDIT: I adjusted the commit, it turned out that _renderControls(ctx) already handles applying the viewport transform, so the context just needed to be restored before that line. This issue appears to be completely fixed now.

@asturur
Copy link
Member

asturur commented May 18, 2016

i'm guessing if is better to transform the coordinate of mouse or the context from a performance point of view.
I added that shouldTransform because i did not want to save restore and transform on every mouse move when isTargetTransparent is used.

@kherock
Copy link
Contributor Author

kherock commented May 18, 2016

I suppose the only optimization that could be made there is to check that viewportTransform hasn't deviated from its default setting before we start saving or restoring the context. However it should be expected that there be some performance hit when we have perPixelTargetFind turned on.

What do you suggest should be done to get this resolved?

@kherock
Copy link
Contributor Author

kherock commented May 18, 2016

Keep in mind, this transform is already being done when _renderControls(ctx) is called. If you wanted, we could just have _renderControls() ignore the viewport and have the caller take care of that, like it currently is in renderAll() calling render():

/* static_canvas.class.js */

    renderAll: function () {
      ...
      canvasToDrawOn.save();
      objsToRender = this._chooseObjectsToRender();
      //apply viewport transform once for all rendering process
      canvasToDrawOn.transform.apply(canvasToDrawOn, this.viewportTransform);
      this._renderObjects(canvasToDrawOn, objsToRender);
      ...
    }

@asturur
Copy link
Member

asturur commented May 18, 2016

no renderControls can't be touched easily. Jsut guessing if is lighter to tranform a context or a mouse coordinates.

@kherock
Copy link
Contributor Author

kherock commented May 18, 2016

Ok. I'm not sure transforming mouse coordinates would be a proper fix though. I updated the jsfiddle to better illustrate the issue. The problem with transforming mouse coordinates is that when your transformed pointer leaves the original viewport, it is seen as transparent since the cache canvas has not rendered that area.

@asturur
Copy link
Member

asturur commented May 19, 2016

I'm getting a mac next week. waiting for it so i test this + retina screen and i will merge or ask you for tweak.

@kherock
Copy link
Contributor Author

kherock commented May 26, 2016

Any updates?

By the way, you can set the device pixel ratio with Chrome's dev tools or just by setting the browser's zoom level before the page loads. I've tested that to all work fine.

@asturur
Copy link
Member

asturur commented May 26, 2016

got mac yesterday. I know i can test with device pixel ration ( also with browser zoom sadly, that is the problem ). I need some days to get back on the issues and prs.

@kherock
Copy link
Contributor Author

kherock commented Jun 10, 2016

Bumping. Have you had time to test this recently?

@asturur asturur merged commit 62da4fd into fabricjs:master Jul 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants