From: dvlierop2 Date: Thu, 28 Aug 2008 19:32:55 +0000 (+0000) Subject: Modify the parameters required for setting up the SnapManager X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=700fe8603c02a9d683dd7b1ccdfae489b61ea2c2;p=inkscape.git Modify the parameters required for setting up the SnapManager --- diff --git a/src/arc-context.cpp b/src/arc-context.cpp index 3df9dc4b2..ae6ee88ad 100644 --- a/src/arc-context.cpp +++ b/src/arc-context.cpp @@ -265,7 +265,7 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent /* Snap center */ SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop, NULL); //null, because we don't have an item yet + m.setup(desktop); Geom::Point pt2g = to_2geom(ac->center); m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, pt2g); ac->center = from_2geom(pt2g); diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp index 393340cc4..0ea8b1dbd 100644 --- a/src/box3d-context.cpp +++ b/src/box3d-context.cpp @@ -330,7 +330,7 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven /* Snap center */ SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop, bc->item); + m.setup(desktop, true, bc->item); m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, button_dt); bc->center = from_2geom(button_dt); @@ -362,7 +362,7 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven Geom::Point motion_dt(to_2geom(desktop->w2d(motion_w))); SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop, bc->item); + m.setup(desktop, true, bc->item); m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt); bc->ctrl_dragged = event->motion.state & GDK_CONTROL_MASK; diff --git a/src/context-fns.cpp b/src/context-fns.cpp index e58476147..9acba2827 100644 --- a/src/context-fns.cpp +++ b/src/context-fns.cpp @@ -86,7 +86,7 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item, bool const control = state & GDK_CONTROL_MASK; SnapManager &m = desktop->namedview->snap_manager; - m.setup(NULL, item); + m.setup(desktop, false, item); Inkscape::SnappedPoint snappoint; if (control) { diff --git a/src/draw-context.cpp b/src/draw-context.cpp index 7b40e7c95..6b98c17e5 100644 --- a/src/draw-context.cpp +++ b/src/draw-context.cpp @@ -504,7 +504,7 @@ void spdc_endpoint_snap_rotation(SPEventContext const *const ec, NR::Point &p, N //pressing CTRL /* Snap it along best vector */ SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager; - m.setup(SP_EVENT_CONTEXT_DESKTOP(ec), NULL); + m.setup(SP_EVENT_CONTEXT_DESKTOP(ec)); Geom::Point pt2g = to_2geom(p); m.constrainedSnapReturnByRef( Inkscape::Snapper::SNAPPOINT_NODE, pt2g, Inkscape::Snapper::ConstraintLine(best)); p = from_2geom(pt2g); @@ -516,7 +516,7 @@ void spdc_endpoint_snap_rotation(SPEventContext const *const ec, NR::Point &p, N void spdc_endpoint_snap_free(SPEventContext const * const ec, NR::Point& p, guint const /*state*/) { SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager; - m.setup(SP_EVENT_CONTEXT_DESKTOP(ec), NULL); + m.setup(SP_EVENT_CONTEXT_DESKTOP(ec)); Geom::Point pt2g = to_2geom(p); m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, pt2g); p = from_2geom(pt2g); diff --git a/src/knot-holder-entity.cpp b/src/knot-holder-entity.cpp index 9d890e2fc..46f21965b 100644 --- a/src/knot-holder-entity.cpp +++ b/src/knot-holder-entity.cpp @@ -92,7 +92,7 @@ KnotHolderEntity::snap_knot_position(Geom::Point const &p) Geom::Matrix const i2d (sp_item_i2d_affine(item)); Geom::Point s = p * i2d; SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop, item); + m.setup(desktop, true, item); m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, s); return s * i2d.inverse(); } diff --git a/src/nodepath.cpp b/src/nodepath.cpp index 3544b7441..7e46b2f10 100644 --- a/src/nodepath.cpp +++ b/src/nodepath.cpp @@ -1311,7 +1311,7 @@ static void sp_nodepath_selected_nodes_move(Inkscape::NodePath::Path *nodepath, for (GList *l = nodepath->selected; l != NULL; l = l->next) { Inkscape::NodePath::Node *n = (Inkscape::NodePath::Node *) l->data; - m.setup(NULL, SP_PATH(n->subpath->nodepath->item), &unselected_nodes); + m.setup(nodepath->desktop, false, SP_PATH(n->subpath->nodepath->item), &unselected_nodes); Inkscape::SnappedPoint s; if (constrained) { Inkscape::Snapper::ConstraintLine dedicated_constraint = constraint; @@ -3778,7 +3778,7 @@ static gboolean node_handle_request(SPKnot *knot, NR::Point *p, guint state, gpo SPDesktop *desktop = n->subpath->nodepath->desktop; SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop, n->subpath->nodepath->item); + m.setup(desktop, true, n->subpath->nodepath->item); Inkscape::SnappedPoint s; if ((state & GDK_SHIFT_MASK) != 0) { diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index 69afdf614..cb1039119 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -350,7 +350,7 @@ pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mev p = to_2geom(anchor->dp); } else if ((mevent.state & GDK_SHIFT_MASK) == 0) { SnapManager &m = dt->namedview->snap_manager; - m.setup(dt, NULL); + m.setup(dt); m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, p); } if ( pc->npoints != 0 ) { // buttonpress may have happened before we entered draw context! diff --git a/src/rect-context.cpp b/src/rect-context.cpp index 999aa03b8..bbb809ef2 100644 --- a/src/rect-context.cpp +++ b/src/rect-context.cpp @@ -305,7 +305,7 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent /* Snap center */ SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop, NULL); //null, because we don't have an item yet + m.setup(desktop); m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, button_dt); rc->center = from_2geom(button_dt); diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 95c92ba69..d5e6afd8a 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -919,7 +919,7 @@ gboolean Inkscape::SelTrans::scaleRequest(NR::Point &pt, guint state) } else { // In all other cases we should try to snap now SnapManager &m = _desktop->namedview->snap_manager; - m.setup(NULL, _items_const); + m.setup(_desktop, false, _items_const); Inkscape::SnappedPoint bb, sn; NR::Coord bd(NR_HUGE); @@ -1032,7 +1032,7 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR:: // In all other cases we should try to snap now SnapManager &m = _desktop->namedview->snap_manager; - m.setup(NULL, _items_const); + m.setup(_desktop, false, _items_const); Inkscape::SnappedPoint bb, sn; g_assert(bb.getSnapped() == false); // Check initialization to catch any regression @@ -1156,7 +1156,7 @@ gboolean Inkscape::SelTrans::skewRequest(SPSelTransHandle const &handle, NR::Poi // Snap to objects, grids, guides SnapManager &m = _desktop->namedview->snap_manager; - m.setup(NULL, _items_const); + m.setup(_desktop, false, _items_const); Inkscape::Snapper::ConstraintLine const constraint(component_vectors[dim_b]); NR::Point const s(skew[dim_a], scale[dim_a]); @@ -1364,7 +1364,7 @@ void sp_sel_trans_center(Inkscape::SelTrans *seltrans, SPSelTransHandle const &, void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state) { SnapManager &m = _desktop->namedview->snap_manager; - m.setup(_desktop, _items_const); + m.setup(_desktop, true, _items_const); /* The amount that we've moved by during this drag */ Geom::Point dxy = to_2geom(xy - _point); diff --git a/src/snap.cpp b/src/snap.cpp index 9ae330b77..15bc8658d 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -871,11 +871,11 @@ Inkscape::SnappedPoint SnapManager::findBestSnap(Geom::Point const &p, SnappedCo // Update the snap indicator, if requested - if (_desktop_for_snapindicator) { + if (_snapindicator) { if (bestSnappedPoint.getSnapped()) { - _desktop_for_snapindicator->snapindicator->set_new_snappoint(bestSnappedPoint); + _desktop->snapindicator->set_new_snappoint(bestSnappedPoint); } else { - _desktop_for_snapindicator->snapindicator->remove_snappoint(); + _desktop->snapindicator->remove_snappoint(); } } @@ -883,19 +883,23 @@ Inkscape::SnappedPoint SnapManager::findBestSnap(Geom::Point const &p, SnappedCo return bestSnappedPoint; } -void SnapManager::setup(SPDesktop const *desktop_for_snapindicator, SPItem const *item_to_ignore, std::vector *unselected_nodes) +void SnapManager::setup(SPDesktop const *desktop, bool snapindicator, SPItem const *item_to_ignore, std::vector *unselected_nodes) { - _item_to_ignore = item_to_ignore; + g_assert(desktop != NULL); + _item_to_ignore = item_to_ignore; _items_to_ignore = NULL; - _desktop_for_snapindicator = desktop_for_snapindicator; + _desktop = desktop; + _snapindicator = snapindicator; _unselected_nodes = unselected_nodes; } -void SnapManager::setup(SPDesktop const *desktop_for_snapindicator, std::vector &items_to_ignore, std::vector *unselected_nodes) +void SnapManager::setup(SPDesktop const *desktop, bool snapindicator, std::vector &items_to_ignore, std::vector *unselected_nodes) { - _item_to_ignore = NULL; + g_assert(desktop != NULL); + _item_to_ignore = NULL; _items_to_ignore = &items_to_ignore; - _desktop_for_snapindicator = desktop_for_snapindicator; + _desktop = desktop; + _snapindicator = snapindicator; _unselected_nodes = unselected_nodes; } diff --git a/src/snap.h b/src/snap.h index e4f9aaddf..02cee70ca 100644 --- a/src/snap.h +++ b/src/snap.h @@ -47,8 +47,8 @@ public: bool SomeSnapperMightSnap() const; - void setup(SPDesktop const *desktop_for_snapindicator = NULL, SPItem const *item_to_ignore = NULL, std::vector *unselected_nodes = NULL); - void setup(SPDesktop const *desktop_for_snapindicator, std::vector &items_to_ignore, std::vector *unselected_nodes = NULL); + void setup(SPDesktop const *desktop, bool snapindicator = true, SPItem const *item_to_ignore = NULL, std::vector *unselected_nodes = NULL); + void setup(SPDesktop const *desktop, bool snapindicator, std::vector &items_to_ignore, std::vector *unselected_nodes = NULL); // freeSnapReturnByRef() is preferred over freeSnap(), because it only returns a // point if snapping has occured (by overwriting p); otherwise p is untouched @@ -172,7 +172,8 @@ private: std::vector *_items_to_ignore; SPItem const *_item_to_ignore; - SPDesktop const *_desktop_for_snapindicator; + SPDesktop const *_desktop; + bool _snapindicator; std::vector *_unselected_nodes; Inkscape::SnappedPoint _snapTransformed(Inkscape::Snapper::PointType type, diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp index b42195c60..dc2e99e07 100644 --- a/src/spiral-context.cpp +++ b/src/spiral-context.cpp @@ -266,7 +266,7 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event) sc->center = Inkscape::setup_for_drag_start(desktop, event_context, event); SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop, NULL); //null, because we don't have an item yet + m.setup(desktop); Geom::Point pt2g = to_2geom(sc->center); m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, pt2g); sc->center = from_2geom(pt2g); @@ -298,7 +298,7 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event) Geom::Point motion_dt(to_2geom(event_context->desktop->w2d(motion_w))); SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop, sc->item); + m.setup(desktop, true, sc->item); m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt); sp_spiral_drag(sc, from_2geom(motion_dt), event->motion.state); @@ -442,7 +442,7 @@ sp_spiral_drag(SPSpiralContext *sc, NR::Point p, guint state) Geom::Point const p0 = to_2geom(sp_desktop_dt2root_xy_point(desktop, sc->center)); Geom::Point p1 = to_2geom(sp_desktop_dt2root_xy_point(desktop, p)); SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop, sc->item); + m.setup(desktop, true, sc->item); m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, p1); SPSpiral *spiral = SP_SPIRAL(sc->item); diff --git a/src/star-context.cpp b/src/star-context.cpp index 824fd53a4..97577bcba 100644 --- a/src/star-context.cpp +++ b/src/star-context.cpp @@ -282,7 +282,7 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent /* Snap center */ SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop, NULL); //null, because we don't have an item yet + m.setup(desktop, true); Geom::Point pt2g = to_2geom(sc->center); m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, pt2g); sc->center = from_2geom(pt2g); @@ -452,7 +452,7 @@ static void sp_star_drag(SPStarContext *sc, NR::Point p, guint state) /* Snap corner point with no constraints */ SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop, sc->item); + m.setup(desktop, true, sc->item); Geom::Point pt2g = to_2geom(p); m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, pt2g); diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index a3f1b9c0d..ac35e7be6 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -803,7 +803,7 @@ void ClipboardManagerImpl::_pasteDocument(SPDocument *clipdoc, bool in_place) offset = rel_pos_original; } else { // Stick to the grid if snapping is enabled, otherwise paste at mouse position; SnapManager &m = desktop->namedview->snap_manager; - m.setup(NULL, NULL); //Don't display the snapindicator + m.setup(desktop, false); //Don't display the snapindicator offset = rel_pos_original + m.multipleOfGridPitch(rel_pos_mouse - rel_pos_original); }