From: dvlierop2 Date: Wed, 12 Mar 2008 00:08:38 +0000 (+0000) Subject: Snap to page border X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=005e390103cfa31f1f78190fd78252b6b341bdd1;p=inkscape.git Snap to page border --- diff --git a/src/attributes-test.h b/src/attributes-test.h index cdc82a475..b5c05e988 100644 --- a/src/attributes-test.h +++ b/src/attributes-test.h @@ -345,6 +345,7 @@ struct {char const *attr; bool supported;} const all_attrs[] = { {"inkscape:object-nodes", true}, {"inkscape:bbox-paths", true}, {"inkscape:bbox-nodes", true}, + {"inkscape:snap-page", true}, {"inkscape:snap-global", true}, {"inkscape:snap-bbox", true}, {"inkscape:snap-nodes", true}, diff --git a/src/attributes.cpp b/src/attributes.cpp index 66a7b66c8..a8ecb872b 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -96,6 +96,7 @@ static SPStyleProp const props[] = { {SP_ATTR_INKSCAPE_OBJECT_NODES, "inkscape:object-nodes"}, {SP_ATTR_INKSCAPE_BBOX_PATHS, "inkscape:bbox-paths"}, {SP_ATTR_INKSCAPE_BBOX_NODES, "inkscape:bbox-nodes"}, + {SP_ATTR_INKSCAPE_SNAP_PAGE, "inkscape:snap-page"}, {SP_ATTR_INKSCAPE_CURRENT_LAYER, "inkscape:current-layer"}, {SP_ATTR_INKSCAPE_DOCUMENT_UNITS, "inkscape:document-units"}, {SP_ATTR_INKSCAPE_CONNECTOR_SPACING, "inkscape:connector-spacing"}, diff --git a/src/attributes.h b/src/attributes.h index b59c17ec8..8591258fe 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -96,6 +96,7 @@ enum SPAttributeEnum { SP_ATTR_INKSCAPE_OBJECT_NODES, SP_ATTR_INKSCAPE_BBOX_PATHS, SP_ATTR_INKSCAPE_BBOX_NODES, + SP_ATTR_INKSCAPE_SNAP_PAGE, SP_ATTR_INKSCAPE_CURRENT_LAYER, SP_ATTR_INKSCAPE_DOCUMENT_UNITS, SP_ATTR_INKSCAPE_CONNECTOR_SPACING, diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 6c94679ec..934925ad0 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -34,7 +34,7 @@ Inkscape::ObjectSnapper::ObjectSnapper(SPNamedView const *nv, NR::Coord const d) : Snapper(nv, d), _snap_to_itemnode(true), _snap_to_itempath(true), _snap_to_bboxnode(true), _snap_to_bboxpath(true), _strict_snapping(true), - _include_item_center(false) + _snap_to_page_border(false), _include_item_center(false) { _candidates = new std::vector; _points_to_snap_to = new std::vector; @@ -251,7 +251,8 @@ void Inkscape::ObjectSnapper::_snapTranslatingGuideToNodes(SnappedConstraints &s void Inkscape::ObjectSnapper::_collectPaths(Inkscape::Snapper::PointType const &t, bool const &first_point, - SPPath const *selected_path) const + SPPath const *selected_path, + NArtBpath *border_bpath) const { // Now, let's first collect all paths to snap to. If we have a whole bunch of points to snap, // e.g. when translating an item using the selector tool, then we will only do this for the @@ -269,6 +270,11 @@ void Inkscape::ObjectSnapper::_collectPaths(Inkscape::Snapper::PointType const & bbox_type = (prefs_bbox != NULL && strcmp(prefs_bbox, "geometric")==0)? SPItem::GEOMETRIC_BBOX : SPItem::APPROXIMATE_BBOX; } + // Consider the page border for snapping + if (border_bpath != NULL) { + _bpaths_to_snap_to->push_back(border_bpath); + } + /* While editing a path in the node tool, findCandidates must ignore that path because * of the node snapping requirements (i.e. only unselected nodes must be snapable). * This path must not be ignored however when snapping to the paths, so we add it here @@ -350,9 +356,10 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, NR::Point const &p, bool const &first_point, std::vector *unselected_nodes, - SPPath const *selected_path) const + SPPath const *selected_path, + NArtBpath *border_bpath) const { - _collectPaths(t, first_point, selected_path); + _collectPaths(t, first_point, selected_path, border_bpath); // Now we can finally do the real snapping, using the paths collected above SnappedPoint s; @@ -417,7 +424,7 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, (*k)->PointAt(o->piece, 0, start_point); (*k)->PointAt(o->piece, 1, end_point); start_point = desktop->doc2dt(start_point); - end_point = desktop->doc2dt(end_point); + end_point = desktop->doc2dt(end_point); } if (o && o->t >= 0 && o->t <= 1) { @@ -478,7 +485,11 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc, bool const &first_point, ConstraintLine const &c) const { - _collectPaths(t, first_point); + + // Consider the page's border for snapping to + NArtBpath *border_bpath = _snap_to_page_border ? _getBorderBPath() : NULL; + + _collectPaths(t, first_point, NULL, border_bpath); // Now we can finally do the real snapping, using the paths collected above @@ -506,7 +517,7 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc, Geom::Path cl; cl.start(p_min_on_cl.to_2geom()); cl.appendNew(p_max_on_cl.to_2geom()); - + for (std::vector::const_iterator k = _bpaths_to_snap_to->begin(); k != _bpaths_to_snap_to->end(); k++) { if (*k) { // convert a Path object (see src/livarot/Path.h) to a 2geom's path object (see 2geom/path.h) @@ -554,7 +565,10 @@ void Inkscape::ObjectSnapper::_doFreeSnap(SnappedConstraints &sc, _snapNodes(sc, t, p, first_point, unselected_nodes); } - if (_snap_to_itempath || _snap_to_bboxpath) { + // Consider the page's border for snapping to + NArtBpath *border_bpath = _snap_to_page_border ? _getBorderBPath() : NULL; + + if (_snap_to_itempath || _snap_to_bboxpath || _snap_to_page_border) { unsigned n = (unselected_nodes == NULL) ? 0 : unselected_nodes->size(); if (n > 0) { /* While editing a path in the node tool, findCandidates must ignore that path because @@ -564,15 +578,14 @@ void Inkscape::ObjectSnapper::_doFreeSnap(SnappedConstraints &sc, */ g_assert(it.size() == 1); g_assert(SP_IS_PATH(*it.begin())); - _snapPaths(sc, t, p, first_point, unselected_nodes, SP_PATH(*it.begin())); + _snapPaths(sc, t, p, first_point, unselected_nodes, SP_PATH(*it.begin()), border_bpath); + } else { - _snapPaths(sc, t, p, first_point, NULL, NULL); + _snapPaths(sc, t, p, first_point, NULL, NULL, border_bpath); } } } - - void Inkscape::ObjectSnapper::_doConstrainedSnap( SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, NR::Point const &p, @@ -599,7 +612,7 @@ void Inkscape::ObjectSnapper::_doConstrainedSnap( SnappedConstraints &sc, // to objects we will only consider the object's paths. Beside, the nodes will be at these paths, // so we will more or less snap to them anyhow. - if (_snap_to_itempath || _snap_to_bboxpath) { + if (_snap_to_itempath || _snap_to_bboxpath || _snap_to_page_border) { _snapPathsConstrained(sc, t, p, first_point, c); } } @@ -650,7 +663,7 @@ void Inkscape::ObjectSnapper::guideSnap(SnappedConstraints &sc, */ bool Inkscape::ObjectSnapper::ThisSnapperMightSnap() const { - bool snap_to_something = _snap_to_itempath || _snap_to_itemnode || _snap_to_bboxpath || _snap_to_bboxnode; + bool snap_to_something = _snap_to_itempath || _snap_to_itemnode || _snap_to_bboxpath || _snap_to_bboxnode || _snap_to_page_border; return (_snap_enabled && _snap_from != 0 && snap_to_something); } @@ -673,6 +686,17 @@ void Inkscape::ObjectSnapper::_clear_paths() const _paths_to_snap_to->clear(); } +NArtBpath* Inkscape::ObjectSnapper::_getBorderBPath() const +{ + NArtBpath *border_bpath = NULL; + NR::Rect const border_rect = NR::Rect(NR::Point(0,0), NR::Point(sp_document_width(_named_view->document),sp_document_height(_named_view->document))); + SPCurve const *border_curve = sp_curve_new_from_rect(border_rect); + if (border_curve) { + border_bpath = SP_CURVE_BPATH(border_curve); + } + + return border_bpath; +} /* Local Variables: mode:c++ diff --git a/src/object-snapper.h b/src/object-snapper.h index ef43af0e9..32dd0fb3b 100644 --- a/src/object-snapper.h +++ b/src/object-snapper.h @@ -71,6 +71,14 @@ public: return _snap_to_bboxpath; } + void setSnapToPageBorder(bool s) { + _snap_to_page_border = s; + } + + bool getSnapToPageBorder() const { + return _snap_to_page_border; + } + void setIncludeItemCenter(bool s) { _include_item_center = s; } @@ -137,7 +145,8 @@ private: NR::Point const &p, bool const &first_point, std::vector *unselected_nodes, - SPPath const *selected_path) const; + SPPath const *selected_path, + NArtBpath *border_bpath) const; void _snapPathsConstrained(SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, @@ -148,13 +157,16 @@ private: void _collectPaths(Inkscape::Snapper::PointType const &t, bool const &first_point, - SPPath const *selected_path = NULL) const; + SPPath const *selected_path = NULL, + NArtBpath *border_bpath = NULL) const; void _clear_paths() const; + NArtBpath* _getBorderBPath() const; bool _snap_to_itemnode; bool _snap_to_itempath; bool _snap_to_bboxnode; bool _snap_to_bboxpath; + bool _snap_to_page_border; //If enabled, then bbox corners will only snap to bboxes, //and nodes will only snap to nodes and paths. We will not diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 268150a16..ec0552653 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -256,6 +256,7 @@ static void sp_namedview_build(SPObject *object, SPDocument *document, Inkscape: sp_object_read_attr(object, "inkscape:object-nodes"); sp_object_read_attr(object, "inkscape:bbox-paths"); sp_object_read_attr(object, "inkscape:bbox-nodes"); + sp_object_read_attr(object, "inkscape:snap-page"); sp_object_read_attr(object, "inkscape:current-layer"); sp_object_read_attr(object, "inkscape:connector-spacing"); @@ -495,6 +496,10 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va nv->snap_manager.object.setSnapToBBoxNode(value ? sp_str_to_bool(value) : FALSE); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_INKSCAPE_SNAP_PAGE: + nv->snap_manager.object.setSnapToPageBorder(value ? sp_str_to_bool(value) : FALSE); + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; case SP_ATTR_INKSCAPE_CURRENT_LAYER: nv->default_layer_id = value ? g_quark_from_string(value) : 0; object->requestModified(SP_OBJECT_MODIFIED_FLAG); diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index ac4fb9285..acf76f034 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -8,9 +8,10 @@ * Lauris Kaplinski * Jon Phillips * Ralf Stephan (Gtkmm) + * Diederik van Lierop * * Copyright (C) 2006-2008 Johan Engelen - * Copyright (C) 2000 - 2005 Authors + * Copyright (C) 2000 - 2008 Authors * * Released under GNU GPL. Read the file 'COPYING' for more information */ @@ -109,6 +110,7 @@ DocumentProperties::DocumentProperties() _rcbsnon(_("Snap to n_odes"), _("Snap nodes and guides to object nodes"), "inkscape:object-nodes", _wr), _rcbsnbbp(_("Snap to bounding bo_x edges"), _("Snap bounding box corners and guides to bounding box edges"), "inkscape:bbox-paths", _wr), _rcbsnbbn(_("Snap to bounding box co_rners"), _("Snap bounding box corners to other bounding box corners"), "inkscape:bbox-nodes", _wr), + _rcbsnpb(_("Snap to page border"), _("Snap bounding box corners and nodes to the page border"), "inkscape:snap-page", _wr), //--------------------------------------------------------------- //Applies to both nodes and guides, but not to bboxes, that's why its located here _rcbic( _("Rotation _center"), _("Consider the rotation center of an object when snapping"), "inkscape:snap-center", _wr), @@ -332,6 +334,7 @@ DocumentProperties::build_snap() 0, &_rcbsnon, 0, &_rcbsnbbp, 0, &_rcbsnbbn, + 0, &_rcbsnpb, 0, _rsu_sno._vbox, 0, 0, label_gr, 0, @@ -494,6 +497,7 @@ DocumentProperties::update() _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode()); _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath()); _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode()); + _rcbsnpb.setActive(nv->snap_manager.object.getSnapToPageBorder()); _rsu_sno.setValue (nv->objecttolerance); _rsu_sn.setValue (nv->gridtolerance); diff --git a/src/ui/dialog/document-properties.h b/src/ui/dialog/document-properties.h index d2509d8a4..6d6b77e5d 100644 --- a/src/ui/dialog/document-properties.h +++ b/src/ui/dialog/document-properties.h @@ -75,7 +75,7 @@ protected: RegisteredColorPicker _rcp_gui, _rcp_hgui; //--------------------------------------------------------------- RegisteredCheckButton _rcbsg, _rcbsnbb, _rcbsnn, _rcbsnop; - RegisteredCheckButton _rcbsnon, _rcbsnbbp, _rcbsnbbn; + RegisteredCheckButton _rcbsnon, _rcbsnbbp, _rcbsnbbn, _rcbsnpb; ToleranceSlider _rsu_sno, _rsu_sn, _rsu_gusn; //--------------------------------------------------------------- RegisteredCheckButton _rcbic;