X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fselection.cpp;h=d3b667a128a0e76cdd5650ed276898bc41af71ba;hb=84e5676034b77e63dbc43746cec0a8b48fd06f7c;hp=c6b307c3b0ddd0918411f374e2852f560e0988ed;hpb=d414fe3e051a6fced9010f6b610fdca5c7285304;p=inkscape.git diff --git a/src/selection.cpp b/src/selection.cpp index c6b307c3b..d3b667a12 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -27,6 +27,9 @@ #include "xml/repr.h" #include "sp-shape.h" +#include "sp-path.h" +#include "sp-item-group.h" +#include "box3d.h" #include @@ -56,7 +59,7 @@ Selection::~Selection() { /* Handler for selected objects "modified" signal */ -void Selection::_schedule_modified(SPObject *obj, guint flags) { +void Selection::_schedule_modified(SPObject */*obj*/, guint flags) { if (!this->_idle) { /* Request handling to be run in _idle loop */ this->_idle = g_idle_add_full(SP_SELECTION_UPDATE_PRIORITY, GSourceFunc(&Selection::_emit_modified), this, NULL); @@ -164,6 +167,11 @@ void Selection::_add(SPObject *obj) { _objs = g_slist_prepend(_objs, obj); + if (SP_IS_BOX3D(obj)) { + // keep track of selected boxes for transformations + box3d_add_to_selection(SP_BOX3D(obj)); + } + _release_connections[obj] = obj->connectRelease(sigc::mem_fun(*this, (void (Selection::*)(SPObject *))&Selection::remove)); _modified_connections[obj] = obj->connectModified(sigc::mem_fun(*this, &Selection::_schedule_modified)); } @@ -198,6 +206,11 @@ void Selection::_remove(SPObject *obj) { _release_connections[obj].disconnect(); _release_connections.erase(obj); + if (SP_IS_BOX3D(obj)) { + // keep track of selected boxes for transformations + box3d_remove_from_selection(SP_BOX3D(obj)); + } + _objs = g_slist_remove(_objs, obj); } @@ -303,25 +316,25 @@ Inkscape::XML::Node *Selection::singleRepr() { return obj ? SP_OBJECT_REPR(obj) : NULL; } -NRRect *Selection::bounds(NRRect *bbox) const +NRRect *Selection::bounds(NRRect *bbox, SPItem::BBoxType type) const { g_return_val_if_fail (bbox != NULL, NULL); - *bbox = NRRect(bounds()); + *bbox = NRRect(bounds(type)); return bbox; } -NR::Maybe Selection::bounds() const +NR::Maybe Selection::bounds(SPItem::BBoxType type) const { GSList const *items = const_cast(this)->itemList(); NR::Maybe bbox = NR::Nothing(); for ( GSList const *i = items ; i != NULL ; i = i->next ) { - bbox = NR::union_bounds(bbox, sp_item_bbox_desktop(SP_ITEM(i->data))); + bbox = NR::union_bounds(bbox, sp_item_bbox_desktop(SP_ITEM(i->data), type)); } return bbox; } -NRRect *Selection::boundsInDocument(NRRect *bbox) const { +NRRect *Selection::boundsInDocument(NRRect *bbox, SPItem::BBoxType type) const { g_return_val_if_fail (bbox != NULL, NULL); GSList const *items=const_cast(this)->itemList(); @@ -335,16 +348,16 @@ NRRect *Selection::boundsInDocument(NRRect *bbox) const { for ( GSList const *iter=items ; iter != NULL ; iter = iter->next ) { SPItem *item=SP_ITEM(iter->data); - NR::Matrix const i2doc(sp_item_i2doc_affine(item)); - sp_item_invoke_bbox(item, bbox, i2doc, FALSE); + NR::Matrix i2doc(sp_item_i2doc_affine(item)); + sp_item_invoke_bbox(item, bbox, i2doc, FALSE, type); } return bbox; } -NR::Maybe Selection::boundsInDocument() const { +NR::Maybe Selection::boundsInDocument(SPItem::BBoxType type) const { NRRect r; - return boundsInDocument(&r)->upgrade(); + return boundsInDocument(&r, type)->upgrade(); } /** Extract the position of the center from the first selected object */ @@ -368,11 +381,17 @@ NR::Maybe Selection::center() const { /** * Compute the list of points in the selection that are to be considered for snapping. */ -std::vector Selection::getSnapPoints() const { +std::vector Selection::getSnapPoints(bool includeItemCenter) const { GSList const *items = const_cast(this)->itemList(); std::vector p; for (GSList const *iter = items; iter != NULL; iter = iter->next) { - sp_item_snappoints(SP_ITEM(iter->data), SnapPointsIter(p)); + SPItem *this_item = SP_ITEM(iter->data); + sp_item_snappoints(this_item, false, SnapPointsIter(p)); + //Include the transformation origin for snapping + //For a group only the group's origin is considered + if (includeItemCenter) { + p.push_back(this_item->getCenter()); + } } return p; @@ -380,24 +399,28 @@ std::vector Selection::getSnapPoints() const { std::vector Selection::getSnapPointsConvexHull() const { GSList const *items = const_cast(this)->itemList(); + std::vector p; for (GSList const *iter = items; iter != NULL; iter = iter->next) { - sp_item_snappoints(SP_ITEM(iter->data), SnapPointsIter(p)); + sp_item_snappoints(SP_ITEM(iter->data), false, SnapPointsIter(p)); } - std::vector::iterator i; - NR::ConvexHull cvh(*(p.begin())); - for (i = p.begin(); i != p.end(); i++) { - // these are the points we get back - cvh.add(*i); - } + std::vector pHull; + if (!p.empty()) { + std::vector::iterator i; + NR::ConvexHull cvh(p.front()); + for (i = p.begin(); i != p.end(); i++) { + // these are the points we get back + cvh.add(*i); + } - NR::Rect rHull = cvh.bounds(); - std::vector pHull(4); - pHull[0] = rHull.corner(0); - pHull[1] = rHull.corner(1); - pHull[2] = rHull.corner(2); - pHull[3] = rHull.corner(3); + NR::Maybe rHull = cvh.bounds(); + if (rHull) { + for ( unsigned i = 0 ; i < 4 ; ++i ) { + pHull.push_back(rHull->corner(i)); + } + } + } return pHull; }