Code

Add option to either suppress path flash for items with LPE (e.g., spiro splines...
authorcilix42 <cilix42@users.sourceforge.net>
Sun, 8 Jun 2008 18:47:19 +0000 (18:47 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Sun, 8 Jun 2008 18:47:19 +0000 (18:47 +0000)
src/live_effects/effect.h
src/live_effects/lpe-spiro.cpp
src/live_effects/lpe-spiro.h
src/live_effects/lpe-tangent_to_curve.h
src/node-context.cpp
src/node-context.h

index 21d86f80ad9dbb6ba1792f1f42346145c17f9aeb..f0d0ffdd5669c802ab96fb96fc3e6ba7c8ee34aa 100644 (file)
@@ -77,6 +77,12 @@ enum EffectType {
 extern const Util::EnumData<EffectType> LPETypeData[INVALID_LPE];
 extern const Util::EnumDataConverter<EffectType> LPETypeConverter;
 
+enum LPEPathFlashType {
+    SUPPRESS_FLASH,
+    PERMANENT_FLASH,
+    DEFAULT
+};
+
 class Effect {
 public:
     static Effect* New(EffectType lpenr, LivePathEffectObject *lpeobj);
@@ -102,6 +108,7 @@ public:
     virtual void transform_multiply(Geom::Matrix const& postmul, bool set);
 
     bool providesKnotholder() { return (kh_entity_vector.size() > 0); }
+    virtual LPEPathFlashType pathFlashType() { return DEFAULT; }
     void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
 
     Glib::ustring          getName();
index e4a0af741ed002b251679d0c1d1a6525458248c6..bbf952e19925eada68e15c08923dc2cf35587c80 100644 (file)
@@ -88,7 +88,7 @@ void
 LPESpiro::setup_nodepath(Inkscape::NodePath::Path *np)
 {
     sp_nodepath_show_handles(np, false);
-    sp_nodepath_show_helperpath(np, false);
+//    sp_nodepath_show_helperpath(np, false);
 }
 
 void
index 292b07fb82ffbe660dee951fced32b672cabb9ec..7256665a2ea3254ea465bf89c9093c26ef2dbb9f 100644 (file)
@@ -22,6 +22,8 @@ public:
     LPESpiro(LivePathEffectObject *lpeobject);
     virtual ~LPESpiro();
 
+    virtual LPEPathFlashType pathFlashType() { return SUPPRESS_FLASH; }
+
     virtual void setup_nodepath(Inkscape::NodePath::Path *np);
     virtual void doEffect(SPCurve * curve);
 
index 8fe54335cbd0646971cd7c713280de5c4998afb3..8d9622c672cf95d888c8685fddf14ec6f081491a 100644 (file)
@@ -38,6 +38,8 @@ public:
     virtual Geom::Piecewise<Geom::D2<Geom::SBasis> >
       doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
 
+    virtual LPEPathFlashType pathFlashType() { return PERMANENT_FLASH; }
+
     /* the knotholder entity classes must be declared friends */
     friend class TtC::KnotHolderEntityLeftEnd;
     friend class TtC::KnotHolderEntityRightEnd;
index c3523e3c5a6d88d6ba0cbf3435cfd005dfea705c..286f55c4b2bcbe81770c383b5976e2b1c681096b 100644 (file)
@@ -35,6 +35,7 @@
 #include "style.h"
 #include "splivarot.h"
 #include "shape-editor.h"
+#include "live_effects/effect.h"
 
 // needed for flash nodepath upon mouseover:
 #include "display/canvas-bpath.h"
@@ -115,6 +116,12 @@ sp_node_context_dispose(GObject *object)
 
     ec->enableGrDrag(false);
 
+    if (nc->flash_permitem) {
+        // hack!!! (we add a temporary canvasitem with life time 1 ms)
+        nc->flash_tempitem = nc->event_context.desktop->add_temporary_canvasitem (nc->flash_permitem, 1);
+        nc->flash_permitem = NULL;
+    }
+
     nc->sel_changed_connection.disconnect();
     nc->sel_changed_connection.~connection();
 
@@ -170,6 +177,44 @@ sp_node_context_setup(SPEventContext *ec)
     nc->shape_editor->update_statusbar();
 }
 
+static SPCanvasItem *
+sp_node_context_generate_helperpath(SPDesktop *desktop, SPPath *path) {
+    // This should be put somewhere else under the name of "generate helperpath" or something. Because basically this is copied of code from nodepath...
+    SPCurve *curve_new = sp_path_get_curve_for_edit(path);
+    SPCurve *flash_curve = curve_new->copy();
+    flash_curve->transform(sp_item_i2d_affine(SP_ITEM(path)));
+    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);
+    flash_curve->unref();
+    return canvasitem;
+}
+
+static void
+sp_node_context_flash_path(SPEventContext *event_context, SPItem *item, guint timeout) {
+    SPNodeContext *nc = SP_NODE_CONTEXT(event_context);
+
+    nc->remove_flash_counter = 3; // for some reason root_handler is called twice after each item_handler...
+    if (nc->flashed_item != item) {
+        // we entered a new item
+        nc->flashed_item = item;
+        SPDesktop *desktop = event_context->desktop;
+        if (nc->flash_tempitem) {
+            desktop->remove_temporary_canvasitem(nc->flash_tempitem);
+            nc->flash_tempitem = NULL;
+        }
+
+        if (SP_IS_PATH(item)) {
+            SPCanvasItem *canvasitem = sp_node_context_generate_helperpath(desktop, SP_PATH(item));
+            nc->flash_tempitem = desktop->add_temporary_canvasitem (canvasitem, timeout);
+        }
+    }
+}
+
 /**
 \brief  Callback that processes the "changed" signal on the selection;
 destroys old and creates new nodepath and reassigns listeners to the new selected item's repr
@@ -184,6 +229,21 @@ sp_node_context_selection_changed(Inkscape::Selection *selection, gpointer data)
     SPItem *item = selection->singleItem(); 
     nc->shape_editor->set_item(item);
 
+    if (nc->flash_permitem) {
+        // hack!!! (we add a temporary canvasitem with life time 1 ms)
+        nc->flash_tempitem = nc->event_context.desktop->add_temporary_canvasitem (nc->flash_permitem, 1);
+        nc->flash_permitem = NULL;
+    }
+    if (SP_IS_LPE_ITEM(item)) {
+        Inkscape::LivePathEffect::Effect *lpe = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
+        if (lpe && lpe->pathFlashType() == Inkscape::LivePathEffect::PERMANENT_FLASH) {
+            if (SP_IS_PATH(item)) {
+                SPCanvasItem *canvasitem = sp_node_context_generate_helperpath(nc->event_context.desktop, SP_PATH(item));
+                nc->flash_permitem = canvasitem;
+            }
+        }
+    }
+
     nc->shape_editor->update_statusbar();
 }
 
@@ -197,41 +257,27 @@ sp_node_context_show_modifier_tip(SPEventContext *event_context, GdkEvent *event
          _("<b>Alt</b>: lock handle length; <b>Ctrl+Alt</b>: move along handles"));
 }
 
-
 static gint
 sp_node_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
 {
     gint ret = FALSE;
-    SPNodeContext *nc = SP_NODE_CONTEXT(event_context);
-
-    if (  prefs_get_int_attribute ("tools.nodes", "pathflash_enabled", 0) == 1  ) {
-        nc->remove_flash_counter = 3; // for some reason root_handler is called twice after each item_handler...
-        if (nc->flashed_item != item) {
-            // we entered a new item
-            nc->flashed_item = item;
-            SPDesktop *desktop = event_context->desktop;
-            if (nc->flash_tempitem) {
-                desktop->remove_temporary_canvasitem(nc->flash_tempitem);
-                nc->flash_tempitem = NULL;
-            }
 
-            if (SP_IS_PATH(item)) {
-            // This should be put somewhere else under the name of "generate helperpath" or something. Because basically this is copied of code from nodepath...
-                SPCurve *curve_new = sp_path_get_curve_for_edit(SP_PATH(item));
-                SPCurve *flash_curve = curve_new->copy();
-                flash_curve->transform(sp_item_i2d_affine(item) );
-                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);
-                flash_curve->unref();
-                guint timeout = prefs_get_int_attribute("tools.nodes", "pathflash_timeout", 500);
-                nc->flash_tempitem = desktop->add_temporary_canvasitem (canvasitem, timeout);
+    if (prefs_get_int_attribute ("tools.nodes", "pathflash_enabled", 0) == 1) {
+        guint timeout = prefs_get_int_attribute("tools.nodes", "pathflash_timeout", 500);
+        if (SP_IS_LPE_ITEM(item)) {
+            Inkscape::LivePathEffect::Effect *lpe = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
+            if (lpe) {
+                if (lpe->pathFlashType() == Inkscape::LivePathEffect::SUPPRESS_FLASH) {
+                    // return if flash is suppressed or if we want a permanent "flash" (this is handled
+                    // in sp_node_context_selection_changed()
+                    return ret;
+                }
+                if (lpe->pathFlashType() == Inkscape::LivePathEffect::PERMANENT_FLASH) {
+                    timeout = 0;
+                }
             }
         }
+        sp_node_context_flash_path(event_context, item, timeout);
     }
 
     if (((SPEventContextClass *) parent_class)->item_handler)
index 4a52c28a0064bdbc5aab4ef7d75e47f8e47ea6a2..baa37af915f6658d82c3c60d8db66b2aecc68109 100644 (file)
@@ -32,6 +32,7 @@ class SPNodeContext;
 class SPNodeContextClass;
 
 struct SPNodeContext {
+        // FIXME: shouldn't this be a pointer???
        SPEventContext event_context;
 
        guint drag : 1;
@@ -58,6 +59,7 @@ struct SPNodeContext {
  
     SPItem * flashed_item;
     Inkscape::Display::TemporaryItem * flash_tempitem;
+    SPCanvasItem * flash_permitem;
     int remove_flash_counter;
 };