diff options
| author | Martin Owens <doctormo@gmail.com> | 2013-07-11 02:24:38 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2013-07-11 02:24:38 +0000 |
| commit | 80a911db81b651f38205c1eb926af4986bc033e8 (patch) | |
| tree | 2bdba48782869d4eb6f69bdd1030c99b4002f2c3 /src/selection.cpp | |
| parent | Merge in Eric's dbus name option (diff) | |
| download | inkscape-80a911db81b651f38205c1eb926af4986bc033e8.tar.gz inkscape-80a911db81b651f38205c1eb926af4986bc033e8.zip | |
Step 2 refactoring the align functions, added some functionality to selection.
(bzr r12413)
Diffstat (limited to 'src/selection.cpp')
| -rw-r--r-- | src/selection.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/selection.cpp b/src/selection.cpp index d018aba0c..83caaf459 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -42,6 +42,7 @@ namespace Inkscape { Selection::Selection(LayerModel *layers, SPDesktop *desktop) : + align_point(NULL), _objs(NULL), _reprs(NULL), _items(NULL), @@ -358,6 +359,35 @@ SPItem *Selection::singleItem() { } } +SPItem *Selection::smallestItem(Selection::CompareSize compare) { + return _sizeistItem(true, compare); +} + +SPItem *Selection::largestItem(Selection::CompareSize compare) { + return _sizeistItem(false, compare); +} + +SPItem *Selection::_sizeistItem(bool small, Selection::CompareSize compare) { + GSList const *items = const_cast<Selection *>(this)->itemList(); + gdouble max = small ? 1e18 : 0; + SPItem *ist = NULL; + + for ( GSList const *i = items; i != NULL ; i = i->next ) { + Geom::OptRect bbox = SP_ITEM(i->data)->desktopPreferredBounds(); + if (!bbox) continue; + + gdouble size = compare == 2 ? + (*bbox)[Geom::X].extent() * (*bbox)[Geom::Y].extent() : + (*bbox)[compare == 1 ? Geom::X : Geom::Y].extent(); + size = small ? size : size * -1; + if (size < max) { + max = size; + ist = SP_ITEM(i->data); + } + } + return ist; +} + Inkscape::XML::Node *Selection::singleRepr() { SPObject *obj=single(); return obj ? obj->getRepr() : NULL; |
