Code

NR::Maybe => boost::optional
[inkscape.git] / src / node-context.cpp
index 29b8886b863cc198f0b3183f424363906d8328ac..d8a1ec1d7deb953f20517561dfd35d78ff8b5d2b 100644 (file)
@@ -35,6 +35,9 @@
 #include "style.h"
 #include "splivarot.h"
 #include "shape-editor.h"
+#include "live_effects/effect.h"
+
+#include "sp-lpe-item.h"
 
 // needed for flash nodepath upon mouseover:
 #include "display/canvas-bpath.h"
@@ -135,10 +138,11 @@ sp_node_context_setup(SPEventContext *ec)
     if (((SPEventContextClass *) parent_class)->setup)
         ((SPEventContextClass *) parent_class)->setup(ec);
 
+    Inkscape::Selection *selection = sp_desktop_selection (ec->desktop);
     nc->sel_changed_connection.disconnect();
-    nc->sel_changed_connection = sp_desktop_selection(ec->desktop)->connectChanged(sigc::bind(sigc::ptr_fun(&sp_node_context_selection_changed), (gpointer)nc));
+    nc->sel_changed_connection =
+        selection->connectChanged(sigc::bind(sigc::ptr_fun(&sp_node_context_selection_changed), (gpointer)nc));
 
-    Inkscape::Selection *selection = sp_desktop_selection(ec->desktop);
     SPItem *item = selection->singleItem();
 
     nc->shape_editor = new ShapeEditor(ec->desktop);
@@ -152,7 +156,8 @@ sp_node_context_setup(SPEventContext *ec)
     nc->current_state = SP_NODE_CONTEXT_INACTIVE;
 
     if (item) {
-        nc->shape_editor->set_item(item);
+        nc->shape_editor->set_item(item, SH_NODEPATH);
+        nc->shape_editor->set_item(item, SH_KNOTHOLDER);
     }
 
     if (prefs_get_int_attribute("tools.nodes", "selcue", 0) != 0) {
@@ -170,6 +175,28 @@ sp_node_context_setup(SPEventContext *ec)
     nc->shape_editor->update_statusbar();
 }
 
+static void
+sp_node_context_flash_path(SPEventContext *event_context, SPItem *item, guint timeout) {
+    g_print ("-----> sp_node_context_flash_path(): TODO: generate the helper path!!\n");
+    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_nodepath_helperpath_from_path(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
@@ -180,10 +207,11 @@ sp_node_context_selection_changed(Inkscape::Selection *selection, gpointer data)
     SPNodeContext *nc = SP_NODE_CONTEXT(data);
 
     // TODO: update ShapeEditorsCollective instead
-    nc->shape_editor->unset_item();
+    nc->shape_editor->unset_item(SH_NODEPATH);
+    nc->shape_editor->unset_item(SH_KNOTHOLDER);
     SPItem *item = selection->singleItem(); 
-    nc->shape_editor->set_item(item);
-
+    nc->shape_editor->set_item(item, SH_NODEPATH);
+    nc->shape_editor->set_item(item, SH_KNOTHOLDER);
     nc->shape_editor->update_statusbar();
 }
 
@@ -197,37 +225,23 @@ 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);
 
-    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 = sp_curve_copy(curve_new);
-            sp_curve_transform(flash_curve, 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...
-            sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(canvasitem), 0xff0000ff, 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);
-            sp_curve_unref(flash_curve);
-            nc->flash_tempitem = desktop->add_temporary_canvasitem (canvasitem, 600);
+    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 && (lpe->providesOwnFlashPaths() ||
+                        lpe->pathFlashType() == Inkscape::LivePathEffect::SUPPRESS_FLASH)) {
+                // path should be suppressed or permanent; this is handled in
+                // sp_node_context_selection_changed()
+                return ret;
+            }
         }
+        sp_node_context_flash_path(event_context, item, timeout);
     }
 
     if (((SPEventContextClass *) parent_class)->item_handler)
@@ -423,7 +437,7 @@ sp_node_context_root_handler(SPEventContext *event_context, GdkEvent *event)
             if (event->type == GDK_BUTTON_RELEASE) {
                 event_context->xp = event_context->yp = 0;
                 if (event->button.button == 1) {
-                    NR::Maybe<NR::Rect> b = Inkscape::Rubberband::get()->getRectangle();
+                    boost::optional<NR::Rect> b = Inkscape::Rubberband::get()->getRectangle();
 
                     if (nc->shape_editor->hits_curve() && !event_context->within_tolerance) { //drag curve
                         nc->shape_editor->finish_drag();
@@ -606,7 +620,7 @@ sp_node_context_root_handler(SPEventContext *event_context, GdkEvent *event)
                     break;
                 case GDK_Escape:
                 {
-                    NR::Maybe<NR::Rect> const b = Inkscape::Rubberband::get()->getRectangle();
+                    boost::optional<NR::Rect> const b = Inkscape::Rubberband::get()->getRectangle();
                     if (b) {
                         Inkscape::Rubberband::get()->stop();
                         nc->current_state = SP_NODE_CONTEXT_INACTIVE;