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

limitedToCanvasSize property to brush #6719

Merged
merged 8 commits into from
Jan 30, 2021
Merged

limitedToCanvasSize property to brush #6719

merged 8 commits into from
Jan 30, 2021

Conversation

CharlesRA
Copy link
Contributor

In fabricjs it's quite difficult to control the different tools and manage their limits. Moreover, the stackoverflow question remained unanswered.

So I added the limitedToCanvasSize property to prevent free drawing outside canvas boudaries.

@asturur
Copy link
Member

asturur commented Dec 12, 2020

I'm not opposed to this, but i would like it to a method of base brush class, and used in all the brushes. It can't be a one thing for the pencil brush.

*/

_isOutSideCanvas: function(pointer) {
if (pointer.x < 0 || pointer.x > this.canvas.getWidth() || pointer.y < 0 || pointer.y > this.canvas.getHeight()) {
Copy link
Member

Choose a reason for hiding this comment

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

I would like to return this expression rather than having an if that return true or false.

@@ -76,6 +76,9 @@ fabric.CircleBrush = fabric.util.createClass(fabric.BaseBrush, /** @lends fabric
this._render();
}
else {
if (this.limitedToCanvasSize === true && this._isOutSideCanvas(pointer)) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

in the pencil brush we are returning immediately if the condition match.
Why are we allowing the full render here?

return;
}
fabric.BaseBrush = fabric.util.createClass(
/** @lends fabric.BaseBrush.prototype */ {
Copy link
Member

Choose a reason for hiding this comment

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

sending this comment one line down makes all the diff bigger than necessary.
This is kind of a problem for an open project since is less clear what has changed and makes the PR harder to review.

@asturur
Copy link
Member

asturur commented Dec 19, 2020

Hi @CharlesRA i left a couple of minor comments and questions.
When you make the PR, please do not commit the full build library.
To restore it back you can user git checkout master dist will bring back the dist folder to the master version.
We build it each release.

@CharlesRA
Copy link
Contributor Author

CharlesRA commented Dec 20, 2020

Hi !
Sorry for the mistakes, I'm new to open source contribution and programming but i try to help here or on stackoverflow 😊.
I made the changes you asked me to do, are there other things that are wrong ?

@CharlesRA CharlesRA changed the title limitedToCanvasSize property to pencil brush limitedToCanvasSize property to brush Dec 21, 2020
@asturur
Copy link
Member

asturur commented Dec 23, 2020

Testing this today and merging

@stale
Copy link

stale bot commented Jan 6, 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 Jan 6, 2021
@stale stale bot closed this Jan 14, 2021
@CharlesRA
Copy link
Contributor Author

Hello, do I need to do something else for this PR ?

@asturur asturur reopened this Jan 28, 2021
@stale stale bot removed the stale Issue marked as stale by the stale bot label Jan 28, 2021
@asturur
Copy link
Member

asturur commented Jan 28, 2021

I do not remember outstanding comments, i have just been busy.

@asturur asturur merged commit b4ab0ff into fabricjs:master Jan 30, 2021
@asturur
Copy link
Member

asturur commented Jan 30, 2021

Thank you for the PR, and sorry for taking so much time to handle it.

@asturur
Copy link
Member

asturur commented Jan 30, 2021

I'll add a test for it, please have a look at how is done, so next time you can write one too

@asturur asturur mentioned this pull request Apr 7, 2021
@SatwinderKaur
Copy link

SatwinderKaur commented May 27, 2021

@asturur I hwas having issues with LimitedToCanvasSize when we have zoom on Canvas. I could not draw on the whole canvas, only on a part of it. I think because we ignore zoom , when getting pointer. :
_onMouseMoveInDrawingMode: function(e) { if (this._isCurrentlyDrawing) { var pointer = this.getPointer(e); // this.getPointer(e,true) seemed to work in my case

Can we please include zoomed canvas support in the code and pass correct pointer in _isOutSideCanvas: function(pointer)

@KonMost
Copy link

KonMost commented Feb 15, 2022

Hi all,

can someone help me on how to modify the circle_brush.class in order to get an ellipse/slanted line instead of a circle as brush tip to draw the freedrawing lines? i think this would be the place to add a calligraphy kind of brush. i tried changing my min.js but it did not take the slanted line or oval as brush tip. please advise

@KonMost KonMost mentioned this pull request Feb 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants