Coder Social home page Coder Social logo

Comments (7)

asturur avatar asturur commented on June 8, 2024 1

As a side not, offtopic from the discussion, the positioning problems are generally solved with setPositionByOrigin: on your mouse up event, take the object.getCenterPoint() as first thing, do what you want to the object, then do object.setPositionByOrigin(oldCenter, 'center', 'center') and will probably stop jumping.
But let's keep the offtopic as minimal as possible.

from api-discussion.

asturur avatar asturur commented on June 8, 2024

So this feature has been requested for ages.
A coworker of mine sort of made a prototype that is not exactly what you are talking about but is similar.

First of all i want to highlight that SVG behaves as fabricJS ( or vice versa ) a scaling is a scaling, and should scale the stroke too.

There are 2 options to keep in mind here.

First option:

You can either change the size of the objects as you are doing, in this case the boiler plate code would be sort of embedded in fabricJS but will not be less
The code is potentially very slow for complex paths, and need to be executed on each frame of scaling, and invalidates the cache each frame of scaling, it can't be optional.

Second option:

Do not resize objects, add an option to represent stroke always has object had scale of 1. This is much easier to implement and requires less coding. It requires anyway to rewrite the logic of bounding box for objects, it has the same drawback on cache, needs an invalidation per frame of scaling to be visually consistent. ( it can be left as an option )

This is does not include the skewing logic, and i m not sure it can.

Other things to consider:
Having the ability to make a path absorb a transformation and get the new points of the path ( or poly{thing}) is anyway a wanted feature and should be implemented.

Customizable controls is something else that people are looking forward to, and instead of mess up the scaling logic with a resizing one, it would be nice if devs could add their own handlers to controls in a way that the original logic is disconnected and a new one can be used.
Rewriting the actual rotation/scaling logic as an handler would be required and would serve as an example on how to build your own, for example, resizing logic.

Groups:
When scaling a group i can assure you that scaling the stroke with it is really the only option, or otherwise anything that looks like a composition gets screwed up. Also in this case resizing is sort of harder. In this case i would not even know what is the best thing to do.

In some way we will have consistent stroke during scaling, probably after clipPath have landed and canvas rotation is setup for a try, this is definitely a discussion i would like to bring on.
@stefanhayden is someone could have an opinion about it, and also @fabricjs/api-discussion involved in the group.

from api-discussion.

Aubron avatar Aubron commented on June 8, 2024

Agree with most of the above, one thought:

What we do is let the object scale from cache during the resizing operation, then just recalculate after modification. I would describe it as 'good enough', but that may be not enough for what you'd want to do with it. So in this example, we would show the deformed stroke until mouseup, and then it would recalculate the shape based on the modification, so that its size is 1:1 with canvas pixels. We just, overall, find having shapes be 1:1 with a canvas coordinate pixels makes a lot of logic easier as things get more complex, and try and avoid using scaleX and scaleY as much as possible. (We also completely replace polygons on modification with ones that line up to the canvas coordinates, for the same reason) We do the same thing with images, let the scaling operation show a blurry version until mouseup, then swap out the underlying src with a version that is 1:1 with the pixels being shown.

from api-discussion.

Aubron avatar Aubron commented on June 8, 2024

Again, we're probably taking an over simplistic approach here, but for us and groups, the same logic applies ('it should line up with what the cached scale looks like before mouseup, with the exception of stroke and whatnot')

from api-discussion.

Aubron avatar Aubron commented on June 8, 2024

On further inspection I am seeing some issues with how we do this. If a complex object already has a stroke, it jumps on modification, as taking into account the bounding box of the changing stroke is prohibitively difficult. For rectangle it looks like we take into account the stroke when calculating the width and height, but I don't really want to think about anything more complex than that.

from api-discussion.

stefanhayden avatar stefanhayden commented on June 8, 2024

yeah I would go for changing the stroke as the object scales. The math for this is fairly simple. You can do it live as the object scales though you obviously loose some performance.

This breaks svg compatibility as well but in many situations that's not really a big deal.

from api-discussion.

blobinabottle avatar blobinabottle commented on June 8, 2024

Note regarding svg compatibility you can use vector-effect="non-scaling-stroke"

from api-discussion.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.