Code

Display helper grid for LPELattice; automatically add helper paths for LPE PathParams
authorcilix42 <cilix42@users.sourceforge.net>
Wed, 18 Jun 2008 22:30:36 +0000 (22:30 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Wed, 18 Jun 2008 22:30:36 +0000 (22:30 +0000)
src/live_effects/effect.cpp
src/live_effects/lpe-lattice.cpp
src/live_effects/lpe-lattice.h
src/nodepath.cpp
src/nodepath.h

index 4e500a4981fb6e73eece9fe5e6cdfd1cabbca4da..9326f54b99341972f8a335c6538422c4bd96ed35 100644 (file)
@@ -434,11 +434,21 @@ Effect::addHelperPaths(SPLPEItem *lpeitem, SPDesktop *desktop)
         // must create the helper curve for the original path manually; once we allow nodepaths and
         // knotholders alongside each other, this needs to be rethought!
         SPCanvasItem *canvasitem = sp_nodepath_generate_helperpath(desktop, SP_PATH(lpeitem));
-        // TODO: Make sure the tempitem doesn't get destroyed when the mouse leaves the item
         Inkscape::Display::TemporaryItem* tmpitem = desktop->add_temporary_canvasitem (canvasitem, 0);
         lpeitem->lpe_helperpaths.push_back(tmpitem);
     }
 
+    for (std::vector<Parameter *>::iterator p = param_vector.begin(); p != param_vector.end(); ++p) {
+        if ((*p)->paramType() == Inkscape::LivePathEffect::PATH_PARAM) {
+            SPCurve *c = new SPCurve(static_cast<Inkscape::LivePathEffect::PathParam*>(*p)->get_pathvector());
+
+            // TODO: factor this out (also the copied code above); see also lpe-lattice.cpp
+            SPCanvasItem *canvasitem = sp_nodepath_generate_helperpath(desktop, c, SP_ITEM(lpeitem), 0x009000ff);
+            Inkscape::Display::TemporaryItem* tmpitem = desktop->add_temporary_canvasitem (canvasitem, 0);
+            lpeitem->lpe_helperpaths.push_back(tmpitem);
+        }
+    }
+
     addHelperPathsImpl(lpeitem, desktop);
 }
 
index d70920279ae02e21c22a8d740ad5a1bf1379c4c9..6f929a9e50ff3894c66ce699979f022339f7bce3 100644 (file)
@@ -23,6 +23,7 @@
 #include "display/curve.h"
 #include "libnr/n-art-bpath-2geom.h"
 #include "svg/svg.h"
+#include "nodepath.h"
 
 #include <2geom/sbasis.h>
 #include <2geom/sbasis-2d.h>
@@ -33,6 +34,8 @@
 #include <2geom/piecewise.h>
 #include <2geom/transforms.h>
 
+#include "desktop.h" // TODO: should be factored out (see below)
+
 using namespace Geom;
 
 namespace Inkscape {
@@ -231,9 +234,59 @@ LPELattice::resetDefaults(SPItem * item)
     
     grid_point15[Geom::X] = 2.0/3*boundingbox_X.max()+1.0/3*boundingbox_X.min();
     grid_point15[Geom::Y] = 2.0/3*boundingbox_Y.max()+1.0/3*boundingbox_Y.min();
+}
 
+void
+LPELattice::addHelperPathsImpl(SPLPEItem *lpeitem, SPDesktop *desktop)
+{
+    SPCurve *c = new SPCurve ();
+    c->moveto(grid_point0);
+    c->lineto(grid_point4);
+    c->lineto(grid_point5);
+    c->lineto(grid_point1);
 
-    
+    c->moveto(grid_point8);
+    c->lineto(grid_point12);
+    c->lineto(grid_point13);
+    c->lineto(grid_point9);
+
+    c->moveto(grid_point10);
+    c->lineto(grid_point14);
+    c->lineto(grid_point15);
+    c->lineto(grid_point11);
+
+    c->moveto(grid_point2);
+    c->lineto(grid_point6);
+    c->lineto(grid_point7);
+    c->lineto(grid_point3);
+
+
+    c->moveto(grid_point0);
+    c->lineto(grid_point8);
+    c->lineto(grid_point10);
+    c->lineto(grid_point2);
+
+    c->moveto(grid_point4);
+    c->lineto(grid_point12);
+    c->lineto(grid_point14);
+    c->lineto(grid_point6);
+
+    c->moveto(grid_point5);
+    c->lineto(grid_point13);
+    c->lineto(grid_point15);
+    c->lineto(grid_point7);
+
+    c->moveto(grid_point1);
+    c->lineto(grid_point9);
+    c->lineto(grid_point11);
+    c->lineto(grid_point3);
+
+    // TODO: factor this out (and remove the #include of desktop.h above)
+    SPCanvasItem *canvasitem = sp_nodepath_generate_helperpath(desktop, c, SP_ITEM(lpeitem), 0x009000ff);
+    Inkscape::Display::TemporaryItem* tmpitem = desktop->add_temporary_canvasitem (canvasitem, 0);
+    lpeitem->lpe_helperpaths.push_back(tmpitem);
+
+    c->unref();
 }
 
 /* ######################## */
index 16c15083a4d18e072879c1074cf0f5d13a56ae71..f22525b82bbd57514c50665fc111d0ac40533aa0 100644 (file)
@@ -39,6 +39,8 @@ public:
     
     virtual void resetDefaults(SPItem * item);
 
+protected:
+    virtual void addHelperPathsImpl(SPLPEItem *lpeitem, SPDesktop *desktop);
 
 
 private:
index 0a599382364754b9266a98985926cf99b157d256..efa356fab3c9df5c0bed642eaebdaef22f76e953 100644 (file)
@@ -4741,14 +4741,13 @@ void sp_nodepath_set_curve (Inkscape::NodePath::Path *np, SPCurve *curve) {
 }
 
 SPCanvasItem *
-sp_nodepath_generate_helperpath(SPDesktop *desktop, SPCurve *curve, const SPItem *item) {
+sp_nodepath_generate_helperpath(SPDesktop *desktop, SPCurve *curve, const SPItem *item, 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...
     // unless we also flash the nodes...
-    guint32 color = prefs_get_int_attribute("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);
@@ -4758,7 +4757,8 @@ sp_nodepath_generate_helperpath(SPDesktop *desktop, SPCurve *curve, const SPItem
 
 SPCanvasItem *
 sp_nodepath_generate_helperpath(SPDesktop *desktop, SPPath *path) {
-    return sp_nodepath_generate_helperpath(desktop, sp_path_get_curve_for_edit(path), SP_ITEM(path));
+    return sp_nodepath_generate_helperpath(desktop, sp_path_get_curve_for_edit(path), SP_ITEM(path),
+                                           prefs_get_int_attribute("tools.nodes", "highlight_color", 0xff0000ff));
 }
 
 void sp_nodepath_show_helperpath(Inkscape::NodePath::Path *np, bool show) {
index 77cf5a5184c24ba28047b05572e589a6627f3060..fbcfe69dabbda01cfe56cc0684a7c446552fd57b 100644 (file)
@@ -307,7 +307,7 @@ NR::Rect sp_node_selected_bbox (Inkscape::NodePath::Path *nodepath);
 NR::Maybe<NR::Coord> sp_node_selected_common_coord (Inkscape::NodePath::Path *nodepath, NR::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);
+SPCanvasItem *sp_nodepath_generate_helperpath(SPDesktop *desktop, SPCurve *curve, const SPItem *item, guint32 color);
 SPCanvasItem *sp_nodepath_generate_helperpath(SPDesktop *desktop, SPPath *path);
 void sp_nodepath_show_helperpath(Inkscape::NodePath::Path *nodepath, bool show);
 void sp_nodepath_make_straight_path(Inkscape::NodePath::Path *np);