[PATCH/RFC] New feature: Enclose objects in groups when applying mask
Hi all,
I prefer adding objects into a group before applying a mask, because it allows me to manipulate masked content easily without unsetting mask. But I often forget to group objects before I apply a clip/mask. So I decided to take a look at inkscape source code and made this little feature that does it automatically for me. It needs one more thing to work properly though - when automatically enclosing each object in a group it should mark that group as made by that feature so when unsetting mask it ungroups only those automatically added groups.
So where should be stored some info about whether this group should be automatically removed? There are two possibilities that I think of: either inkscape:groupmode attribute or custom attribute for this purpose
Also, is it sufficient to manipulate those attributes directly or is there any class that takes responsibility for this? At least there is some code managing inkscape:groupmode attribute, right?
I've added a new checkbox in Inkscape Preferences/Clippaths and masks called "Enclose masked objects in groups" to activate this feature (disabled by default to be consistent with previous behavior), so don't forget to check it before testing ;)
As I'm not very familar with C++ or Inkscape source code I hope I've not introduced any memory leaks or crashes. Also if you find any coding style violations, please notify me.
Patch attached.
Any comments are welcome ;)
Best regards, Martin Sucha
Hi,
Sure this patch is wonderful, long awaited! Congrats!
Just to remember: there´s a bug that *should* be fixed as soon as possible. I don´t know if it occurs in mask too, but I´m sure it wasn´t there in 0.46, so, it's a regression.
https://bugs.launchpad.net/bugs/365458
As Granjow pointed in comments, "Isn't this a matter of 10 minutes if you know the code?"
Thanks
On Wed, Jan 27, 2010 at 5:20 PM, Martin Sucha <martin.sucha-ml@...2313...> wrote:
Hi all,
I prefer adding objects into a group before applying a mask, because it allows me to manipulate masked content easily without unsetting mask. But I often forget to group objects before I apply a clip/mask. So I decided to take a look at inkscape source code and made this little feature that does it automatically for me. It needs one more thing to work properly though - when automatically enclosing each object in a group it should mark that group as made by that feature so when unsetting mask it ungroups only those automatically added groups.
So where should be stored some info about whether this group should be automatically removed? There are two possibilities that I think of: either inkscape:groupmode attribute or custom attribute for this purpose
Also, is it sufficient to manipulate those attributes directly or is there any class that takes responsibility for this? At least there is some code managing inkscape:groupmode attribute, right?
I've added a new checkbox in Inkscape Preferences/Clippaths and masks called "Enclose masked objects in groups" to activate this feature (disabled by default to be consistent with previous behavior), so don't forget to check it before testing ;)
As I'm not very familar with C++ or Inkscape source code I hope I've not introduced any memory leaks or crashes. Also if you find any coding style violations, please notify me.
Patch attached.
Any comments are welcome ;)
Best regards, Martin Sucha
The Planet: dedicated and managed hosting, cloud storage, colocation Stay online with enterprise data centers and the best network in the business Choose flexible plans and management services without long-term contracts Personal 24x7 support from experience hosting pros just a phone call away. http://p.sf.net/sfu/theplanet-com _______________________________________________ Inkscape-devel mailing list Inkscape-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/inkscape-devel
Hi,
On Thursday 28 January 2010 17:18:24 Karlisson wrote:
Sure this patch is wonderful, long awaited! Congrats!
Thanks. It does need some more polishing though. (Also it currently adds objects to groups separately (if you are applying mask to more than one object, so it may not work exactly like you expect it to.)
There is a function that ungroups objects from groups (sp_item_group_ungroup) , but I have not seen any to group a list of objects into a group (it is done in selection-chemistry.cpp/sp_selection_group, but I'm not sure I can call it from sp_selection_set_mask directly... maybe little refactoring would help here... comments, anyone?)
Just to remember: there´s a bug that *should* be fixed as soon as possible. I don´t know if it occurs in mask too, but I´m sure it wasn´t there in 0.46, so, it's a regression.
Actually this bug is related to other parts of code. My patch modifies what is done when you are setting clip/mask whereas the bug is related to canvas editing. But I agree fixing this would be very useful (probably with some additional toolbar button/keystroke to temporarily disable clip/mask (not unset it) so the masked content could be easily edited?)
As Granjow pointed in comments, "Isn't this a matter of 10 minutes if you know the code?"
I'm afraid it would take more than 10 minutes even for an experienced Inkscape developer (unfortunately I'm beginner Inkscape developer) to fix this. Is there someone on this list willing to take a look at that?
Best regards, Martin Sucha
2010/1/28 Martin Sucha <martin.sucha-ml@...2313...>:
I'm afraid it would take more than 10 minutes even for an experienced Inkscape developer (unfortunately I'm beginner Inkscape developer) to fix this. Is there someone on this list willing to take a look at that?
What is the last known version of Inkscape that behaves correctly? Regards, Krzysztof
Hi Krzysztof and Karlisson,
On Thursday 28 January 2010 21:13:12 you wrote:
What is the last known version of Inkscape that behaves correctly? Regards, Krzysztof
I investigated this issue a little and it seems that it actually did not work (even) in Inkscape 0.46.
In 0.46, you can select invisible (clipped/masked) objects as well. The difference is that you need to click inside bounding box of visible part of the clipped object, so if you try this just with rectangles, it seems it is working. However, if you try this with e.g. circles, you can select that invisible part of the clipped object (provided you click inside the bounding box).
In current version (to be precise r9020, but I think it is current enough), you can select invisible parts of clipped objects even outside of that "small" bounding box that was in effect in 0.46. Please note that you cannot select invisible objects outside of area of drawing (as when you select "Resize page to drawing or selection" in Document properties). So it appears handling of bounding boxes is at least inconsistent in whether invisible parts of masked objects should be selected or not.
So one may say that neither version behaves correctly.
The change in behavior described above was caused by revision 7451, in nr_arena_item.cpp, nr_arena_item_invoke_update function, particularly: @@ -272,7 +278,8 @@ item->state |= NR_ARENA_ITEM_STATE_INVALID; return item->state; } - nr_rect_l_intersect (&item->bbox, &item->bbox, &item->clip->bbox); + // for clipping, we need geometric bbox + nr_rect_l_intersect (&item->drawbox, &item->drawbox, &item->clip-
bbox);
} /* Masking */ if (item->mask) { @@ -281,7 +288,14 @@ item->state |= NR_ARENA_ITEM_STATE_INVALID; return item->state; } - nr_rect_l_intersect (&item->bbox, &item->bbox, &item->mask->bbox); + // for masking, we need full drawbox of mask + nr_rect_l_intersect (&item->drawbox, &item->drawbox, &item->mask-
drawbox);
+ }
I believe it is not good idea just to revert this change though, as it would not solve the problem for non rectangular clip/mask and if I understood it correctly it fixed some rendering issues.
Also I have thought about what the correct behavior really is. For clip it is obvious, but what to do with ([semi]transparent/bitmap) masks? One option would be to take the shape of mask when testing for hits. Other option would be to look whether the mask completely hides the masked object at the mouse location. (Probably this could be configurable as well)
Another issue is: what to do if clip/mask completely hides an object - how could you select it then? (Maybe a toggle button or something to change whether you want to be able to select invisible(masked-out) objects?)
I'll update the bugreport and add there some pictures describing how it does (not) work, so that others in the bugreport are notified as well.
Best regards, Martin Sucha
W dniu 29 stycznia 2010 00:41 użytkownik Martin Sucha <martin.sucha-ml@...2313...> napisał:
I believe it is not good idea just to revert this change though, as it would not solve the problem for non rectangular clip/mask and if I understood it correctly it fixed some rendering issues.
Solving this correctly requires either: a) adding extra dependencies on livarot b) fixing path boolean operations in 2Geom
I would like to go for b) but it requires some time. Putting the rect kludge back in might be a good in the interim.
Another issue is: what to do if clip/mask completely hides an object - how could you select it then? (Maybe a toggle button or something to change whether you want to be able to select invisible(masked-out) objects?)
The behavior should be the same as for other invisible objects - don't select them. For invisible objects (and for many other things) we need an object browser.
Regards, Krzysztof
Hi,
On Friday 29 January 2010 00:54:35 Krzysztof Kosiński wrote:
W dniu 29 stycznia 2010 00:41 użytkownik Martin Sucha
<martin.sucha-ml@...2313...> napisał:
I believe it is not good idea just to revert this change though, as it would not solve the problem for non rectangular clip/mask and if I understood it correctly it fixed some rendering issues.
Solving this correctly requires either: a) adding extra dependencies on livarot b) fixing path boolean operations in 2Geom
Aren't those libraries related to constructing paths? I don't know how hit testing works in inkscape, but I would like to ask: We can check that mouse pointer is inside a path (or any other selectable object) because we can now select objects, right? So it could be done by asking two questions: Is my mouse pointer inside masked object? Is my mouse pointer inside clip/mask? And select masked object only if both answers would be yes.
I would like to go for b) but it requires some time. Putting the rect kludge back in might be a good in the interim.
Another issue is: what to do if clip/mask completely hides an object - how could you select it then? (Maybe a toggle button or something to change whether you want to be able to select invisible(masked-out) objects?)
The behavior should be the same as for other invisible objects - don't select them. For invisible objects (and for many other things) we need an object browser.
OK
Best regards, Martin Sucha
The behavior should be the same as for other invisible objects - don't select them. For invisible objects (and for many other things) we need an object browser.
Additionaly, the hidden objects should not be selected with the Node tool, as it is possible currently. The objects must be *fully* hidden. Not even selectable, by any tool. Only when unclipping the objects would be selectable again.
participants (3)
-
Karlisson
-
Krzysztof Kosiński
-
Martin Sucha