Code

Deweirdification of user visible messages as proposed by Tav
[inkscape.git] / src / nodepath.cpp
index 51d4b9bef8395d07f904881e1644e3a589934948..f9a615583fa438c8689eaec09dfeabe9a88dc656 100644 (file)
@@ -161,11 +161,11 @@ static void sp_nodepath_set_curve (Inkscape::NodePath::Path *np, SPCurve *curve)
 Inkscape::NodePath::Node * Inkscape::NodePath::Path::active_node = NULL;
 
 static SPCanvasItem *
-sp_nodepath_make_helper_item(Inkscape::NodePath::Path *np, /*SPDesktop *desktop, */const SPCurve *curve, bool show = false) {
+sp_nodepath_make_helper_item(Inkscape::NodePath::Path *np, /*SPDesktop *desktop, */const SPCurve *curve, bool show = false, guint32 color = 0xff0000ff) {
     SPCurve *helper_curve = curve->copy();
     helper_curve->transform(np->i2d);
     SPCanvasItem *helper_path = sp_canvas_bpath_new(sp_desktop_controls(np->desktop), helper_curve);
-    sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(helper_path), np->helperpath_rgba, np->helperpath_width, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
+    sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(helper_path), color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
     sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(helper_path), 0, SP_WIND_RULE_NONZERO);
     sp_canvas_item_move_to_z(helper_path, 0);
     if (show) {
@@ -175,12 +175,6 @@ sp_nodepath_make_helper_item(Inkscape::NodePath::Path *np, /*SPDesktop *desktop,
     return helper_path;
 }
 
-static SPCanvasItem *
-canvasitem_from_pathvec(Inkscape::NodePath::Path *np, Geom::PathVector const &pathv, bool show) {
-    SPCurve *helper_curve = new SPCurve(pathv);
-    return sp_nodepath_make_helper_item(np, helper_curve, show);
-}
-
 static void
 sp_nodepath_create_helperpaths(Inkscape::NodePath::Path *np) {
     //std::map<Inkscape::LivePathEffect::Effect *, std::vector<SPCanvasItem *> > helper_path_vec;
@@ -198,7 +192,10 @@ sp_nodepath_create_helperpaths(Inkscape::NodePath::Path *np) {
             // create new canvas items from the effect's helper paths
             std::vector<Geom::PathVector> hpaths = lpe->getHelperPaths(lpeitem);
             for (std::vector<Geom::PathVector>::iterator j = hpaths.begin(); j != hpaths.end(); ++j) {
-                np->helper_path_vec[lpe].push_back(canvasitem_from_pathvec(np, *j, true));
+                SPCurve *helper_curve = new SPCurve(*j);
+                SPCanvasItem * canvasitem = sp_nodepath_make_helper_item(np, helper_curve, true, 0x509050dd);
+                np->helper_path_vec[lpe].push_back(canvasitem);
+                helper_curve->unref();
             }
         }
     }
@@ -248,10 +245,16 @@ sp_nodepath_destroy_helperpaths(Inkscape::NodePath::Path *np) {
 /**
  * \brief Creates new nodepath from item
  *
+ * If repr_key_in is not NULL, object *has* to be a LivePathEffectObject !
+ *
  * \todo create proper constructor for nodepath::path, this method returns null a constructor cannot so this cannot be simply converted to constructor.
  */
 Inkscape::NodePath::Path *sp_nodepath_new(SPDesktop *desktop, SPObject *object, bool show_handles, const char * repr_key_in, SPItem *item)
 {
+    if (repr_key_in) {
+        g_assert(IS_LIVEPATHEFFECT(object));
+    }
+
     Inkscape::XML::Node *repr = object->repr;
 
     /** \todo
@@ -328,7 +331,7 @@ Inkscape::NodePath::Path *sp_nodepath_new(SPDesktop *desktop, SPObject *object,
     np->d2i  = np->i2d.inverse();
 
     np->repr = repr;
-    if (repr_key_in) { // apparently the object is an LPEObject (this is a dirty check, hopefully nobody tries feeding non-lpeobjects into this method with non-null repr_key_in)
+    if (repr_key_in) { // apparently the object is an LPEObject
         np->repr_key = g_strdup(repr_key_in);
         np->repr_nodetypes_key = g_strconcat(np->repr_key, "-nodetypes", NULL);
         Inkscape::LivePathEffect::Effect * lpe = LIVEPATHEFFECT(object)->get_lpe();
@@ -378,7 +381,7 @@ Inkscape::NodePath::Path *sp_nodepath_new(SPDesktop *desktop, SPObject *object,
 
     // Draw helper curve
     if (np->show_helperpath) {
-        np->helper_path = sp_nodepath_make_helper_item(np, /*desktop, */np->curve, true);
+        np->helper_path = sp_nodepath_make_helper_item(np, /*desktop, */np->curve, true, np->helperpath_rgba);
     }
 
     sp_nodepath_create_helperpaths(np);
@@ -1385,7 +1388,7 @@ static void sp_nodepath_selected_nodes_move(Inkscape::NodePath::Path *nodepath,
         }
 
        // Iterate through all selected nodes
-       m.setup(nodepath->desktop, false, SP_PATH(nodepath->item), &unselected_nodes);
+       m.setup(nodepath->desktop, false, nodepath->item, &unselected_nodes);
        for (GList *l = nodepath->selected; l != NULL; l = l->next) {
             Inkscape::NodePath::Node *n = (Inkscape::NodePath::Node *) l->data;
             if (!closest_only || n == closest_node) { //try to snap either all selected nodes or only the closest one
@@ -1394,7 +1397,7 @@ static void sp_nodepath_selected_nodes_move(Inkscape::NodePath::Path *nodepath,
                    if (constrained) {
                        Inkscape::Snapper::ConstraintLine dedicated_constraint = constraint;
                        dedicated_constraint.setPoint(n->pos);
-                       s = m.constrainedSnap(Inkscape::SnapPreferences::SNAPPOINT_NODE, to_2geom(n->pos + delta), source_type, dedicated_constraint);
+                       s = m.constrainedSnap(Inkscape::SnapPreferences::SNAPPOINT_NODE, to_2geom(n->pos + delta), source_type, dedicated_constraint, false);
                    } else {
                        s = m.freeSnap(Inkscape::SnapPreferences::SNAPPOINT_NODE, to_2geom(n->pos + delta), source_type);
                    }
@@ -3587,7 +3590,6 @@ static void node_grabbed(SPKnot *knot, guint state, gpointer data)
     }
 
     n->is_dragging = true;
-    //sp_canvas_set_snap_delay_active(n->subpath->nodepath->desktop->canvas, true);
     // Reconstruct and store the location of the mouse pointer at the time when we started dragging (needed for snapping)
     n->subpath->nodepath->drag_origin_mouse = knot->grabbed_rel_pos + knot->drag_origin;
 
@@ -3605,7 +3607,6 @@ static void node_ungrabbed(SPKnot */*knot*/, guint /*state*/, gpointer data)
 
    n->dragging_out = NULL;
    n->is_dragging = false;
-   //sp_canvas_set_snap_delay_active(n->subpath->nodepath->desktop->canvas, false);
    n->subpath->nodepath->drag_origin_mouse = Geom::Point(NR_HUGE, NR_HUGE);
    sp_canvas_end_forced_full_redraws(n->subpath->nodepath->desktop->canvas);
 
@@ -3962,7 +3963,7 @@ static gboolean node_handle_request(SPKnot *knot, Geom::Point &p, guint state, g
                 p = n->pos + (scal / linelen) * ndelta;
             }
             if ((state & GDK_SHIFT_MASK) == 0) {
-                s = m.constrainedSnap(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, source_type, Inkscape::Snapper::ConstraintLine(p, ndelta));
+                s = m.constrainedSnap(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, source_type, Inkscape::Snapper::ConstraintLine(p, ndelta), false);
             }
         } else {
             if ((state & GDK_SHIFT_MASK) == 0) {
@@ -5064,7 +5065,9 @@ sp_nodepath_generate_helperpath(SPDesktop *desktop, SPItem *item) {
     } else if ( SP_IS_SHAPE(item) && SP_SHAPE(item)->curve ) {
         curve = sp_shape_get_curve (SP_SHAPE(item));
     } else if ( SP_IS_TEXT(item) ) {
-        curve = SP_TEXT(item)->getNormalizedBpath();
+        // do not display helperpath for text - we cannot do anything with it in Node tool anyway
+        // curve = SP_TEXT(item)->getNormalizedBpath();
+        return NULL;
     } else {
         g_warning ("-----> sp_nodepath_generate_helperpath(SPDesktop *desktop, SPItem *item): TODO: generate the helper path for this item type!\n");
         return NULL;