summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Jeanmougin <marc@jeanmougin.fr>2015-05-08 23:05:06 +0000
committerMarc Jeanmougin <marcjeanmougin@free.fr>2015-05-08 23:05:06 +0000
commit7cb183695ed9eec9fb3e08045e4a265d10eca76e (patch)
tree3e7d6f95aa0ac7c72d146ce3f4959a21cdea836a
parentfixes various bugs with clipping and masking (diff)
downloadinkscape-7cb183695ed9eec9fb3e08045e4a265d10eca76e.tar.gz
inkscape-7cb183695ed9eec9fb3e08045e4a265d10eca76e.zip
refactor sp_selection_set_mask
(bzr r14131)
-rw-r--r--src/selection-chemistry.cpp94
-rw-r--r--src/sp-clippath.cpp6
-rw-r--r--src/sp-clippath.h2
-rw-r--r--src/sp-mask.cpp6
-rw-r--r--src/sp-mask.h2
5 files changed, 40 insertions, 70 deletions
diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp
index f72bd1259..7be1e3ec0 100644
--- a/src/selection-chemistry.cpp
+++ b/src/selection-chemistry.cpp
@@ -3787,13 +3787,11 @@ void sp_selection_set_clipgroup(SPDesktop *desktop)
clone->setAttribute("inkscape:transform-center-y", inner->attribute("inkscape:transform-center-y"), false);
const Geom::Affine maskTransform(Geom::Affine::identity());
- GSList *templist = NULL;
-
- templist = g_slist_append(templist, clone);
+ std::vector<Inkscape::XML::Node*> templist;
+ templist.push_back(clone);
// add the new clone to the top of the original's parent
gchar const *mask_id = SPClipPath::create(templist, doc, &maskTransform);
- g_slist_free(templist);
outer->setAttribute("clip-path", g_strdup_printf("url(#%s)", mask_id));
@@ -3851,9 +3849,9 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_
selection->clear();
// create a list of duplicates
- GSList *mask_items = NULL;
- GSList *apply_to_items = NULL;
- GSList *items_to_delete = NULL;
+ std::vector<Inkscape::XML::Node*> mask_items;
+ std::vector<SPItem*> apply_to_items;
+ std::vector<SPItem*> items_to_delete;
std::vector<SPItem*> items_to_select;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
@@ -3863,57 +3861,36 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_
if (apply_to_layer) {
// all selected items are used for mask, which is applied to a layer
- apply_to_items = g_slist_prepend(apply_to_items, desktop->currentLayer());
+ apply_to_items.push_back(SP_ITEM(desktop->currentLayer()));
+ }
+
+ for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++) {
+ if((!topmost && !apply_to_layer && *i == items.front())
+ || (topmost && !apply_to_layer && *i == items.back())
+ || apply_to_layer){
- for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++) {
+ Geom::Affine oldtr=(*i)->transform;
+ (*i)->doWriteTransform((*i)->getRepr(), (*i)->i2doc_affine());
Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc);
- mask_items = g_slist_prepend(mask_items, dup);
+ (*i)->doWriteTransform((*i)->getRepr(), oldtr);
+ mask_items.push_back(dup);
- SPObject *item = *i;
if (remove_original) {
- items_to_delete = g_slist_prepend(items_to_delete, item);
+ items_to_delete.push_back(*i);
}
else {
- items_to_select.push_back((SPItem*)item);
+ items_to_select.push_back(*i);
}
- }
- } else if (!topmost) {
- // topmost item is used as a mask, which is applied to other items in a selection
- Inkscape::XML::Node *dup = items[0]->getRepr()->duplicate(xml_doc);
- mask_items = g_slist_prepend(mask_items, dup);
-
- if (remove_original) {
- SPObject *item = items.front();
- items_to_delete = g_slist_prepend(items_to_delete, item);
- }
-
- for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++) {
- if(i==items.begin())continue;
- apply_to_items = g_slist_prepend(apply_to_items, *i);
+ continue;
+ }else{
+ apply_to_items.push_back(*i);
items_to_select.push_back(*i);
}
- } else {
- SPItem *i = items.front();
- for (std::vector<SPItem*>::const_iterator j=items.begin();(j+1)!=items.end();j++) {
- apply_to_items = g_slist_prepend(apply_to_items, i);
- items_to_select.push_back(i);
- i=*(j+1);
- }
- Geom::Affine oldtr=i->transform;
- i->doWriteTransform(i->getRepr(), i->i2doc_affine());
- Inkscape::XML::Node *dup = SP_OBJECT(i)->getRepr()->duplicate(xml_doc);
- i->doWriteTransform(i->getRepr(), oldtr);
-
- mask_items = g_slist_prepend(mask_items, dup);
-
- if (remove_original) {
- SPObject *item = reinterpret_cast<SPObject*>(i);
- items_to_delete = g_slist_prepend(items_to_delete, item);
- }
}
+
items.clear();
- if (apply_to_items && grouping == PREFS_MASKOBJECT_GROUPING_ALL) {
+ if (grouping == PREFS_MASKOBJECT_GROUPING_ALL) {
// group all those objects into one group
// and apply mask to that
Inkscape::XML::Node *group = xml_doc->createElement("svg:g");
@@ -3922,19 +3899,16 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_
group->setAttribute("inkscape:groupmode", "maskhelper");
std::vector<Inkscape::XML::Node*> reprs_to_group;
-
- for (GSList *i = apply_to_items ; NULL != i ; i = i->next) {
- reprs_to_group.push_back(static_cast<SPObject*>(i->data)->getRepr());
- //items_to_select.erase(remove(items_to_select.begin(), items_to_select.end(), static_cast<SPObject*>(i->data)), items_to_select.end());
+ for (std::vector<SPItem*>::const_iterator i = apply_to_items.begin(); i != apply_to_items.end(); i++) {
+ reprs_to_group.push_back(static_cast<SPObject*>(*i)->getRepr());
}
items_to_select.clear();
sp_selection_group_impl(reprs_to_group, group, xml_doc, doc);
// apply clip/mask only to newly created group
- g_slist_free(apply_to_items);
- apply_to_items = NULL;
- apply_to_items = g_slist_prepend(apply_to_items, doc->getObjectByRepr(group));
+ apply_to_items.clear();
+ apply_to_items.push_back(dynamic_cast<SPItem*>(doc->getObjectByRepr(group)));
items_to_select.push_back((SPItem*)(doc->getObjectByRepr(group)));
@@ -3946,8 +3920,8 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_
gchar const *attributeName = apply_clip_path ? "clip-path" : "mask";
- for (GSList *i = apply_to_items; NULL != i; i = i->next) {
- SPItem *item = reinterpret_cast<SPItem *>(i->data);
+ for (std::vector<SPItem*>::const_reverse_iterator i = apply_to_items.rbegin(); i != apply_to_items.rend(); i++) {
+ SPItem *item = reinterpret_cast<SPItem *>(*i);
// inverted object transform should be applied to a mask object,
// as mask is calculated in user space (after applying transform)
Geom::Affine maskTransform(item->i2doc_affine().inverse());
@@ -3959,7 +3933,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_
mask_id = sp_mask_create(mask_items, doc, &maskTransform);
}
- Inkscape::XML::Node *current = SP_OBJECT(i->data)->getRepr();
+ Inkscape::XML::Node *current = SP_OBJECT(*i)->getRepr();
// Node to apply mask to
Inkscape::XML::Node *apply_mask_to = current;
@@ -3988,15 +3962,11 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_
}
- g_slist_free(mask_items);
- g_slist_free(apply_to_items);
-
- for (GSList *i = items_to_delete; NULL != i; i = i->next) {
- SPObject *item = reinterpret_cast<SPObject*>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = items_to_delete.begin(); i != items_to_delete.end(); i++) {
+ SPObject *item = reinterpret_cast<SPObject*>(*i);
item->deleteObject(false);
items_to_select.erase(remove(items_to_select.begin(), items_to_select.end(), item), items_to_select.end());
}
- g_slist_free(items_to_delete);
selection->addList(items_to_select);
diff --git a/src/sp-clippath.cpp b/src/sp-clippath.cpp
index 0c13ca80d..d66508eae 100644
--- a/src/sp-clippath.cpp
+++ b/src/sp-clippath.cpp
@@ -296,7 +296,7 @@ sp_clippath_view_list_remove(SPClipPathView *list, SPClipPathView *view)
}
// Create a mask element (using passed elements), add it to <defs>
-const gchar *SPClipPath::create (GSList *reprs, SPDocument *document, Geom::Affine const* applyTransform)
+const gchar *SPClipPath::create (std::vector<Inkscape::XML::Node*> &reprs, SPDocument *document, Geom::Affine const* applyTransform)
{
Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr();
@@ -308,8 +308,8 @@ const gchar *SPClipPath::create (GSList *reprs, SPDocument *document, Geom::Affi
const gchar *id = repr->attribute("id");
SPObject *clip_path_object = document->getObjectById(id);
- for (GSList *it = reprs; it != NULL; it = it->next) {
- Inkscape::XML::Node *node = (Inkscape::XML::Node *)(it->data);
+ for (std::vector<Inkscape::XML::Node*>::const_iterator it = reprs.begin(); it != reprs.end(); it++) {
+ Inkscape::XML::Node *node = (*it);
SPItem *item = SP_ITEM(clip_path_object->appendChildRepr(node));
if (NULL != applyTransform) {
diff --git a/src/sp-clippath.h b/src/sp-clippath.h
index eb8b14174..91dcfd625 100644
--- a/src/sp-clippath.h
+++ b/src/sp-clippath.h
@@ -45,7 +45,7 @@ public:
unsigned int clipPathUnits : 1;
SPClipPathView *display;
- static char const *create(GSList *reprs, SPDocument *document, Geom::Affine const* applyTransform);
+ static char const *create(std::vector<Inkscape::XML::Node*> &reprs, SPDocument *document, Geom::Affine const* applyTransform);
//static GType sp_clippath_get_type(void);
Inkscape::DrawingItem *show(Inkscape::Drawing &drawing, unsigned int key);
diff --git a/src/sp-mask.cpp b/src/sp-mask.cpp
index c36c3c005..f8fb7aff4 100644
--- a/src/sp-mask.cpp
+++ b/src/sp-mask.cpp
@@ -209,7 +209,7 @@ Inkscape::XML::Node* SPMask::write(Inkscape::XML::Document* xml_doc, Inkscape::X
// Create a mask element (using passed elements), add it to <defs>
const gchar *
-sp_mask_create (GSList *reprs, SPDocument *document, Geom::Affine const* applyTransform)
+sp_mask_create (std::vector<Inkscape::XML::Node*> &reprs, SPDocument *document, Geom::Affine const* applyTransform)
{
Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr();
@@ -221,8 +221,8 @@ sp_mask_create (GSList *reprs, SPDocument *document, Geom::Affine const* applyTr
const gchar *mask_id = repr->attribute("id");
SPObject *mask_object = document->getObjectById(mask_id);
- for (GSList *it = reprs; it != NULL; it = it->next) {
- Inkscape::XML::Node *node = (Inkscape::XML::Node *)(it->data);
+ for (std::vector<Inkscape::XML::Node*>::const_iterator it = reprs.begin(); it != reprs.end(); it++) {
+ Inkscape::XML::Node *node = (*it);
SPItem *item = SP_ITEM(mask_object->appendChildRepr(node));
if (NULL != applyTransform) {
diff --git a/src/sp-mask.h b/src/sp-mask.h
index e991fedb6..3559483bb 100644
--- a/src/sp-mask.h
+++ b/src/sp-mask.h
@@ -108,6 +108,6 @@ protected:
}
};
-const char *sp_mask_create (GSList *reprs, SPDocument *document, Geom::Affine const* applyTransform);
+const char *sp_mask_create (std::vector<Inkscape::XML::Node*> &reprs, SPDocument *document, Geom::Affine const* applyTransform);
#endif // SEEN_SP_MASK_H