Code

improve helperpath generation on mouse-over
authorjohanengelen <johanengelen@users.sourceforge.net>
Tue, 3 Mar 2009 21:37:20 +0000 (21:37 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Tue, 3 Mar 2009 21:37:20 +0000 (21:37 +0000)
src/node-context.cpp
src/nodepath.cpp
src/nodepath.h

index 4a36c5d615eef273386dd3088e7000fad33ac6af..a8f6fcf972931dc00fd9ede1d97d5e0c8d3d547f 100644 (file)
@@ -193,12 +193,7 @@ sp_node_context_flash_path(SPEventContext *event_context, SPItem *item, guint ti
             nc->flash_tempitem = NULL;
         }
 
-        SPCanvasItem *canvasitem = NULL;
-        if (SP_IS_PATH(item)) {
-            canvasitem = sp_nodepath_helperpath_from_path(desktop, SP_PATH(item));
-        } else {
-            g_print ("-----> sp_node_context_flash_path(): TODO: generate the helper path!!\n");
-        }
+        SPCanvasItem *canvasitem = sp_nodepath_generate_helperpath(desktop, item);
 
         if (canvasitem) {
             nc->flash_tempitem = desktop->add_temporary_canvasitem (canvasitem, timeout);
index 845d47b3b23d781166dbeab68ac56bd36ca94d67..dfd06b660bf5b6c3cf8375ec73faa9ecf9f24fe2 100644 (file)
@@ -5029,11 +5029,11 @@ sp_nodepath_path_to_canvasitem(Inkscape::NodePath::Path *np, SPPath *path) {
 }
 */
 
-/*
+
+/// \todo this code to generate a helper canvasitem from an spcurve should be moved to different file
 SPCanvasItem *
-sp_nodepath_generate_helperpath(SPDesktop *desktop, SPCurve *curve, const SPItem *item, guint32 color = 0xff0000ff) {
+sp_nodepath_generate_helperpath(SPDesktop *desktop, SPCurve *curve, const Geom::Matrix & i2d, guint32 color = 0xff0000ff) {
     SPCurve *flash_curve = curve->copy();
-    Geom::Matrix i2d = item ? sp_item_i2d_affine(item) : Geom::identity();
     flash_curve->transform(i2d);
     SPCanvasItem * canvasitem = sp_canvas_bpath_new(sp_desktop_tempgroup(desktop), flash_curve);
     // would be nice if its color could be XORed or something, now it is invisible for red stroked objects...
@@ -5046,30 +5046,32 @@ sp_nodepath_generate_helperpath(SPDesktop *desktop, SPCurve *curve, const SPItem
 }
 
 SPCanvasItem *
-sp_nodepath_generate_helperpath(SPDesktop *desktop, SPPath *path) {
-    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
-    return sp_nodepath_generate_helperpath(desktop, sp_path_get_curve_for_edit(path), SP_ITEM(path),
-                                           prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff));
-}
-*/
+sp_nodepath_generate_helperpath(SPDesktop *desktop, SPItem *item) {
+    if (!item || !desktop) {
+        return NULL;
+    }
 
-SPCanvasItem *
-sp_nodepath_helperpath_from_path(SPDesktop *desktop, SPPath *path) {
-    SPCurve *flash_curve = sp_path_get_curve_for_edit(path)->copy();
-    Geom::Matrix i2d = sp_item_i2d_affine(SP_ITEM(path));
-    flash_curve->transform(i2d);
-    SPCanvasItem * canvasitem = sp_canvas_bpath_new(sp_desktop_tempgroup(desktop), flash_curve);
-    // would be nice if its color could be XORed or something, now it is invisible for red stroked objects...
-    // unless we also flash the nodes...
     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
     guint32 color = prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff);
-    sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(canvasitem), color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
-    sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(canvasitem), 0, SP_WIND_RULE_NONZERO);
-    sp_canvas_item_show(canvasitem);
-    flash_curve->unref();
-    return canvasitem;
+
+    Geom::Matrix i2d = sp_item_i2d_affine(item);
+
+    SPCurve *curve = NULL;
+    if (SP_IS_PATH(item)) {
+        curve = sp_path_get_curve_for_edit(SP_PATH(item));
+    } else {
+        g_warning ("-----> sp_nodepath_generate_helperpath(SPDesktop *desktop, SPItem *item): TODO: generate the helper path for this item type!\n");
+        return NULL;
+    }
+
+    SPCanvasItem * helperpath = sp_nodepath_generate_helperpath(desktop, curve, i2d, color);
+
+    curve->unref();
+
+    return helperpath;
 }
 
+
 // TODO: Merge this with sp_nodepath_make_helper_item()!
 void sp_nodepath_show_helperpath(Inkscape::NodePath::Path *np, bool show) {
     np->show_helperpath = show;
index 7a0c671e1a8900f428c704ff76083757e78408dd..1dcb4527c64ca0ef0cd57bf010e0f75f8583c407 100644 (file)
@@ -329,9 +329,8 @@ Geom::Rect sp_node_selected_bbox (Inkscape::NodePath::Path *nodepath);
 boost::optional<Geom::Coord> sp_node_selected_common_coord (Inkscape::NodePath::Path *nodepath, Geom::Dim2 axis);
 
 void sp_nodepath_show_handles(Inkscape::NodePath::Path *nodepath, bool show);
-//SPCanvasItem *sp_nodepath_generate_helperpath(SPDesktop *desktop, SPCurve *curve, const SPItem *item, guint32 color);
-//SPCanvasItem *sp_nodepath_generate_helperpath(SPDesktop *desktop, SPPath *path);
-SPCanvasItem *sp_nodepath_helperpath_from_path(SPDesktop *desktop, SPPath *path);
+SPCanvasItem *sp_nodepath_generate_helperpath(SPDesktop *desktop, SPCurve *curve, const Geom::Matrix & i2d, guint32 color);
+SPCanvasItem *sp_nodepath_generate_helperpath(SPDesktop *desktop, SPItem *item);
 void sp_nodepath_show_helperpath(Inkscape::NodePath::Path *nodepath, bool show);
 void sp_nodepath_update_helperpaths(Inkscape::NodePath::Path *np);
 void sp_nodepath_make_straight_path(Inkscape::NodePath::Path *np);