X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fui%2Fdialog%2Falign-and-distribute.cpp;h=924a987907a6591dd8d664e291845dcc3c134ae8;hb=11a7559367dd1824198fe3b75e6d6ceb208ea1b7;hp=c1f4a10a11620a9124eeeef7eb4866abc8441906;hpb=6e3576be211b59b7d8a9e7afe3493d961c053b75;p=inkscape.git diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index c1f4a10a1..924a98790 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -183,9 +183,13 @@ private : case AlignAndDistribute::SELECTION: { - NR::Rect b = selection->bounds(); - 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 b = selection->bounds(); + 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; } @@ -590,12 +594,16 @@ private : //Check 2 or more selected objects if (selected.size() < 2) return; + NR::Maybe sel_bbox = selection->bounds(); + if (!sel_bbox) { + return; + } + // This bbox is cached between calls to randomize, so that there's no growth nor shrink // nor drift on sequential randomizations. Discard cache on global (or better active // desktop's) selection_change signal. - if (!_dialog.randomize_bbox_set) { - _dialog.randomize_bbox = selection->bounds(); - _dialog.randomize_bbox_set = true; + if (!_dialog.randomize_bbox) { + _dialog.randomize_bbox = *sel_bbox; } // see comment in ActionAlign above @@ -610,10 +618,10 @@ private : NR::Maybe 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)); + 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)); @@ -758,7 +766,7 @@ void on_tool_changed(Inkscape::Application *inkscape, SPEventContext *context, A void on_selection_changed(Inkscape::Application *inkscape, Inkscape::Selection *selection, AlignAndDistribute *daad) { - daad->randomize_bbox_set = false; + daad->randomize_bbox = NR::Nothing(); } ///////////////////////////////////////////////////////// @@ -766,9 +774,9 @@ void on_selection_changed(Inkscape::Application *inkscape, Inkscape::Selection * -AlignAndDistribute::AlignAndDistribute() - : Dialog ("dialogs.align", SP_VERB_DIALOG_ALIGN_DISTRIBUTE), - randomize_bbox (NR::Point (0, 0), NR::Point (0, 0)), +AlignAndDistribute::AlignAndDistribute(Behavior::BehaviorFactory behavior_factory) + : Dialog (behavior_factory, "dialogs.align", SP_VERB_DIALOG_ALIGN_DISTRIBUTE), + randomize_bbox(NR::Nothing()), _alignFrame(_("Align")), _distributeFrame(_("Distribute")), _removeOverlapFrame(_("Remove overlaps")), @@ -932,8 +940,7 @@ AlignAndDistribute::AlignAndDistribute() // Connect to the global selection change, to invalidate cached randomize_bbox g_signal_connect (G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (on_selection_changed), this); - randomize_bbox = NR::Rect (NR::Point (0, 0), NR::Point (0, 0)); - randomize_bbox_set = false; + randomize_bbox = NR::Nothing(); show_all_children();