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

Group selection Resize and Rotate not working when canvas has perPixelTargetFind true #6631

Closed
mpecenin opened this issue Oct 4, 2020 · 18 comments
Labels

Comments

@mpecenin
Copy link

mpecenin commented Oct 4, 2020

Version

4.2.0

  • fails from 4.0.0
  • works until 4.0.0-rc.1

Test Case

http://jsfiddle.net/s0tn3e15/

Information about environment

  • Chrome Browser - Ubuntu Linux
  • Firefox Browser - Ubuntu Linux

Steps to reproduce

  • create a fabric.Canvas with perPixelTargetFind=true
  • create and select multiple objects on the canvas
  • try to resize or rotate the selection

Expected Behavior

  • allow resize and rotate the group selection
    image

Actual Behavior

  • does not recognize mouse pointer at resize and rotation points of the group
  • works only when in the upper left corner of the canvas
    image
@asturur
Copy link
Member

asturur commented Oct 4, 2020

does it work with normal objects?

@mpecenin
Copy link
Author

mpecenin commented Oct 4, 2020

Yes, it works fine with a single object.

@stale
Copy link

stale bot commented Oct 18, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issue marked as stale by the stale bot label Oct 18, 2020
@phil-r
Copy link

phil-r commented Oct 19, 2020

That's still an issue, I don't think it should be closed

@stale stale bot removed the stale Issue marked as stale by the stale bot label Oct 19, 2020
@stale
Copy link

stale bot commented Nov 3, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issue marked as stale by the stale bot label Nov 3, 2020
@mpecenin
Copy link
Author

mpecenin commented Nov 3, 2020

Unfortunately still a problem on linux environment.

@stale stale bot removed the stale Issue marked as stale by the stale bot label Nov 3, 2020
@asturur
Copy link
Member

asturur commented Nov 15, 2020

I do not have any linux machine to test it out.
@phil-r does this happen on every OS?

@asturur
Copy link
Member

asturur commented Nov 15, 2020

No the problem is clearly on macOS too.

@asturur asturur added the bug label Nov 15, 2020
@phil-r
Copy link

phil-r commented Nov 16, 2020

Tested on windows - seems to be fine, but on Mac OS there is an issue.

@marshall76963
Copy link

I think I have seen similar behaviour on windows using 4.2 but with ActiveSelection.

The grab handles are only available where the selection intersects with an object within the group (hence why in the original example. top-left works).

After some experimentation, the issue is that ActiveSelection is transparent and, with per-pixel target set, this causes the area inside the selection (including the corners) to be ignored.

This check is performed in the _checkTarget(pointer, obj, globalPointer) function in fabric.Canvas

My workaround is to remove the per-pixel target find check by overriding the default implementation as follows:

fabric.Canvas.prototype._checkTarget = (function (_checkTarget) {
    return function (pointer, obj, _globalPointer) {
        return obj && obj.visible && obj.evented && (obj.containsPoint(pointer) || !!obj._findTargetCorner(pointer));
    };
})(fabric.Canvas.prototype._checkTarget);

This makes the entire area of an ActiveSelection selectable and all control points accessible.

Hope this helps someone!

@linrz
Copy link
Contributor

linrz commented Nov 25, 2020

I debug this problem for a long time, your patch helped me, thanks very much! @marshall76963

@marshall76963
Copy link

Glad it helped you @linrz

I just came up with an alternative solution that might be slightly better. The issue with overriding the _checkTarget(pointer, obj, globalPointer) function in fabric.Canvas is it changes the select behaviour of the whole object, not just the selection points.

If you just want to make the selection points available to ActiveSelections, then try this:

fabric.Canvas.prototype.findTarget = (function (findTarget) {
    return function (e, skipGroup) {
        var result = findTarget.apply(this, [e, skipGroup]);
        if (!(result && (skipGroup || this.skipTargetFind))) {
            var obj = this._activeObject;
            if (obj && obj.type === "activeSelection" && obj._findTargetCorner(this.getPointer(e, true), fabric.util.isTouchEvent(e))) {
                result = obj;
            }
        }
        return result
    };
})(fabric.Canvas.prototype.findTarget);

Cheers

@mpecenin
Copy link
Author

It works again from Fabric-4.4.0 and up

@asturur
Copy link
Member

asturur commented Jun 1, 2021

i think this was fixed from this:
#6798
in version 4.3.1
Sorry i missed this there are so many open issues i can't discern easily which are help request and which are actual bugs

@mpecenin
Copy link
Author

mpecenin commented Jun 1, 2021

Ok thanks, but I checked it again, only from version 4.4.0 it works on my Linux. Version 4.3.1 (cdnjs.com) does not work on Linux, but it works normally on Windows.

@asturur
Copy link
Member

asturur commented Jun 6, 2021

not sure why the os should make a difference. The code change between 4.3.1 and 4.4.0 was effectively fixing a generic bug.

@mpecenin
Copy link
Author

mpecenin commented Jun 7, 2021

Yeah, i agree, it sounds weird, i haven't figured out why this only happens with Chrome on Linux.

But i checked that version 4.4.0 has this fix #6798, not 4.3.1, and looking the files changed, it has this commit 537eeb5 to canvas.class.js. Testing with the previous commit ee17127 i got the problem again.

So it looks fixed with #6798 as you mentioned earlier, but it looks like it was released with v4.4.0

@guidolx
Copy link

guidolx commented Dec 23, 2022

Hi,
This still seems not to be working in Fabric 5.2.4. I can't resize or rotate groups , no matter if the value of perPixelTargetFind is true or false. I am on a Mac and using Firefox, same results in Safari.

This is my code to create a fabric.Group

export class GraphNode extends fabric.Group{
node: Node;

constructor(left: number, top: number, node:Node){
    super([],{
        left:left,
        top:top,
        originX:'center',
        originY:'center',
        data:node
    });
    this.node = node;
    this.init();
    this._calcBounds(true);
}

}

I

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants