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

Record group selection in transformed coordinates to support panning/zooming while group selecting #7088

Merged
merged 3 commits into from
Jul 4, 2021

Conversation

SLKnutson
Copy link
Contributor

Fixes this issue: #7086

There is still a slight issue because the group select controls don't get immediately rerendered when transforming, but I didn't want to shove too much into a single PR. I thought about making a feature toggle on fabric.Canvas, but I couldn't think of any use cases for the way it behaved before. I didn't see any existing methods of testing the contents of _drawSelection(). I'm glad to make changes as needed.

I changed _drawSelection to accommodate varying selectionLineWidth, since the previous implementation was essentially hardcoded to 1, and would draw outside the box for values > 1, now it should always draw within the box.

Thank you!

ex: pointer.x,
ey: pointer.y,
ex: this._absolutePointer.x,
ey: this._absolutePointer.y,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dream a day in which the local pointer goes away entirely and fabric uses only the absolute values, and we remove most of the conversions.

fabric.util.drawDashedLine(ctx, minX, minY, maxX, minY, this.selectionDashArray);
fabric.util.drawDashedLine(ctx, minX, maxY, maxX, maxY, this.selectionDashArray);
fabric.util.drawDashedLine(ctx, minX, minY, minX, maxY, this.selectionDashArray);
fabric.util.drawDashedLine(ctx, maxX, minY, maxX, maxY, this.selectionDashArray);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you check if IE11 supports dashed stroke? if it does, we can finally get rid of the block (!supportedLineDash)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the support link. Looks like IE 11 supports but I'm not sure if the support is good enough on other browsers like chrome? https://caniuse.com/mdn-api_canvasrenderingcontext2d_setlinedash

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes setLineDash is an old feature that was missing on ie10 only.
Since we do not support ie10 anymore, this is safe to go.

@asturur
Copy link
Member

asturur commented Jun 1, 2021

I think this PR is fine.
Not sure we can write an automated test for this, but ideally the only task of _drawSelection is to draw that rect. If while not zooming it works as before we are ok.
Can you capture in some way the issue you are referring to?

supportLineDash = fabric.StaticCanvas.supports('setLineDash'),
isTouchEvent = fabric.util.isTouchEvent,
STROKE_OFFSET = 0.5;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think STROKE_OFFSET is still needed. it is used because mouse events are always round numbers, while we want to draw single pixels line at 0.5.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, I think this actually to account for canvas drawing strokes down the center of the line. The hardcoded stroke offset of 0.5 works well for the default selectionLineWidth of 1, but doesn't look right for larger values. I think what I did accomplishes the same thing but allows for selectionLineWidth != 1

@asturur
Copy link
Member

asturur commented Jun 13, 2021

@SLKnutson any chance we can move this forward.
If you are busy is ok, just let me know if you know you won't have time, i ll do it ( if i'm enabled to push on your branch )

@SLKnutson
Copy link
Contributor Author

@asturur You can make changes as needed. I will eventually have time for this, but I'm not sure how far out in the future that would be. Thanks!

@stale
Copy link

stale bot commented Jun 28, 2021

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 Jun 28, 2021
@stale stale bot removed the stale Issue marked as stale by the stale bot label Jul 3, 2021
@asturur asturur merged commit 7efc732 into fabricjs:master Jul 4, 2021
@asturur asturur mentioned this pull request Aug 27, 2021
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.

None yet

2 participants