1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
#include <glib-object.h>
|
2001-01-25 06:36:18 +08:00
|
|
|
|
2001-07-05 03:31:35 +08:00
|
|
|
#include "core-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/pixel-region.h"
|
|
|
|
#include "base/tile-manager.h"
|
2001-06-26 20:09:43 +08:00
|
|
|
#include "base/tile-manager-crop.h"
|
2001-05-15 19:25:25 +08:00
|
|
|
|
2001-04-07 23:58:26 +08:00
|
|
|
#include "paint-funcs/paint-funcs.h"
|
|
|
|
|
2001-07-05 03:31:35 +08:00
|
|
|
#include "gimp.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "gimpbuffer.h"
|
|
|
|
#include "gimpchannel.h"
|
|
|
|
#include "gimpcontext.h"
|
|
|
|
#include "gimpedit.h"
|
|
|
|
#include "gimpimage.h"
|
|
|
|
#include "gimpimage-mask.h"
|
2003-02-13 19:23:50 +08:00
|
|
|
#include "gimpimage-undo.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "gimplayer.h"
|
2002-02-22 06:19:45 +08:00
|
|
|
#include "gimplayer-floating-sel.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "gimplist.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
1998-11-23 22:47:09 +08:00
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
|
2001-12-13 07:48:18 +08:00
|
|
|
GimpBuffer *
|
2001-06-30 03:25:03 +08:00
|
|
|
gimp_edit_cut (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
TileManager *cut;
|
|
|
|
TileManager *cropped_cut;
|
2001-06-26 20:09:43 +08:00
|
|
|
gboolean empty;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Start a group undo */
|
2003-02-13 19:23:50 +08:00
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_CUT,
|
|
|
|
_("Cut"));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* See if the gimage mask is empty */
|
2001-11-29 06:42:19 +08:00
|
|
|
empty = gimp_image_mask_is_empty (gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Next, cut the mask portion from the gimage */
|
2001-11-29 06:42:19 +08:00
|
|
|
cut = gimp_image_mask_extract (gimage, drawable, TRUE, FALSE, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
if (cut)
|
2002-05-13 23:35:27 +08:00
|
|
|
gimage->gimp->have_current_cut_buffer = TRUE;
|
2001-06-26 20:09:43 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Only crop if the gimage mask wasn't empty */
|
2001-06-26 20:09:43 +08:00
|
|
|
if (cut && ! empty)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-06-26 20:09:43 +08:00
|
|
|
cropped_cut = tile_manager_crop (cut, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (cropped_cut != cut)
|
2001-06-26 20:09:43 +08:00
|
|
|
{
|
|
|
|
tile_manager_destroy (cut);
|
|
|
|
cut = NULL;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else if (cut)
|
|
|
|
cropped_cut = cut;
|
|
|
|
else
|
|
|
|
cropped_cut = NULL;
|
|
|
|
|
|
|
|
/* end the group undo */
|
2003-02-13 19:23:50 +08:00
|
|
|
gimp_image_undo_group_end (gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (cropped_cut)
|
|
|
|
{
|
|
|
|
/* Free the old global edit buffer */
|
2001-07-05 03:31:35 +08:00
|
|
|
if (gimage->gimp->global_buffer)
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (gimage->gimp->global_buffer);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
/* Set the global edit buffer */
|
2001-12-13 07:48:18 +08:00
|
|
|
gimage->gimp->global_buffer = gimp_buffer_new (cropped_cut,
|
|
|
|
"Global Buffer",
|
|
|
|
TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2001-06-26 20:09:43 +08:00
|
|
|
|
2001-12-13 07:48:18 +08:00
|
|
|
return gimp_buffer_new (cropped_cut, "Cut Pixels", FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-12-13 07:48:18 +08:00
|
|
|
GimpBuffer *
|
2001-06-30 03:25:03 +08:00
|
|
|
gimp_edit_copy (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-02-11 05:54:12 +08:00
|
|
|
TileManager *copy;
|
|
|
|
TileManager *cropped_copy;
|
2001-06-26 20:09:43 +08:00
|
|
|
gboolean empty;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-01-02 21:38:09 +08:00
|
|
|
/* Start a group undo */
|
2003-02-13 19:23:50 +08:00
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_COPY,
|
|
|
|
_("Copy"));
|
2003-01-02 21:38:09 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* See if the gimage mask is empty */
|
2001-11-29 06:42:19 +08:00
|
|
|
empty = gimp_image_mask_is_empty (gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* First, copy the masked portion of the gimage */
|
2001-11-29 06:42:19 +08:00
|
|
|
copy = gimp_image_mask_extract (gimage, drawable, FALSE, FALSE, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
if (copy)
|
2002-05-13 23:35:27 +08:00
|
|
|
gimage->gimp->have_current_cut_buffer = TRUE;
|
2001-06-26 20:09:43 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Only crop if the gimage mask wasn't empty */
|
2001-06-26 20:09:43 +08:00
|
|
|
if (copy && ! empty)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-06-26 20:09:43 +08:00
|
|
|
cropped_copy = tile_manager_crop (copy, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (cropped_copy != copy)
|
2001-06-26 20:09:43 +08:00
|
|
|
{
|
|
|
|
tile_manager_destroy (copy);
|
|
|
|
copy = NULL;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else if (copy)
|
|
|
|
cropped_copy = copy;
|
|
|
|
else
|
|
|
|
cropped_copy = NULL;
|
|
|
|
|
2003-01-02 21:38:09 +08:00
|
|
|
/* end the group undo */
|
2003-02-13 19:23:50 +08:00
|
|
|
gimp_image_undo_group_end (gimage);
|
2003-01-02 21:38:09 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (cropped_copy)
|
|
|
|
{
|
|
|
|
/* Free the old global edit buffer */
|
2001-07-05 03:31:35 +08:00
|
|
|
if (gimage->gimp->global_buffer)
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (gimage->gimp->global_buffer);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
/* Set the global edit buffer */
|
2001-12-13 07:48:18 +08:00
|
|
|
gimage->gimp->global_buffer = gimp_buffer_new (cropped_copy,
|
|
|
|
"Global Buffer",
|
|
|
|
TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2001-06-26 20:09:43 +08:00
|
|
|
|
2001-12-13 07:48:18 +08:00
|
|
|
return gimp_buffer_new (cropped_copy, "Copied Pixels", FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-02-11 05:54:12 +08:00
|
|
|
GimpLayer *
|
2001-06-30 03:25:03 +08:00
|
|
|
gimp_edit_paste (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable,
|
2001-12-13 07:48:18 +08:00
|
|
|
GimpBuffer *paste,
|
2001-06-30 03:25:03 +08:00
|
|
|
gboolean paste_into)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-05-21 19:29:20 +08:00
|
|
|
GimpLayer *layer;
|
|
|
|
GimpImageType type;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
gint cx, cy;
|
2000-02-11 05:54:12 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
|
|
|
|
g_return_val_if_fail (! drawable || GIMP_IS_DRAWABLE (drawable), NULL);
|
|
|
|
|
|
|
|
/* Make a new layer: if drawable == NULL,
|
|
|
|
* user is pasting into an empty image.
|
2000-02-11 05:54:12 +08:00
|
|
|
*/
|
|
|
|
|
2002-05-21 19:29:20 +08:00
|
|
|
if (drawable)
|
|
|
|
type = gimp_drawable_type_with_alpha (drawable);
|
2000-01-16 17:34:45 +08:00
|
|
|
else
|
2002-05-21 19:29:20 +08:00
|
|
|
type = gimp_image_base_type_with_alpha (gimage);
|
|
|
|
|
|
|
|
layer = gimp_layer_new_from_tiles (paste->tiles,
|
|
|
|
gimage,
|
|
|
|
type,
|
|
|
|
_("Pasted Layer"),
|
|
|
|
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
|
|
|
|
|
2001-03-30 19:16:05 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
if (! layer)
|
|
|
|
return NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
/* Start a group undo */
|
2003-02-13 19:23:50 +08:00
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_PASTE,
|
|
|
|
_("Paste"));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
/* Set the offsets to the center of the image */
|
2001-12-13 07:48:18 +08:00
|
|
|
if (drawable)
|
2001-06-26 20:09:43 +08:00
|
|
|
{
|
2003-05-08 22:06:03 +08:00
|
|
|
gimp_item_offsets (GIMP_ITEM (drawable), &cx, &cy);
|
2001-06-26 20:09:43 +08:00
|
|
|
gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
|
|
|
|
cx += (x1 + x2) >> 1;
|
|
|
|
cy += (y1 + y2) >> 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cx = gimage->width >> 1;
|
|
|
|
cy = gimage->height >> 1;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-05-08 19:52:31 +08:00
|
|
|
GIMP_ITEM (layer)->offset_x = cx - (GIMP_ITEM (layer)->width >> 1);
|
|
|
|
GIMP_ITEM (layer)->offset_y = cy - (GIMP_ITEM (layer)->height >> 1);
|
2001-03-30 19:16:05 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
/* If there is a selection mask clear it--
|
|
|
|
* this might not always be desired, but in general,
|
|
|
|
* it seems like the correct behavior.
|
|
|
|
*/
|
2001-11-29 06:42:19 +08:00
|
|
|
if (! gimp_image_mask_is_empty (gimage) && ! paste_into)
|
2003-02-14 22:14:29 +08:00
|
|
|
gimp_image_mask_clear (gimage, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
/* if there's a drawable, add a new floating selection */
|
|
|
|
if (drawable != NULL)
|
|
|
|
{
|
|
|
|
floating_sel_attach (layer, drawable);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-02-26 01:58:50 +08:00
|
|
|
gimp_item_set_image (GIMP_ITEM (layer), gimage);
|
2001-06-26 20:09:43 +08:00
|
|
|
gimp_image_add_layer (gimage, layer, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-02-11 05:54:12 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
/* end the group undo */
|
2003-02-13 19:23:50 +08:00
|
|
|
gimp_image_undo_group_end (gimage);
|
2001-06-26 20:09:43 +08:00
|
|
|
|
|
|
|
return layer;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-01-16 17:34:45 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
GimpImage *
|
2001-12-13 07:48:18 +08:00
|
|
|
gimp_edit_paste_as_new (Gimp *gimp,
|
|
|
|
GimpImage *invoke,
|
|
|
|
GimpBuffer *paste)
|
1999-07-07 04:43:52 +08:00
|
|
|
{
|
2001-07-03 07:18:10 +08:00
|
|
|
GimpImage *gimage;
|
|
|
|
GimpLayer *layer;
|
1999-07-07 04:43:52 +08:00
|
|
|
|
2001-12-11 23:58:07 +08:00
|
|
|
/* create a new image (always of type GIMP_RGB) */
|
2001-07-06 00:21:36 +08:00
|
|
|
gimage = gimp_create_image (gimp,
|
2001-12-13 07:48:18 +08:00
|
|
|
gimp_buffer_get_width (paste),
|
|
|
|
gimp_buffer_get_height (paste),
|
2001-12-11 23:58:07 +08:00
|
|
|
GIMP_RGB,
|
2001-07-06 00:21:36 +08:00
|
|
|
TRUE);
|
2000-12-30 08:16:50 +08:00
|
|
|
gimp_image_undo_disable (gimage);
|
2001-07-03 04:57:58 +08:00
|
|
|
|
|
|
|
if (invoke)
|
|
|
|
{
|
|
|
|
gimp_image_set_resolution (gimage,
|
|
|
|
invoke->xresolution, invoke->yresolution);
|
|
|
|
gimp_image_set_unit (gimage, invoke->unit);
|
|
|
|
}
|
2001-06-26 20:09:43 +08:00
|
|
|
|
2002-02-26 01:58:50 +08:00
|
|
|
layer = gimp_layer_new_from_tiles (paste->tiles,
|
|
|
|
gimage,
|
2002-05-21 19:29:20 +08:00
|
|
|
gimp_image_base_type_with_alpha (gimage),
|
2001-01-29 07:25:25 +08:00
|
|
|
_("Pasted Layer"),
|
2002-03-04 22:52:54 +08:00
|
|
|
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
|
1999-07-07 04:43:52 +08:00
|
|
|
|
2000-02-11 05:54:12 +08:00
|
|
|
if (layer)
|
2000-01-16 00:32:02 +08:00
|
|
|
{
|
2002-02-26 01:58:50 +08:00
|
|
|
gimp_item_set_image (GIMP_ITEM (layer), gimage);
|
2000-12-30 08:16:50 +08:00
|
|
|
gimp_image_add_layer (gimage, layer, 0);
|
2000-01-02 02:33:40 +08:00
|
|
|
|
2000-12-30 08:16:50 +08:00
|
|
|
gimp_image_undo_enable (gimage);
|
2000-01-02 02:33:40 +08:00
|
|
|
|
2001-11-01 05:18:57 +08:00
|
|
|
gimp_create_display (gimp, gimage, 0x0101);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (gimage);
|
1999-07-07 04:43:52 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
return gimage;
|
2000-01-16 00:32:02 +08:00
|
|
|
}
|
2000-02-11 05:54:12 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
return NULL;
|
1999-07-07 04:43:52 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-06-30 09:14:36 +08:00
|
|
|
gboolean
|
2001-06-30 03:25:03 +08:00
|
|
|
gimp_edit_clear (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
TileManager *buf_tiles;
|
2000-02-11 05:54:12 +08:00
|
|
|
PixelRegion bufPR;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
guchar col[MAX_CHANNELS];
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-12-30 08:16:50 +08:00
|
|
|
gimp_image_get_background (gimage, drawable, col);
|
2001-01-15 05:11:52 +08:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
|
|
|
col [gimp_drawable_bytes (drawable) - 1] = OPAQUE_OPACITY;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-15 05:11:52 +08:00
|
|
|
gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (!(x2 - x1) || !(y2 - y1))
|
2000-01-23 01:53:23 +08:00
|
|
|
return TRUE; /* nothing to do, but the clear succeded */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-15 05:11:52 +08:00
|
|
|
buf_tiles = tile_manager_new ((x2 - x1), (y2 - y1),
|
|
|
|
gimp_drawable_bytes (drawable));
|
1997-11-25 06:05:25 +08:00
|
|
|
pixel_region_init (&bufPR, buf_tiles, 0, 0, (x2 - x1), (y2 - y1), TRUE);
|
|
|
|
color_region (&bufPR, col);
|
|
|
|
|
|
|
|
pixel_region_init (&bufPR, buf_tiles, 0, 0, (x2 - x1), (y2 - y1), FALSE);
|
2003-02-14 22:14:29 +08:00
|
|
|
gimp_image_apply_image (gimage, drawable, &bufPR,
|
|
|
|
TRUE, _("Clear"),
|
2002-03-04 01:38:12 +08:00
|
|
|
GIMP_OPACITY_OPAQUE, GIMP_ERASE_MODE,
|
|
|
|
NULL, x1, y1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* update the image */
|
2001-07-08 06:49:01 +08:00
|
|
|
gimp_drawable_update (drawable,
|
|
|
|
x1, y1,
|
|
|
|
(x2 - x1), (y2 - y1));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* free the temporary tiles */
|
|
|
|
tile_manager_destroy (buf_tiles);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1998-06-30 09:14:36 +08:00
|
|
|
gboolean
|
2001-06-30 03:25:03 +08:00
|
|
|
gimp_edit_fill (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpFillType fill_type)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
TileManager *buf_tiles;
|
2000-02-11 05:54:12 +08:00
|
|
|
PixelRegion bufPR;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
guchar col[MAX_CHANNELS];
|
2003-02-17 19:32:02 +08:00
|
|
|
const gchar *undo_desc;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-15 05:11:52 +08:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
|
|
|
col [gimp_drawable_bytes (drawable) - 1] = OPAQUE_OPACITY;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-03-24 22:54:59 +08:00
|
|
|
switch (fill_type)
|
|
|
|
{
|
2002-03-18 19:07:34 +08:00
|
|
|
case GIMP_FOREGROUND_FILL:
|
2000-12-30 08:16:50 +08:00
|
|
|
gimp_image_get_foreground (gimage, drawable, col);
|
2003-02-17 19:32:02 +08:00
|
|
|
undo_desc = _("Fill with FG Color");
|
2000-03-24 22:54:59 +08:00
|
|
|
break;
|
|
|
|
|
2002-03-18 19:07:34 +08:00
|
|
|
case GIMP_BACKGROUND_FILL:
|
2000-12-30 08:16:50 +08:00
|
|
|
gimp_image_get_background (gimage, drawable, col);
|
2003-02-17 19:32:02 +08:00
|
|
|
undo_desc = _("Fill with BG Color");
|
2000-03-24 22:54:59 +08:00
|
|
|
break;
|
|
|
|
|
2002-03-18 19:07:34 +08:00
|
|
|
case GIMP_WHITE_FILL:
|
2001-03-30 19:16:05 +08:00
|
|
|
col[RED_PIX] = 255;
|
2000-03-24 22:54:59 +08:00
|
|
|
col[GREEN_PIX] = 255;
|
2001-03-30 19:16:05 +08:00
|
|
|
col[BLUE_PIX] = 255;
|
2003-02-17 19:32:02 +08:00
|
|
|
undo_desc = _("Fill with White");
|
2000-03-24 22:54:59 +08:00
|
|
|
break;
|
|
|
|
|
2002-03-18 19:07:34 +08:00
|
|
|
case GIMP_TRANSPARENT_FILL:
|
2001-03-30 19:16:05 +08:00
|
|
|
col[RED_PIX] = 0;
|
2000-03-24 22:54:59 +08:00
|
|
|
col[GREEN_PIX] = 0;
|
2001-03-30 19:16:05 +08:00
|
|
|
col[BLUE_PIX] = 0;
|
2001-01-15 05:11:52 +08:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
|
|
|
col [gimp_drawable_bytes (drawable) - 1] = TRANSPARENT_OPACITY;
|
2003-02-17 19:32:02 +08:00
|
|
|
undo_desc = _("Fill with Transparency");
|
2000-03-24 22:54:59 +08:00
|
|
|
break;
|
|
|
|
|
2002-03-18 19:07:34 +08:00
|
|
|
case GIMP_NO_FILL:
|
2000-03-24 22:54:59 +08:00
|
|
|
return TRUE; /* nothing to do, but the fill succeded */
|
|
|
|
|
|
|
|
default:
|
2001-11-20 23:07:45 +08:00
|
|
|
g_warning ("%s: unknown fill type", G_GNUC_PRETTY_FUNCTION);
|
2000-12-30 08:16:50 +08:00
|
|
|
gimp_image_get_background (gimage, drawable, col);
|
2003-02-17 19:32:02 +08:00
|
|
|
undo_desc = _("Fill with BG Color");
|
2000-03-24 22:54:59 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-01-15 05:11:52 +08:00
|
|
|
gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (!(x2 - x1) || !(y2 - y1))
|
2000-01-23 01:53:23 +08:00
|
|
|
return TRUE; /* nothing to do, but the fill succeded */
|
2001-03-30 19:16:05 +08:00
|
|
|
|
2001-01-15 05:11:52 +08:00
|
|
|
buf_tiles = tile_manager_new ((x2 - x1), (y2 - y1),
|
|
|
|
gimp_drawable_bytes (drawable));
|
1997-11-25 06:05:25 +08:00
|
|
|
pixel_region_init (&bufPR, buf_tiles, 0, 0, (x2 - x1), (y2 - y1), TRUE);
|
|
|
|
color_region (&bufPR, col);
|
|
|
|
|
|
|
|
pixel_region_init (&bufPR, buf_tiles, 0, 0, (x2 - x1), (y2 - y1), FALSE);
|
2003-02-14 22:14:29 +08:00
|
|
|
gimp_image_apply_image (gimage, drawable, &bufPR,
|
2003-02-17 19:32:02 +08:00
|
|
|
TRUE, undo_desc,
|
2002-03-04 01:38:12 +08:00
|
|
|
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE,
|
|
|
|
NULL, x1, y1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* update the image */
|
2001-07-08 06:49:01 +08:00
|
|
|
gimp_drawable_update (drawable,
|
|
|
|
x1, y1,
|
|
|
|
(x2 - x1), (y2 - y1));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* free the temporary tiles */
|
|
|
|
tile_manager_destroy (buf_tiles);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|