added "gboolean cut_image" parameter so we can float selections without

2003-05-16  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpimage-mask.[ch] (gimp_image_mask_extract): added
	"gboolean cut_image" parameter so we can float selections
	without cutting them from the original drawable.

	* app/gui/select-commands.c
	* tools/pdbgen/pdb/selection.pdb: pass cut_image == TRUE.

	* app/pdb/selection_cmds.c: regenerated.

	* app/tools/tools-enums.[ch]: added SELECTION_MOVE_COPY value
	to the SelectOps enum.

	* app/tools/gimpselectiontool.c: use the new mode when
	<ctrl>+<alt>-dragging a selction (yes, this is evil but there are
	no modifiers left).

	* app/tools/gimpeditselectiontool.[ch]: extended EditType enum by
	EDIT_MASK_COPY_TO_LAYER_TRANSLATE and pass cut_image == FALSE if
	it's passed to init_edit_selection().

	* app/tools/gimpfreeselecttool.c
	* app/tools/gimpfuzzyselecttool.c
	* app/tools/gimprectselecttool.c: pass the new mode to
	GimpEditSelectionTool.
This commit is contained in:
Michael Natterer 2003-05-16 12:10:47 +00:00 committed by Michael Natterer
parent a8598c6969
commit 9981c4645c
16 changed files with 92 additions and 20 deletions

View File

@ -1,3 +1,30 @@
2003-05-16 Michael Natterer <mitch@gimp.org>
* app/core/gimpimage-mask.[ch] (gimp_image_mask_extract): added
"gboolean cut_image" parameter so we can float selections
without cutting them from the original drawable.
* app/gui/select-commands.c
* tools/pdbgen/pdb/selection.pdb: pass cut_image == TRUE.
* app/pdb/selection_cmds.c: regenerated.
* app/tools/tools-enums.[ch]: added SELECTION_MOVE_COPY value
to the SelectOps enum.
* app/tools/gimpselectiontool.c: use the new mode when
<ctrl>+<alt>-dragging a selction (yes, this is evil but there are
no modifiers left).
* app/tools/gimpeditselectiontool.[ch]: extended EditType enum by
EDIT_MASK_COPY_TO_LAYER_TRANSLATE and pass cut_image == FALSE if
it's passed to init_edit_selection().
* app/tools/gimpfreeselecttool.c
* app/tools/gimpfuzzyselecttool.c
* app/tools/gimprectselecttool.c: pass the new mode to
GimpEditSelectionTool.
2003-05-16 Michael Natterer <mitch@gimp.org> 2003-05-16 Michael Natterer <mitch@gimp.org>
* app/gui/color-notebook.[ch]: added dialog_factory and * app/gui/color-notebook.[ch]: added dialog_factory and

View File

@ -127,7 +127,8 @@ select_float_cmd_callback (GtkWidget *widget,
GimpImage *gimage; GimpImage *gimage;
return_if_no_image (gimage, data); return_if_no_image (gimage, data);
gimp_image_mask_float (gimage, gimp_image_active_drawable (gimage), 0, 0); gimp_image_mask_float (gimage, gimp_image_active_drawable (gimage),
TRUE, 0, 0);
gimp_image_flush (gimage); gimp_image_flush (gimage);
} }

View File

@ -197,7 +197,7 @@ gimp_image_mask_is_empty (GimpImage *gimage)
TileManager * TileManager *
gimp_image_mask_extract (GimpImage *gimage, gimp_image_mask_extract (GimpImage *gimage,
GimpDrawable *drawable, GimpDrawable *drawable,
gboolean cut_gimage, gboolean cut_image,
gboolean keep_indexed, gboolean keep_indexed,
gboolean add_alpha) gboolean add_alpha)
{ {
@ -270,7 +270,7 @@ gimp_image_mask_extract (GimpImage *gimage,
/* If a cut was specified, and the selection mask is not empty, /* If a cut was specified, and the selection mask is not empty,
* push an undo * push an undo
*/ */
if (cut_gimage && non_empty) if (cut_image && non_empty)
gimp_drawable_push_undo (drawable, NULL, x1, y1, x2, y2, NULL, FALSE); gimp_drawable_push_undo (drawable, NULL, x1, y1, x2, y2, NULL, FALSE);
gimp_item_offsets (GIMP_ITEM (drawable), &off_x, &off_y); gimp_item_offsets (GIMP_ITEM (drawable), &off_x, &off_y);
@ -283,7 +283,7 @@ gimp_image_mask_extract (GimpImage *gimage,
pixel_region_init (&srcPR, gimp_drawable_data (drawable), pixel_region_init (&srcPR, gimp_drawable_data (drawable),
x1, y1, x1, y1,
x2 - x1, y2 - y1, x2 - x1, y2 - y1,
cut_gimage); cut_image);
pixel_region_init (&destPR, tiles, pixel_region_init (&destPR, tiles,
0, 0, 0, 0,
x2 - x1, y2 - y1, x2 - x1, y2 - y1,
@ -298,9 +298,9 @@ gimp_image_mask_extract (GimpImage *gimage,
extract_from_region (&srcPR, &destPR, &maskPR, extract_from_region (&srcPR, &destPR, &maskPR,
gimp_drawable_cmap (drawable), gimp_drawable_cmap (drawable),
bg_color, base_type, bg_color, base_type,
gimp_drawable_has_alpha (drawable), cut_gimage); gimp_drawable_has_alpha (drawable), cut_image);
if (cut_gimage) if (cut_image)
{ {
/* Clear the region */ /* Clear the region */
gimp_image_mask_clear (gimage, NULL); gimp_image_mask_clear (gimage, NULL);
@ -332,7 +332,7 @@ gimp_image_mask_extract (GimpImage *gimage,
/* If we're cutting, remove either the layer (or floating selection), /* If we're cutting, remove either the layer (or floating selection),
* the layer mask, or the channel * the layer mask, or the channel
*/ */
if (cut_gimage) if (cut_image)
{ {
if (GIMP_IS_LAYER (drawable)) if (GIMP_IS_LAYER (drawable))
{ {
@ -359,6 +359,7 @@ gimp_image_mask_extract (GimpImage *gimage,
GimpLayer * GimpLayer *
gimp_image_mask_float (GimpImage *gimage, gimp_image_mask_float (GimpImage *gimage,
GimpDrawable *drawable, GimpDrawable *drawable,
gboolean cut_image,
gint off_x, /* optional offset */ gint off_x, /* optional offset */
gint off_y) gint off_y)
{ {
@ -382,8 +383,12 @@ gimp_image_mask_float (GimpImage *gimage,
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_FS_FLOAT, gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_FS_FLOAT,
_("Float Selection")); _("Float Selection"));
/* Cut the selected region */ /* Cut or copy the selected region */
tiles = gimp_image_mask_extract (gimage, drawable, TRUE, FALSE, TRUE); tiles = gimp_image_mask_extract (gimage, drawable, cut_image, FALSE, TRUE);
/* Clear the selection as if we had cut the pixels */
if (! cut_image)
gimp_image_mask_clear (gimage, NULL);
/* Create a new layer from the buffer, using the drawable's type /* Create a new layer from the buffer, using the drawable's type
* because it may be different from the image's type if we cut from * because it may be different from the image's type if we cut from

View File

@ -42,12 +42,13 @@ gboolean gimp_image_mask_is_empty (GimpImage *gimage);
TileManager * gimp_image_mask_extract (GimpImage *gimage, TileManager * gimp_image_mask_extract (GimpImage *gimage,
GimpDrawable *drawable, GimpDrawable *drawable,
gboolean cut_gimage, gboolean cut_image,
gboolean keep_indexed, gboolean keep_indexed,
gboolean add_alpha); gboolean add_alpha);
GimpLayer * gimp_image_mask_float (GimpImage *gimage, GimpLayer * gimp_image_mask_float (GimpImage *gimage,
GimpDrawable *drawable, GimpDrawable *drawable,
gboolean cut_image,
gint off_x, gint off_x,
gint off_y); gint off_y);

View File

@ -127,7 +127,8 @@ select_float_cmd_callback (GtkWidget *widget,
GimpImage *gimage; GimpImage *gimage;
return_if_no_image (gimage, data); return_if_no_image (gimage, data);
gimp_image_mask_float (gimage, gimp_image_active_drawable (gimage), 0, 0); gimp_image_mask_float (gimage, gimp_image_active_drawable (gimage),
TRUE, 0, 0);
gimp_image_flush (gimage); gimp_image_flush (gimage);
} }

View File

@ -369,7 +369,7 @@ selection_float_invoker (Gimp *gimp,
if (success) if (success)
{ {
gimage = gimp_item_get_image (GIMP_ITEM (drawable)); gimage = gimp_item_get_image (GIMP_ITEM (drawable));
layer = gimp_image_mask_float (gimage, drawable, offx, offy); layer = gimp_image_mask_float (gimage, drawable, TRUE, offx, offy);
success = layer != NULL; success = layer != NULL;
} }

View File

@ -296,6 +296,7 @@ init_edit_selection (GimpTool *tool,
break; break;
case EDIT_MASK_TO_LAYER_TRANSLATE: case EDIT_MASK_TO_LAYER_TRANSLATE:
case EDIT_MASK_COPY_TO_LAYER_TRANSLATE:
x1 = edit_select->x1 + off_x; x1 = edit_select->x1 + off_x;
y1 = edit_select->y1 + off_y; y1 = edit_select->y1 + off_y;
x2 = edit_select->x2 + off_x; x2 = edit_select->x2 + off_x;
@ -589,8 +590,11 @@ gimp_edit_selection_tool_motion (GimpTool *tool,
break; break;
case EDIT_MASK_TO_LAYER_TRANSLATE: case EDIT_MASK_TO_LAYER_TRANSLATE:
case EDIT_MASK_COPY_TO_LAYER_TRANSLATE:
if (! gimp_image_mask_float (gdisp->gimage, if (! gimp_image_mask_float (gdisp->gimage,
gimp_image_active_drawable (gdisp->gimage), gimp_image_active_drawable (gdisp->gimage),
edit_select->edit_type ==
EDIT_MASK_TO_LAYER_TRANSLATE,
0, 0)) 0, 0))
{ {
/* no region to float, abort safely */ /* no region to float, abort safely */
@ -741,6 +745,7 @@ gimp_edit_selection_tool_draw (GimpDrawTool *draw_tool)
break; break;
case EDIT_MASK_TO_LAYER_TRANSLATE: case EDIT_MASK_TO_LAYER_TRANSLATE:
case EDIT_MASK_COPY_TO_LAYER_TRANSLATE:
gimp_draw_tool_draw_rectangle (draw_tool, gimp_draw_tool_draw_rectangle (draw_tool,
FALSE, FALSE,
edit_select->x1, edit_select->x1,
@ -1089,7 +1094,8 @@ gimp_edit_selection_tool_arrow_key (GimpTool *tool,
{ {
case EDIT_MASK_TRANSLATE: case EDIT_MASK_TRANSLATE:
case EDIT_MASK_TO_LAYER_TRANSLATE: case EDIT_MASK_TO_LAYER_TRANSLATE:
/* this won't happen */ case EDIT_MASK_COPY_TO_LAYER_TRANSLATE:
/* this won't happen */
break; break;
case EDIT_LAYER_TRANSLATE: case EDIT_LAYER_TRANSLATE:

View File

@ -24,6 +24,7 @@ typedef enum
{ {
EDIT_MASK_TRANSLATE, EDIT_MASK_TRANSLATE,
EDIT_MASK_TO_LAYER_TRANSLATE, EDIT_MASK_TO_LAYER_TRANSLATE,
EDIT_MASK_COPY_TO_LAYER_TRANSLATE,
EDIT_LAYER_TRANSLATE, EDIT_LAYER_TRANSLATE,
EDIT_FLOATING_SEL_TRANSLATE EDIT_FLOATING_SEL_TRANSLATE
} EditType; } EditType;

View File

@ -206,6 +206,9 @@ gimp_free_select_tool_button_press (GimpTool *tool,
case SELECTION_MOVE: case SELECTION_MOVE:
init_edit_selection (tool, gdisp, coords, EDIT_MASK_TO_LAYER_TRANSLATE); init_edit_selection (tool, gdisp, coords, EDIT_MASK_TO_LAYER_TRANSLATE);
return; return;
case SELECTION_MOVE_COPY:
init_edit_selection (tool, gdisp, coords, EDIT_MASK_COPY_TO_LAYER_TRANSLATE);
return;
default: default:
break; break;
} }

View File

@ -231,6 +231,9 @@ gimp_fuzzy_select_tool_button_press (GimpTool *tool,
case SELECTION_MOVE: case SELECTION_MOVE:
init_edit_selection (tool, gdisp, coords, EDIT_MASK_TO_LAYER_TRANSLATE); init_edit_selection (tool, gdisp, coords, EDIT_MASK_TO_LAYER_TRANSLATE);
return; return;
case SELECTION_MOVE_COPY:
init_edit_selection (tool, gdisp, coords, EDIT_MASK_COPY_TO_LAYER_TRANSLATE);
return;
default: default:
break; break;
} }

View File

@ -229,6 +229,9 @@ gimp_rect_select_tool_button_press (GimpTool *tool,
case SELECTION_MOVE: case SELECTION_MOVE:
init_edit_selection (tool, gdisp, coords, EDIT_MASK_TO_LAYER_TRANSLATE); init_edit_selection (tool, gdisp, coords, EDIT_MASK_TO_LAYER_TRANSLATE);
return; return;
case SELECTION_MOVE_COPY:
init_edit_selection (tool, gdisp, coords, EDIT_MASK_COPY_TO_LAYER_TRANSLATE);
return;
default: default:
break; break;
} }

View File

@ -231,6 +231,9 @@ gimp_fuzzy_select_tool_button_press (GimpTool *tool,
case SELECTION_MOVE: case SELECTION_MOVE:
init_edit_selection (tool, gdisp, coords, EDIT_MASK_TO_LAYER_TRANSLATE); init_edit_selection (tool, gdisp, coords, EDIT_MASK_TO_LAYER_TRANSLATE);
return; return;
case SELECTION_MOVE_COPY:
init_edit_selection (tool, gdisp, coords, EDIT_MASK_COPY_TO_LAYER_TRANSLATE);
return;
default: default:
break; break;
} }

View File

@ -179,6 +179,8 @@ gimp_selection_tool_oper_update (GimpTool *tool,
GimpSelectionOptions *options; GimpSelectionOptions *options;
GimpLayer *layer; GimpLayer *layer;
GimpLayer *floating_sel; GimpLayer *floating_sel;
gboolean move_layer = FALSE;
gboolean move_floating_sel = FALSE;
selection_tool = GIMP_SELECTION_TOOL (tool); selection_tool = GIMP_SELECTION_TOOL (tool);
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options); options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
@ -186,15 +188,29 @@ gimp_selection_tool_oper_update (GimpTool *tool,
layer = gimp_image_pick_correlate_layer (gdisp->gimage, coords->x, coords->y); layer = gimp_image_pick_correlate_layer (gdisp->gimage, coords->x, coords->y);
floating_sel = gimp_image_floating_sel (gdisp->gimage); floating_sel = gimp_image_floating_sel (gdisp->gimage);
if ((state & GDK_MOD1_MASK) && ! gimp_image_mask_is_empty (gdisp->gimage)) if (layer)
{
if (floating_sel)
{
if (layer == floating_sel)
move_floating_sel = TRUE;
}
else if (gimp_image_mask_value (gdisp->gimage, coords->x, coords->y))
{
move_layer = TRUE;
}
}
if ((state & GDK_MOD1_MASK) && (state & GDK_CONTROL_MASK) && move_layer)
{
selection_tool->op = SELECTION_MOVE_COPY; /* move a copy of the selection */
}
else if ((state & GDK_MOD1_MASK) && ! gimp_image_mask_is_empty (gdisp->gimage))
{ {
selection_tool->op = SELECTION_MOVE_MASK; /* move the selection mask */ selection_tool->op = SELECTION_MOVE_MASK; /* move the selection mask */
} }
else if (! (state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK)) && else if (! (state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK)) &&
layer && (move_layer || move_floating_sel))
(layer == floating_sel ||
(gimp_image_mask_value (gdisp->gimage, coords->x, coords->y) &&
floating_sel == NULL)))
{ {
selection_tool->op = SELECTION_MOVE; /* move the selection */ selection_tool->op = SELECTION_MOVE; /* move the selection */
} }
@ -252,8 +268,8 @@ gimp_selection_tool_cursor_update (GimpTool *tool,
cmodifier = GIMP_CURSOR_MODIFIER_MOVE; cmodifier = GIMP_CURSOR_MODIFIER_MOVE;
break; break;
case SELECTION_MOVE: case SELECTION_MOVE:
case SELECTION_MOVE_COPY:
tool_cursor = GIMP_MOVE_TOOL_CURSOR; tool_cursor = GIMP_MOVE_TOOL_CURSOR;
cmodifier = GIMP_CURSOR_MODIFIER_NONE;
break; break;
case SELECTION_ANCHOR: case SELECTION_ANCHOR:
cmodifier = GIMP_CURSOR_MODIFIER_ANCHOR; cmodifier = GIMP_CURSOR_MODIFIER_ANCHOR;

View File

@ -36,6 +36,7 @@ static const GEnumValue select_ops_enum_values[] =
{ SELECTION_INTERSECT, "SELECTION_INTERSECT", "intersect" }, { SELECTION_INTERSECT, "SELECTION_INTERSECT", "intersect" },
{ SELECTION_MOVE_MASK, "SELECTION_MOVE_MASK", "move-mask" }, { SELECTION_MOVE_MASK, "SELECTION_MOVE_MASK", "move-mask" },
{ SELECTION_MOVE, "SELECTION_MOVE", "move" }, { SELECTION_MOVE, "SELECTION_MOVE", "move" },
{ SELECTION_MOVE_COPY, "SELECTION_MOVE_COPY", "move-copy" },
{ SELECTION_ANCHOR, "SELECTION_ANCHOR", "anchor" }, { SELECTION_ANCHOR, "SELECTION_ANCHOR", "anchor" },
{ 0, NULL, NULL } { 0, NULL, NULL }
}; };

View File

@ -59,6 +59,7 @@ typedef enum /*< pdb-skip >*/ /*< skip >*/
SELECTION_INTERSECT = GIMP_CHANNEL_OP_INTERSECT, SELECTION_INTERSECT = GIMP_CHANNEL_OP_INTERSECT,
SELECTION_MOVE_MASK, SELECTION_MOVE_MASK,
SELECTION_MOVE, SELECTION_MOVE,
SELECTION_MOVE_COPY,
SELECTION_ANCHOR SELECTION_ANCHOR
} SelectOps; } SelectOps;

View File

@ -190,7 +190,7 @@ HELP
code => <<'CODE' code => <<'CODE'
{ {
gimage = gimp_item_get_image (GIMP_ITEM (drawable)); gimage = gimp_item_get_image (GIMP_ITEM (drawable));
layer = gimp_image_mask_float (gimage, drawable, offx, offy); layer = gimp_image_mask_float (gimage, drawable, TRUE, offx, offy);
success = layer != NULL; success = layer != NULL;
} }
CODE CODE