From: dvlierop2 Date: Wed, 28 Jan 2009 21:19:16 +0000 (+0000) Subject: Add buttons for snapping to grids and/or guides X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=bc2c9f897bc52112f52a3977137983e8fa3a7cc2;p=inkscape.git Add buttons for snapping to grids and/or guides --- diff --git a/share/icons/icons.svg b/share/icons/icons.svg index 10b3a6d05..ec05ea392 100644 --- a/share/icons/icons.svg +++ b/share/icons/icons.svg @@ -1,5 +1,5 @@ - + @@ -710,8 +710,10 @@ + + - + @@ -734,7 +736,7 @@ http://www.inkscape.org/ Inkscape Developers - + @@ -3314,4 +3316,9 @@ http://www.inkscape.org/ + + + + + diff --git a/share/icons/tango_icons.svg b/share/icons/tango_icons.svg index cc8827d75..11dc11e7c 100644 --- a/share/icons/tango_icons.svg +++ b/share/icons/tango_icons.svg @@ -1,5 +1,5 @@ - + @@ -2432,8 +2432,21 @@ + + + + + + + + + + + + + - + @@ -2455,7 +2468,7 @@ http://www.inkscape.org/ Inkscape Developers -Icon Sheet + jEsuSdA 8) www.jesusda.com @@ -2722,6 +2735,19 @@ http://www.inkscape.org/ + + + + + + + + + + + + + @@ -5291,7 +5317,7 @@ http://www.inkscape.org/ - + diff --git a/src/attributes-test.h b/src/attributes-test.h index 1148953ec..7b021a543 100644 --- a/src/attributes-test.h +++ b/src/attributes-test.h @@ -348,14 +348,16 @@ struct {char const *attr; bool supported;} const all_attrs[] = { {"inkscape:snap-global", true}, {"inkscape:snap-bbox", true}, {"inkscape:snap-nodes", true}, - {"inkscape:snap-guide", true}, + {"inkscape:snap-from-guide", true}, {"inkscape:snap-center", true}, {"inkscape:snap-smooth-nodes", true}, {"inkscape:snap-midpoints", true}, {"inkscape:snap-object-midpoints", true}, {"inkscape:snap-bbox-edge-midpoints", true}, {"inkscape:snap-bbox-midpoints", true}, - {"inkscape:snap-intersection-grid-guide", true}, + //{"inkscape:snap-intersection-grid-guide", true}, + {"inkscape:snap-grids", true}, + {"inkscape:snap-to-guides", true}, {"inkscape:snap-intersection-paths", true}, {"inkscape:pageopacity", true}, {"inkscape:pageshadow", true}, diff --git a/src/attributes.cpp b/src/attributes.cpp index 049632e50..f2fb62a1c 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -89,14 +89,16 @@ static SPStyleProp const props[] = { {SP_ATTR_INKSCAPE_SNAP_GLOBAL, "inkscape:snap-global"}, {SP_ATTR_INKSCAPE_SNAP_BBOX, "inkscape:snap-bbox"}, {SP_ATTR_INKSCAPE_SNAP_NODES, "inkscape:snap-nodes"}, - {SP_ATTR_INKSCAPE_SNAP_GUIDE, "inkscape:snap-guide"}, + {SP_ATTR_INKSCAPE_SNAP_FROM_GUIDE, "inkscape:snap-from-guide"}, {SP_ATTR_INKSCAPE_SNAP_CENTER, "inkscape:snap-center"}, + {SP_ATTR_INKSCAPE_SNAP_GRIDS, "inkscape:snap-grids"}, + {SP_ATTR_INKSCAPE_SNAP_TO_GUIDES, "inkscape:snap-to-guides"}, {SP_ATTR_INKSCAPE_SNAP_SMOOTH_NODES, "inkscape:snap-smooth-nodes"}, {SP_ATTR_INKSCAPE_SNAP_LINE_MIDPOINTS, "inkscape:snap-midpoints"}, {SP_ATTR_INKSCAPE_SNAP_OBJECT_MIDPOINTS, "inkscape:snap-object-midpoints"}, {SP_ATTR_INKSCAPE_SNAP_BBOX_EDGE_MIDPOINTS, "inkscape:snap-bbox-edge-midpoints"}, {SP_ATTR_INKSCAPE_SNAP_BBOX_MIDPOINTS, "inkscape:snap-bbox-midpoints"}, - {SP_ATTR_INKSCAPE_SNAP_INTERS_GRIDGUIDE, "inkscape:snap-intersection-grid-guide"}, + //{SP_ATTR_INKSCAPE_SNAP_INTERS_GRIDGUIDE, "inkscape:snap-intersection-grid-guide"}, {SP_ATTR_INKSCAPE_SNAP_INTERS_PATHS, "inkscape:snap-intersection-paths"}, {SP_ATTR_INKSCAPE_OBJECT_PATHS, "inkscape:object-paths"}, {SP_ATTR_INKSCAPE_OBJECT_NODES, "inkscape:object-nodes"}, diff --git a/src/attributes.h b/src/attributes.h index 6fe3ebb80..fc9e49f2b 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -89,14 +89,16 @@ enum SPAttributeEnum { SP_ATTR_INKSCAPE_SNAP_GLOBAL, SP_ATTR_INKSCAPE_SNAP_BBOX, SP_ATTR_INKSCAPE_SNAP_NODES, - SP_ATTR_INKSCAPE_SNAP_GUIDE, + SP_ATTR_INKSCAPE_SNAP_FROM_GUIDE, SP_ATTR_INKSCAPE_SNAP_CENTER, + SP_ATTR_INKSCAPE_SNAP_GRIDS, + SP_ATTR_INKSCAPE_SNAP_TO_GUIDES, SP_ATTR_INKSCAPE_SNAP_SMOOTH_NODES, SP_ATTR_INKSCAPE_SNAP_LINE_MIDPOINTS, SP_ATTR_INKSCAPE_SNAP_OBJECT_MIDPOINTS, SP_ATTR_INKSCAPE_SNAP_BBOX_EDGE_MIDPOINTS, SP_ATTR_INKSCAPE_SNAP_BBOX_MIDPOINTS, - SP_ATTR_INKSCAPE_SNAP_INTERS_GRIDGUIDE, + //SP_ATTR_INKSCAPE_SNAP_INTERS_GRIDGUIDE, SP_ATTR_INKSCAPE_SNAP_INTERS_PATHS, SP_ATTR_INKSCAPE_OBJECT_PATHS, SP_ATTR_INKSCAPE_OBJECT_NODES, diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index 4b45eae33..283f58a01 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -748,6 +748,10 @@ void CanvasAxonomGridSnapper::_addSnappedLine(SnappedConstraints &sc, Geom::Poin sc.grid_lines.push_back(dummy); } +bool CanvasAxonomGridSnapper::ThisSnapperMightSnap() const +{ + return _snap_enabled && _snapmanager->snapprefs.getSnapToGrids() && _snapmanager->snapprefs.getSnapModeBBoxOrNodes(); +} }; // namespace Inkscape diff --git a/src/display/canvas-axonomgrid.h b/src/display/canvas-axonomgrid.h index 0654a9429..9067e2e13 100644 --- a/src/display/canvas-axonomgrid.h +++ b/src/display/canvas-axonomgrid.h @@ -71,6 +71,7 @@ class CanvasAxonomGridSnapper : public LineSnapper { public: CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SnapManager *sm, Geom::Coord const d); + bool ThisSnapperMightSnap() const; private: LineList _getSnapLines(Geom::Point const &p) const; diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index b03bfca9e..0d5cabd8d 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -999,7 +999,7 @@ void CanvasXYGridSnapper::_addSnappedLine(SnappedConstraints &sc, Geom::Point co */ bool CanvasXYGridSnapper::ThisSnapperMightSnap() const { - return _snapmanager->snapprefs.getSnapModeBBoxOrNodes(); + return _snap_enabled && _snapmanager->snapprefs.getSnapToGrids() && _snapmanager->snapprefs.getSnapModeBBoxOrNodes(); } } // namespace Inkscape diff --git a/src/guide-snapper.cpp b/src/guide-snapper.cpp index b05466ede..54a4086a4 100644 --- a/src/guide-snapper.cpp +++ b/src/guide-snapper.cpp @@ -47,7 +47,7 @@ bool Inkscape::GuideSnapper::ThisSnapperMightSnap() const return false; } - return (_snap_enabled && _snapmanager->snapprefs.getSnapModeBBoxOrNodes() && _snapmanager->getNamedView()->showguides); + return (_snap_enabled && _snapmanager->snapprefs.getSnapToGuides() && _snapmanager->snapprefs.getSnapModeBBoxOrNodes() && _snapmanager->getNamedView()->showguides); } void Inkscape::GuideSnapper::_addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, Geom::Point const normal_to_line, Geom::Point const point_on_line) const diff --git a/src/snap-preferences.cpp b/src/snap-preferences.cpp index d21259983..e8c9e0641 100644 --- a/src/snap-preferences.cpp +++ b/src/snap-preferences.cpp @@ -22,6 +22,9 @@ Inkscape::SnapPreferences::PointType const Inkscape::SnapPreferences::SNAPPOINT_ Inkscape::SnapPreferences::SnapPreferences() : _include_item_center(false), + _intersectionGG(true), + _snap_to_grids(true), + _snap_to_guides(true), _snap_enabled_globally(true), _snap_postponed_globally(false), _snap_to_itemnode(true), _snap_to_itempath(true), diff --git a/src/snap-preferences.h b/src/snap-preferences.h index 97ef3cec2..258b1f5ed 100644 --- a/src/snap-preferences.h +++ b/src/snap-preferences.h @@ -51,6 +51,12 @@ public: bool getSnapBBoxEdgeMidpoints() const {return _bbox_edge_midpoints;} bool getSnapBBoxMidpoints() const {return _bbox_midpoints;} + void setSnapToGrids(bool enabled) {_snap_to_grids = enabled;} + bool getSnapToGrids() const {return _snap_to_grids;} + + void setSnapToGuides(bool enabled) {_snap_to_guides = enabled;} + bool getSnapToGuides() const {return _snap_to_guides;} + void setIncludeItemCenter(bool enabled) {_include_item_center = enabled;} bool getIncludeItemCenter() const {return _include_item_center;} @@ -85,6 +91,8 @@ private: bool _object_midpoints; // the midpoint of shapes (e.g. a circle, rect, polygon) or of any other shape (at [h/2, w/2]) bool _bbox_edge_midpoints; bool _bbox_midpoints; + bool _snap_to_grids; + bool _snap_to_guides; bool _snap_enabled_globally; // Toggles ALL snapping bool _snap_postponed_globally; // Hold all snapping temporarily when the mouse is moving fast PointType _snap_from; ///< bitmap of point types that we will snap from diff --git a/src/snap.cpp b/src/snap.cpp index 04521f07f..548741455 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -77,7 +77,7 @@ SnapManager::getGridSnappers() const SnapperList s; //FIXME: this code should actually do this: add new grid snappers that are active for this desktop. now it just adds all gridsnappers - if (_desktop && _desktop->gridsEnabled()) { + if (_desktop && _desktop->gridsEnabled() && snapprefs.getSnapToGrids()) { for ( GSList const *l = _named_view->grids; l != NULL; l = l->next) { Inkscape::CanvasGrid *grid = (Inkscape::CanvasGrid*) l->data; s.push_back(grid->snapper); diff --git a/src/snapper.h b/src/snapper.h index f6e1a086e..7bea9b423 100644 --- a/src/snapper.h +++ b/src/snapper.h @@ -55,7 +55,7 @@ public: //virtual bool ThisSnapperMightSnap() const; virtual bool ThisSnapperMightSnap() const {return _snap_enabled;} // will likely be overridden by derived classes - void setEnabled(bool s); + void setEnabled(bool s); // This is only used for grids, for which snapping can be enabled individually bool getEnabled() const {return _snap_enabled;} virtual void freeSnap(SnappedConstraints &/*sc*/, @@ -108,6 +108,7 @@ protected: SnapManager *_snapmanager; bool _snap_enabled; ///< true if this snapper is enabled, otherwise false + // This is only used for grids, for which snapping can be enabled individually private: Geom::Coord _snapper_tolerance; ///< snap tolerance in desktop coordinates diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 4ff66f6c3..4bde2b191 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -245,14 +245,16 @@ static void sp_namedview_build(SPObject *object, SPDocument *document, Inkscape: sp_object_read_attr(object, "inkscape:snap-global"); sp_object_read_attr(object, "inkscape:snap-bbox"); sp_object_read_attr(object, "inkscape:snap-nodes"); - sp_object_read_attr(object, "inkscape:snap-guide"); + sp_object_read_attr(object, "inkscape:snap-from-guide"); sp_object_read_attr(object, "inkscape:snap-center"); sp_object_read_attr(object, "inkscape:snap-smooth-nodes"); sp_object_read_attr(object, "inkscape:snap-midpoints"); sp_object_read_attr(object, "inkscape:snap-object-midpoints"); sp_object_read_attr(object, "inkscape:snap-bbox-edge-midpoints"); sp_object_read_attr(object, "inkscape:snap-bbox-midpoints"); - sp_object_read_attr(object, "inkscape:snap-intersection-grid-guide"); + //sp_object_read_attr(object, "inkscape:snap-intersection-grid-guide"); + sp_object_read_attr(object, "inkscape:snap-to-guides"); + sp_object_read_attr(object, "inkscape:snap-grids"); sp_object_read_attr(object, "inkscape:snap-intersection-paths"); sp_object_read_attr(object, "inkscape:object-paths"); sp_object_read_attr(object, "inkscape:object-nodes"); @@ -470,7 +472,15 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va nv->snap_manager.snapprefs.setIncludeItemCenter(value ? sp_str_to_bool(value) : FALSE); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; - case SP_ATTR_INKSCAPE_SNAP_SMOOTH_NODES: + case SP_ATTR_INKSCAPE_SNAP_GRIDS: + nv->snap_manager.snapprefs.setSnapToGrids(value ? sp_str_to_bool(value) : TRUE); + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; + case SP_ATTR_INKSCAPE_SNAP_TO_GUIDES: + nv->snap_manager.snapprefs.setSnapToGuides(value ? sp_str_to_bool(value) : TRUE); + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; + case SP_ATTR_INKSCAPE_SNAP_SMOOTH_NODES: nv->snap_manager.snapprefs.setSnapSmoothNodes(value ? sp_str_to_bool(value) : FALSE); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; @@ -490,14 +500,14 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va nv->snap_manager.snapprefs.setSnapBBoxMidpoints(value ? sp_str_to_bool(value) : FALSE); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; - case SP_ATTR_INKSCAPE_SNAP_GUIDE: + case SP_ATTR_INKSCAPE_SNAP_FROM_GUIDE: nv->snap_manager.snapprefs.setSnapModeGuide(value ? sp_str_to_bool(value) : FALSE); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; - case SP_ATTR_INKSCAPE_SNAP_INTERS_GRIDGUIDE: + /*case SP_ATTR_INKSCAPE_SNAP_INTERS_GRIDGUIDE: nv->snap_manager.snapprefs.setSnapIntersectionGG(value ? sp_str_to_bool(value) : TRUE); object->requestModified(SP_OBJECT_MODIFIED_FLAG); - break; + break;*/ case SP_ATTR_INKSCAPE_SNAP_INTERS_PATHS: nv->snap_manager.snapprefs.setSnapIntersectionCS(value ? sp_str_to_bool(value) : FALSE); object->requestModified(SP_OBJECT_MODIFIED_FLAG); diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index cbc3d79b9..76a50c9c7 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -101,7 +101,7 @@ DocumentProperties::DocumentProperties() //General snap options _rcb_sgui(_("Show _guides"), _("Show or hide guides"), "showguides", _wr), _rcbsng(_("_Snap guides while dragging"), _("While dragging a guide, snap to object nodes or bounding box corners ('Snap to nodes' or 'snap to bounding box corners' must be enabled in the 'Snap' tab; only a small part of the guide near the cursor will snap)"), - "inkscape:snap-guide", _wr), + "inkscape:snap-from-guide", _wr), _rcp_gui(_("Guide co_lor:"), _("Guideline color"), _("Color of guidelines"), "guidecolor", "guideopacity", _wr), _rcp_hgui(_("_Highlight color:"), _("Highlighted guideline color"), _("Color of a guideline when it is under mouse"), "guidehicolor", "guidehiopacity", _wr), //--------------------------------------------------------------- diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 0acc7731a..a2be7e238 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -1940,14 +1940,22 @@ void toggle_snap_callback (GtkToggleAction *act, gpointer data) { //data points v = nv->snap_manager.snapprefs.getIncludeItemCenter(); sp_repr_set_boolean(repr, "inkscape:snap-center", !v); break; + case SP_ATTR_INKSCAPE_SNAP_GRIDS: + v = nv->snap_manager.snapprefs.getSnapToGrids(); + sp_repr_set_boolean(repr, "inkscape:snap-grids", !v); + break; + case SP_ATTR_INKSCAPE_SNAP_TO_GUIDES: + v = nv->snap_manager.snapprefs.getSnapToGuides(); + sp_repr_set_boolean(repr, "inkscape:snap-to-guides", !v); + break; case SP_ATTR_INKSCAPE_SNAP_PAGE: v = nv->snap_manager.snapprefs.getSnapToPageBorder(); sp_repr_set_boolean(repr, "inkscape:snap-page", !v); break; - case SP_ATTR_INKSCAPE_SNAP_INTERS_GRIDGUIDE: + /*case SP_ATTR_INKSCAPE_SNAP_INTERS_GRIDGUIDE: v = nv->snap_manager.snapprefs.getSnapIntersectionGG(); sp_repr_set_boolean(repr, "inkscape:snap-intersection-grid-guide", !v); - break; + break;*/ case SP_ATTR_INKSCAPE_SNAP_LINE_MIDPOINTS: v = nv->snap_manager.snapprefs.getSnapLineMidpoints(); sp_repr_set_boolean(repr, "inkscape:snap-midpoints", !v); @@ -2000,7 +2008,9 @@ void setup_snap_toolbox(GtkWidget *toolbox, SPDesktop *desktop) " " " " " " - " " + " " + " " + //" " " " ""; @@ -2187,6 +2197,30 @@ void setup_snap_toolbox(GtkWidget *toolbox, SPDesktop *desktop) } { + InkToggleAction* act = ink_toggle_action_new("ToggleSnapToGrids", // "name" + _("Grids"), // "label" + _("Snap to grids"), // "tooltip" + "grid_xy", // "iconId" + secondarySize, + SP_ATTR_INKSCAPE_SNAP_GRIDS); + + gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox ); + } + + { + InkToggleAction* act = ink_toggle_action_new("ToggleSnapToGuides", // "name" + _("Guides"), // "label" + _("Snap to guides"), // "tooltip" + "guide", // "iconId" + secondarySize, + SP_ATTR_INKSCAPE_SNAP_TO_GUIDES); + + gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox ); + } + + /*{ InkToggleAction* act = ink_toggle_action_new("ToggleSnapToGridGuideIntersections", // "name" _("Grid/guide intersections"), // "label" _("Snap to intersections of a grid with a guide"), // "tooltip" @@ -2196,7 +2230,7 @@ void setup_snap_toolbox(GtkWidget *toolbox, SPDesktop *desktop) gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox ); - } + }*/ GtkUIManager* mgr = gtk_ui_manager_new(); GError* errVal = 0; @@ -2254,7 +2288,9 @@ void update_snap_toolbox(SPDesktop *desktop, SPEventContext */*eventcontext*/, G Glib::RefPtr act10 = mainActions->get_action("ToggleSnapToFromObjectMidpoints"); Glib::RefPtr act11 = mainActions->get_action("ToggleSnapToFromCenter"); Glib::RefPtr act12 = mainActions->get_action("ToggleSnapToPageBorder"); - Glib::RefPtr act13 = mainActions->get_action("ToggleSnapToGridGuideIntersections"); + //Glib::RefPtr act13 = mainActions->get_action("ToggleSnapToGridGuideIntersections"); + Glib::RefPtr act14 = mainActions->get_action("ToggleSnapToGrids"); + Glib::RefPtr act15 = mainActions->get_action("ToggleSnapToGuides"); if (!act1) { @@ -2304,8 +2340,14 @@ void update_snap_toolbox(SPDesktop *desktop, SPEventContext */*eventcontext*/, G gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act12->gobj()), nv->snap_manager.snapprefs.getSnapToPageBorder()); gtk_action_set_sensitive(GTK_ACTION(act12->gobj()), c1); - gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act13->gobj()), nv->snap_manager.snapprefs.getSnapIntersectionGG()); - gtk_action_set_sensitive(GTK_ACTION(act13->gobj()), c1); + //gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act13->gobj()), nv->snap_manager.snapprefs.getSnapIntersectionGG()); + //gtk_action_set_sensitive(GTK_ACTION(act13->gobj()), c1); + + gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act14->gobj()), nv->snap_manager.snapprefs.getSnapToGrids()); + gtk_action_set_sensitive(GTK_ACTION(act14->gobj()), c1); + gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act15->gobj()), nv->snap_manager.snapprefs.getSnapToGuides()); + gtk_action_set_sensitive(GTK_ACTION(act15->gobj()), c1); + g_object_set_data(G_OBJECT(toolbox), "freeze", GINT_TO_POINTER(FALSE)); // unfreeze (see above) }