1997-11-24 22:05:25 +00: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 05:44:11 +00:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-24 22:05:25 +00:00
|
|
|
*/
|
2000-12-16 21:37:03 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
#include <stdlib.h>
|
2000-12-16 21:37:03 +00:00
|
|
|
|
2001-08-14 14:53:55 +00:00
|
|
|
#include <glib-object.h>
|
2001-01-24 22:36:18 +00:00
|
|
|
|
2001-07-04 19:31:35 +00:00
|
|
|
#include "core-types.h"
|
2000-12-16 21:37:03 +00:00
|
|
|
|
2001-05-15 11:25:25 +00:00
|
|
|
#include "base/pixel-region.h"
|
|
|
|
#include "base/tile-manager.h"
|
2001-06-26 12:09:43 +00:00
|
|
|
#include "base/tile-manager-crop.h"
|
2001-05-15 11:25:25 +00:00
|
|
|
|
2001-04-07 15:58:26 +00:00
|
|
|
#include "paint-funcs/paint-funcs.h"
|
|
|
|
|
2001-07-04 19:31:35 +00:00
|
|
|
#include "gimp.h"
|
2001-07-03 18:38:56 +00:00
|
|
|
#include "gimpbuffer.h"
|
|
|
|
#include "gimpchannel.h"
|
|
|
|
#include "gimpcontext.h"
|
|
|
|
#include "gimpedit.h"
|
|
|
|
#include "gimpimage.h"
|
|
|
|
#include "gimpimage-mask.h"
|
2003-02-13 11:23:50 +00:00
|
|
|
#include "gimpimage-undo.h"
|
2001-07-03 18:38:56 +00:00
|
|
|
#include "gimplayer.h"
|
2002-02-21 22:19:45 +00:00
|
|
|
#include "gimplayer-floating-sel.h"
|
2001-07-03 18:38:56 +00:00
|
|
|
#include "gimplist.h"
|
|
|
|
|
1998-11-23 14:47:09 +00:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
1998-01-22 07:02:57 +00:00
|
|
|
|
2001-12-12 23:48:18 +00:00
|
|
|
GimpBuffer *
|
2001-06-29 19:25:03 +00:00
|
|
|
gimp_edit_cut (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
|
|
|
TileManager *cut;
|
|
|
|
TileManager *cropped_cut;
|
2001-06-26 12:09:43 +00:00
|
|
|
gboolean empty;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
/* Start a group undo */
|
2003-02-13 11:23:50 +00:00
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_CUT,
|
|
|
|
_("Cut"));
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
/* See if the gimage mask is empty */
|
2001-11-28 22:42:19 +00:00
|
|
|
empty = gimp_image_mask_is_empty (gimage);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
/* Next, cut the mask portion from the gimage */
|
2001-11-28 22:42:19 +00:00
|
|
|
cut = gimp_image_mask_extract (gimage, drawable, TRUE, FALSE, TRUE);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
if (cut)
|
2002-05-13 15:35:27 +00:00
|
|
|
gimage->gimp->have_current_cut_buffer = TRUE;
|
2001-06-26 12:09:43 +00:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
/* Only crop if the gimage mask wasn't empty */
|
2001-06-26 12:09:43 +00:00
|
|
|
if (cut && ! empty)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2001-06-26 12:09:43 +00:00
|
|
|
cropped_cut = tile_manager_crop (cut, 0);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
if (cropped_cut != cut)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
|
|
|
tile_manager_destroy (cut);
|
|
|
|
cut = NULL;
|
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
else if (cut)
|
|
|
|
cropped_cut = cut;
|
|
|
|
else
|
|
|
|
cropped_cut = NULL;
|
|
|
|
|
|
|
|
/* end the group undo */
|
2003-02-13 11:23:50 +00:00
|
|
|
gimp_image_undo_group_end (gimage);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
if (cropped_cut)
|
|
|
|
{
|
|
|
|
/* Free the old global edit buffer */
|
2001-07-04 19:31:35 +00:00
|
|
|
if (gimage->gimp->global_buffer)
|
2003-01-05 22:07:10 +00:00
|
|
|
g_object_unref (gimage->gimp->global_buffer);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
/* Set the global edit buffer */
|
2001-12-12 23:48:18 +00:00
|
|
|
gimage->gimp->global_buffer = gimp_buffer_new (cropped_cut,
|
|
|
|
"Global Buffer",
|
|
|
|
TRUE);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2001-12-12 23:48:18 +00:00
|
|
|
return gimp_buffer_new (cropped_cut, "Cut Pixels", FALSE);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2001-12-12 23:48:18 +00:00
|
|
|
GimpBuffer *
|
2001-06-29 19:25:03 +00:00
|
|
|
gimp_edit_copy (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2000-02-10 21:54:12 +00:00
|
|
|
TileManager *copy;
|
|
|
|
TileManager *cropped_copy;
|
2001-06-26 12:09:43 +00:00
|
|
|
gboolean empty;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2003-01-02 13:38:09 +00:00
|
|
|
/* Start a group undo */
|
2003-02-13 11:23:50 +00:00
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_COPY,
|
|
|
|
_("Copy"));
|
2003-01-02 13:38:09 +00:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
/* See if the gimage mask is empty */
|
2001-11-28 22:42:19 +00:00
|
|
|
empty = gimp_image_mask_is_empty (gimage);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
/* First, copy the masked portion of the gimage */
|
2001-11-28 22:42:19 +00:00
|
|
|
copy = gimp_image_mask_extract (gimage, drawable, FALSE, FALSE, TRUE);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
if (copy)
|
2002-05-13 15:35:27 +00:00
|
|
|
gimage->gimp->have_current_cut_buffer = TRUE;
|
2001-06-26 12:09:43 +00:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
/* Only crop if the gimage mask wasn't empty */
|
2001-06-26 12:09:43 +00:00
|
|
|
if (copy && ! empty)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2001-06-26 12:09:43 +00:00
|
|
|
cropped_copy = tile_manager_crop (copy, 0);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
if (cropped_copy != copy)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
|
|
|
tile_manager_destroy (copy);
|
|
|
|
copy = NULL;
|
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
else if (copy)
|
|
|
|
cropped_copy = copy;
|
|
|
|
else
|
|
|
|
cropped_copy = NULL;
|
|
|
|
|
2003-01-02 13:38:09 +00:00
|
|
|
/* end the group undo */
|
2003-02-13 11:23:50 +00:00
|
|
|
gimp_image_undo_group_end (gimage);
|
2003-01-02 13:38:09 +00:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
if (cropped_copy)
|
|
|
|
{
|
|
|
|
/* Free the old global edit buffer */
|
2001-07-04 19:31:35 +00:00
|
|
|
if (gimage->gimp->global_buffer)
|
2003-01-05 22:07:10 +00:00
|
|
|
g_object_unref (gimage->gimp->global_buffer);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
/* Set the global edit buffer */
|
2001-12-12 23:48:18 +00:00
|
|
|
gimage->gimp->global_buffer = gimp_buffer_new (cropped_copy,
|
|
|
|
"Global Buffer",
|
|
|
|
TRUE);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2001-12-12 23:48:18 +00:00
|
|
|
return gimp_buffer_new (cropped_copy, "Copied Pixels", FALSE);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2000-02-10 21:54:12 +00:00
|
|
|
GimpLayer *
|
2001-06-29 19:25:03 +00:00
|
|
|
gimp_edit_paste (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable,
|
2001-12-12 23:48:18 +00:00
|
|
|
GimpBuffer *paste,
|
2001-06-29 19:25:03 +00:00
|
|
|
gboolean paste_into)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2002-05-21 11:29:20 +00:00
|
|
|
GimpLayer *layer;
|
|
|
|
GimpImageType type;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
gint cx, cy;
|
2000-02-10 21:54:12 +00:00
|
|
|
|
2001-06-26 12:09:43 +00: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-10 21:54:12 +00:00
|
|
|
*/
|
|
|
|
|
2002-05-21 11:29:20 +00:00
|
|
|
if (drawable)
|
|
|
|
type = gimp_drawable_type_with_alpha (drawable);
|
2000-01-16 09:34:45 +00:00
|
|
|
else
|
2002-05-21 11:29:20 +00: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 11:16:05 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
if (! layer)
|
|
|
|
return NULL;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
/* Start a group undo */
|
2003-02-13 11:23:50 +00:00
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_PASTE,
|
|
|
|
_("Paste"));
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
/* Set the offsets to the center of the image */
|
2001-12-12 23:48:18 +00:00
|
|
|
if (drawable)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
|
|
|
gimp_drawable_offsets (drawable, &cx, &cy);
|
|
|
|
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-24 22:05:25 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
GIMP_DRAWABLE (layer)->offset_x = cx - (GIMP_DRAWABLE (layer)->width >> 1);
|
|
|
|
GIMP_DRAWABLE (layer)->offset_y = cy - (GIMP_DRAWABLE (layer)->height >> 1);
|
2001-03-30 11:16:05 +00:00
|
|
|
|
2001-06-26 12:09:43 +00: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-28 22:42:19 +00:00
|
|
|
if (! gimp_image_mask_is_empty (gimage) && ! paste_into)
|
2003-02-14 14:14:29 +00:00
|
|
|
gimp_image_mask_clear (gimage, NULL);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
/* if there's a drawable, add a new floating selection */
|
|
|
|
if (drawable != NULL)
|
|
|
|
{
|
|
|
|
floating_sel_attach (layer, drawable);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-02-25 17:58:50 +00:00
|
|
|
gimp_item_set_image (GIMP_ITEM (layer), gimage);
|
2001-06-26 12:09:43 +00:00
|
|
|
gimp_image_add_layer (gimage, layer, 0);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
2000-02-10 21:54:12 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
/* end the group undo */
|
2003-02-13 11:23:50 +00:00
|
|
|
gimp_image_undo_group_end (gimage);
|
2001-06-26 12:09:43 +00:00
|
|
|
|
|
|
|
return layer;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
2000-01-16 09:34:45 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
GimpImage *
|
2001-12-12 23:48:18 +00:00
|
|
|
gimp_edit_paste_as_new (Gimp *gimp,
|
|
|
|
GimpImage *invoke,
|
|
|
|
GimpBuffer *paste)
|
1999-07-06 20:43:52 +00:00
|
|
|
{
|
2001-07-02 23:18:10 +00:00
|
|
|
GimpImage *gimage;
|
|
|
|
GimpLayer *layer;
|
1999-07-06 20:43:52 +00:00
|
|
|
|
2001-12-11 15:58:07 +00:00
|
|
|
/* create a new image (always of type GIMP_RGB) */
|
2001-07-05 16:21:36 +00:00
|
|
|
gimage = gimp_create_image (gimp,
|
2001-12-12 23:48:18 +00:00
|
|
|
gimp_buffer_get_width (paste),
|
|
|
|
gimp_buffer_get_height (paste),
|
2001-12-11 15:58:07 +00:00
|
|
|
GIMP_RGB,
|
2001-07-05 16:21:36 +00:00
|
|
|
TRUE);
|
2000-12-30 00:16:50 +00:00
|
|
|
gimp_image_undo_disable (gimage);
|
2001-07-02 20:57:58 +00:00
|
|
|
|
|
|
|
if (invoke)
|
|
|
|
{
|
|
|
|
gimp_image_set_resolution (gimage,
|
|
|
|
invoke->xresolution, invoke->yresolution);
|
|
|
|
gimp_image_set_unit (gimage, invoke->unit);
|
|
|
|
}
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2002-02-25 17:58:50 +00:00
|
|
|
layer = gimp_layer_new_from_tiles (paste->tiles,
|
|
|
|
gimage,
|
2002-05-21 11:29:20 +00:00
|
|
|
gimp_image_base_type_with_alpha (gimage),
|
2001-01-28 23:25:25 +00:00
|
|
|
_("Pasted Layer"),
|
2002-03-04 14:52:54 +00:00
|
|
|
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
|
1999-07-06 20:43:52 +00:00
|
|
|
|
2000-02-10 21:54:12 +00:00
|
|
|
if (layer)
|
2000-01-15 16:32:02 +00:00
|
|
|
{
|
2002-02-25 17:58:50 +00:00
|
|
|
gimp_item_set_image (GIMP_ITEM (layer), gimage);
|
2000-12-30 00:16:50 +00:00
|
|
|
gimp_image_add_layer (gimage, layer, 0);
|
2000-01-01 18:33:40 +00:00
|
|
|
|
2000-12-30 00:16:50 +00:00
|
|
|
gimp_image_undo_enable (gimage);
|
2000-01-01 18:33:40 +00:00
|
|
|
|
2001-10-31 21:18:57 +00:00
|
|
|
gimp_create_display (gimp, gimage, 0x0101);
|
|
|
|
|
2003-01-05 22:07:10 +00:00
|
|
|
g_object_unref (gimage);
|
1999-07-06 20:43:52 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
return gimage;
|
2000-01-15 16:32:02 +00:00
|
|
|
}
|
2000-02-10 21:54:12 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
return NULL;
|
1999-07-06 20:43:52 +00:00
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
|
1998-06-30 01:14:36 +00:00
|
|
|
gboolean
|
2001-06-29 19:25:03 +00:00
|
|
|
gimp_edit_clear (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
|
|
|
TileManager *buf_tiles;
|
2000-02-10 21:54:12 +00:00
|
|
|
PixelRegion bufPR;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
guchar col[MAX_CHANNELS];
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2000-12-30 00:16:50 +00:00
|
|
|
gimp_image_get_background (gimage, drawable, col);
|
2001-01-14 21:11:52 +00:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
|
|
|
col [gimp_drawable_bytes (drawable) - 1] = OPAQUE_OPACITY;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-01-14 21:11:52 +00:00
|
|
|
gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
if (!(x2 - x1) || !(y2 - y1))
|
2000-01-22 17:53:23 +00:00
|
|
|
return TRUE; /* nothing to do, but the clear succeded */
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-01-14 21:11:52 +00:00
|
|
|
buf_tiles = tile_manager_new ((x2 - x1), (y2 - y1),
|
|
|
|
gimp_drawable_bytes (drawable));
|
1997-11-24 22:05:25 +00: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 14:14:29 +00:00
|
|
|
gimp_image_apply_image (gimage, drawable, &bufPR,
|
|
|
|
TRUE, _("Clear"),
|
2002-03-03 17:38:12 +00:00
|
|
|
GIMP_OPACITY_OPAQUE, GIMP_ERASE_MODE,
|
|
|
|
NULL, x1, y1);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
/* update the image */
|
2001-07-07 22:49:01 +00:00
|
|
|
gimp_drawable_update (drawable,
|
|
|
|
x1, y1,
|
|
|
|
(x2 - x1), (y2 - y1));
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
/* free the temporary tiles */
|
|
|
|
tile_manager_destroy (buf_tiles);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1998-06-30 01:14:36 +00:00
|
|
|
gboolean
|
2001-06-29 19:25:03 +00:00
|
|
|
gimp_edit_fill (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpFillType fill_type)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
|
|
|
TileManager *buf_tiles;
|
2000-02-10 21:54:12 +00:00
|
|
|
PixelRegion bufPR;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
guchar col[MAX_CHANNELS];
|
2003-02-17 11:32:02 +00:00
|
|
|
const gchar *undo_desc;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-01-14 21:11:52 +00:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
|
|
|
col [gimp_drawable_bytes (drawable) - 1] = OPAQUE_OPACITY;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2000-03-24 14:54:59 +00:00
|
|
|
switch (fill_type)
|
|
|
|
{
|
2002-03-18 11:07:34 +00:00
|
|
|
case GIMP_FOREGROUND_FILL:
|
2000-12-30 00:16:50 +00:00
|
|
|
gimp_image_get_foreground (gimage, drawable, col);
|
2003-02-17 11:32:02 +00:00
|
|
|
undo_desc = _("Fill with FG Color");
|
2000-03-24 14:54:59 +00:00
|
|
|
break;
|
|
|
|
|
2002-03-18 11:07:34 +00:00
|
|
|
case GIMP_BACKGROUND_FILL:
|
2000-12-30 00:16:50 +00:00
|
|
|
gimp_image_get_background (gimage, drawable, col);
|
2003-02-17 11:32:02 +00:00
|
|
|
undo_desc = _("Fill with BG Color");
|
2000-03-24 14:54:59 +00:00
|
|
|
break;
|
|
|
|
|
2002-03-18 11:07:34 +00:00
|
|
|
case GIMP_WHITE_FILL:
|
2001-03-30 11:16:05 +00:00
|
|
|
col[RED_PIX] = 255;
|
2000-03-24 14:54:59 +00:00
|
|
|
col[GREEN_PIX] = 255;
|
2001-03-30 11:16:05 +00:00
|
|
|
col[BLUE_PIX] = 255;
|
2003-02-17 11:32:02 +00:00
|
|
|
undo_desc = _("Fill with White");
|
2000-03-24 14:54:59 +00:00
|
|
|
break;
|
|
|
|
|
2002-03-18 11:07:34 +00:00
|
|
|
case GIMP_TRANSPARENT_FILL:
|
2001-03-30 11:16:05 +00:00
|
|
|
col[RED_PIX] = 0;
|
2000-03-24 14:54:59 +00:00
|
|
|
col[GREEN_PIX] = 0;
|
2001-03-30 11:16:05 +00:00
|
|
|
col[BLUE_PIX] = 0;
|
2001-01-14 21:11:52 +00:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
|
|
|
col [gimp_drawable_bytes (drawable) - 1] = TRANSPARENT_OPACITY;
|
2003-02-17 11:32:02 +00:00
|
|
|
undo_desc = _("Fill with Transparency");
|
2000-03-24 14:54:59 +00:00
|
|
|
break;
|
|
|
|
|
2002-03-18 11:07:34 +00:00
|
|
|
case GIMP_NO_FILL:
|
2000-03-24 14:54:59 +00:00
|
|
|
return TRUE; /* nothing to do, but the fill succeded */
|
|
|
|
|
|
|
|
default:
|
2001-11-20 15:07:45 +00:00
|
|
|
g_warning ("%s: unknown fill type", G_GNUC_PRETTY_FUNCTION);
|
2000-12-30 00:16:50 +00:00
|
|
|
gimp_image_get_background (gimage, drawable, col);
|
2003-02-17 11:32:02 +00:00
|
|
|
undo_desc = _("Fill with BG Color");
|
2000-03-24 14:54:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-01-14 21:11:52 +00:00
|
|
|
gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
if (!(x2 - x1) || !(y2 - y1))
|
2000-01-22 17:53:23 +00:00
|
|
|
return TRUE; /* nothing to do, but the fill succeded */
|
2001-03-30 11:16:05 +00:00
|
|
|
|
2001-01-14 21:11:52 +00:00
|
|
|
buf_tiles = tile_manager_new ((x2 - x1), (y2 - y1),
|
|
|
|
gimp_drawable_bytes (drawable));
|
1997-11-24 22:05:25 +00: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 14:14:29 +00:00
|
|
|
gimp_image_apply_image (gimage, drawable, &bufPR,
|
2003-02-17 11:32:02 +00:00
|
|
|
TRUE, undo_desc,
|
2002-03-03 17:38:12 +00:00
|
|
|
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE,
|
|
|
|
NULL, x1, y1);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
/* update the image */
|
2001-07-07 22:49:01 +00:00
|
|
|
gimp_drawable_update (drawable,
|
|
|
|
x1, y1,
|
|
|
|
(x2 - x1), (y2 - y1));
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
/* free the temporary tiles */
|
|
|
|
tile_manager_destroy (buf_tiles);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|