diff --git a/ChangeLog b/ChangeLog index f8409afa9a..503ff4b1fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2001-02-27 Jay Cox + + * app/appenums.h + * app/gimplayer.c + * app/layers_dialog.c: When adding a layer mask allow the option + of using the current selection (or it's inverse) to initialise + the mask. + 2001-02-28 Michael Natterer * app/gdisplay.c diff --git a/app/appenums.h b/app/appenums.h index 6bf2d61967..c597dc6fd7 100644 --- a/app/appenums.h +++ b/app/appenums.h @@ -109,7 +109,9 @@ typedef enum /*< chop=ADD_ >*/ { ADD_WHITE_MASK, ADD_BLACK_MASK, - ADD_ALPHA_MASK + ADD_ALPHA_MASK, + ADD_SELECTION_MASK, + ADD_INV_SELECTION_MASK } AddMaskType; /* gradient paint modes */ diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c index e1146399ec..ceb2f6d96d 100644 --- a/app/core/gimplayer.c +++ b/app/core/gimplayer.c @@ -44,6 +44,7 @@ #include "temp_buf.h" #include "tile_manager.h" #include "tile.h" +#include "invert.h" #include "libgimp/gimpparasite.h" @@ -450,15 +451,24 @@ gimp_layer_create_mask (GimpLayer *layer, PixelRegion maskPR; PixelRegion layerPR; GimpLayerMask *mask; + GimpImage *gimage; + GimpDrawable *selection; gchar *mask_name; GimpRGB black = { 0.0, 0.0, 0.0, 1.0 }; guchar white_mask = OPAQUE_OPACITY; guchar black_mask = TRANSPARENT_OPACITY; + gimage = GIMP_DRAWABLE (layer)->gimage; + + selection = GIMP_DRAWABLE(gimage->selection_mask); + mask_name = g_strdup_printf (_("%s mask"), gimp_object_get_name (GIMP_OBJECT (layer))); + /* Start an undo group. Needed if we are modifying the selection */ + undo_push_group_start (gimage, LAYER_MASK_ADD_UNDO); /* Create the layer mask */ + mask = gimp_layer_mask_new (GIMP_DRAWABLE (layer)->gimage, GIMP_DRAWABLE (layer)->width, GIMP_DRAWABLE (layer)->height, @@ -491,8 +501,32 @@ gimp_layer_create_mask (GimpLayer *layer, extract_alpha_region (&layerPR, NULL, &maskPR); } break; + case ADD_SELECTION_MASK: + pixel_region_init (&layerPR, GIMP_DRAWABLE (selection)->tiles, + GIMP_DRAWABLE (layer)->offset_x, + GIMP_DRAWABLE (layer)->offset_y, + GIMP_DRAWABLE (layer)->width, + GIMP_DRAWABLE (layer)->height, + FALSE); + copy_region (&layerPR, &maskPR); + gimage_mask_none (gimage); + break; + case ADD_INV_SELECTION_MASK: + pixel_region_init (&layerPR, GIMP_DRAWABLE (selection)->tiles, + GIMP_DRAWABLE (layer)->offset_x, + GIMP_DRAWABLE (layer)->offset_y, + GIMP_DRAWABLE (layer)->width, + GIMP_DRAWABLE (layer)->height, + FALSE); + copy_region (&layerPR, &maskPR); + gimage_mask_none (gimage); + invert(GIMP_DRAWABLE(mask)); + break; } + /* finish the undo group. */ + undo_push_group_end (gimage); + g_free (mask_name); return mask; diff --git a/app/gimplayer.c b/app/gimplayer.c index e1146399ec..ceb2f6d96d 100644 --- a/app/gimplayer.c +++ b/app/gimplayer.c @@ -44,6 +44,7 @@ #include "temp_buf.h" #include "tile_manager.h" #include "tile.h" +#include "invert.h" #include "libgimp/gimpparasite.h" @@ -450,15 +451,24 @@ gimp_layer_create_mask (GimpLayer *layer, PixelRegion maskPR; PixelRegion layerPR; GimpLayerMask *mask; + GimpImage *gimage; + GimpDrawable *selection; gchar *mask_name; GimpRGB black = { 0.0, 0.0, 0.0, 1.0 }; guchar white_mask = OPAQUE_OPACITY; guchar black_mask = TRANSPARENT_OPACITY; + gimage = GIMP_DRAWABLE (layer)->gimage; + + selection = GIMP_DRAWABLE(gimage->selection_mask); + mask_name = g_strdup_printf (_("%s mask"), gimp_object_get_name (GIMP_OBJECT (layer))); + /* Start an undo group. Needed if we are modifying the selection */ + undo_push_group_start (gimage, LAYER_MASK_ADD_UNDO); /* Create the layer mask */ + mask = gimp_layer_mask_new (GIMP_DRAWABLE (layer)->gimage, GIMP_DRAWABLE (layer)->width, GIMP_DRAWABLE (layer)->height, @@ -491,8 +501,32 @@ gimp_layer_create_mask (GimpLayer *layer, extract_alpha_region (&layerPR, NULL, &maskPR); } break; + case ADD_SELECTION_MASK: + pixel_region_init (&layerPR, GIMP_DRAWABLE (selection)->tiles, + GIMP_DRAWABLE (layer)->offset_x, + GIMP_DRAWABLE (layer)->offset_y, + GIMP_DRAWABLE (layer)->width, + GIMP_DRAWABLE (layer)->height, + FALSE); + copy_region (&layerPR, &maskPR); + gimage_mask_none (gimage); + break; + case ADD_INV_SELECTION_MASK: + pixel_region_init (&layerPR, GIMP_DRAWABLE (selection)->tiles, + GIMP_DRAWABLE (layer)->offset_x, + GIMP_DRAWABLE (layer)->offset_y, + GIMP_DRAWABLE (layer)->width, + GIMP_DRAWABLE (layer)->height, + FALSE); + copy_region (&layerPR, &maskPR); + gimage_mask_none (gimage); + invert(GIMP_DRAWABLE(mask)); + break; } + /* finish the undo group. */ + undo_push_group_end (gimage); + g_free (mask_name); return mask; diff --git a/app/gui/layers-dialog.c b/app/gui/layers-dialog.c index 858d6ed04a..c209e282dc 100644 --- a/app/gui/layers-dialog.c +++ b/app/gui/layers-dialog.c @@ -3856,12 +3856,15 @@ layers_dialog_add_mask_query (GimpLayer *layer) { AddMaskOptions *options; GtkWidget *frame; - + GimpImage *gimage; + /* The new options structure */ options = g_new (AddMaskOptions, 1); options->layer = layer; options->add_mask_type = ADD_WHITE_MASK; + gimage = GIMP_DRAWABLE (layer)->gimage; + /* The dialog */ options->query_box = gimp_dialog_new (_("Add Mask Options"), "add_mask_options", @@ -3882,19 +3885,41 @@ layers_dialog_add_mask_query (GimpLayer *layer) (GtkObject *) options); /* The radio frame and box */ - frame = gimp_radio_group_new2 (TRUE, _("Initialize Layer Mask to:"), - gimp_radio_button_update, - &options->add_mask_type, - (gpointer) options->add_mask_type, + if (gimage->selection_mask) + { + options->add_mask_type = ADD_SELECTION_MASK; + frame = gimp_radio_group_new2 (TRUE, _("Initialize Layer Mask to:"), + gimp_radio_button_update, + &options->add_mask_type, + (gpointer) options->add_mask_type, - _("White (Full Opacity)"), - (gpointer) ADD_WHITE_MASK, NULL, - _("Black (Full Transparency)"), - (gpointer) ADD_BLACK_MASK, NULL, - _("Layer's Alpha Channel"), - (gpointer) ADD_ALPHA_MASK, NULL, - NULL); + _("Show Selection"), + (gpointer) ADD_SELECTION_MASK, NULL, + _("Hide Selection"), + (gpointer) ADD_INV_SELECTION_MASK, NULL, + _("White (Full Opacity)"), + (gpointer) ADD_WHITE_MASK, NULL, + _("Black (Full Transparency)"), + (gpointer) ADD_BLACK_MASK, NULL, + _("Layer's Alpha Channel"), + (gpointer) ADD_ALPHA_MASK, NULL, + NULL); + } + else + { + frame = gimp_radio_group_new2 (TRUE, _("Initialize Layer Mask to:"), + gimp_radio_button_update, + &options->add_mask_type, + (gpointer) options->add_mask_type, + _("White (Full Opacity)"), + (gpointer) ADD_WHITE_MASK, NULL, + _("Black (Full Transparency)"), + (gpointer) ADD_BLACK_MASK, NULL, + _("Layer's Alpha Channel"), + (gpointer) ADD_ALPHA_MASK, NULL, + NULL); + } gtk_container_set_border_width (GTK_CONTAINER (frame), 6); gtk_container_add (GTK_CONTAINER (GTK_DIALOG (options->query_box)->vbox), frame); diff --git a/app/layers_dialog.c b/app/layers_dialog.c index 858d6ed04a..c209e282dc 100644 --- a/app/layers_dialog.c +++ b/app/layers_dialog.c @@ -3856,12 +3856,15 @@ layers_dialog_add_mask_query (GimpLayer *layer) { AddMaskOptions *options; GtkWidget *frame; - + GimpImage *gimage; + /* The new options structure */ options = g_new (AddMaskOptions, 1); options->layer = layer; options->add_mask_type = ADD_WHITE_MASK; + gimage = GIMP_DRAWABLE (layer)->gimage; + /* The dialog */ options->query_box = gimp_dialog_new (_("Add Mask Options"), "add_mask_options", @@ -3882,19 +3885,41 @@ layers_dialog_add_mask_query (GimpLayer *layer) (GtkObject *) options); /* The radio frame and box */ - frame = gimp_radio_group_new2 (TRUE, _("Initialize Layer Mask to:"), - gimp_radio_button_update, - &options->add_mask_type, - (gpointer) options->add_mask_type, + if (gimage->selection_mask) + { + options->add_mask_type = ADD_SELECTION_MASK; + frame = gimp_radio_group_new2 (TRUE, _("Initialize Layer Mask to:"), + gimp_radio_button_update, + &options->add_mask_type, + (gpointer) options->add_mask_type, - _("White (Full Opacity)"), - (gpointer) ADD_WHITE_MASK, NULL, - _("Black (Full Transparency)"), - (gpointer) ADD_BLACK_MASK, NULL, - _("Layer's Alpha Channel"), - (gpointer) ADD_ALPHA_MASK, NULL, - NULL); + _("Show Selection"), + (gpointer) ADD_SELECTION_MASK, NULL, + _("Hide Selection"), + (gpointer) ADD_INV_SELECTION_MASK, NULL, + _("White (Full Opacity)"), + (gpointer) ADD_WHITE_MASK, NULL, + _("Black (Full Transparency)"), + (gpointer) ADD_BLACK_MASK, NULL, + _("Layer's Alpha Channel"), + (gpointer) ADD_ALPHA_MASK, NULL, + NULL); + } + else + { + frame = gimp_radio_group_new2 (TRUE, _("Initialize Layer Mask to:"), + gimp_radio_button_update, + &options->add_mask_type, + (gpointer) options->add_mask_type, + _("White (Full Opacity)"), + (gpointer) ADD_WHITE_MASK, NULL, + _("Black (Full Transparency)"), + (gpointer) ADD_BLACK_MASK, NULL, + _("Layer's Alpha Channel"), + (gpointer) ADD_ALPHA_MASK, NULL, + NULL); + } gtk_container_set_border_width (GTK_CONTAINER (frame), 6); gtk_container_add (GTK_CONTAINER (GTK_DIALOG (options->query_box)->vbox), frame);