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
Added clipping feature #114
Conversation
This is really cool! 😃 The only suggestion I have is to not patch the Great work, thanks! |
Well, I realized that canvas.clip() function only uses the last drawn path. In other words, it will not work with Display Objects with more than one path. We cannot guarantee that "clipChildren" property will work on all Display Objects, because any programmer can create his own display object. With this in mind, I think that the best solution is setting "clipChildren" property as a custom property of some display objects (actually all except Line and Text). When another programmer wants to create a new display object including the "clipChildren" property, he will have the resposibility of using "rect", "fill" and "stroke" (instead of "fillRect" and "strokeRect") and call canvas.clip() when "clipChildren" is true. If you agree with this, I will adapt all the current display objects and push a new commit. |
Oh you're right. It is possible to clip off things by drawing to a secondary canvas with |
I have adapted the following Display Objects:
I was just thinking about using For now we can use It is a pleasure to help the development of this library! 😀 |
The new commit (cbbb645) includes the changes. I am new using git, maybe its better for you copying the changed files instead of doing a merge:
|
Great! 😃 Well it's a great chance to learn git a bit more then! You seem to have gotten my latest commits bundled into your second commit here. The workflow that I try to follow is basically this: Add this official repo as a remote:
Start from the main development branch and pull in any changes from upstream:
Check out a new branch based on the current branch:
Make changes. Then stuff might have happened on upstream, so might want to pull these changes in, but as your commits are not merged to the main repo yet, you want your commits on top. You use
Then you need to make your branch be based on
Most often this will go just fine. If code changed in upstream in the same place as your change, there might be a conflict that you'll need to resolve. There's lots of good docs online about that. Right now you're in a bad state where your last commit contains stuff I changed on |
Now an object can "clip" its childs into its shape.
Before this change, the drawObject function restored the canvas before draw object's children. In that way, clipping feature was not possible.
Instead of restoring canvas and making again all parent's transformations, now the canvas is restored after children were drawn. This allows us to use the clip() function before draw the object's children.
I realized that the fillRect() function doesn't work fine with clip() -it paints the object above its children. That's the reason why I wrote the function fillRectClipping. This function executes a rect() then a fill() instead of a fillRect(). Using rect()+fill(), the object is painted below its children as expected.
Now the trick begins: when an object has a "clipChildren" property with a truthly value, the following happens:
When "clipChildren" property is not defined or it has a falsy value, only "obj.draw()" is invoked.
Here its an example of this clipping feature: