Code

Only in the selector tool we should snap in bbox mode (PointType = SNAPPOINT_BBOX)
[inkscape.git] / src / draw-context.cpp
index 0cb408293decefe06134213148c046793cbaa997..43e028aa5655032071f821e2c089a40e58b623e8 100644 (file)
@@ -39,7 +39,7 @@
 #include "selection-chemistry.h"
 #include "snap.h"
 #include "sp-path.h"
-
+#include "sp-namedview.h"
 
 static void sp_draw_context_class_init(SPDrawContextClass *klass);
 static void sp_draw_context_init(SPDrawContext *dc);
@@ -150,7 +150,7 @@ sp_draw_context_setup(SPEventContext *ec)
         ((SPEventContextClass *) draw_parent_class)->setup(ec);
     }
 
-    dc->selection = SP_DT_SELECTION(dt);
+    dc->selection = sp_desktop_selection(dt);
 
     /* Connect signals to track selection changes */
     dc->sel_changed_connection = dc->selection->connectChanged(
@@ -161,13 +161,13 @@ sp_draw_context_setup(SPEventContext *ec)
     );
 
     /* Create red bpath */
-    dc->red_bpath = sp_canvas_bpath_new(SP_DT_SKETCH(ec->desktop), NULL);
+    dc->red_bpath = sp_canvas_bpath_new(sp_desktop_sketch(ec->desktop), NULL);
     sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->red_bpath), dc->red_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
     /* Create red curve */
     dc->red_curve = sp_curve_new_sized(4);
 
     /* Create blue bpath */
-    dc->blue_bpath = sp_canvas_bpath_new(SP_DT_SKETCH(ec->desktop), NULL);
+    dc->blue_bpath = sp_canvas_bpath_new(sp_desktop_sketch(ec->desktop), NULL);
     sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->blue_bpath), dc->blue_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
     /* Create blue curve */
     dc->blue_curve = sp_curve_new_sized(8);
@@ -209,30 +209,11 @@ sp_draw_context_set(SPEventContext *ec, const gchar *key, const gchar *value)
 gint
 sp_draw_context_root_handler(SPEventContext *ec, GdkEvent *event)
 {
-    //SPDrawContext *dc = SP_DRAW_CONTEXT(ec);
-    SPDesktop *desktop = ec->desktop;
-
     gint ret = FALSE;
 
     switch (event->type) {
         case GDK_KEY_PRESS:
             switch (get_group0_keyval (&event->key)) {
-                case GDK_Escape:
-                    SP_DT_SELECTION(desktop)->clear();
-                    ret = TRUE;
-                    break;
-                case GDK_Tab: // Tab - cycle selection forward
-                    if (!(MOD__CTRL_ONLY || (MOD__CTRL && MOD__SHIFT))) {
-                        sp_selection_item_next();
-                        ret = TRUE;
-                    }
-                    break;
-                case GDK_ISO_Left_Tab: // Shift Tab - cycle selection backward
-                    if (!(MOD__CTRL_ONLY || (MOD__CTRL && MOD__SHIFT))) {
-                        sp_selection_item_prev();
-                        ret = TRUE;
-                    }
-                    break;
                 case GDK_Up:
                 case GDK_Down:
                 case GDK_KP_Up:
@@ -301,14 +282,14 @@ spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection *sel)
         SPCurve *norm = sp_shape_get_curve(SP_SHAPE(item));
         sp_curve_transform(norm, sp_item_i2d_affine(dc->white_item));
         g_return_if_fail( norm != NULL );
-        dc->white_curves = sp_curve_split(norm);
+        dc->white_curves = g_slist_reverse(sp_curve_split(norm));
         sp_curve_unref(norm);
         /* Anchor list */
         for (GSList *l = dc->white_curves; l != NULL; l = l->next) {
             SPCurve *c;
             c = (SPCurve*)l->data;
             g_return_if_fail( c->end > 1 );
-            if ( c->bpath->code == NR_MOVETO_OPEN ) {
+            if ( SP_CURVE_BPATH(c)->code == NR_MOVETO_OPEN ) {
                 NArtBpath *s, *e;
                 SPDrawAnchor *a;
                 s = sp_curve_first_bpath(c);
@@ -372,9 +353,9 @@ void spdc_endpoint_snap_rotation(SPEventContext const *const ec, NR::Point &p, N
         p = o + bdot * best;
 
         /* Snap it along best vector */
-        SnapManager const m(SP_EVENT_CONTEXT_DESKTOP(ec)->namedview);
-        p = m.constrainedSnap(Inkscape::Snapper::SNAP_POINT | Inkscape::Snapper::BBOX_POINT,
-                              p, best, NULL).getPoint();
+        SnapManager const &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager;
+        p = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE,
+                              p, Inkscape::Snapper::ConstraintLine(best), NULL).getPoint();
     }
 }
 
@@ -386,9 +367,8 @@ void spdc_endpoint_snap_free(SPEventContext const * const ec, NR::Point& p, guin
         return;
     }
 
-    /* FIXME: this should be doing bbox snap as well */
-    SnapManager const m(SP_EVENT_CONTEXT_DESKTOP(ec)->namedview);
-    p = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, p, NULL).getPoint();
+    SnapManager const &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager;
+    p = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p, NULL).getPoint();
 }
 
 static SPCurve *
@@ -529,7 +509,8 @@ spdc_flush_white(SPDrawContext *dc, SPCurve *gc)
                             : sp_desktop_dt2root_affine(SP_EVENT_CONTEXT_DESKTOP(dc)) ));
 
     SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(dc);
-    SPDocument *doc = SP_DT_DOCUMENT(desktop);
+    SPDocument *doc = sp_desktop_document(desktop);
+    Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
 
     if ( c && !sp_curve_empty(c) ) {
         /* We actually have something to write */
@@ -538,7 +519,7 @@ spdc_flush_white(SPDrawContext *dc, SPCurve *gc)
         if (dc->white_item) {
             repr = SP_OBJECT_REPR(dc->white_item);
         } else {
-            repr = sp_repr_new("svg:path");
+            repr = xml_doc->createElement("svg:path");
             /* Set style */
             sp_desktop_apply_style_tool(desktop, repr, tool_name(dc), false);
         }
@@ -557,7 +538,8 @@ spdc_flush_white(SPDrawContext *dc, SPCurve *gc)
             item->updateRepr();
         }
 
-        sp_document_done(doc);
+        sp_document_done(doc, SP_IS_PEN_CONTEXT(dc)? SP_VERB_CONTEXT_PEN : SP_VERB_CONTEXT_PENCIL, 
+                         _("Draw path"));
     }
 
     sp_curve_unref(c);