diff options
| author | Martin Owens <doctormo@gmail.com> | 2013-07-10 00:46:51 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2013-07-10 00:46:51 +0000 |
| commit | 4d232a223d1dcb7b2381615de1a64b20b2fb6165 (patch) | |
| tree | 698134d73546364e488f3e6cd42fa22eb924e21e /src | |
| parent | Fix for Bug #1185132 (colorspace.h not included in the tarball when doing a m... (diff) | |
| download | inkscape-4d232a223d1dcb7b2381615de1a64b20b2fb6165.tar.gz inkscape-4d232a223d1dcb7b2381615de1a64b20b2fb6165.zip | |
Small refactor of align and distribute to reduce complexity.
(bzr r12411)
Diffstat (limited to 'src')
| -rw-r--r-- | src/document.cpp | 5 | ||||
| -rw-r--r-- | src/document.h | 1 | ||||
| -rw-r--r-- | src/ui/dialog/align-and-distribute.cpp | 59 |
3 files changed, 23 insertions, 42 deletions
diff --git a/src/document.cpp b/src/document.cpp index 706710cfc..0e9c43fe4 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -611,6 +611,11 @@ Geom::Point SPDocument::getDimensions() const return Geom::Point(getWidth(), getHeight()); } +Geom::OptRect SPDocument::preferredBounds() const +{ + return Geom::OptRect( Geom::Point(0, 0), getDimensions() ); +} + /** * Given a Geom::Rect that may, for example, correspond to the bbox of an object, * this function fits the canvas to that rect by resizing the canvas diff --git a/src/document.h b/src/document.h index 606a83be8..d49067250 100644 --- a/src/document.h +++ b/src/document.h @@ -228,6 +228,7 @@ public: gdouble getWidth() const; gdouble getHeight() const; Geom::Point getDimensions() const; + Geom::OptRect preferredBounds() const; void setWidth(gdouble width, const SPUnit *unit); void setHeight(gdouble height, const SPUnit *unit); void requestModified(); diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index 7f88824f7..6a1cfc0ba 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -88,23 +88,23 @@ Action::Action(const Glib::ustring &id, } -void ActionAlign::do_action(SPDesktop *desktop, int index) { - +void ActionAlign::do_action(SPDesktop *desktop, int index) +{ Inkscape::Selection *selection = sp_desktop_selection(desktop); if (!selection) return; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool sel_as_group = prefs->getBool("/dialogs/align/sel-as-groups"); - int prefs_bbox = prefs->getBool("/tools/bounding_box"); using Inkscape::Util::GSListConstIterator; std::list<SPItem *> selected; selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL); if (selected.empty()) return; - Geom::Point mp; //Anchor point + const Coeffs &a = _allCoeffs[index]; + Geom::OptRect b = Geom::OptRect(); AlignAndDistribute::AlignTarget target = AlignAndDistribute::getAlignTarget(); - const Coeffs &a= _allCoeffs[index]; + switch (target) { case AlignAndDistribute::LAST: @@ -132,51 +132,27 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) { /*if (!sel_as_group) { */ selected.erase(master); /*}*/ - //Compute the anchor point - Geom::OptRect b = !prefs_bbox ? thing->desktopVisualBounds() : thing->desktopGeometricBounds(); - if (b) { - mp = Geom::Point(a.mx0 * b->min()[Geom::X] + a.mx1 * b->max()[Geom::X], - a.my0 * b->min()[Geom::Y] + a.my1 * b->max()[Geom::Y]); - } else { - return; - } + b = thing->desktopPreferredBounds(); break; } - case AlignAndDistribute::PAGE: - mp = Geom::Point(a.mx1 * sp_desktop_document(desktop)->getWidth(), - a.my1 * sp_desktop_document(desktop)->getHeight()); + b = sp_desktop_document(desktop)->preferredBounds(); break; - case AlignAndDistribute::DRAWING: - { - Geom::OptRect b = !prefs_bbox ? sp_desktop_document(desktop)->getRoot()->desktopVisualBounds() - : sp_desktop_document(desktop)->getRoot()->desktopGeometricBounds(); - if (b) { - mp = Geom::Point(a.mx0 * b->min()[Geom::X] + a.mx1 * b->max()[Geom::X], - a.my0 * b->min()[Geom::Y] + a.my1 * b->max()[Geom::Y]); - } else { - return; - } + b = sp_desktop_document(desktop)->getRoot()->desktopPreferredBounds(); break; - } - case AlignAndDistribute::SELECTION: - { - Geom::OptRect b = !prefs_bbox ? selection->visualBounds() : selection->geometricBounds(); - if (b) { - mp = Geom::Point(a.mx0 * b->min()[Geom::X] + a.mx1 * b->max()[Geom::X], - a.my0 * b->min()[Geom::Y] + a.my1 * b->max()[Geom::Y]); - } else { - return; - } + b = selection->preferredBounds(); break; - } - default: g_assert_not_reached (); break; - }; // end of switch + }; + + g_return_if_fail(b); + + Geom::Point mp = Geom::Point(a.mx0 * b->min()[Geom::X] + a.mx1 * b->max()[Geom::X], + a.my0 * b->min()[Geom::Y] + a.my1 * b->max()[Geom::Y]); // Top hack: temporarily set clone compensation to unmoved, so that we can align/distribute // clones with their original (and the move of the original does not disturb the @@ -188,9 +164,8 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) { prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); bool changed = false; - Geom::OptRect b; if (sel_as_group) - b = !prefs_bbox ? selection->visualBounds() : selection->geometricBounds(); + b = selection->preferredBounds(); //Move each item in the selected list separately for (std::list<SPItem *>::iterator it(selected.begin()); @@ -199,7 +174,7 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) { { sp_desktop_document (desktop)->ensureUpToDate(); if (!sel_as_group) - b = !prefs_bbox ? (*it)->desktopVisualBounds() : (*it)->desktopGeometricBounds(); + b = (*it)->desktopPreferredBounds(); if (b) { Geom::Point const sp(a.sx0 * b->min()[Geom::X] + a.sx1 * b->max()[Geom::X], a.sy0 * b->min()[Geom::Y] + a.sy1 * b->max()[Geom::Y]); |
