diff options
| author | Marc Jeanmougin <marc@jeanmougin.fr> | 2017-10-02 00:12:27 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <marc@jeanmougin.fr> | 2017-10-02 00:12:27 +0000 |
| commit | 8761f46f7b8c2a2df82203f5be89d60072998a82 (patch) | |
| tree | 98718445ab30910a8e053bcf2a0d83a1b002630d /src/ui | |
| parent | First batch (diff) | |
| download | inkscape-8761f46f7b8c2a2df82203f5be89d60072998a82.tar.gz inkscape-8761f46f7b8c2a2df82203f5be89d60072998a82.zip | |
Second batch
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/tools/gradient-tool.cpp | 85 | ||||
| -rw-r--r-- | src/ui/tools/mesh-tool.cpp | 62 | ||||
| -rw-r--r-- | src/ui/tools/tweak-tool.cpp | 13 |
3 files changed, 42 insertions, 118 deletions
diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp index 95d940bd6..966183b1a 100644 --- a/src/ui/tools/gradient-tool.cpp +++ b/src/ui/tools/gradient-tool.cpp @@ -219,7 +219,7 @@ sp_gradient_context_is_over_line (GradientTool *rc, SPItem *item, Geom::Point ev } static std::vector<Geom::Point> -sp_gradient_context_get_stop_intervals (GrDrag *drag, GSList **these_stops, GSList **next_stops) +sp_gradient_context_get_stop_intervals (GrDrag *drag, std::vector<SPStop *> &these_stops, std::vector<SPStop *> &next_stops) { std::vector<Geom::Point> coords; @@ -285,15 +285,15 @@ sp_gradient_context_get_stop_intervals (GrDrag *drag, GSList **these_stops, GSLi } // if both adjacent draggers selected, - if (!g_slist_find(*these_stops, this_stop) && dnext && dnext->isSelected()) { + if ((std::find(these_stops.begin(),these_stops.end(),this_stop)==these_stops.end()) && dnext && dnext->isSelected()) { // remember the coords of the future dragger to select it coords.push_back(0.5*(dragger->point + dnext->point)); // do not insert a stop now, it will confuse the loop; // just remember the stops - *these_stops = g_slist_prepend (*these_stops, this_stop); - *next_stops = g_slist_prepend (*next_stops, next_stop); + these_stops.push_back(this_stop); + next_stops.push_back(next_stop); } } } @@ -307,12 +307,12 @@ sp_gradient_context_add_stops_between_selected_stops (GradientTool *rc) SPDocument *doc = NULL; GrDrag *drag = rc->_grdrag; - GSList *these_stops = NULL; - GSList *next_stops = NULL; + std::vector<SPStop *> these_stops; + std::vector<SPStop *> next_stops; - std::vector<Geom::Point> coords = sp_gradient_context_get_stop_intervals (drag, &these_stops, &next_stops); + std::vector<Geom::Point> coords = sp_gradient_context_get_stop_intervals (drag, these_stops, next_stops); - if (g_slist_length(these_stops) == 0 && drag->numSelected() == 1) { + if (these_stops.empty() && drag->numSelected() == 1) { // if a single stop is selected, add between that stop and the next one GrDragger *dragger = *(drag->selected.begin()); for (std::vector<GrDraggable *>::const_iterator j = dragger->draggables.begin(); j != dragger->draggables.end(); ++j) { @@ -330,47 +330,42 @@ sp_gradient_context_add_stops_between_selected_stops (GradientTool *rc) if (this_stop) { SPStop *next_stop = this_stop->getNextStop(); if (next_stop) { - these_stops = g_slist_prepend (these_stops, this_stop); - next_stops = g_slist_prepend (next_stops, next_stop); + these_stops.push_back(this_stop); + next_stops.push_back(next_stop); } } } } // now actually create the new stops - GSList *i = these_stops; - GSList *j = next_stops; - GSList *new_stops = NULL; + auto i = these_stops.rbegin(); + auto j = next_stops.rbegin(); + std::vector<SPStop *> new_stops; - for (; i != NULL && j != NULL; i = i->next, j = j->next) { - SPStop *this_stop = (SPStop *) i->data; - SPStop *next_stop = (SPStop *) j->data; + for (;i != these_stops.rend() && j != next_stops.rend(); ++i, ++j ) { + SPStop *this_stop = *i; + SPStop *next_stop = *j; gfloat offset = 0.5*(this_stop->offset + next_stop->offset); SPObject *parent = this_stop->parent; if (SP_IS_GRADIENT (parent)) { doc = parent->document; SPStop *new_stop = sp_vector_add_stop (SP_GRADIENT (parent), this_stop, next_stop, offset); - new_stops = g_slist_prepend (new_stops, new_stop); + new_stops.push_back(new_stop); SP_GRADIENT(parent)->ensureVector(); } } - if (g_slist_length(these_stops) > 0 && doc) { + if (!these_stops.empty() && doc) { DocumentUndo::done(doc, SP_VERB_CONTEXT_GRADIENT, _("Add gradient stop")); drag->updateDraggers(); // so that it does not automatically update draggers in idle loop, as this would deselect drag->local_change = true; // select the newly created stops - for (GSList *s = new_stops; s != NULL; s = s->next) { - drag->selectByStop((SPStop *)s->data); + for (auto i:new_stops) { + drag->selectByStop(i); } - } - - g_slist_free (these_stops); - g_slist_free (next_stops); - g_slist_free (new_stops); } static double sqr(double x) {return x*x;} @@ -381,26 +376,25 @@ sp_gradient_simplify(GradientTool *rc, double tolerance) SPDocument *doc = NULL; GrDrag *drag = rc->_grdrag; - GSList *these_stops = NULL; - GSList *next_stops = NULL; + std::vector<SPStop *> these_stops; + std::vector<SPStop *> next_stops; - std::vector<Geom::Point> coords = sp_gradient_context_get_stop_intervals (drag, &these_stops, &next_stops); + std::vector<Geom::Point> coords = sp_gradient_context_get_stop_intervals (drag, these_stops, next_stops); - GSList *todel = NULL; + std::set<SPStop *> todel; - GSList *i = these_stops; - GSList *j = next_stops; - for (; i != NULL && j != NULL; i = i->next, j = j->next) { - SPStop *stop0 = (SPStop *) i->data; - SPStop *stop1 = (SPStop *) j->data; + auto i = these_stops.begin(); + auto j = next_stops.end(); + for (; i != these_stops.end() && j != next_stops.end(); ++i, ++j) { + SPStop *stop0 = *i; + SPStop *stop1 = *j; - gint i1 = g_slist_index(these_stops, stop1); - if (i1 != -1) { - GSList *next_next = g_slist_nth (next_stops, i1); - if (next_next) { - SPStop *stop2 = (SPStop *) next_next->data; + auto i1 = std::find(these_stops.begin(), these_stops.end(), stop1); + if (i1 != these_stops.end()) { + if (next_stops.size()>(i1-these_stops.begin())) { + SPStop *stop2 = *(next_stops.begin() + (i1-these_stops.begin())); - if (g_slist_find(todel, stop0) || g_slist_find(todel, stop2)) + if (todel.find(stop0)!=todel.end() || todel.find(stop2) != todel.end()) continue; guint32 const c0 = stop0->get_rgba32(); @@ -416,28 +410,23 @@ sp_gradient_simplify(GradientTool *rc, double tolerance) sqr(SP_RGBA32_A_F(c1) - SP_RGBA32_A_F(c1r)); if (diff < tolerance) - todel = g_slist_prepend (todel, stop1); + todel.insert(stop1); } } } - for (i = todel; i != NULL; i = i->next) { - SPStop *stop = (SPStop*) i->data; + for (auto stop : todel) { doc = stop->document; Inkscape::XML::Node * parent = stop->getRepr()->parent(); parent->removeChild( stop->getRepr() ); } - if (g_slist_length(todel) > 0) { + if (!todel.empty()) { DocumentUndo::done(doc, SP_VERB_CONTEXT_GRADIENT, _("Simplify gradient")); drag->local_change = true; drag->updateDraggers(); drag->selectByCoords(coords); } - - g_slist_free (todel); - g_slist_free (these_stops); - g_slist_free (next_stops); } diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp index d79741270..1ded5e146 100644 --- a/src/ui/tools/mesh-tool.cpp +++ b/src/ui/tools/mesh-tool.cpp @@ -170,68 +170,6 @@ void MeshTool::selection_changed(Inkscape::Selection* /*sel*/) { // FIXME // We need to update mesh gradient handles. // Get gradient this drag belongs too.. - // std::cout << "mesh_selection_changed: selection: objects: " << n_obj << std::endl; - // GSList *itemList = (GSList *) selection->itemList(); - // while( itemList ) { - - // SPItem *item = SP_ITEM( itemList->data ); - // // std::cout << " item: " << SP_OBJECT(item)->getId() << std::endl; - - // SPStyle *style = item->style; - // if (style && (style->fill.isPaintserver())) { - - // SPPaintServer *server = item->style->getFillPaintServer(); - // if ( SP_IS_MESHGRADIENT(server) ) { - - // SPMeshGradient *mg = SP_MESHGRADIENT(server); - - // guint rows = 0;//mg->array.patches.size(); - // for ( guint i = 0; i < rows; ++i ) { - // guint columns = 0;//mg->array.patches[0].size(); - // for ( guint j = 0; j < columns; ++j ) { - // } - // } - // } - // } - // itemList = itemList->next; - // } - - // GList* dragger_ptr = drag->draggers; // Points to GrDragger class (group of GrDraggable) - // guint count = 0; - // while( dragger_ptr ) { - - // std::cout << "mesh_selection_changed: dragger: " << ++count << std::endl; - // GSList* draggable_ptr = ((GrDragger *) dragger_ptr->data)->draggables; - - // while( draggable_ptr ) { - - // std::cout << "mesh_selection_changed: draggable: " << draggable_ptr << std::endl; - // GrDraggable *draggable = (GrDraggable *) draggable_ptr->data; - - // gint point_type = draggable->point_type; - // gint point_i = draggable->point_i; - // bool fill_or_stroke = draggable->fill_or_stroke; - - // if( point_type == POINT_MG_CORNER ) { - - // //std::cout << "mesh_selection_changed: POINT_MG_CORNER: " << point_i << std::endl; - // // Now we must create or destroy corresponding handles. - - // if( g_list_find( drag->selected, dragger_ptr->data ) ) { - // //std::cout << "gradient_selection_changed: Selected: " << point_i << std::endl; - // // Which meshes does this point belong to? - - // } else { - // //std::cout << "mesh_selection_changed: Not Selected: " << point_i << std::endl; - // } - // } - - // draggable_ptr = draggable_ptr->next; - - // } - - // dragger_ptr = dragger_ptr->next; - // } } void MeshTool::setup() { diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp index dcd9413fb..fca96a483 100644 --- a/src/ui/tools/tweak-tool.cpp +++ b/src/ui/tools/tweak-tool.cpp @@ -374,23 +374,20 @@ sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, Geom::P } if (dynamic_cast<SPGroup *>(item) && !dynamic_cast<SPBox3D *>(item)) { - GSList *children = NULL; + std::vector<SPItem *> children; for (auto& child: item->children) { - if (dynamic_cast<SPItem *>(static_cast<SPObject *>(&child))) { - children = g_slist_prepend(children, &child); + if (dynamic_cast<SPItem *>(&child)) { + children.push_back(dynamic_cast<SPItem *>(&child)); } } - for (GSList *i = children; i; i = i->next) { - SPItem *child = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data)); + for (auto i = children.rbegin(); i!= children.rend(); ++i) { + SPItem *child = *i; g_assert(child != NULL); if (sp_tweak_dilate_recursive (selection, child, p, vector, mode, radius, force, fidelity, reverse)) { did = true; } } - - g_slist_free(children); - } else { if (mode == TWEAK_MODE_MOVE) { |
