From 1a259d681a3047dc94a283ba010db871ff1f48fd Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Fri, 12 Apr 2002 12:29:51 +0000 Subject: [PATCH] reordered some lines, no logic changed. 2002-04-12 Michael Natterer * app/core/gimpimage-crop.c: reordered some lines, no logic changed. * app/core/gimplayer.[ch]: made gimp_layer_pick_correlate() return a gboolean, not gint. * app/display/gimpdisplayshell.c * app/gui/layers-commands.[ch] * app/gui/menus.c: added "/Layers/Crop Layer" which resizes the active layer to the current selection's bounds, just as "/Image/Crop Image" --- ChangeLog | 14 +++++++ app/actions/layers-commands.c | 58 +++++++++++++++++++++++------ app/actions/layers-commands.h | 6 ++- app/core/gimpimage-crop.c | 11 +++--- app/core/gimplayer.c | 2 +- app/core/gimplayer.h | 2 +- app/display/gimpdisplayshell-draw.c | 1 + app/display/gimpdisplayshell.c | 1 + app/gui/layers-commands.c | 58 +++++++++++++++++++++++------ app/gui/layers-commands.h | 6 ++- app/gui/menus.c | 5 +++ app/menus/menus.c | 5 +++ 12 files changed, 136 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index a264a52f1c..71298d2f89 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2002-04-12 Michael Natterer + + * app/core/gimpimage-crop.c: reordered some lines, no logic + changed. + + * app/core/gimplayer.[ch]: made gimp_layer_pick_correlate() + return a gboolean, not gint. + + * app/display/gimpdisplayshell.c + * app/gui/layers-commands.[ch] + * app/gui/menus.c: added "/Layers/Crop Layer" which resizes + the active layer to the current selection's bounds, just as + "/Image/Crop Image" + 2002-04-12 Zbigniew Chyla * app/gui/dialogs-constructors.c: Marked some strings for translation. diff --git a/app/actions/layers-commands.c b/app/actions/layers-commands.c index 814c77a064..08b719b323 100644 --- a/app/actions/layers-commands.c +++ b/app/actions/layers-commands.c @@ -240,17 +240,6 @@ layers_delete_cmd_callback (GtkWidget *widget, gdisplays_flush (); } -void -layers_scale_cmd_callback (GtkWidget *widget, - gpointer data) -{ - GimpImage *gimage; - GimpLayer *active_layer; - return_if_no_layer (gimage, active_layer); - - layers_scale_layer_query (gimage, active_layer); -} - void layers_resize_cmd_callback (GtkWidget *widget, gpointer data) @@ -274,6 +263,53 @@ layers_resize_to_image_cmd_callback (GtkWidget *widget, gdisplays_flush (); } +void +layers_scale_cmd_callback (GtkWidget *widget, + gpointer data) +{ + GimpImage *gimage; + GimpLayer *active_layer; + return_if_no_layer (gimage, active_layer); + + layers_scale_layer_query (gimage, active_layer); +} + +void +layers_crop_cmd_callback (GtkWidget *widget, + gpointer data) +{ + GimpImage *gimage; + GimpLayer *active_layer; + gint x1, y1, x2, y2; + gint off_x, off_y; + return_if_no_layer (gimage, active_layer); + + if (! gimp_image_mask_bounds (gimage, &x1, &y1, &x2, &y2)) + { + g_message (_("Cannot crop because the current selection is empty.")); + return; + } + + gimp_drawable_offsets (GIMP_DRAWABLE (active_layer), &off_x, &off_y); + + off_x -= x1; + off_y -= y1; + + undo_push_group_start (gimage, LAYER_RESIZE_UNDO_GROUP); + + if (gimp_layer_is_floating_sel (active_layer)) + floating_sel_relax (active_layer, TRUE); + + gimp_layer_resize (active_layer, x2 - x1, y2 - y1, off_x, off_y); + + if (gimp_layer_is_floating_sel (active_layer)) + floating_sel_rigor (active_layer, TRUE); + + undo_push_group_end (gimage); + + gdisplays_flush (); +} + void layers_add_layer_mask_cmd_callback (GtkWidget *widget, gpointer data) diff --git a/app/actions/layers-commands.h b/app/actions/layers-commands.h index 6b37d245d2..984248597a 100644 --- a/app/actions/layers-commands.h +++ b/app/actions/layers-commands.h @@ -44,12 +44,14 @@ void layers_merge_down_cmd_callback (GtkWidget *widet, void layers_delete_cmd_callback (GtkWidget *widet, gpointer data); -void layers_scale_cmd_callback (GtkWidget *widet, - gpointer data); void layers_resize_cmd_callback (GtkWidget *widet, gpointer data); void layers_resize_to_image_cmd_callback (GtkWidget *widet, gpointer data); +void layers_scale_cmd_callback (GtkWidget *widet, + gpointer data); +void layers_crop_cmd_callback (GtkWidget *widet, + gpointer data); void layers_add_layer_mask_cmd_callback (GtkWidget *widet, gpointer data); diff --git a/app/core/gimpimage-crop.c b/app/core/gimpimage-crop.c index 4944a900d5..e588a656fc 100644 --- a/app/core/gimpimage-crop.c +++ b/app/core/gimpimage-crop.c @@ -101,7 +101,6 @@ gimp_image_crop (GimpImage *gimage, gint width, height; gint lx1, ly1, lx2, ly2; gint off_x, off_y; - gint doff_x, doff_y; g_return_if_fail (gimage != NULL); g_return_if_fail (GIMP_IS_IMAGE (gimage)); @@ -116,18 +115,20 @@ gimp_image_crop (GimpImage *gimage, if (active_layer_only) { - undo_push_group_start (gimage, LAYER_RESIZE_UNDO_GROUP); + gint doff_x, doff_y; layer = gimp_image_get_active_layer (gimage); - if (gimp_layer_is_floating_sel (layer)) - floating_sel_relax (layer, TRUE); - gimp_drawable_offsets (GIMP_DRAWABLE (layer), &doff_x, &doff_y); off_x = (doff_x - x1); off_y = (doff_y - y1); + undo_push_group_start (gimage, LAYER_RESIZE_UNDO_GROUP); + + if (gimp_layer_is_floating_sel (layer)) + floating_sel_relax (layer, TRUE); + gimp_layer_resize (layer, width, height, off_x, off_y); if (gimp_layer_is_floating_sel (layer)) diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c index 49e7ce820b..fc6591251f 100644 --- a/app/core/gimplayer.c +++ b/app/core/gimplayer.c @@ -1391,7 +1391,7 @@ gimp_layer_invalidate_boundary (GimpLayer *layer) floating_sel_invalidate (layer); } -gint +gboolean gimp_layer_pick_correlate (GimpLayer *layer, gint x, gint y) diff --git a/app/core/gimplayer.h b/app/core/gimplayer.h index 4d7256a8ca..93f0326e43 100644 --- a/app/core/gimplayer.h +++ b/app/core/gimplayer.h @@ -126,7 +126,7 @@ void gimp_layer_resize_to_image (GimpLayer *layer); BoundSeg * gimp_layer_boundary (GimpLayer *layer, gint *num_segs); void gimp_layer_invalidate_boundary (GimpLayer *layer); -gint gimp_layer_pick_correlate (GimpLayer *layer, +gboolean gimp_layer_pick_correlate (GimpLayer *layer, gint x, gint y); diff --git a/app/display/gimpdisplayshell-draw.c b/app/display/gimpdisplayshell-draw.c index 1926c1dc36..a68fe6f807 100644 --- a/app/display/gimpdisplayshell-draw.c +++ b/app/display/gimpdisplayshell-draw.c @@ -1048,6 +1048,7 @@ gimp_display_shell_set_menu_sensitivity (GimpDisplayShell *shell, SET_SENSITIVE ("/Layer/Layer Boundary Size...", lp && !aux); SET_SENSITIVE ("/Layer/Layer to Imagesize", lp && !aux); SET_SENSITIVE ("/Layer/Scale Layer...", lp && !aux); + SET_SENSITIVE ("/Layer/Crop Layer", lp && !aux && sel); SET_SENSITIVE ("/Layer/Transform/Offset...", lp); diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c index 1926c1dc36..a68fe6f807 100644 --- a/app/display/gimpdisplayshell.c +++ b/app/display/gimpdisplayshell.c @@ -1048,6 +1048,7 @@ gimp_display_shell_set_menu_sensitivity (GimpDisplayShell *shell, SET_SENSITIVE ("/Layer/Layer Boundary Size...", lp && !aux); SET_SENSITIVE ("/Layer/Layer to Imagesize", lp && !aux); SET_SENSITIVE ("/Layer/Scale Layer...", lp && !aux); + SET_SENSITIVE ("/Layer/Crop Layer", lp && !aux && sel); SET_SENSITIVE ("/Layer/Transform/Offset...", lp); diff --git a/app/gui/layers-commands.c b/app/gui/layers-commands.c index 814c77a064..08b719b323 100644 --- a/app/gui/layers-commands.c +++ b/app/gui/layers-commands.c @@ -240,17 +240,6 @@ layers_delete_cmd_callback (GtkWidget *widget, gdisplays_flush (); } -void -layers_scale_cmd_callback (GtkWidget *widget, - gpointer data) -{ - GimpImage *gimage; - GimpLayer *active_layer; - return_if_no_layer (gimage, active_layer); - - layers_scale_layer_query (gimage, active_layer); -} - void layers_resize_cmd_callback (GtkWidget *widget, gpointer data) @@ -274,6 +263,53 @@ layers_resize_to_image_cmd_callback (GtkWidget *widget, gdisplays_flush (); } +void +layers_scale_cmd_callback (GtkWidget *widget, + gpointer data) +{ + GimpImage *gimage; + GimpLayer *active_layer; + return_if_no_layer (gimage, active_layer); + + layers_scale_layer_query (gimage, active_layer); +} + +void +layers_crop_cmd_callback (GtkWidget *widget, + gpointer data) +{ + GimpImage *gimage; + GimpLayer *active_layer; + gint x1, y1, x2, y2; + gint off_x, off_y; + return_if_no_layer (gimage, active_layer); + + if (! gimp_image_mask_bounds (gimage, &x1, &y1, &x2, &y2)) + { + g_message (_("Cannot crop because the current selection is empty.")); + return; + } + + gimp_drawable_offsets (GIMP_DRAWABLE (active_layer), &off_x, &off_y); + + off_x -= x1; + off_y -= y1; + + undo_push_group_start (gimage, LAYER_RESIZE_UNDO_GROUP); + + if (gimp_layer_is_floating_sel (active_layer)) + floating_sel_relax (active_layer, TRUE); + + gimp_layer_resize (active_layer, x2 - x1, y2 - y1, off_x, off_y); + + if (gimp_layer_is_floating_sel (active_layer)) + floating_sel_rigor (active_layer, TRUE); + + undo_push_group_end (gimage); + + gdisplays_flush (); +} + void layers_add_layer_mask_cmd_callback (GtkWidget *widget, gpointer data) diff --git a/app/gui/layers-commands.h b/app/gui/layers-commands.h index 6b37d245d2..984248597a 100644 --- a/app/gui/layers-commands.h +++ b/app/gui/layers-commands.h @@ -44,12 +44,14 @@ void layers_merge_down_cmd_callback (GtkWidget *widet, void layers_delete_cmd_callback (GtkWidget *widet, gpointer data); -void layers_scale_cmd_callback (GtkWidget *widet, - gpointer data); void layers_resize_cmd_callback (GtkWidget *widet, gpointer data); void layers_resize_to_image_cmd_callback (GtkWidget *widet, gpointer data); +void layers_scale_cmd_callback (GtkWidget *widet, + gpointer data); +void layers_crop_cmd_callback (GtkWidget *widet, + gpointer data); void layers_add_layer_mask_cmd_callback (GtkWidget *widet, gpointer data); diff --git a/app/gui/menus.c b/app/gui/menus.c index 95a94523d8..322d068097 100644 --- a/app/gui/menus.c +++ b/app/gui/menus.c @@ -738,6 +738,11 @@ static GimpItemFactoryEntry image_entries[] = "", GIMP_STOCK_SCALE }, NULL, "layers/dialogs/scale_layer.html", NULL }, + { { N_("/Layer/Crop Layer"), NULL, + layers_crop_cmd_callback, 0, + "", GIMP_STOCK_TOOL_CROP }, + NULL, + "layers/dialogs/scale_layer.html", NULL }, /* /Layer/Transform */ diff --git a/app/menus/menus.c b/app/menus/menus.c index 95a94523d8..322d068097 100644 --- a/app/menus/menus.c +++ b/app/menus/menus.c @@ -738,6 +738,11 @@ static GimpItemFactoryEntry image_entries[] = "", GIMP_STOCK_SCALE }, NULL, "layers/dialogs/scale_layer.html", NULL }, + { { N_("/Layer/Crop Layer"), NULL, + layers_crop_cmd_callback, 0, + "", GIMP_STOCK_TOOL_CROP }, + NULL, + "layers/dialogs/scale_layer.html", NULL }, /* /Layer/Transform */