"Fossies" - the Fresh Open Source Software Archive

Member "gimp-2.10.28/plug-ins/common/align-layers.c" (14 Sep 2021, 21373 Bytes) of package /linux/misc/gimp-2.10.28.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "align-layers.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.99.4_vs_2.99.6.

    1 /* align_layers.c
    2  * Author: Shuji Narazaki <narazaki@InetQ.or.jp>
    3  * Version:  0.26
    4  *
    5  * Copyright (C) 1997-1998 Shuji Narazaki <narazaki@InetQ.or.jp>
    6  *
    7  * This program is free software: you can redistribute it and/or modify
    8  * it under the terms of the GNU General Public License as published by
    9  * the Free Software Foundation; either version 3 of the License, or
   10  * (at your option) any later version.
   11  *
   12  * This program is distributed in the hope that it will be useful,
   13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15  * GNU General Public License for more details.
   16  *
   17  * You should have received a copy of the GNU General Public License
   18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
   19  */
   20 
   21 #include "config.h"
   22 
   23 #include <libgimp/gimp.h>
   24 #include <libgimp/gimpui.h>
   25 
   26 #include "libgimp/stdplugins-intl.h"
   27 
   28 #define PLUG_IN_PROC   "plug-in-align-layers"
   29 #define PLUG_IN_BINARY "align-layers"
   30 #define PLUG_IN_ROLE   "gimp-align-layers"
   31 #define SCALE_WIDTH    150
   32 
   33 enum
   34 {
   35   H_NONE,
   36   H_COLLECT,
   37   LEFT2RIGHT,
   38   RIGHT2LEFT,
   39   SNAP2HGRID
   40 };
   41 
   42 enum
   43 {
   44   H_BASE_LEFT,
   45   H_BASE_CENTER,
   46   H_BASE_RIGHT
   47 };
   48 
   49 enum
   50 {
   51   V_NONE,
   52   V_COLLECT,
   53   TOP2BOTTOM,
   54   BOTTOM2TOP,
   55   SNAP2VGRID
   56 };
   57 
   58 enum
   59 {
   60   V_BASE_TOP,
   61   V_BASE_CENTER,
   62   V_BASE_BOTTOM
   63 };
   64 
   65 
   66 typedef struct
   67 {
   68   gint step_x;
   69   gint step_y;
   70   gint base_x;
   71   gint base_y;
   72 } AlignData;
   73 
   74 
   75 static void     query   (void);
   76 static void     run     (const gchar      *name,
   77                          gint              nparams,
   78                          const GimpParam  *param,
   79                          gint             *nreturn_vals,
   80                          GimpParam       **return_vals);
   81 
   82 /* Main function */
   83 static GimpPDBStatusType align_layers                (gint32  image_id);
   84 
   85 /* Helpers and internal functions */
   86 static gint      align_layers_count_visibles_layers  (gint     *layers,
   87                                                       gint      length);
   88 static gint      align_layers_find_last_layer        (gint     *layers,
   89                                                       gint      layers_num,
   90                                                       gboolean *found);
   91 static gint      align_layers_spread_visibles_layers (gint     *layers,
   92                                                       gint      layers_num,
   93                                                       gint     *layers_array);
   94 static gint    * align_layers_spread_image           (gint32    image_id,
   95                                                       gint     *layer_num);
   96 static gint      align_layers_find_background        (gint32    image_id);
   97 static AlignData align_layers_gather_data            (gint     *layers,
   98                                                       gint      layer_num,
   99                                                       gint      background);
  100 static void      align_layers_perform_alignment      (gint     *layers,
  101                                                       gint      layer_num,
  102                                                       AlignData data);
  103 static void      align_layers_get_align_offsets      (gint32    drawable_id,
  104                                                       gint     *x,
  105                                                       gint     *y);
  106 static gint      align_layers_dialog                 (void);
  107 
  108 
  109 
  110 const GimpPlugInInfo PLUG_IN_INFO =
  111 {
  112   NULL,  /* init_proc  */
  113   NULL,  /* quit_proc  */
  114   query, /* query_proc */
  115   run,   /* run_proc   */
  116 };
  117 
  118 
  119 /* dialog variables */
  120 typedef struct
  121 {
  122   gint     h_style;
  123   gint     h_base;
  124   gint     v_style;
  125   gint     v_base;
  126   gboolean ignore_bottom;
  127   gboolean base_is_bottom_layer;
  128   gint     grid_size;
  129 } ValueType;
  130 
  131 static ValueType VALS =
  132 {
  133   H_NONE,
  134   H_BASE_LEFT,
  135   V_NONE,
  136   V_BASE_TOP,
  137   TRUE,
  138   FALSE,
  139   10
  140 };
  141 
  142 
  143 MAIN ()
  144 
  145 static void
  146 query (void)
  147 {
  148   static const GimpParamDef args [] =
  149   {
  150     { GIMP_PDB_INT32,    "run-mode",             "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }"},
  151     { GIMP_PDB_IMAGE,    "image",                "Input image"},
  152     { GIMP_PDB_DRAWABLE, "drawable",             "Input drawable (not used)"},
  153     { GIMP_PDB_INT32,    "link-after-alignment", "Link the visible layers after alignment { TRUE, FALSE }"},
  154     { GIMP_PDB_INT32,    "use-bottom",           "use the bottom layer as the base of alignment { TRUE, FALSE }"}
  155   };
  156 
  157   gimp_install_procedure (PLUG_IN_PROC,
  158                           N_("Align all visible layers of the image"),
  159                           "Align visible layers",
  160                           "Shuji Narazaki <narazaki@InetQ.or.jp>",
  161                           "Shuji Narazaki",
  162                           "1997",
  163                           N_("Align Visi_ble Layers..."),
  164                           "RGB*,GRAY*,INDEXED*",
  165                           GIMP_PLUGIN,
  166                           G_N_ELEMENTS (args), 0,
  167                           args, NULL);
  168 
  169   gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Image/Arrange");
  170 }
  171 
  172 static void
  173 run (const gchar      *name,
  174      gint              nparams,
  175      const GimpParam  *param,
  176      gint             *nreturn_vals,
  177      GimpParam       **return_vals)
  178 {
  179   static GimpParam  values[2];
  180   GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR;
  181   GimpRunMode       run_mode;
  182   gint              image_id, layer_num;
  183   gint             *layers;
  184 
  185   run_mode = param[0].data.d_int32;
  186   image_id = param[1].data.d_int32;
  187 
  188   INIT_I18N ();
  189 
  190   *nreturn_vals = 1;
  191   *return_vals  = values;
  192 
  193   values[0].type          = GIMP_PDB_STATUS;
  194   values[0].data.d_status = status;
  195 
  196   switch ( run_mode )
  197     {
  198     case GIMP_RUN_INTERACTIVE:
  199       layers = gimp_image_get_layers (image_id, &layer_num);
  200       layer_num = align_layers_count_visibles_layers (layers,
  201                                                       layer_num);
  202       g_free (layers);
  203       if (layer_num < 2)
  204         {
  205           *nreturn_vals = 2;
  206           values[1].type          = GIMP_PDB_STRING;
  207           values[1].data.d_string = _("There are not enough layers to align.");
  208           return;
  209         }
  210       gimp_get_data (PLUG_IN_PROC, &VALS);
  211       VALS.grid_size = MAX (VALS.grid_size, 1);
  212       if (! align_layers_dialog ())
  213         return;
  214       break;
  215 
  216     case GIMP_RUN_NONINTERACTIVE:
  217       break;
  218 
  219     case GIMP_RUN_WITH_LAST_VALS:
  220       gimp_get_data (PLUG_IN_PROC, &VALS);
  221       break;
  222     }
  223 
  224   status = align_layers (image_id);
  225 
  226   if (run_mode != GIMP_RUN_NONINTERACTIVE)
  227     gimp_displays_flush ();
  228 
  229   if (run_mode == GIMP_RUN_INTERACTIVE && status == GIMP_PDB_SUCCESS)
  230     gimp_set_data (PLUG_IN_PROC, &VALS, sizeof (ValueType));
  231 
  232   values[0].data.d_status = status;
  233 }
  234 
  235 /*
  236  * Main function
  237  */
  238 static GimpPDBStatusType
  239 align_layers (gint32 image_id)
  240 {
  241   gint       layer_num  = 0;
  242   gint      *layers     = NULL;
  243   gint       background = 0;
  244   AlignData  data;
  245 
  246   layers = align_layers_spread_image (image_id, &layer_num);
  247   if (layer_num < 2)
  248     {
  249       g_free (layers);
  250       return GIMP_PDB_EXECUTION_ERROR;
  251     }
  252 
  253   background = align_layers_find_background (image_id);
  254 
  255   /* If we want to ignore the bottom layer and if it's visible */
  256   if (VALS.ignore_bottom && background == layers[layer_num - 1])
  257     {
  258       layer_num--;
  259     }
  260 
  261   data = align_layers_gather_data (layers,
  262                                    layer_num,
  263                                    background);
  264 
  265   gimp_image_undo_group_start (image_id);
  266 
  267   align_layers_perform_alignment (layers,
  268                                   layer_num,
  269                                   data);
  270 
  271   gimp_image_undo_group_end (image_id);
  272 
  273   g_free (layers);
  274 
  275   return GIMP_PDB_SUCCESS;
  276 }
  277 
  278 /*
  279  * Find the bottommost layer, visible or not
  280  * The image must contain at least one layer.
  281  */
  282 static gint
  283 align_layers_find_last_layer (gint     *layers,
  284                               gint      layers_num,
  285                               gboolean *found)
  286 {
  287   gint i;
  288 
  289   for (i = layers_num - 1; i >= 0; i--)
  290     {
  291       gint item = layers[i];
  292 
  293       if (gimp_item_is_group (item))
  294         {
  295           gint *children;
  296           gint  children_num;
  297           gint  last_layer;
  298 
  299           children = gimp_item_get_children (item, &children_num);
  300           last_layer = align_layers_find_last_layer (children,
  301                                                      children_num,
  302                                                      found);
  303           g_free (children);
  304           if (*found)
  305             return last_layer;
  306         }
  307       else if (gimp_item_is_layer (item))
  308         {
  309           *found = TRUE;
  310           return item;
  311         }
  312     }
  313 
  314   /* should never happen */
  315   return -1;
  316 }
  317 
  318 /*
  319  * Return the bottom layer.
  320  */
  321 static gint
  322 align_layers_find_background (gint32 image_id)
  323 {
  324   gint    *layers;
  325   gint     layers_num;
  326   gint     background;
  327   gboolean found = FALSE;
  328 
  329   layers = gimp_image_get_layers (image_id, &layers_num);
  330   background = align_layers_find_last_layer (layers,
  331                                              layers_num,
  332                                              &found);
  333   g_free (layers);
  334 
  335   return background;
  336 }
  337 
  338 /*
  339  * Fill layers_array with all visible layers.
  340  * layers_array needs to be allocated before the call
  341  */
  342 static gint
  343 align_layers_spread_visibles_layers (gint *layers,
  344                                      gint  layers_num,
  345                                      gint *layers_array)
  346 {
  347   gint i;
  348   gint index = 0;
  349 
  350   for (i = 0; i < layers_num; i++)
  351     {
  352       gint item = layers[i];
  353 
  354       if (gimp_item_get_visible (item))
  355         {
  356           if (gimp_item_is_group (item))
  357             {
  358               gint *children;
  359               gint  children_num;
  360 
  361               children = gimp_item_get_children (item, &children_num);
  362               index += align_layers_spread_visibles_layers (children,
  363                                                             children_num,
  364                                                             &(layers_array[index]));
  365               g_free (children);
  366             }
  367           else if (gimp_item_is_layer (item))
  368             {
  369               layers_array[index] = item;
  370               index++;
  371             }
  372         }
  373     }
  374 
  375   return index;
  376 }
  377 
  378 /*
  379  * Return a contiguous array of all visible layers
  380  */
  381 static gint *
  382 align_layers_spread_image (gint32  image_id,
  383                            gint   *layer_num)
  384 {
  385   gint *layers;
  386   gint *layers_array;
  387   gint  layer_num_loc;
  388 
  389   layers = gimp_image_get_layers (image_id, &layer_num_loc);
  390   *layer_num = align_layers_count_visibles_layers (layers,
  391                                                    layer_num_loc);
  392 
  393   layers_array = g_malloc (sizeof (gint) * *layer_num);
  394 
  395   align_layers_spread_visibles_layers (layers,
  396                                        layer_num_loc,
  397                                        layers_array);
  398   g_free (layers);
  399 
  400   return layers_array;
  401 }
  402 
  403 static gint
  404 align_layers_count_visibles_layers (gint *layers,
  405                                     gint  length)
  406 {
  407   gint i;
  408   gint count = 0;
  409 
  410   for (i = 0; i<length; i++)
  411     {
  412       gint item = layers[i];
  413 
  414       if (gimp_item_get_visible (item))
  415         {
  416           if (gimp_item_is_group (item))
  417             {
  418               gint *children;
  419               gint  children_num;
  420 
  421               children = gimp_item_get_children (item, &children_num);
  422               count += align_layers_count_visibles_layers (children,
  423                                                            children_num);
  424               g_free (children);
  425             }
  426           else if (gimp_item_is_layer (item))
  427             {
  428               count += 1;
  429             }
  430         }
  431     }
  432 
  433   return count;
  434 }
  435 
  436 static AlignData
  437 align_layers_gather_data (gint *layers,
  438                           gint  layer_num,
  439                           gint  background)
  440 {
  441   AlignData data;
  442   gint   min_x = G_MAXINT;
  443   gint   min_y = G_MAXINT;
  444   gint   max_x = G_MININT;
  445   gint   max_y = G_MININT;
  446   gint   index;
  447   gint   orig_x   = 0;
  448   gint   orig_y   = 0;
  449   gint   offset_x = 0;
  450   gint   offset_y = 0;
  451 
  452   data.step_x = 0;
  453   data.step_y = 0;
  454   data.base_x = 0;
  455   data.base_y = 0;
  456 
  457   /* 0 is the top layer */
  458   for (index = 0; index < layer_num; index++)
  459     {
  460       gimp_drawable_offsets (layers[index], &orig_x, &orig_y);
  461 
  462       align_layers_get_align_offsets (layers[index],
  463                                       &offset_x,
  464                                       &offset_y);
  465       orig_x += offset_x;
  466       orig_y += offset_y;
  467 
  468       min_x = MIN (min_x, orig_x);
  469       max_x = MAX (max_x, orig_x);
  470       min_y = MIN (min_y, orig_y);
  471       max_y = MAX (max_y, orig_y);
  472     }
  473 
  474   if (VALS.base_is_bottom_layer)
  475     {
  476       gimp_drawable_offsets (background, &orig_x, &orig_y);
  477 
  478       align_layers_get_align_offsets (background,
  479                                       &offset_x,
  480                                       &offset_y);
  481       orig_x += offset_x;
  482       orig_y += offset_y;
  483       data.base_x = min_x = orig_x;
  484       data.base_y = min_y = orig_y;
  485     }
  486 
  487   if (layer_num > 1)
  488     {
  489       data.step_x = (max_x - min_x) / (layer_num - 1);
  490       data.step_y = (max_y - min_y) / (layer_num - 1);
  491     }
  492 
  493   if ( (VALS.h_style == LEFT2RIGHT) || (VALS.h_style == RIGHT2LEFT))
  494     data.base_x = min_x;
  495 
  496   if ( (VALS.v_style == TOP2BOTTOM) || (VALS.v_style == BOTTOM2TOP))
  497     data.base_y = min_y;
  498 
  499   return data;
  500 }
  501 
  502 /*
  503  * Modifies position of each visible layers
  504  * according to data.
  505  */
  506 static void
  507 align_layers_perform_alignment (gint      *layers,
  508                                 gint       layer_num,
  509                                 AlignData  data)
  510 {
  511   gint index;
  512 
  513   for (index = 0; index < layer_num; index++)
  514     {
  515       gint x = 0;
  516       gint y = 0;
  517       gint orig_x;
  518       gint orig_y;
  519       gint offset_x;
  520       gint offset_y;
  521 
  522       gimp_drawable_offsets (layers[index], &orig_x, &orig_y);
  523 
  524       align_layers_get_align_offsets (layers[index],
  525                                       &offset_x,
  526                                       &offset_y);
  527       switch (VALS.h_style)
  528         {
  529         case H_NONE:
  530           x = orig_x;
  531           break;
  532         case H_COLLECT:
  533           x = data.base_x - offset_x;
  534           break;
  535         case LEFT2RIGHT:
  536           x = (data.base_x + index * data.step_x) - offset_x;
  537           break;
  538         case RIGHT2LEFT:
  539           x = (data.base_x + (layer_num - index - 1) * data.step_x) - offset_x;
  540           break;
  541         case SNAP2HGRID:
  542           x = VALS.grid_size
  543             * (int) ((orig_x + offset_x + VALS.grid_size /2) / VALS.grid_size)
  544             - offset_x;
  545           break;
  546         }
  547 
  548       switch (VALS.v_style)
  549         {
  550         case V_NONE:
  551           y = orig_y;
  552           break;
  553         case V_COLLECT:
  554           y = data.base_y - offset_y;
  555           break;
  556         case TOP2BOTTOM:
  557           y = (data.base_y + index * data.step_y) - offset_y;
  558           break;
  559         case BOTTOM2TOP:
  560           y = (data.base_y + (layer_num - index - 1) * data.step_y) - offset_y;
  561           break;
  562         case SNAP2VGRID:
  563           y = VALS.grid_size
  564             * (int) ((orig_y + offset_y + VALS.grid_size / 2) / VALS.grid_size)
  565             - offset_y;
  566           break;
  567         }
  568 
  569       gimp_layer_set_offsets (layers[index], x, y);
  570     }
  571 }
  572 
  573 static void
  574 align_layers_get_align_offsets (gint32  drawable_id,
  575                                 gint   *x,
  576                                 gint   *y)
  577 {
  578   gint width  = gimp_drawable_width  (drawable_id);
  579   gint height = gimp_drawable_height (drawable_id);
  580 
  581   switch (VALS.h_base)
  582     {
  583     case H_BASE_LEFT:
  584       *x = 0;
  585       break;
  586     case H_BASE_CENTER:
  587       *x = width / 2;
  588       break;
  589     case H_BASE_RIGHT:
  590       *x = width;
  591       break;
  592     default:
  593       *x = 0;
  594       break;
  595     }
  596 
  597   switch (VALS.v_base)
  598     {
  599     case V_BASE_TOP:
  600       *y = 0;
  601       break;
  602     case V_BASE_CENTER:
  603       *y = height / 2;
  604       break;
  605     case V_BASE_BOTTOM:
  606       *y = height;
  607       break;
  608     default:
  609       *y = 0;
  610       break;
  611     }
  612 }
  613 
  614 static int
  615 align_layers_dialog (void)
  616 {
  617   GtkWidget *dialog;
  618   GtkWidget *table;
  619   GtkWidget *combo;
  620   GtkWidget *toggle;
  621   GtkObject *adj;
  622   gboolean   run;
  623 
  624   gimp_ui_init (PLUG_IN_BINARY, FALSE);
  625 
  626   dialog = gimp_dialog_new (_("Align Visible Layers"), PLUG_IN_ROLE,
  627                             NULL, 0,
  628                             gimp_standard_help_func, PLUG_IN_PROC,
  629 
  630                             _("_Cancel"), GTK_RESPONSE_CANCEL,
  631                             _("_OK"),     GTK_RESPONSE_OK,
  632 
  633                             NULL);
  634 
  635   gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
  636                                            GTK_RESPONSE_OK,
  637                                            GTK_RESPONSE_CANCEL,
  638                                            -1);
  639 
  640   gimp_window_set_transient (GTK_WINDOW (dialog));
  641 
  642   table = gtk_table_new (7, 3, FALSE);
  643   gtk_table_set_col_spacings (GTK_TABLE (table), 6);
  644   gtk_table_set_row_spacings (GTK_TABLE (table), 6);
  645   gtk_container_set_border_width (GTK_CONTAINER (table), 12);
  646   gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
  647                       table, FALSE, FALSE, 0);
  648   gtk_widget_show (table);
  649 
  650   combo = gimp_int_combo_box_new (C_("align-style", "None"), H_NONE,
  651                                   _("Collect"),              H_COLLECT,
  652                                   _("Fill (left to right)"), LEFT2RIGHT,
  653                                   _("Fill (right to left)"), RIGHT2LEFT,
  654                                   _("Snap to grid"),         SNAP2HGRID,
  655                                   NULL);
  656   gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo), VALS.h_style);
  657 
  658   g_signal_connect (combo, "changed",
  659                     G_CALLBACK (gimp_int_combo_box_get_active),
  660                     &VALS.h_style);
  661 
  662   gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
  663                              _("_Horizontal style:"), 0.0, 0.5,
  664                              combo, 2, FALSE);
  665 
  666 
  667   combo = gimp_int_combo_box_new (_("Left edge"),  H_BASE_LEFT,
  668                                   _("Center"),     H_BASE_CENTER,
  669                                   _("Right edge"), H_BASE_RIGHT,
  670                                   NULL);
  671   gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo), VALS.h_base);
  672 
  673   g_signal_connect (combo, "changed",
  674                     G_CALLBACK (gimp_int_combo_box_get_active),
  675                     &VALS.h_base);
  676 
  677   gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
  678                              _("Ho_rizontal base:"), 0.0, 0.5,
  679                              combo, 2, FALSE);
  680 
  681   combo = gimp_int_combo_box_new (C_("align-style", "None"), V_NONE,
  682                                   _("Collect"),              V_COLLECT,
  683                                   _("Fill (top to bottom)"), TOP2BOTTOM,
  684                                   _("Fill (bottom to top)"), BOTTOM2TOP,
  685                                   _("Snap to grid"),         SNAP2VGRID,
  686                                   NULL);
  687   gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo), VALS.v_style);
  688 
  689   g_signal_connect (combo, "changed",
  690                     G_CALLBACK (gimp_int_combo_box_get_active),
  691                     &VALS.v_style);
  692 
  693   gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
  694                              _("_Vertical style:"), 0.0, 0.5,
  695                              combo, 2, FALSE);
  696 
  697   combo = gimp_int_combo_box_new (_("Top edge"),    V_BASE_TOP,
  698                                   _("Center"),      V_BASE_CENTER,
  699                                   _("Bottom edge"), V_BASE_BOTTOM,
  700                                   NULL);
  701   gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo), VALS.v_base);
  702 
  703   g_signal_connect (combo, "changed",
  704                     G_CALLBACK (gimp_int_combo_box_get_active),
  705                     &VALS.v_base);
  706 
  707   gimp_table_attach_aligned (GTK_TABLE (table), 0, 3,
  708                              _("Ver_tical base:"), 0.0, 0.5,
  709                              combo, 2, FALSE);
  710 
  711   adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 4,
  712                               _("_Grid size:"), SCALE_WIDTH, 0,
  713                               VALS.grid_size, 1, 200, 1, 10, 0,
  714                               TRUE, 0, 0,
  715                               NULL, NULL);
  716   g_signal_connect (adj, "value-changed",
  717                     G_CALLBACK (gimp_int_adjustment_update),
  718                     &VALS.grid_size);
  719 
  720   toggle = gtk_check_button_new_with_mnemonic
  721     (_("_Ignore the bottom layer even if visible"));
  722   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), VALS.ignore_bottom);
  723   gtk_table_attach_defaults (GTK_TABLE (table), toggle, 0, 3, 5, 6);
  724   gtk_widget_show (toggle);
  725 
  726   g_signal_connect (toggle, "toggled",
  727                     G_CALLBACK (gimp_toggle_button_update),
  728                     &VALS.ignore_bottom);
  729 
  730   toggle = gtk_check_button_new_with_mnemonic
  731     (_("_Use the (invisible) bottom layer as the base"));
  732   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
  733                                 VALS.base_is_bottom_layer);
  734   gtk_table_attach_defaults (GTK_TABLE (table), toggle, 0, 3, 6, 7);
  735   gtk_widget_show (toggle);
  736 
  737   g_signal_connect (toggle, "toggled",
  738                     G_CALLBACK (gimp_toggle_button_update),
  739                     &VALS.base_is_bottom_layer);
  740 
  741   gtk_widget_show (dialog);
  742 
  743   run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
  744 
  745   gtk_widget_destroy (dialog);
  746 
  747   return run;
  748 }