diff options
| author | MenTaLguY <mental@rydia.net> | 2007-03-10 20:54:38 +0000 |
|---|---|---|
| committer | mental <mental@users.sourceforge.net> | 2007-03-10 20:54:38 +0000 |
| commit | a99764de718f7331615d3f9449e10a56dee62fb6 (patch) | |
| tree | d60bc8389777a4384b8c931867a93c6491fffee5 /src/ui | |
| parent | fix setting knot->pos for node handles, but remove coords updating - now done... (diff) | |
| download | inkscape-a99764de718f7331615d3f9449e10a56dee62fb6.tar.gz inkscape-a99764de718f7331615d3f9449e10a56dee62fb6.zip | |
Merge further bbox work
(bzr r2596)
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/dialog/align-and-distribute.cpp | 90 | ||||
| -rw-r--r-- | src/ui/dialog/transformation.cpp | 24 | ||||
| -rw-r--r-- | src/ui/view/edit-widget.cpp | 10 |
3 files changed, 73 insertions, 51 deletions
diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index b8f840520..c1f4a10a1 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -153,9 +153,13 @@ private : SPItem * thing = *master; selected.erase(master); //Compute the anchor point - NR::Rect b = sp_item_bbox_desktop (thing); - mp = NR::Point(a.mx0 * b.min()[NR::X] + a.mx1 * b.max()[NR::X], - a.my0 * b.min()[NR::Y] + a.my1 * b.max()[NR::Y]); + NR::Maybe<NR::Rect> b = sp_item_bbox_desktop (thing); + if (b) { + mp = NR::Point(a.mx0 * b->min()[NR::X] + a.mx1 * b->max()[NR::X], + a.my0 * b->min()[NR::Y] + a.my1 * b->max()[NR::Y]); + } else { + return; + } break; } @@ -166,10 +170,14 @@ private : case AlignAndDistribute::DRAWING: { - NR::Rect b = sp_item_bbox_desktop + NR::Maybe<NR::Rect> b = sp_item_bbox_desktop ( (SPItem *) sp_document_root (sp_desktop_document (desktop)) ); - mp = NR::Point(a.mx0 * b.min()[NR::X] + a.mx1 * b.max()[NR::X], - a.my0 * b.min()[NR::Y] + a.my1 * b.max()[NR::Y]); + if (b) { + mp = NR::Point(a.mx0 * b->min()[NR::X] + a.mx1 * b->max()[NR::X], + a.my0 * b->min()[NR::Y] + a.my1 * b->max()[NR::Y]); + } else { + return; + } break; } @@ -202,13 +210,15 @@ private : it++) { sp_document_ensure_up_to_date(sp_desktop_document (desktop)); - NR::Rect b = sp_item_bbox_desktop (*it); - NR::Point const sp(a.sx0 * b.min()[NR::X] + a.sx1 * b.max()[NR::X], - a.sy0 * b.min()[NR::Y] + a.sy1 * b.max()[NR::Y]); - NR::Point const mp_rel( mp - sp ); - if (LInfty(mp_rel) > 1e-9) { - sp_item_move_rel(*it, NR::translate(mp_rel)); - changed = true; + NR::Maybe<NR::Rect> b = sp_item_bbox_desktop (*it); + if (b) { + NR::Point const sp(a.sx0 * b->min()[NR::X] + a.sx1 * b->max()[NR::X], + a.sy0 * b->min()[NR::Y] + a.sy1 * b->max()[NR::Y]); + NR::Point const mp_rel( mp - sp ); + if (LInfty(mp_rel) > 1e-9) { + sp_item_move_rel(*it, NR::translate(mp_rel)); + changed = true; + } } } @@ -246,9 +256,9 @@ struct BBoxSort SPItem *item; float anchor; NR::Rect bbox; - BBoxSort(SPItem *pItem, NR::Dim2 orientation, double kBegin, double kEnd) : + BBoxSort(SPItem *pItem, NR::Rect bounds, NR::Dim2 orientation, double kBegin, double kEnd) : item(pItem), - bbox (sp_item_bbox_desktop (pItem)) + bbox (bounds) { anchor = kBegin * bbox.min()[orientation] + kEnd * bbox.max()[orientation]; } @@ -308,8 +318,10 @@ private : it != selected.end(); ++it) { - BBoxSort b (*it, _orientation, _kBegin, _kEnd); - sorted.push_back(b); + NR::Maybe<NR::Rect> bbox = sp_item_bbox_desktop(*it); + if (bbox) { + sorted.push_back(BBoxSort(*it, *bbox, _orientation, _kBegin, _kEnd)); + } } //sort bbox by anchors std::sort(sorted.begin(), sorted.end()); @@ -595,15 +607,17 @@ private : ++it) { sp_document_ensure_up_to_date(sp_desktop_document (desktop)); - NR::Rect item_box = sp_item_bbox_desktop (*it); - // find new center, staying within bbox - double x = _dialog.randomize_bbox.min()[NR::X] + item_box.extent(NR::X)/2 + - g_random_double_range (0, _dialog.randomize_bbox.extent(NR::X) - item_box.extent(NR::X)); - double y = _dialog.randomize_bbox.min()[NR::Y] + item_box.extent(NR::Y)/2 + - g_random_double_range (0, _dialog.randomize_bbox.extent(NR::Y) - item_box.extent(NR::Y)); - // displacement is the new center minus old: - NR::Point t = NR::Point (x, y) - 0.5*(item_box.max() + item_box.min()); - sp_item_move_rel(*it, NR::translate(t)); + NR::Maybe<NR::Rect> item_box = sp_item_bbox_desktop (*it); + if (item_box) { + // find new center, staying within bbox + double x = _dialog.randomize_bbox.min()[NR::X] + item_box->extent(NR::X)/2 + + g_random_double_range (0, _dialog.randomize_bbox.extent(NR::X) - item_box->extent(NR::X)); + double y = _dialog.randomize_bbox.min()[NR::Y] + item_box->extent(NR::Y)/2 + + g_random_double_range (0, _dialog.randomize_bbox.extent(NR::Y) - item_box->extent(NR::Y)); + // displacement is the new center minus old: + NR::Point t = NR::Point (x, y) - 0.5*(item_box->max() + item_box->min()); + sp_item_move_rel(*it, NR::translate(t)); + } } // restore compensation setting @@ -1054,11 +1068,13 @@ std::list<SPItem *>::iterator AlignAndDistribute::find_master( std::list<SPItem { gdouble max = -1e18; for (std::list<SPItem *>::iterator it = list.begin(); it != list.end(); it++) { - NR::Rect b = sp_item_bbox_desktop (*it); - gdouble dim = b.extent(horizontal ? NR::X : NR::Y); - if (dim > max) { - max = dim; - master = it; + NR::Maybe<NR::Rect> b = sp_item_bbox_desktop (*it); + if (b) { + gdouble dim = b->extent(horizontal ? NR::X : NR::Y); + if (dim > max) { + max = dim; + master = it; + } } } return master; @@ -1069,11 +1085,13 @@ std::list<SPItem *>::iterator AlignAndDistribute::find_master( std::list<SPItem { gdouble max = 1e18; for (std::list<SPItem *>::iterator it = list.begin(); it != list.end(); it++) { - NR::Rect b = sp_item_bbox_desktop (*it); - gdouble dim = b.extent(horizontal ? NR::X : NR::Y); - if (dim < max) { - max = dim; - master = it; + NR::Maybe<NR::Rect> b = sp_item_bbox_desktop (*it); + if (b) { + gdouble dim = b->extent(horizontal ? NR::X : NR::Y); + if (dim < max) { + max = dim; + master = it; + } } } return master; diff --git a/src/ui/dialog/transformation.cpp b/src/ui/dialog/transformation.cpp index 99ac56cbd..90cac7425 100644 --- a/src/ui/dialog/transformation.cpp +++ b/src/ui/dialog/transformation.cpp @@ -604,15 +604,17 @@ Transformation::applyPageScale(Inkscape::Selection *selection) if (prefs_get_int_attribute_limited ("dialogs.transformation", "applyseparately", 0, 0, 1) == 1) { for (GSList const *l = selection->itemList(); l != NULL; l = l->next) { SPItem *item = SP_ITEM(l->data); - NR::Rect bbox (sp_item_bbox_desktop(item)); NR::scale scale (0,0); // the values are increments! if (_units_scale.isAbsolute()) { - double new_width = bbox.extent(NR::X) + scaleX; - if (new_width < 1e-6) new_width = 1e-6; // not 0, as this would result in a nasty no-bbox object - double new_height = bbox.extent(NR::Y) + scaleY; - if (new_height < 1e-6) new_height = 1e-6; - scale = NR::scale(new_width / bbox.extent(NR::X), new_height / bbox.extent(NR::Y)); + NR::Maybe<NR::Rect> bbox(sp_item_bbox_desktop(item)); + if (bbox) { + double new_width = bbox->extent(NR::X) + scaleX; + if (new_width < 1e-6) new_width = 1e-6; // not 0, as this would result in a nasty no-bbox object + double new_height = bbox->extent(NR::Y) + scaleY; + if (new_height < 1e-6) new_height = 1e-6; + scale = NR::scale(new_width / bbox->extent(NR::X), new_height / bbox->extent(NR::Y)); + } } else { double new_width = 100 + scaleX; if (new_width < 1e-6) new_width = 1e-6; @@ -686,10 +688,12 @@ Transformation::applyPageSkew(Inkscape::Selection *selection) } else { // absolute displacement double skewX = _scalar_skew_horizontal.getValue("px"); double skewY = _scalar_skew_vertical.getValue("px"); - NR::Rect bbox(sp_item_bbox_desktop(item)); - double width = bbox.dimensions()[NR::X]; - double height = bbox.dimensions()[NR::Y]; - sp_item_skew_rel (item, skewX/height, skewY/width); + NR::Maybe<NR::Rect> bbox(sp_item_bbox_desktop(item)); + if (bbox) { + double width = bbox->dimensions()[NR::X]; + double height = bbox->dimensions()[NR::Y]; + sp_item_skew_rel (item, skewX/height, skewY/width); + } } } } else { // transform whole selection diff --git a/src/ui/view/edit-widget.cpp b/src/ui/view/edit-widget.cpp index f386aefcc..99fd2fb80 100644 --- a/src/ui/view/edit-widget.cpp +++ b/src/ui/view/edit-widget.cpp @@ -1380,11 +1380,11 @@ EditWidget::updateScrollbars (double scale) /* The desktop region we always show unconditionally */ SPDocument *doc = _desktop->doc(); - NR::Rect const r = sp_item_bbox_desktop(SP_ITEM(SP_DOCUMENT_ROOT(doc))); - NR::Rect darea(NR::Point(MIN(r.min()[NR::X], -sp_document_width(doc)), - MIN(r.min()[NR::Y], -sp_document_height(doc))), - NR::Point(MAX(r.max()[NR::X], 2 * sp_document_width(doc)), - MAX(r.max()[NR::Y], 2 * sp_document_height(doc)))); + NR::Rect darea = NR::Rect(NR::Point(-sp_document_width(doc), + -sp_document_height(doc)), + NR::Point(2 * sp_document_width(doc), + 2 * sp_document_height(doc))); + darea = NR::union_bounds(darea, sp_item_bbox_desktop(SP_ITEM(SP_DOCUMENT_ROOT(doc)))); /* Canvas region we always show unconditionally */ NR::Rect carea(NR::Point(darea.min()[NR::X] * scale - 64, |
