133
static GimpChannelClass *parent_class = NULL;
137
gimp_selection_get_type (void)
139
static GType selection_type = 0;
141
if (! selection_type)
143
static const GTypeInfo selection_info =
145
sizeof (GimpSelectionClass),
146
(GBaseInitFunc) NULL,
147
(GBaseFinalizeFunc) NULL,
148
(GClassInitFunc) gimp_selection_class_init,
149
NULL, /* class_finalize */
150
NULL, /* class_data */
151
sizeof (GimpSelection),
153
(GInstanceInitFunc) gimp_selection_init,
156
selection_type = g_type_register_static (GIMP_TYPE_CHANNEL,
161
return selection_type;
129
G_DEFINE_TYPE (GimpSelection, gimp_selection, GIMP_TYPE_CHANNEL)
131
#define parent_class gimp_selection_parent_class
165
135
gimp_selection_class_init (GimpSelectionClass *klass)
333
300
* we need to do this since this selection mask can act as an additional
334
301
* mask in the composition of the floating selection
336
layer = gimp_image_get_active_layer (gimage);
303
layer = gimp_image_get_active_layer (image);
338
305
if (layer && gimp_layer_is_floating_sel (layer))
339
306
gimp_drawable_update (GIMP_DRAWABLE (layer),
341
GIMP_ITEM (layer)->width,
342
GIMP_ITEM (layer)->height);
308
GIMP_ITEM (layer)->width,
309
GIMP_ITEM (layer)->height);
344
311
/* invalidate the preview */
345
312
drawable->preview_valid = FALSE;
408
375
gimp_item_offsets (GIMP_ITEM (layer), &off_x, &off_y);
410
x1 = CLAMP (off_x, 0, gimage->width);
411
y1 = CLAMP (off_y, 0, gimage->height);
377
x1 = CLAMP (off_x, 0, image->width);
378
y1 = CLAMP (off_y, 0, image->height);
412
379
x2 = CLAMP (off_x + gimp_item_width (GIMP_ITEM (layer)), 0,
414
381
y2 = CLAMP (off_y + gimp_item_height (GIMP_ITEM (layer)), 0,
417
384
return GIMP_CHANNEL_CLASS (parent_class)->boundary (channel,
418
385
segs_in, segs_out,
539
504
/* Set the contents of the tile to empty */
540
505
memset (tile_data_pointer (tile, 0, 0),
541
TRANSPARENT_OPACITY, tile_size (tile));
506
TRANSPARENT_OPACITY, tile_size (tile));
545
510
/* public functions */
548
gimp_selection_new (GimpImage *gimage,
513
gimp_selection_new (GimpImage *image,
552
517
GimpRGB black = { 0.0, 0.0, 0.0, 0.5 };
553
518
GimpChannel *channel;
555
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
520
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
557
522
channel = g_object_new (GIMP_TYPE_SELECTION, NULL);
559
524
gimp_drawable_configure (GIMP_DRAWABLE (channel),
561
526
0, 0, width, height,
563
528
_("Selection Mask"));
597
562
/* copy the channel to the mask */
598
563
pixel_region_init (&srcPR, GIMP_DRAWABLE (channel)->tiles,
599
0, 0, src_item->width, src_item->height,
564
0, 0, src_item->width, src_item->height,
601
566
pixel_region_init (&destPR, GIMP_DRAWABLE (selection)->tiles,
602
0, 0, dest_item->width, dest_item->height,
567
0, 0, dest_item->width, dest_item->height,
604
569
copy_region (&srcPR, &destPR);
665
630
non_empty = gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
666
631
if (non_empty && ((x1 == x2) || (y1 == y2)))
668
g_message (_("Unable to cut or copy because the "
669
"selected region is empty."));
633
gimp_message (image->gimp, NULL, GIMP_MESSAGE_WARNING,
634
_("Unable to cut or copy because the "
635
"selected region is empty."));
639
/* If there is a selection, we must add alpha because the selection
640
* could have any shape.
673
645
/* How many bytes in the temp buffer? */
674
646
switch (GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (drawable)))
728
702
if (non_empty) /* If there is a selection, extract from it */
730
pixel_region_init (&maskPR, gimp_drawable_data (GIMP_DRAWABLE (selection)),
731
(x1 + off_x), (y1 + off_y), (x2 - x1), (y2 - y1),
704
pixel_region_init (&maskPR,
705
gimp_drawable_get_tiles (GIMP_DRAWABLE (selection)),
706
(x1 + off_x), (y1 + off_y), (x2 - x1), (y2 - y1),
734
709
extract_from_region (&srcPR, &destPR, &maskPR,
735
gimp_drawable_cmap (drawable),
737
gimp_drawable_has_alpha (drawable), cut_image);
710
gimp_drawable_get_colormap (drawable),
711
bg_color, base_type, cut_image);
741
/* Clear the region */
742
gimp_channel_clear (selection, NULL, TRUE);
715
/* Clear the region */
716
gimp_channel_clear (selection, NULL, TRUE);
744
/* Update the region */
745
gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1));
718
/* Update the region */
719
gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1));
748
722
else /* Otherwise, get the entire active layer */
750
724
/* If the layer is indexed...we need to extract pixels */
751
725
if (base_type == GIMP_INDEXED && !keep_indexed)
752
extract_from_region (&srcPR, &destPR, NULL,
753
gimp_drawable_cmap (drawable),
755
gimp_drawable_has_alpha (drawable), FALSE);
726
extract_from_region (&srcPR, &destPR, NULL,
727
gimp_drawable_get_colormap (drawable),
728
bg_color, base_type, FALSE);
756
729
/* If the layer doesn't have an alpha channel, add one */
757
730
else if (bytes > srcPR.bytes)
758
add_alpha_region (&srcPR, &destPR);
731
add_alpha_region (&srcPR, &destPR);
759
732
/* Otherwise, do a straight copy */
761
copy_region (&srcPR, &destPR);
734
copy_region (&srcPR, &destPR);
763
736
/* If we're cutting, remove either the layer (or floating selection),
764
737
* the layer mask, or the channel
768
if (GIMP_IS_LAYER (drawable))
770
if (gimp_layer_is_floating_sel (GIMP_LAYER (drawable)))
771
floating_sel_remove (GIMP_LAYER (drawable));
773
gimp_image_remove_layer (gimage, GIMP_LAYER (drawable));
775
else if (GIMP_IS_LAYER_MASK (drawable))
777
gimp_layer_apply_mask (gimp_layer_mask_get_layer (GIMP_LAYER_MASK (drawable)),
778
GIMP_MASK_DISCARD, TRUE);
780
else if (GIMP_IS_CHANNEL (drawable))
782
gimp_image_remove_channel (gimage, GIMP_CHANNEL (drawable));
741
if (GIMP_IS_LAYER (drawable))
743
if (gimp_layer_is_floating_sel (GIMP_LAYER (drawable)))
744
floating_sel_remove (GIMP_LAYER (drawable));
746
gimp_image_remove_layer (image, GIMP_LAYER (drawable));
748
else if (GIMP_IS_LAYER_MASK (drawable))
750
gimp_layer_apply_mask (gimp_layer_mask_get_layer (GIMP_LAYER_MASK (drawable)),
751
GIMP_MASK_DISCARD, TRUE);
753
else if (GIMP_IS_CHANNEL (drawable))
755
gimp_image_remove_channel (image, GIMP_CHANNEL (drawable));
806
779
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
807
780
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
809
gimage = gimp_item_get_image (GIMP_ITEM (selection));
782
image = gimp_item_get_image (GIMP_ITEM (selection));
811
784
/* Make sure there is a region to float... */
812
785
non_empty = gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
813
786
if (! non_empty || (x1 == x2) || (y1 == y2))
815
g_message (_("Cannot float selection because the "
816
"selected region is empty."));
788
gimp_message (image->gimp, NULL, GIMP_MESSAGE_WARNING,
789
_("Cannot float selection because the "
790
"selected region is empty."));
820
794
/* Start an undo group */
821
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_FS_FLOAT,
795
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_FS_FLOAT,
822
796
_("Float Selection"));
824
798
/* Cut or copy the selected region */