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-04-28 01:27:28 +08:00
|
|
|
#include "config.h"
|
2000-01-26 07:06:12 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "appenv.h"
|
|
|
|
#include "drawable.h"
|
1998-01-22 15:02:57 +08:00
|
|
|
#include "layer.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "floating_sel.h"
|
1998-09-27 04:07:46 +08:00
|
|
|
#include "gdisplay.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "gimage.h"
|
|
|
|
#include "gimage_mask.h"
|
|
|
|
#include "paint_funcs.h"
|
|
|
|
#include "undo.h"
|
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
#include "layer_pvt.h"
|
|
|
|
#include "tile_manager_pvt.h" /* ick. */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-04-28 01:27:28 +08:00
|
|
|
#include "libgimp/gimpmath.h"
|
|
|
|
|
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
void
|
1999-08-22 19:45:31 +08:00
|
|
|
floating_sel_attach (Layer *layer,
|
1998-01-22 15:02:57 +08:00
|
|
|
GimpDrawable *drawable)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
GImage *gimage;
|
1998-01-22 15:02:57 +08:00
|
|
|
Layer *floating_sel;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
if (! (gimage = drawable_gimage (drawable)))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* If there is already a floating selection, anchor it */
|
1998-01-22 15:02:57 +08:00
|
|
|
if (gimage->floating_sel != NULL)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
floating_sel = gimage->floating_sel;
|
|
|
|
floating_sel_anchor (gimage_floating_sel (gimage));
|
|
|
|
|
|
|
|
/* if we were pasting to the old floating selection, paste now to the drawable */
|
1999-08-22 19:45:31 +08:00
|
|
|
if (drawable == GIMP_DRAWABLE (floating_sel))
|
1998-01-22 15:02:57 +08:00
|
|
|
drawable = gimage_active_drawable (gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set the drawable and allocate a backing store */
|
|
|
|
layer->preserve_trans = TRUE;
|
1998-01-22 15:02:57 +08:00
|
|
|
layer->fs.drawable = drawable;
|
1999-08-22 19:45:31 +08:00
|
|
|
layer->fs.backing_store =
|
|
|
|
tile_manager_new (GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height,
|
|
|
|
drawable_bytes (drawable));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* because setting the sensitivity in the layers_dialog lock call redraws the
|
|
|
|
* previews, we need to lock the dialogs before the floating sel is actually added.
|
|
|
|
* however, they won't lock unless we set the gimage's floating sel pointer
|
|
|
|
*/
|
1998-01-22 15:02:57 +08:00
|
|
|
gimage->floating_sel = layer;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* add the layer to the gimage */
|
|
|
|
gimage_add_layer (gimage, layer, 0);
|
|
|
|
|
|
|
|
/* store the affected area from the drawable in the backing store */
|
|
|
|
floating_sel_rigor (layer, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
floating_sel_remove (Layer *layer)
|
|
|
|
{
|
|
|
|
GImage *gimage;
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
if (! (gimage = drawable_gimage (layer->fs.drawable)))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* store the affected area from the drawable in the backing store */
|
|
|
|
floating_sel_relax (layer, TRUE);
|
|
|
|
|
|
|
|
/* invalidate the preview of the obscured drawable. We do this here
|
|
|
|
* because it will not be done until the floating selection is removed,
|
|
|
|
* at which point the obscured drawable's preview will not be declared invalid
|
|
|
|
*/
|
2000-06-04 02:19:22 +08:00
|
|
|
gimp_drawable_invalidate_preview (GIMP_DRAWABLE (layer), TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* remove the layer from the gimage */
|
1998-01-22 15:02:57 +08:00
|
|
|
gimage_remove_layer (gimage, layer);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
floating_sel_anchor (Layer *layer)
|
|
|
|
{
|
|
|
|
GImage *gimage;
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
if (! (gimage = drawable_gimage (GIMP_DRAWABLE (layer))))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
if (! layer_is_floating_sel (layer))
|
|
|
|
{
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
|
|
|
g_message (_("Cannot anchor this layer because\nit is not a floating selection."));
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start a floating selection anchoring undo */
|
|
|
|
undo_push_group_start (gimage, FS_ANCHOR_UNDO);
|
|
|
|
|
1999-09-12 05:51:08 +08:00
|
|
|
/* Invalidate the previews of the layer that will be composited with the floating section. */
|
|
|
|
|
2000-06-04 02:19:22 +08:00
|
|
|
gimp_drawable_invalidate_preview (layer->fs.drawable, TRUE);
|
1999-09-12 05:51:08 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Relax the floating selection */
|
|
|
|
floating_sel_relax (layer, TRUE);
|
|
|
|
|
|
|
|
/* Composite the floating selection contents */
|
1999-08-22 19:45:31 +08:00
|
|
|
floating_sel_composite (layer,
|
|
|
|
GIMP_DRAWABLE (layer)->offset_x,
|
|
|
|
GIMP_DRAWABLE (layer)->offset_y,
|
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* remove the floating selection */
|
1998-01-22 15:02:57 +08:00
|
|
|
gimage_remove_layer (gimage, layer);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* end the group undo */
|
|
|
|
undo_push_group_end (gimage);
|
|
|
|
|
|
|
|
/* invalidate the boundaries */
|
|
|
|
gimage_mask_invalidate (gimage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-08-22 19:45:31 +08:00
|
|
|
floating_sel_reset (Layer *layer)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
GImage *gimage;
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
if (! (gimage = drawable_gimage (GIMP_DRAWABLE (layer))))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* set the underlying drawable to active */
|
1999-08-22 19:45:31 +08:00
|
|
|
if (GIMP_IS_LAYER (layer->fs.drawable))
|
1998-01-22 15:02:57 +08:00
|
|
|
gimage_set_active_layer (gimage, GIMP_LAYER (layer->fs.drawable));
|
1999-08-22 19:45:31 +08:00
|
|
|
else if (GIMP_IS_LAYER_MASK (layer->fs.drawable))
|
|
|
|
gimage_set_active_layer (gimage,
|
|
|
|
GIMP_LAYER_MASK (layer->fs.drawable)->layer);
|
|
|
|
else if (GIMP_IS_CHANNEL (layer->fs.drawable))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
gimage_set_active_channel (gimage, GIMP_CHANNEL (layer->fs.drawable));
|
1997-11-25 06:05:25 +08:00
|
|
|
if (gimage->layers)
|
1998-01-22 15:02:57 +08:00
|
|
|
gimage->active_layer = (((Layer *) gimage->layer_stack->data));
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
1998-01-22 15:02:57 +08:00
|
|
|
gimage->active_layer = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
floating_sel_to_layer (Layer *layer)
|
|
|
|
{
|
|
|
|
FStoLayerUndo *fsu;
|
|
|
|
int off_x, off_y;
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
GImage *gimage;
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
if (! (gimage = drawable_gimage (GIMP_DRAWABLE (layer))))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Check if the floating layer belongs to a channel... */
|
1999-08-22 19:45:31 +08:00
|
|
|
if (GIMP_IS_CHANNEL (layer->fs.drawable))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
|
|
|
g_message (_("Cannot create a new layer from the floating\n"
|
1998-05-28 17:03:57 +08:00
|
|
|
"selection because it belongs to a\n"
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
|
|
|
"layer mask or channel."));
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* restore the contents of the drawable */
|
1999-08-22 19:45:31 +08:00
|
|
|
floating_sel_restore (layer,
|
|
|
|
GIMP_DRAWABLE (layer)->offset_x,
|
|
|
|
GIMP_DRAWABLE (layer)->offset_y,
|
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* determine whether the resulting layer needs an update */
|
|
|
|
drawable_offsets (layer->fs.drawable, &off_x, &off_y);
|
|
|
|
width = drawable_width (layer->fs.drawable);
|
|
|
|
height = drawable_height (layer->fs.drawable);
|
|
|
|
|
|
|
|
/* update the fs drawable--this updates the gimage composite preview
|
|
|
|
* as well as the underlying drawable's
|
|
|
|
*/
|
2000-06-04 02:19:22 +08:00
|
|
|
gimp_drawable_invalidate_preview (GIMP_DRAWABLE (layer), TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* allocate the undo structure */
|
1999-08-22 19:45:31 +08:00
|
|
|
fsu = g_new (FStoLayerUndo, 1);
|
|
|
|
fsu->layer = layer;
|
1997-11-25 06:05:25 +08:00
|
|
|
fsu->drawable = layer->fs.drawable;
|
|
|
|
|
|
|
|
undo_push_fs_to_layer (gimage, fsu);
|
|
|
|
|
|
|
|
/* clear the selection */
|
|
|
|
layer_invalidate_boundary (layer);
|
|
|
|
|
|
|
|
/* Set pointers */
|
1998-01-22 15:02:57 +08:00
|
|
|
layer->fs.drawable = NULL;
|
|
|
|
gimage->floating_sel = NULL;
|
1999-08-22 19:45:31 +08:00
|
|
|
GIMP_DRAWABLE (layer)->visible = TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-03-28 05:21:57 +08:00
|
|
|
/* if the floating selection exceeds the attached layer's extents,
|
|
|
|
update the new layer */
|
|
|
|
|
|
|
|
/* I don't think that the preview is ever valid as is, since the layer
|
|
|
|
will be added on top of the others. Revert this if I'm wrong.
|
|
|
|
msw@gimp.org
|
|
|
|
*/
|
|
|
|
|
2000-01-26 07:06:12 +08:00
|
|
|
drawable_update (GIMP_DRAWABLE (layer),
|
|
|
|
0, 0,
|
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height);
|
1998-10-01 19:53:20 +08:00
|
|
|
|
1998-09-27 04:07:46 +08:00
|
|
|
/* This may be undesirable when invoked non-interactively... we'll see. */
|
1998-10-01 19:53:20 +08:00
|
|
|
/*reinit_layer_idlerender (gimage, layer);*/
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
floating_sel_store (Layer *layer,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int w,
|
|
|
|
int h)
|
|
|
|
{
|
|
|
|
PixelRegion srcPR, destPR;
|
|
|
|
int offx, offy;
|
|
|
|
int x1, y1, x2, y2;
|
|
|
|
|
|
|
|
/* Check the backing store & make sure it has the correct dimensions */
|
1998-08-16 03:17:36 +08:00
|
|
|
if (layer->fs.backing_store->width != drawable_width (GIMP_DRAWABLE(layer)) ||
|
|
|
|
layer->fs.backing_store->height != drawable_height (GIMP_DRAWABLE(layer)) ||
|
|
|
|
layer->fs.backing_store->bpp != drawable_bytes (layer->fs.drawable))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
/* free the backing store and allocate anew */
|
|
|
|
tile_manager_destroy (layer->fs.backing_store);
|
|
|
|
|
2000-01-26 07:06:12 +08:00
|
|
|
layer->fs.backing_store = tile_manager_new (GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height,
|
1997-11-25 06:05:25 +08:00
|
|
|
drawable_bytes (layer->fs.drawable));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* What this function does is save the specified area of the
|
|
|
|
* drawable that this floating selection obscures. We do this so
|
|
|
|
* that it will be possible to subsequently restore the drawable's area
|
|
|
|
*/
|
|
|
|
drawable_offsets (layer->fs.drawable, &offx, &offy);
|
|
|
|
|
|
|
|
/* Find the minimum area we need to uncover -- in gimage space */
|
2000-01-26 07:06:12 +08:00
|
|
|
x1 = MAX (GIMP_DRAWABLE (layer)->offset_x, offx);
|
|
|
|
y1 = MAX (GIMP_DRAWABLE (layer)->offset_y, offy);
|
|
|
|
x2 = MIN (GIMP_DRAWABLE (layer)->offset_x + GIMP_DRAWABLE (layer)->width,
|
|
|
|
offx + drawable_width (layer->fs.drawable));
|
|
|
|
y2 = MIN (GIMP_DRAWABLE (layer)->offset_y + GIMP_DRAWABLE (layer)->height,
|
|
|
|
offy + drawable_height (layer->fs.drawable));
|
|
|
|
|
|
|
|
x1 = CLAMP (x, x1, x2);
|
|
|
|
y1 = CLAMP (y, y1, y2);
|
|
|
|
x2 = CLAMP (x + w, x1, x2);
|
|
|
|
y2 = CLAMP (y + h, y1, y2);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if ((x2 - x1) > 0 && (y2 - y1) > 0)
|
|
|
|
{
|
|
|
|
/* Copy the area from the drawable to the backing store */
|
|
|
|
pixel_region_init (&srcPR, drawable_data (layer->fs.drawable),
|
|
|
|
(x1 - offx), (y1 - offy), (x2 - x1), (y2 - y1), FALSE);
|
|
|
|
pixel_region_init (&destPR, layer->fs.backing_store,
|
2000-01-26 07:06:12 +08:00
|
|
|
(x1 - GIMP_DRAWABLE (layer)->offset_x),
|
|
|
|
(y1 - GIMP_DRAWABLE(layer)->offset_y),
|
|
|
|
(x2 - x1), (y2 - y1), TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
copy_region (&srcPR, &destPR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
floating_sel_restore (Layer *layer,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int w,
|
|
|
|
int h)
|
|
|
|
{
|
|
|
|
PixelRegion srcPR, destPR;
|
|
|
|
int offx, offy;
|
|
|
|
int x1, y1, x2, y2;
|
|
|
|
|
|
|
|
/* What this function does is "uncover" the specified area in the
|
|
|
|
* drawable that this floating selection obscures. We do this so
|
|
|
|
* that either the floating selection can be removed or it can be
|
|
|
|
* translated
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Find the minimum area we need to uncover -- in gimage space */
|
|
|
|
drawable_offsets (layer->fs.drawable, &offx, &offy);
|
2000-01-26 07:06:12 +08:00
|
|
|
x1 = MAX (GIMP_DRAWABLE (layer)->offset_x, offx);
|
|
|
|
y1 = MAX (GIMP_DRAWABLE (layer)->offset_y, offy);
|
|
|
|
x2 = MIN (GIMP_DRAWABLE (layer)->offset_x + GIMP_DRAWABLE (layer)->width,
|
|
|
|
offx + drawable_width (layer->fs.drawable));
|
|
|
|
y2 = MIN (GIMP_DRAWABLE(layer)->offset_y + GIMP_DRAWABLE (layer)->height,
|
|
|
|
offy + drawable_height (layer->fs.drawable));
|
|
|
|
|
|
|
|
x1 = CLAMP (x, x1, x2);
|
|
|
|
y1 = CLAMP (y, y1, y2);
|
|
|
|
x2 = CLAMP (x + w, x1, x2);
|
|
|
|
y2 = CLAMP (y + h, y1, y2);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if ((x2 - x1) > 0 && (y2 - y1) > 0)
|
|
|
|
{
|
|
|
|
/* Copy the area from the backing store to the drawable */
|
|
|
|
pixel_region_init (&srcPR, layer->fs.backing_store,
|
2000-01-26 07:06:12 +08:00
|
|
|
(x1 - GIMP_DRAWABLE (layer)->offset_x),
|
|
|
|
(y1 - GIMP_DRAWABLE (layer)->offset_y),
|
|
|
|
(x2 - x1), (y2 - y1), FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
pixel_region_init (&destPR, drawable_data (layer->fs.drawable),
|
|
|
|
(x1 - offx), (y1 - offy), (x2 - x1), (y2 - y1), TRUE);
|
|
|
|
|
|
|
|
copy_region (&srcPR, &destPR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
floating_sel_rigor (Layer *layer,
|
|
|
|
int undo)
|
|
|
|
{
|
1998-06-29 08:24:44 +08:00
|
|
|
GImage *gimage = GIMP_DRAWABLE(layer)->gimage;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* store the affected area from the drawable in the backing store */
|
2000-01-26 07:06:12 +08:00
|
|
|
floating_sel_store (layer,
|
|
|
|
GIMP_DRAWABLE (layer)->offset_x,
|
|
|
|
GIMP_DRAWABLE (layer)->offset_y,
|
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height);
|
1997-11-25 06:05:25 +08:00
|
|
|
layer->fs.initial = TRUE;
|
|
|
|
|
|
|
|
if (undo)
|
2000-01-26 07:06:12 +08:00
|
|
|
undo_push_fs_rigor (gimage, GIMP_DRAWABLE (layer)->ID);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
floating_sel_relax (Layer *layer,
|
|
|
|
int undo)
|
|
|
|
{
|
1998-06-29 08:24:44 +08:00
|
|
|
GImage *gimage = GIMP_DRAWABLE(layer)->gimage;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* restore the contents of drawable the floating layer is attached to */
|
|
|
|
if (layer->fs.initial == FALSE)
|
2000-01-26 07:06:12 +08:00
|
|
|
floating_sel_restore (layer,
|
|
|
|
GIMP_DRAWABLE (layer)->offset_x,
|
|
|
|
GIMP_DRAWABLE (layer)->offset_y,
|
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height);
|
1997-11-25 06:05:25 +08:00
|
|
|
layer->fs.initial = TRUE;
|
|
|
|
|
|
|
|
if (undo)
|
2000-01-26 07:06:12 +08:00
|
|
|
undo_push_fs_relax (gimage, GIMP_DRAWABLE (layer)->ID);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
floating_sel_composite (Layer *layer,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int w,
|
|
|
|
int h,
|
|
|
|
int undo)
|
|
|
|
{
|
|
|
|
PixelRegion fsPR;
|
|
|
|
GImage *gimage;
|
|
|
|
Layer *d_layer;
|
|
|
|
int preserve_trans;
|
|
|
|
int active[MAX_CHANNELS];
|
|
|
|
int offx, offy;
|
|
|
|
int x1, y1, x2, y2;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
d_layer = NULL;
|
|
|
|
|
2000-01-26 07:06:12 +08:00
|
|
|
if (! (gimage = drawable_gimage (GIMP_DRAWABLE (layer))))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* What this function does is composite the specified area of the
|
|
|
|
* drawble with the floating selection. We do this when the gimage
|
|
|
|
* is constructed, before any other composition takes place.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* If this isn't the first composite, restore the image underneath */
|
|
|
|
if (! layer->fs.initial)
|
|
|
|
floating_sel_restore (layer, x, y, w, h);
|
1998-01-22 15:02:57 +08:00
|
|
|
else if (GIMP_DRAWABLE(layer)->visible)
|
1997-11-25 06:05:25 +08:00
|
|
|
layer->fs.initial = FALSE;
|
|
|
|
|
|
|
|
/* First restore what's behind the image if necessary, then check for visibility */
|
1998-01-22 15:02:57 +08:00
|
|
|
if (GIMP_DRAWABLE(layer)->visible)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
/* Find the minimum area we need to composite -- in gimage space */
|
|
|
|
drawable_offsets (layer->fs.drawable, &offx, &offy);
|
2000-01-26 07:06:12 +08:00
|
|
|
x1 = MAX (GIMP_DRAWABLE (layer)->offset_x, offx);
|
|
|
|
y1 = MAX (GIMP_DRAWABLE (layer)->offset_y, offy);
|
|
|
|
x2 = MIN (GIMP_DRAWABLE (layer)->offset_x +
|
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
offx + drawable_width (layer->fs.drawable));
|
|
|
|
y2 = MIN (GIMP_DRAWABLE (layer)->offset_y +
|
|
|
|
GIMP_DRAWABLE (layer)->height,
|
|
|
|
offy + drawable_height (layer->fs.drawable));
|
|
|
|
|
|
|
|
x1 = CLAMP (x, x1, x2);
|
|
|
|
y1 = CLAMP (y, y1, y2);
|
|
|
|
x2 = CLAMP (x + w, x1, x2);
|
|
|
|
y2 = CLAMP (y + h, y1, y2);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if ((x2 - x1) > 0 && (y2 - y1) > 0)
|
|
|
|
{
|
|
|
|
/* composite the area from the layer to the drawable */
|
2000-01-26 07:06:12 +08:00
|
|
|
pixel_region_init (&fsPR, GIMP_DRAWABLE (layer)->tiles,
|
|
|
|
(x1 - GIMP_DRAWABLE (layer)->offset_x),
|
|
|
|
(y1 - GIMP_DRAWABLE (layer)->offset_y),
|
1997-11-25 06:05:25 +08:00
|
|
|
(x2 - x1), (y2 - y1), FALSE);
|
|
|
|
|
|
|
|
/* a kludge here to prevent the case of the drawable
|
|
|
|
* underneath having preserve transparency on, and disallowing
|
|
|
|
* the composited floating selection from being shown
|
|
|
|
*/
|
1999-08-22 19:45:31 +08:00
|
|
|
if (GIMP_IS_LAYER (layer->fs.drawable))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-01-22 15:02:57 +08:00
|
|
|
d_layer = GIMP_LAYER (layer->fs.drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
if ((preserve_trans = d_layer->preserve_trans))
|
|
|
|
d_layer->preserve_trans = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
preserve_trans = FALSE;
|
|
|
|
|
|
|
|
/* We need to set all gimage channels to active to make sure that
|
|
|
|
* nothing strange happens while applying the floating selection.
|
|
|
|
* It wouldn't make sense for the floating selection to be affected
|
|
|
|
* by the active gimage channels.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < MAX_CHANNELS; i++)
|
|
|
|
{
|
|
|
|
active[i] = gimage->active[i];
|
|
|
|
gimage->active[i] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* apply the fs with the undo specified by the value
|
|
|
|
* passed to this function
|
|
|
|
*/
|
|
|
|
gimage_apply_image (gimage, layer->fs.drawable, &fsPR,
|
|
|
|
undo, layer->opacity, layer->mode,
|
|
|
|
NULL,
|
|
|
|
(x1 - offx), (y1 - offy));
|
|
|
|
|
|
|
|
/* restore preserve transparency */
|
|
|
|
if (preserve_trans)
|
|
|
|
d_layer->preserve_trans = TRUE;
|
|
|
|
|
|
|
|
/* restore gimage active channels */
|
|
|
|
for (i = 0; i < MAX_CHANNELS; i++)
|
|
|
|
gimage->active[i] = active[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BoundSeg *
|
|
|
|
floating_sel_boundary (Layer *layer,
|
|
|
|
int *num_segs)
|
|
|
|
{
|
|
|
|
PixelRegion bPR;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (layer->fs.boundary_known == FALSE)
|
|
|
|
{
|
|
|
|
if (layer->fs.segs)
|
|
|
|
g_free (layer->fs.segs);
|
|
|
|
|
|
|
|
/* find the segments */
|
2000-01-26 07:06:12 +08:00
|
|
|
pixel_region_init (&bPR, GIMP_DRAWABLE (layer)->tiles,
|
|
|
|
0, 0,
|
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
layer->fs.segs = find_mask_boundary (&bPR, &layer->fs.num_segs,
|
|
|
|
WithinBounds, 0, 0,
|
2000-01-26 07:06:12 +08:00
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* offset the segments */
|
|
|
|
for (i = 0; i < layer->fs.num_segs; i++)
|
|
|
|
{
|
2000-01-26 07:06:12 +08:00
|
|
|
layer->fs.segs[i].x1 += GIMP_DRAWABLE (layer)->offset_x;
|
|
|
|
layer->fs.segs[i].y1 += GIMP_DRAWABLE (layer)->offset_y;
|
|
|
|
layer->fs.segs[i].x2 += GIMP_DRAWABLE (layer)->offset_x;
|
|
|
|
layer->fs.segs[i].y2 += GIMP_DRAWABLE (layer)->offset_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
layer->fs.boundary_known = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*num_segs = layer->fs.num_segs;
|
|
|
|
return layer->fs.segs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
floating_sel_invalidate (Layer *layer)
|
|
|
|
{
|
|
|
|
/* Invalidate the attached-to drawable's preview */
|
2000-06-04 02:19:22 +08:00
|
|
|
gimp_drawable_invalidate_preview (layer->fs.drawable, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Invalidate the boundary */
|
|
|
|
layer->fs.boundary_known = FALSE;
|
|
|
|
}
|