summaryrefslogtreecommitdiffstats
path: root/src/ui/tools/eraser-tool.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/tools/eraser-tool.cpp')
-rw-r--r--src/ui/tools/eraser-tool.cpp57
1 files changed, 31 insertions, 26 deletions
diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp
index af0cbcb78..e416fd7ef 100644
--- a/src/ui/tools/eraser-tool.cpp
+++ b/src/ui/tools/eraser-tool.cpp
@@ -666,8 +666,7 @@ void EraserTool::set_to_accumulated() {
Geom::OptRect eraserBbox = acid->visualBounds();
Geom::Rect bounds = (*eraserBbox) * desktop->doc2dt();
std::vector<SPItem*> remainingItems;
- GSList* toWorkOn = 0;
-
+ std::vector<SPItem*> toWorkOn;
if (selection->isEmpty()) {
if ( eraserMode ) {
toWorkOn = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, bounds);
@@ -675,17 +674,16 @@ void EraserTool::set_to_accumulated() {
Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop);
toWorkOn = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints());
}
-
- toWorkOn = g_slist_remove( toWorkOn, acid );
+ toWorkOn.erase(std::remove(toWorkOn.begin(), toWorkOn.end(), acid), toWorkOn.end());
} else {
- toWorkOn = g_slist_copy(const_cast<GSList*>(selection->itemList()));
+ toWorkOn= selection->itemList();
wasSelection = true;
}
- if ( g_slist_length(toWorkOn) > 0 ) {
+ if ( !toWorkOn.empty() ) {
if ( eraserMode ) {
- for (GSList *i = toWorkOn ; i ; i = i->next ) {
- SPItem *item = SP_ITEM(i->data);
+ for (std::vector<SPItem*>::const_iterator i = toWorkOn.begin(); i != toWorkOn.end(); i++){
+ SPItem *item = *i;
if ( eraserMode ) {
Geom::OptRect bbox = item->visualBounds();
@@ -702,13 +700,10 @@ void EraserTool::set_to_accumulated() {
if ( !selection->isEmpty() ) {
// If the item was not completely erased, track the new remainder.
- GSList *nowSel = g_slist_copy(const_cast<GSList *>(selection->itemList()));
-
- for (GSList const *i2 = nowSel ; i2 ; i2 = i2->next ) {
- remainingItems.push_back(SP_ITEM(i2->data));
+ std::vector<SPItem*> nowSel(selection->itemList());
+ for (std::vector<SPItem*>::const_iterator i2 = nowSel.begin();i2!=nowSel.end();i2++) {
+ remainingItems.push_back(*i2);
}
-
- g_slist_free(nowSel);
}
} else {
remainingItems.push_back(item);
@@ -716,20 +711,18 @@ void EraserTool::set_to_accumulated() {
}
}
} else {
- for (GSList *i = toWorkOn ; i ; i = i->next ) {
- sp_object_ref( SP_ITEM(i->data), 0 );
+ for (std::vector<SPItem*> ::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) {
+ sp_object_ref( *i, 0 );
}
- for (GSList *i = toWorkOn ; i ; i = i->next ) {
- SPItem *item = SP_ITEM(i->data);
+ for (std::vector<SPItem*>::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) {
+ SPItem *item = *i;
item->deleteObject(true);
sp_object_unref(item);
workDone = true;
}
}
- g_slist_free(toWorkOn);
-
if ( !eraserMode ) {
//sp_selection_delete(desktop);
remainingItems.clear();
@@ -796,6 +789,8 @@ add_cap(SPCurve *curve,
}
void EraserTool::accumulate() {
+ // construct a crude outline of the eraser's path.
+ // this desperately needs to be rewritten to use the path outliner...
if ( !this->cal1->is_empty() && !this->cal2->is_empty() ) {
this->accumulated->reset(); /* Is this required ?? */
SPCurve *rev_cal2 = this->cal2->create_reverse();
@@ -805,10 +800,10 @@ void EraserTool::accumulate() {
g_assert( ! this->cal1->first_path()->closed() );
g_assert( ! rev_cal2->first_path()->closed() );
- Geom::CubicBezier const * dc_cal1_firstseg = dynamic_cast<Geom::CubicBezier const *>( this->cal1->first_segment() );
- Geom::CubicBezier const * rev_cal2_firstseg = dynamic_cast<Geom::CubicBezier const *>( rev_cal2->first_segment() );
- Geom::CubicBezier const * dc_cal1_lastseg = dynamic_cast<Geom::CubicBezier const *>( this->cal1->last_segment() );
- Geom::CubicBezier const * rev_cal2_lastseg = dynamic_cast<Geom::CubicBezier const *>( rev_cal2->last_segment() );
+ Geom::BezierCurve const * dc_cal1_firstseg = dynamic_cast<Geom::BezierCurve const *>( this->cal1->first_segment() );
+ Geom::BezierCurve const * rev_cal2_firstseg = dynamic_cast<Geom::BezierCurve const *>( rev_cal2->first_segment() );
+ Geom::BezierCurve const * dc_cal1_lastseg = dynamic_cast<Geom::BezierCurve const *>( this->cal1->last_segment() );
+ Geom::BezierCurve const * rev_cal2_lastseg = dynamic_cast<Geom::BezierCurve const *>( rev_cal2->last_segment() );
g_assert( dc_cal1_firstseg );
g_assert( rev_cal2_firstseg );
@@ -817,11 +812,21 @@ void EraserTool::accumulate() {
this->accumulated->append(this->cal1, FALSE);
- add_cap(this->accumulated, (*dc_cal1_lastseg)[2], (*dc_cal1_lastseg)[3], (*rev_cal2_firstseg)[0], (*rev_cal2_firstseg)[1], this->cap_rounding);
+ add_cap(this->accumulated,
+ dc_cal1_lastseg->finalPoint() - dc_cal1_lastseg->unitTangentAt(1),
+ dc_cal1_lastseg->finalPoint(),
+ rev_cal2_firstseg->initialPoint(),
+ rev_cal2_firstseg->initialPoint() + rev_cal2_firstseg->unitTangentAt(0),
+ this->cap_rounding);
this->accumulated->append(rev_cal2, TRUE);
- add_cap(this->accumulated, (*rev_cal2_lastseg)[2], (*rev_cal2_lastseg)[3], (*dc_cal1_firstseg)[0], (*dc_cal1_firstseg)[1], this->cap_rounding);
+ add_cap(this->accumulated,
+ rev_cal2_lastseg->finalPoint() - rev_cal2_lastseg->unitTangentAt(1),
+ rev_cal2_lastseg->finalPoint(),
+ dc_cal1_firstseg->initialPoint(),
+ dc_cal1_firstseg->initialPoint() + dc_cal1_firstseg->unitTangentAt(0),
+ this->cap_rounding);
this->accumulated->closepath();