X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fnodepath.cpp;h=a5fd2fab8af6f5530d6b9ec343b30f38f1a79a93;hb=91db03f244c420daa37e0b5b8a8359ddc2dd626b;hp=8aed0420bb461f94f5ccf051ea5f6d456535474b;hpb=86c29afc3f5d59aa10867aac6af2cd7d38abe253;p=inkscape.git diff --git a/src/nodepath.cpp b/src/nodepath.cpp index 8aed0420b..a5fd2fab8 100644 --- a/src/nodepath.cpp +++ b/src/nodepath.cpp @@ -411,7 +411,7 @@ static void update_repr_internal(Inkscape::NodePath::Path *np) SPCurve *curve = create_curve(np); gchar *typestr = create_typestr(np); - gchar *svgpath = sp_svg_write_path(curve->bpath); + gchar *svgpath = sp_svg_write_path(SP_CURVE_BPATH(curve)); if (repr->attribute("d") == NULL || strcmp(svgpath, repr->attribute("d"))) { // d changed np->local_change++; @@ -434,7 +434,7 @@ static void update_repr_internal(Inkscape::NodePath::Path *np) void sp_nodepath_update_repr(Inkscape::NodePath::Path *np) { update_repr_internal(np); - sp_document_done(SP_DT_DOCUMENT(np->desktop)); + sp_document_done(sp_desktop_document(np->desktop)); if (np->livarot_path) { delete np->livarot_path; @@ -454,7 +454,7 @@ void sp_nodepath_update_repr(Inkscape::NodePath::Path *np) static void sp_nodepath_update_repr_keyed(Inkscape::NodePath::Path *np, gchar const *key) { update_repr_internal(np); - sp_document_maybe_done(SP_DT_DOCUMENT(np->desktop), key); + sp_document_maybe_done(sp_desktop_document(np->desktop), key); if (np->livarot_path) { delete np->livarot_path; @@ -486,7 +486,7 @@ static void stamp_repr(Inkscape::NodePath::Path *np) SPCurve *curve = create_curve(np); gchar *typestr = create_typestr(np); - gchar *svgpath = sp_svg_write_path(curve->bpath); + gchar *svgpath = sp_svg_write_path(SP_CURVE_BPATH(curve)); new_repr->setAttribute("d", svgpath); new_repr->setAttribute("sodipodi:nodetypes", typestr); @@ -496,7 +496,7 @@ static void stamp_repr(Inkscape::NodePath::Path *np) // move to the saved position new_repr->setPosition(pos > 0 ? pos : 0); - sp_document_done(SP_DT_DOCUMENT(np->desktop)); + sp_document_done(sp_desktop_document(np->desktop)); Inkscape::GC::release(new_repr); g_free(svgpath); @@ -836,9 +836,9 @@ static Inkscape::NodePath::Node *sp_nodepath_set_node_type(Inkscape::NodePath::N } // if one of handles is mouseovered, preserve its position - if (node->p.knot && SP_KNOT_IS_MOSEOVER(node->p.knot)) { + if (node->p.knot && SP_KNOT_IS_MOUSEOVER(node->p.knot)) { sp_node_adjust_handle(node, 1); - } else if (node->n.knot && SP_KNOT_IS_MOSEOVER(node->n.knot)) { + } else if (node->n.knot && SP_KNOT_IS_MOUSEOVER(node->n.knot)) { sp_node_adjust_handle(node, -1); } else { sp_node_adjust_handles(node); @@ -921,22 +921,19 @@ void sp_node_moveto(Inkscape::NodePath::Node *node, NR::Point p) static void sp_nodepath_selected_nodes_move(Inkscape::NodePath::Path *nodepath, NR::Coord dx, NR::Coord dy, bool const snap = true) { - NR::Coord best[2] = { NR_HUGE, NR_HUGE }; + NR::Coord best = NR_HUGE; NR::Point delta(dx, dy); NR::Point best_pt = delta; if (snap) { + SnapManager const &m = nodepath->desktop->namedview->snap_manager; + for (GList *l = nodepath->selected; l != NULL; l = l->next) { - Inkscape::NodePath::Node *n = (Inkscape::NodePath::Node *) l->data; - NR::Point p = n->pos + delta; - for (int dim = 0; dim < 2; dim++) { - NR::Coord dist = namedview_dim_snap(nodepath->desktop->namedview, - Inkscape::Snapper::SNAP_POINT, p, - NR::Dim2(dim), nodepath->path); - if (dist < best[dim]) { - best[dim] = dist; - best_pt[dim] = p[dim] - n->pos[dim]; - } + Inkscape::NodePath::Node *n = (Inkscape::NodePath::Node *) l->data; + Inkscape::SnappedPoint const s = m.freeSnap(Inkscape::Snapper::SNAP_POINT, n->pos + delta, NULL); + if (s.getDistance() < best) { + best = s.getDistance(); + best_pt = s.getPoint() - n->pos; } } } @@ -1021,7 +1018,7 @@ static void sp_node_ensure_knot_exists (SPDesktop *desktop, Inkscape::NodePath:: } if (!side->line) { - side->line = sp_canvas_item_new(SP_DT_CONTROLS(desktop), + side->line = sp_canvas_item_new(sp_desktop_controls(desktop), SP_TYPE_CTRLLINE, NULL); } } @@ -1452,16 +1449,22 @@ void sp_node_selected_join() /* a and b are endpoints */ - NR::Point c = (a->pos + b->pos) / 2; + NR::Point c; + if (a->knot && SP_KNOT_IS_MOUSEOVER(a->knot)) { + c = a->pos; + } else if (b->knot && SP_KNOT_IS_MOUSEOVER(b->knot)) { + c = b->pos; + } else { + c = (a->pos + b->pos) / 2; + } if (a->subpath == b->subpath) { Inkscape::NodePath::SubPath *sp = a->subpath; sp_nodepath_subpath_close(sp); + sp_node_moveto (sp->first, c); sp_nodepath_update_handles(sp->nodepath); - sp_nodepath_update_repr(nodepath); - return; } @@ -1721,7 +1724,7 @@ void sp_node_delete_preserve(GList *nodes_to_delete) // if the entire nodepath is removed, delete the selected object. if (nodepath->subpaths == NULL || sp_nodepath_get_node_count(nodepath) < 2) { - SPDocument *document = SP_DT_DOCUMENT (nodepath->desktop); + SPDocument *document = sp_desktop_document (nodepath->desktop); sp_nodepath_destroy(nodepath); g_list_free(nodes_to_delete); nodes_to_delete = NULL; @@ -1761,7 +1764,7 @@ void sp_node_selected_delete() // if the entire nodepath is removed, delete the selected object. if (nodepath->subpaths == NULL || sp_nodepath_get_node_count(nodepath) < 2) { - SPDocument *document = SP_DT_DOCUMENT (nodepath->desktop); + SPDocument *document = sp_desktop_document (nodepath->desktop); sp_nodepath_destroy(nodepath); sp_selection_delete(); sp_document_done (document); @@ -2833,7 +2836,7 @@ static gboolean node_handle_request(SPKnot *knot, NR::Point *p, guint state, gpo NRPathcode const othercode = sp_node_path_code_from_side(n, opposite); - SnapManager const m(n->subpath->nodepath->desktop->namedview); + SnapManager const &m = n->subpath->nodepath->desktop->namedview->snap_manager; if (opposite->other && (n->type != Inkscape::NodePath::NODE_CUSP) && (othercode == NR_LINETO)) { /* We are smooth node adjacent with line */ @@ -2846,7 +2849,7 @@ static gboolean node_handle_request(SPKnot *knot, NR::Point *p, guint state, gpo NR::Coord const scal = dot(delta, ndelta) / linelen; (*p) = n->pos + (scal / linelen) * ndelta; } - *p = m.constrainedSnap(Inkscape::Snapper::SNAP_POINT, *p, ndelta, NULL).getPoint(); + *p = m.constrainedSnap(Inkscape::Snapper::SNAP_POINT, *p, Inkscape::Snapper::ConstraintLine(*p, ndelta), NULL).getPoint(); } else { *p = m.freeSnap(Inkscape::Snapper::SNAP_POINT, *p, NULL).getPoint(); } @@ -3354,7 +3357,7 @@ static void sp_nodepath_subpath_close(Inkscape::NodePath::SubPath *sp) //Link the head to the tail sp->first->p.other = sp->last; sp->last->n.other = sp->first; - sp->last->n.pos = sp->first->n.pos; + sp->last->n.pos = sp->last->pos + (sp->first->n.pos - sp->first->pos); sp->first = sp->last; //Remove the extra end node