app: distribute while keeping extreme objects unmoved.

After discussing with Aryeom, we decided that "Distribute" should work within
the current horizontal or vertical bounds, as this is how it is usually done in
other software (e.g. Inkscape). For instance, if there are 4 items, the first
and last (coordinate-wise) stay untouched, and only the 2 intermediate items get
distributed evenly.

Since the Reference is not relevant anymore for "Distribute", I undo part of my
previous commit, where I was organizing the reference setting into its own
section of the Alignment tool options. This setting is back as part of the
"Align" section.
This commit is contained in:
Jehan 2022-11-08 21:39:58 +01:00
parent 2b0928d895
commit 09543af82a
2 changed files with 32 additions and 35 deletions

View File

@ -125,7 +125,7 @@ gimp_image_arrange_objects (GimpImage *image,
/* order horizontally for horizontal arrangement */
case GIMP_ARRANGE_HFILL:
if (GIMP_IS_GUIDE (reference))
if (GIMP_IS_GUIDE (reference) || g_list_length (list) <= 2)
return;
use_obj_x_offset = TRUE;
use_ref_x_offset = TRUE;
@ -150,7 +150,7 @@ gimp_image_arrange_objects (GimpImage *image,
/* order vertically for vertical arrangement */
case GIMP_ARRANGE_VFILL:
if (GIMP_IS_GUIDE (reference))
if (GIMP_IS_GUIDE (reference) || g_list_length (list) <= 2)
return;
do_y = TRUE;
break;
@ -167,39 +167,42 @@ gimp_image_arrange_objects (GimpImage *image,
/* now get offsets used for aligning */
compute_offsets (list, use_obj_x_offset, align_x, align_y, align_contents);
if (reference == NULL)
{
reference = G_OBJECT (object_list->data);
object_list = g_list_delete_link (object_list, object_list);
}
/* Compute the offset for the reference (esp. for alignment. */
compute_offset (reference, use_ref_x_offset, reference_x, reference_y, FALSE);
z0 = GPOINTER_TO_INT (g_object_get_data (reference, "align-offset"));
if (object_list)
{
GList *list;
gint n;
gint distr_width = 0;
gint distr_height = 0;
gint distr_length = 0;
gdouble fill_offset = 0;
if (reference_alignment == GIMP_ARRANGE_HFILL)
if (reference_alignment == GIMP_ARRANGE_HFILL ||
reference_alignment == GIMP_ARRANGE_VFILL)
{
distr_width = GPOINTER_TO_INT (g_object_get_data
(reference, "align-width"));
/* Distribution does not use the reference. Extreme coordinate items
* are used instead.
*/
GList *last_object = g_list_last (object_list);
z0 = GPOINTER_TO_INT (g_object_get_data (object_list->data, "align-offset"));
distr_length = GPOINTER_TO_INT (g_object_get_data (last_object->data, "align-offset")) - z0;
/* The offset parameter works as an internal margin */
fill_offset = (distr_width - 2 * offset) /
(gdouble) (g_list_length (object_list) + 1);
fill_offset = (distr_length - 2 * offset) / (gdouble) (g_list_length (object_list) - 1);
/* Removing first and last objects. These stay unmoved. */
object_list = g_list_delete_link (object_list, last_object);
object_list = g_list_delete_link (object_list, object_list);
}
else if (reference_alignment == GIMP_ARRANGE_VFILL)
else
{
distr_height = GPOINTER_TO_INT (g_object_get_data
(reference, "align-height"));
fill_offset = (distr_height - 2 * offset) /
(gdouble) (g_list_length (object_list) + 1);
if (reference == NULL)
{
reference = G_OBJECT (object_list->data);
object_list = g_list_delete_link (object_list, object_list);
}
/* Compute the offset for the reference (for alignment). */
compute_offset (reference, use_ref_x_offset, reference_x, reference_y, FALSE);
z0 = GPOINTER_TO_INT (g_object_get_data (reference, "align-offset"));
}
/* FIXME: undo group type is wrong */

View File

@ -461,8 +461,8 @@ gimp_align_options_gui (GimpToolOptions *tool_options)
gtk_widget_show (widget);
options->priv->selected_guides_label = widget;
/* Reference frame */
frame = gimp_frame_new (_("Reference"));
/* Align frame */
frame = gimp_frame_new (_("Align"));
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
@ -470,6 +470,7 @@ gimp_align_options_gui (GimpToolOptions *tool_options)
gtk_container_add (GTK_CONTAINER (frame), section_vbox);
gtk_widget_show (section_vbox);
/* Align frame: reference */
combo = gimp_prop_enum_combo_box_new (config, "align-reference", 0, 0);
gimp_int_combo_box_set_label (GIMP_INT_COMBO_BOX (combo), _("Relative to"));
g_object_set (combo, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
@ -494,14 +495,7 @@ gimp_align_options_gui (GimpToolOptions *tool_options)
gtk_widget_show (widget);
options->priv->reference_label = widget;
/* Align frame */
frame = gimp_frame_new (_("Align"));
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
section_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_container_add (GTK_CONTAINER (frame), section_vbox);
gtk_widget_show (section_vbox);
/* Align frame: buttons */
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_box_pack_start (GTK_BOX (section_vbox), hbox, FALSE, FALSE, 0);