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
|
|
|
*/
|
Win32 portability changes:
* config.h.win32, README.win32: Small changes.
* tools/pdbgen/pdb/*.pdb: Include <string.h>.
* app/*_cmds.c: Autogenerated files reflect above changes.
* libgimp/makefile.msc app/makefile.msc: Various updates,
including new object files. Gtk+ directory now should be called
gtk+ (not gtk-plus). Use win32-specific gdk subdir. Glib directory
now should be called just glib.
* libgimp/gimp.def: Updates.
* libgimp/gimpfeatures.h.win32: Made current with
gimpfeatures.h.in.
* libgimp/gimpfileselection.c: Define S_ISDIR and S_ISREG if
necessary.
* tools/pdbgen/pdb/fileops.pdb: Must have a
statement (even an empty one) after a label.
* app/fileops_cmds.c: Autogenerated file reflects above changes.
* app/crop.c: Include <string.h>.
* app/{app_procs,batch,fileops,datafiles,errorconsole,general,
plug_in,temp_buf,tile_swap}.c: Test NATIVE_WIN32, not
_MSC_VER. (NATIVE_WIN32 means we are using the Microsoft C
runtime, even if we might be compiling with gcc.)
* app/fileops.c: Don't include <process.h> here.
* app/fileops.h: Do include <process.h> here.
* app/gimpparasite.c: Include config.h, guard inclusion of
<unistd.h>. (Is the inclusion of unistd.h in source files all over
the place really necessary?)
* app/ink.c: MSC doesn't handle conversion from unsigned __int64
to double, so cast to signed.
* app/lut_funcs.c: Include config.h, and define rint() if necessary.
* app/pixel_processor.c: Include config.h without "..", like in
all the other places. Include <string.h>
* app/text_tool.c: Guard the "POINTS" identifier that clashes with
<windows.h>, sigh.
1999-05-05 05:32:17 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "gdk/gdkkeysyms.h"
|
|
|
|
#include "appenv.h"
|
1999-04-13 01:55:06 +08:00
|
|
|
#include "crop.h"
|
1999-01-11 07:36:29 +08:00
|
|
|
#include "cursorutil.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "draw_core.h"
|
|
|
|
#include "drawable.h"
|
|
|
|
#include "floating_sel.h"
|
|
|
|
#include "gdisplay.h"
|
|
|
|
#include "gimage_mask.h"
|
1999-09-28 01:58:10 +08:00
|
|
|
#include "gimphelp.h"
|
1999-10-27 02:27:27 +08:00
|
|
|
#include "gimpui.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "info_dialog.h"
|
1999-04-13 01:55:06 +08:00
|
|
|
#include "tool_options_ui.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "undo.h"
|
|
|
|
|
1999-04-03 03:46:59 +08:00
|
|
|
#include "libgimp/gimpsizeentry.h"
|
1999-04-09 06:25:54 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
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
|
|
|
|
1998-07-27 05:49:42 +08:00
|
|
|
#define STATUSBAR_SIZE 128
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* possible crop functions */
|
|
|
|
#define CREATING 0
|
|
|
|
#define MOVING 1
|
|
|
|
#define RESIZING_LEFT 2
|
|
|
|
#define RESIZING_RIGHT 3
|
|
|
|
#define CROPPING 4
|
1999-04-27 10:09:03 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* speed of key movement */
|
|
|
|
#define ARROW_VELOCITY 25
|
|
|
|
|
|
|
|
/* the crop structures */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
typedef struct _Crop Crop;
|
|
|
|
struct _Crop
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-06-22 06:12:07 +08:00
|
|
|
DrawCore * core; /* Core select object */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-06-22 06:12:07 +08:00
|
|
|
int startx; /* starting x coord */
|
|
|
|
int starty; /* starting y coord */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-06-22 06:12:07 +08:00
|
|
|
int lastx; /* previous x coord */
|
|
|
|
int lasty; /* previous y coord */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-06-22 06:12:07 +08:00
|
|
|
int x1, y1; /* upper left hand coordinate */
|
|
|
|
int x2, y2; /* lower right hand coords */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-06-22 06:12:07 +08:00
|
|
|
int srw, srh; /* width and height of corners */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-06-22 06:12:07 +08:00
|
|
|
int tx1, ty1; /* transformed coords */
|
|
|
|
int tx2, ty2; /* */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-06-22 06:12:07 +08:00
|
|
|
int function; /* moving or resizing */
|
|
|
|
guint context_id; /* for the statusbar */
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
typedef struct _CropOptions CropOptions;
|
|
|
|
struct _CropOptions
|
|
|
|
{
|
1999-04-13 01:55:06 +08:00
|
|
|
ToolOptions tool_options;
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gboolean layer_only;
|
|
|
|
gboolean layer_only_d;
|
1999-04-13 01:55:06 +08:00
|
|
|
GtkWidget *layer_only_w;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gboolean allow_enlarge;
|
|
|
|
gboolean allow_enlarge_d;
|
1999-04-27 10:09:03 +08:00
|
|
|
GtkWidget *allow_enlarge_w;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
1999-04-27 10:09:03 +08:00
|
|
|
CropType type;
|
|
|
|
CropType type_d;
|
1999-04-28 05:06:00 +08:00
|
|
|
GtkWidget *type_w[2];
|
1999-04-09 06:25:54 +08:00
|
|
|
};
|
|
|
|
|
1999-04-27 10:09:03 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* the crop tool options */
|
|
|
|
static CropOptions *crop_options = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* the crop tool info dialog */
|
1999-04-06 20:13:54 +08:00
|
|
|
static InfoDialog *crop_info = NULL;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
1999-05-31 22:11:10 +08:00
|
|
|
static gdouble orig_vals[2];
|
|
|
|
static gdouble size_vals[2];
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-06 20:13:54 +08:00
|
|
|
static GtkWidget *origin_sizeentry;
|
|
|
|
static GtkWidget *size_sizeentry;
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
|
1999-04-27 10:09:03 +08:00
|
|
|
/* Crop type functions */
|
1997-11-25 06:05:25 +08:00
|
|
|
static void crop_button_press (Tool *, GdkEventButton *, gpointer);
|
|
|
|
static void crop_button_release (Tool *, GdkEventButton *, gpointer);
|
|
|
|
static void crop_motion (Tool *, GdkEventMotion *, gpointer);
|
|
|
|
static void crop_cursor_update (Tool *, GdkEventMotion *, gpointer);
|
1999-06-22 06:12:07 +08:00
|
|
|
static void crop_control (Tool *, ToolAction, gpointer);
|
|
|
|
static void crop_arrow_keys_func (Tool *, GdkEventKey *, gpointer);
|
|
|
|
static void crop_modifier_key_func (Tool *, GdkEventKey *, gpointer);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
/* Crop helper functions */
|
1997-11-25 06:05:25 +08:00
|
|
|
static void crop_recalc (Tool *, Crop *);
|
|
|
|
static void crop_start (Tool *, Crop *);
|
|
|
|
static void crop_adjust_guides (GImage *, int, int, int, int);
|
|
|
|
|
|
|
|
/* Crop dialog functions */
|
|
|
|
static void crop_info_update (Tool *);
|
|
|
|
static void crop_info_create (Tool *);
|
1999-04-29 02:58:01 +08:00
|
|
|
static void crop_crop_callback (GtkWidget *, gpointer);
|
1999-04-08 13:20:37 +08:00
|
|
|
static void crop_resize_callback (GtkWidget *, gpointer);
|
1997-11-25 06:05:25 +08:00
|
|
|
static void crop_close_callback (GtkWidget *, gpointer);
|
|
|
|
|
1999-04-13 05:53:41 +08:00
|
|
|
/* Crop area-select functions */
|
1999-10-27 02:27:27 +08:00
|
|
|
typedef enum
|
|
|
|
{
|
1999-04-15 07:39:12 +08:00
|
|
|
AUTO_CROP_NOTHING = 0,
|
|
|
|
AUTO_CROP_ALPHA = 1,
|
|
|
|
AUTO_CROP_COLOR = 2
|
|
|
|
} AutoCropType;
|
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
typedef guchar * (*GetColorFunc) (GtkObject *, int, int);
|
|
|
|
typedef AutoCropType (*ColorsEqualFunc) (guchar *, guchar *, int);
|
1999-04-15 07:39:12 +08:00
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
static void crop_selection_callback (GtkWidget *, gpointer);
|
|
|
|
static void crop_automatic_callback (GtkWidget *, gpointer);
|
1999-07-01 00:19:52 +08:00
|
|
|
static AutoCropType crop_guess_bgcolor (GtkObject *, GetColorFunc,
|
|
|
|
int, int, guchar *, int, int, int, int);
|
1999-06-26 19:16:47 +08:00
|
|
|
static int crop_colors_equal (guchar *, guchar *, int);
|
|
|
|
static int crop_colors_alpha (guchar *, guchar *, int);
|
1999-04-13 05:53:41 +08:00
|
|
|
|
1998-08-15 21:34:54 +08:00
|
|
|
/* Crop dialog callback funtions */
|
1999-06-26 19:16:47 +08:00
|
|
|
static void crop_orig_changed (GtkWidget *, gpointer);
|
|
|
|
static void crop_size_changed (GtkWidget *, gpointer);
|
1998-12-04 14:46:52 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Functions */
|
|
|
|
|
1998-12-04 14:46:52 +08:00
|
|
|
static void
|
1999-04-13 01:55:06 +08:00
|
|
|
crop_options_reset (void)
|
1999-04-09 06:25:54 +08:00
|
|
|
{
|
|
|
|
CropOptions *options = crop_options;
|
|
|
|
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->layer_only_w),
|
|
|
|
options->layer_only_d);
|
1999-04-27 10:09:03 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(options->allow_enlarge_w),
|
|
|
|
options->allow_enlarge_d);
|
1999-04-28 05:06:00 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->type_w[options->type_d]), TRUE);
|
1999-04-09 06:25:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static CropOptions *
|
1999-04-13 01:55:06 +08:00
|
|
|
crop_options_new (void)
|
1998-12-04 14:46:52 +08:00
|
|
|
{
|
1999-04-09 06:25:54 +08:00
|
|
|
CropOptions *options;
|
1999-04-13 01:55:06 +08:00
|
|
|
GtkWidget *vbox;
|
1999-04-27 10:09:03 +08:00
|
|
|
GtkWidget *frame;
|
1999-04-29 02:58:01 +08:00
|
|
|
gchar* type_label[2] = { N_("Crop"), N_("Resize") };
|
1999-04-28 05:06:00 +08:00
|
|
|
gint type_value[2] = { CROP_CROP, RESIZE_CROP };
|
1999-06-26 19:16:47 +08:00
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* the new crop tool options structure */
|
1999-04-09 06:25:54 +08:00
|
|
|
options = (CropOptions *) g_malloc (sizeof (CropOptions));
|
1999-04-13 01:55:06 +08:00
|
|
|
tool_options_init ((ToolOptions *) options,
|
1999-06-22 06:12:07 +08:00
|
|
|
_("Crop & Resize Options"),
|
1999-04-13 01:55:06 +08:00
|
|
|
crop_options_reset);
|
1999-04-27 10:09:03 +08:00
|
|
|
options->layer_only = options->layer_only_d = FALSE;
|
1999-06-18 04:34:50 +08:00
|
|
|
options->allow_enlarge = options->allow_enlarge_d = FALSE;
|
|
|
|
options->type = options->type_d = CROP_CROP;
|
1998-12-04 14:46:52 +08:00
|
|
|
|
|
|
|
/* the main vbox */
|
1999-04-13 01:55:06 +08:00
|
|
|
vbox = options->tool_options.main_vbox;
|
1998-12-04 14:46:52 +08:00
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* layer toggle */
|
1999-04-09 06:25:54 +08:00
|
|
|
options->layer_only_w =
|
1999-12-14 22:10:34 +08:00
|
|
|
gtk_check_button_new_with_label(_("Current Layer Only"));
|
1999-04-09 06:25:54 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), options->layer_only_w,
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (options->layer_only_w), "toggled",
|
1999-04-13 01:55:06 +08:00
|
|
|
(GtkSignalFunc) tool_options_toggle_update,
|
1999-04-09 06:25:54 +08:00
|
|
|
&options->layer_only);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->layer_only_w),
|
|
|
|
options->layer_only_d);
|
|
|
|
gtk_widget_show (options->layer_only_w);
|
1998-12-04 14:46:52 +08:00
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* enlarge toggle */
|
1999-04-27 10:09:03 +08:00
|
|
|
options->allow_enlarge_w = gtk_check_button_new_with_label (_("Allow Enlarging"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), options->allow_enlarge_w,
|
1999-04-09 06:25:54 +08:00
|
|
|
FALSE, FALSE, 0);
|
1999-04-27 10:09:03 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (options->allow_enlarge_w), "toggled",
|
1999-04-13 01:55:06 +08:00
|
|
|
(GtkSignalFunc) tool_options_toggle_update,
|
1999-04-27 10:09:03 +08:00
|
|
|
&options->allow_enlarge);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->allow_enlarge_w),
|
|
|
|
options->allow_enlarge_d);
|
|
|
|
gtk_widget_show (options->allow_enlarge_w);
|
1999-04-09 06:25:54 +08:00
|
|
|
|
1999-04-27 10:09:03 +08:00
|
|
|
/* tool toggle */
|
1999-06-26 19:16:47 +08:00
|
|
|
frame = tool_options_radio_buttons_new (_("Tool Toggle"),
|
1999-04-28 05:06:00 +08:00
|
|
|
&options->type,
|
|
|
|
options->type_w,
|
|
|
|
type_label,
|
|
|
|
type_value,
|
|
|
|
2);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->type_w[options->type_d]), TRUE);
|
1999-04-27 10:09:03 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
1999-04-08 13:20:37 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
return options;
|
1998-12-04 14:46:52 +08:00
|
|
|
}
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
1997-11-25 06:05:25 +08:00
|
|
|
crop_button_press (Tool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
gpointer gdisp_ptr)
|
|
|
|
{
|
|
|
|
Crop * crop;
|
|
|
|
GDisplay * gdisp;
|
|
|
|
|
|
|
|
gdisp = (GDisplay *) gdisp_ptr;
|
|
|
|
crop = (Crop *) tool->private;
|
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
if (tool->state == INACTIVE ||
|
|
|
|
gdisp_ptr != tool->gdisp_ptr)
|
|
|
|
{
|
|
|
|
crop->function = CREATING;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If the cursor is in either the upper left or lower right boxes,
|
|
|
|
The new function will be to resize the current crop area */
|
|
|
|
if (bevent->x == BOUNDS (bevent->x, crop->x1, crop->x1 + crop->srw) &&
|
|
|
|
bevent->y == BOUNDS (bevent->y, crop->y1, crop->y1 + crop->srh))
|
|
|
|
crop->function = RESIZING_LEFT;
|
|
|
|
else if (bevent->x == BOUNDS (bevent->x, crop->x2 - crop->srw, crop->x2) &&
|
|
|
|
bevent->y == BOUNDS (bevent->y, crop->y2 - crop->srh, crop->y2))
|
|
|
|
crop->function = RESIZING_RIGHT;
|
|
|
|
|
|
|
|
/* If the cursor is in either the upper right or lower left boxes,
|
|
|
|
The new function will be to translate the current crop area */
|
|
|
|
else if ((bevent->x == BOUNDS (bevent->x, crop->x1, crop->x1 + crop->srw) &&
|
|
|
|
bevent->y == BOUNDS (bevent->y, crop->y2 - crop->srh, crop->y2)) ||
|
|
|
|
(bevent->x == BOUNDS (bevent->x, crop->x2 - crop->srw, crop->x2) &&
|
|
|
|
bevent->y == BOUNDS (bevent->y, crop->y1, crop->y1 + crop->srh)))
|
|
|
|
crop->function = MOVING;
|
|
|
|
|
1999-04-08 13:20:37 +08:00
|
|
|
/* If the pointer is in the rectangular region, crop or resize it! */
|
1997-11-25 06:05:25 +08:00
|
|
|
else if (bevent->x > crop->x1 && bevent->x < crop->x2 &&
|
|
|
|
bevent->y > crop->y1 && bevent->y < crop->y2)
|
1999-04-29 02:58:01 +08:00
|
|
|
crop->function = CROPPING;
|
1997-11-25 06:05:25 +08:00
|
|
|
/* otherwise, the new function will be creating, since we want to start anew */
|
|
|
|
else
|
|
|
|
crop->function = CREATING;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (crop->function == CREATING)
|
|
|
|
{
|
|
|
|
if (tool->state == ACTIVE)
|
|
|
|
draw_core_stop (crop->core, tool);
|
|
|
|
|
|
|
|
tool->gdisp_ptr = gdisp_ptr;
|
1999-06-26 19:16:47 +08:00
|
|
|
tool->drawable = gimage_active_drawable (gdisp->gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gdisplay_untransform_coords (gdisp, bevent->x, bevent->y,
|
|
|
|
&crop->tx1, &crop->ty1, TRUE, FALSE);
|
|
|
|
crop->tx2 = crop->tx1;
|
|
|
|
crop->ty2 = crop->ty1;
|
|
|
|
|
|
|
|
crop_start (tool, crop);
|
|
|
|
}
|
|
|
|
|
|
|
|
gdisplay_untransform_coords (gdisp, bevent->x, bevent->y,
|
|
|
|
&crop->startx, &crop->starty, TRUE, FALSE);
|
|
|
|
crop->lastx = crop->startx;
|
|
|
|
crop->lasty = crop->starty;
|
|
|
|
|
|
|
|
gdk_pointer_grab (gdisp->canvas->window, FALSE,
|
1999-06-26 19:16:47 +08:00
|
|
|
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON1_MOTION_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK,
|
1997-11-25 06:05:25 +08:00
|
|
|
NULL, NULL, bevent->time);
|
|
|
|
|
|
|
|
tool->state = ACTIVE;
|
|
|
|
}
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
1997-11-25 06:05:25 +08:00
|
|
|
crop_button_release (Tool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
gpointer gdisp_ptr)
|
|
|
|
{
|
|
|
|
Crop * crop;
|
|
|
|
GDisplay *gdisp;
|
|
|
|
|
|
|
|
crop = (Crop *) tool->private;
|
|
|
|
gdisp = (GDisplay *) gdisp_ptr;
|
|
|
|
|
|
|
|
gdk_pointer_ungrab (bevent->time);
|
|
|
|
gdk_flush ();
|
|
|
|
|
1999-04-29 02:58:01 +08:00
|
|
|
gtk_statusbar_pop (GTK_STATUSBAR (gdisp->statusbar), crop->context_id);
|
1998-07-27 05:49:42 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (! (bevent->state & GDK_BUTTON3_MASK))
|
|
|
|
{
|
1999-04-29 02:58:01 +08:00
|
|
|
if (crop->function == CROPPING)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-04-29 02:58:01 +08:00
|
|
|
if (crop_options->type == CROP_CROP)
|
|
|
|
crop_image (gdisp->gimage, crop->tx1, crop->ty1, crop->tx2, crop->ty2,
|
|
|
|
crop_options->layer_only, TRUE);
|
|
|
|
else
|
|
|
|
crop_image (gdisp->gimage, crop->tx1, crop->ty1, crop->tx2, crop->ty2,
|
|
|
|
crop_options->layer_only, FALSE);
|
|
|
|
|
|
|
|
/* Finish the tool */
|
1999-06-26 19:16:47 +08:00
|
|
|
crop_close_callback (NULL, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1999-04-29 02:58:01 +08:00
|
|
|
else
|
|
|
|
crop_info_update (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
1997-11-25 06:05:25 +08:00
|
|
|
crop_adjust_guides (GImage *gimage,
|
|
|
|
int x1, int y1,
|
|
|
|
int x2, int y2)
|
|
|
|
|
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
GList * glist;
|
|
|
|
Guide * guide;
|
|
|
|
gint remove_guide;
|
|
|
|
|
|
|
|
for (glist = gimage->guides; glist; glist = g_list_next (glist))
|
|
|
|
{
|
|
|
|
guide = (Guide *) glist->data;
|
|
|
|
remove_guide = FALSE;
|
|
|
|
|
|
|
|
switch (guide->orientation)
|
|
|
|
{
|
|
|
|
case ORIENTATION_HORIZONTAL:
|
|
|
|
if ((guide->position < y1) ||(guide->position > y2))
|
|
|
|
remove_guide = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ORIENTATION_VERTICAL:
|
|
|
|
if ((guide->position < x1) ||(guide->position > x2))
|
|
|
|
remove_guide = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
/* edit the guide */
|
|
|
|
gdisplays_expose_guide (gimage, guide);
|
|
|
|
gdisplays_flush();
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
if (remove_guide)
|
|
|
|
{
|
1997-11-25 06:05:25 +08:00
|
|
|
guide->position = -1;
|
|
|
|
guide = NULL;
|
|
|
|
}
|
1999-10-27 02:27:27 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (guide->orientation == ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
|
|
|
guide->position -= y1 ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
guide->position -= x1;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1999-10-27 02:27:27 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
1997-11-25 06:05:25 +08:00
|
|
|
crop_motion (Tool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
gpointer gdisp_ptr)
|
|
|
|
{
|
|
|
|
Crop * crop;
|
|
|
|
GDisplay * gdisp;
|
1999-04-08 13:20:37 +08:00
|
|
|
Layer * layer;
|
1997-11-25 06:05:25 +08:00
|
|
|
int x1, y1, x2, y2;
|
|
|
|
int curx, cury;
|
|
|
|
int inc_x, inc_y;
|
1998-07-27 05:49:42 +08:00
|
|
|
gchar size[STATUSBAR_SIZE];
|
1999-04-08 13:20:37 +08:00
|
|
|
int min_x, min_y, max_x, max_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
crop = (Crop *) tool->private;
|
|
|
|
gdisp = (GDisplay *) gdisp_ptr;
|
|
|
|
|
|
|
|
/* This is the only case when the motion events should be ignored--
|
|
|
|
we're just waiting for the button release event to crop the image */
|
1999-04-29 02:58:01 +08:00
|
|
|
if (crop->function == CROPPING)
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &curx, &cury, TRUE, FALSE);
|
|
|
|
x1 = crop->startx;
|
|
|
|
y1 = crop->starty;
|
|
|
|
x2 = curx;
|
|
|
|
y2 = cury;
|
|
|
|
|
|
|
|
inc_x = (x2 - x1);
|
|
|
|
inc_y = (y2 - y1);
|
|
|
|
|
|
|
|
/* If there have been no changes... return */
|
|
|
|
if (crop->lastx == curx && crop->lasty == cury)
|
|
|
|
return;
|
|
|
|
|
|
|
|
draw_core_pause (crop->core, tool);
|
1999-04-08 13:20:37 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
if (crop_options->layer_only)
|
1999-04-08 13:20:37 +08:00
|
|
|
{
|
|
|
|
layer = (gdisp->gimage)->active_layer;
|
|
|
|
drawable_offsets (GIMP_DRAWABLE(layer), &min_x, &min_y);
|
|
|
|
max_x = drawable_width (GIMP_DRAWABLE(layer)) + min_x;
|
|
|
|
max_y = drawable_height (GIMP_DRAWABLE(layer)) + min_y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
min_x = min_y = 0;
|
|
|
|
max_x = gdisp->gimage->width;
|
|
|
|
max_y = gdisp->gimage->height;
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
switch (crop->function)
|
|
|
|
{
|
|
|
|
case CREATING :
|
1999-04-28 05:06:00 +08:00
|
|
|
if (!crop_options->allow_enlarge)
|
1999-04-08 13:20:37 +08:00
|
|
|
{
|
|
|
|
x1 = BOUNDS (x1, min_x, max_x);
|
|
|
|
y1 = BOUNDS (y1, min_y, max_y);
|
|
|
|
x2 = BOUNDS (x2, min_x, max_x);
|
|
|
|
y2 = BOUNDS (y2, min_y, max_y);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RESIZING_LEFT :
|
1999-04-08 13:20:37 +08:00
|
|
|
x1 = crop->tx1 + inc_x;
|
|
|
|
y1 = crop->ty1 + inc_y;
|
1999-04-28 05:06:00 +08:00
|
|
|
if (!crop_options->allow_enlarge)
|
1999-04-08 13:20:37 +08:00
|
|
|
{
|
|
|
|
x1 = BOUNDS (x1, min_x, max_x);
|
|
|
|
y1 = BOUNDS (y1, min_y, max_y);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
x2 = MAXIMUM (x1, crop->tx2);
|
|
|
|
y2 = MAXIMUM (y1, crop->ty2);
|
|
|
|
crop->startx = curx;
|
|
|
|
crop->starty = cury;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RESIZING_RIGHT :
|
1999-04-08 13:20:37 +08:00
|
|
|
x2 = crop->tx2 + inc_x;
|
|
|
|
y2 = crop->ty2 + inc_y;
|
1999-04-28 05:06:00 +08:00
|
|
|
if (!crop_options->allow_enlarge)
|
1999-04-08 13:20:37 +08:00
|
|
|
{
|
|
|
|
x2 = BOUNDS (x2, min_x, max_x);
|
|
|
|
y2 = BOUNDS (y2, min_y, max_y);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
x1 = MINIMUM (crop->tx1, x2);
|
|
|
|
y1 = MINIMUM (crop->ty1, y2);
|
|
|
|
crop->startx = curx;
|
|
|
|
crop->starty = cury;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOVING :
|
1999-04-28 05:06:00 +08:00
|
|
|
if (!crop_options->allow_enlarge)
|
1999-04-08 13:20:37 +08:00
|
|
|
{
|
|
|
|
inc_x = BOUNDS (inc_x, min_x - crop->tx1, max_x - crop->tx2);
|
|
|
|
inc_y = BOUNDS (inc_y, min_y - crop->ty1, max_y - crop->ty2);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
x1 = crop->tx1 + inc_x;
|
|
|
|
x2 = crop->tx2 + inc_x;
|
|
|
|
y1 = crop->ty1 + inc_y;
|
|
|
|
y2 = crop->ty2 + inc_y;
|
|
|
|
crop->startx = curx;
|
|
|
|
crop->starty = cury;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure that the coords are in bounds */
|
|
|
|
crop->tx1 = MINIMUM (x1, x2);
|
|
|
|
crop->ty1 = MINIMUM (y1, y2);
|
|
|
|
crop->tx2 = MAXIMUM (x1, x2);
|
|
|
|
crop->ty2 = MAXIMUM (y1, y2);
|
|
|
|
|
|
|
|
crop->lastx = curx;
|
|
|
|
crop->lasty = cury;
|
|
|
|
|
|
|
|
/* recalculate the coordinates for crop_draw based on the new values */
|
|
|
|
crop_recalc (tool, crop);
|
1998-07-27 05:49:42 +08:00
|
|
|
|
|
|
|
if (crop->function == CREATING ||
|
|
|
|
crop->function == RESIZING_LEFT || crop->function == RESIZING_RIGHT)
|
|
|
|
{
|
|
|
|
gtk_statusbar_pop (GTK_STATUSBAR (gdisp->statusbar), crop->context_id);
|
1999-03-04 01:48:29 +08:00
|
|
|
if (gdisp->dot_for_dot)
|
|
|
|
{
|
|
|
|
g_snprintf (size, STATUSBAR_SIZE, gdisp->cursor_format_str,
|
|
|
|
_("Crop: "),
|
|
|
|
(crop->tx2 - crop->tx1), " x ", (crop->ty2 - crop->ty1));
|
|
|
|
}
|
|
|
|
else /* show real world units */
|
|
|
|
{
|
1999-05-23 01:56:35 +08:00
|
|
|
gdouble unit_factor = gimp_unit_get_factor (gdisp->gimage->unit);
|
1999-03-04 01:48:29 +08:00
|
|
|
|
|
|
|
g_snprintf (size, STATUSBAR_SIZE, gdisp->cursor_format_str,
|
|
|
|
_("Crop: "),
|
1999-05-23 01:56:35 +08:00
|
|
|
(gdouble) (crop->tx2 - crop->tx1) * unit_factor /
|
1999-03-04 01:48:29 +08:00
|
|
|
gdisp->gimage->xresolution,
|
|
|
|
" x ",
|
1999-05-23 01:56:35 +08:00
|
|
|
(gdouble) (crop->ty2 - crop->ty1) * unit_factor /
|
1999-03-04 01:48:29 +08:00
|
|
|
gdisp->gimage->yresolution);
|
|
|
|
}
|
|
|
|
gtk_statusbar_push (GTK_STATUSBAR (gdisp->statusbar), crop->context_id,
|
|
|
|
size);
|
1998-07-27 05:49:42 +08:00
|
|
|
}
|
1999-03-04 01:48:29 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
draw_core_resume (crop->core, tool);
|
|
|
|
}
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
1997-11-25 06:05:25 +08:00
|
|
|
crop_cursor_update (Tool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
gpointer gdisp_ptr)
|
|
|
|
{
|
|
|
|
GDisplay *gdisp;
|
|
|
|
GdkCursorType ctype;
|
|
|
|
Crop * crop;
|
|
|
|
|
|
|
|
gdisp = (GDisplay *) gdisp_ptr;
|
|
|
|
crop = (Crop *) tool->private;
|
|
|
|
|
|
|
|
if (tool->state == INACTIVE ||
|
|
|
|
(tool->state == ACTIVE && tool->gdisp_ptr != gdisp_ptr))
|
|
|
|
ctype = GDK_CROSS;
|
|
|
|
else if (mevent->x == BOUNDS (mevent->x, crop->x1, crop->x1 + crop->srw) &&
|
|
|
|
mevent->y == BOUNDS (mevent->y, crop->y1, crop->y1 + crop->srh))
|
|
|
|
ctype = GDK_TOP_LEFT_CORNER;
|
|
|
|
else if (mevent->x == BOUNDS (mevent->x, crop->x2 - crop->srw, crop->x2) &&
|
|
|
|
mevent->y == BOUNDS (mevent->y, crop->y2 - crop->srh, crop->y2))
|
|
|
|
ctype = GDK_BOTTOM_RIGHT_CORNER;
|
|
|
|
else if (mevent->x == BOUNDS (mevent->x, crop->x1, crop->x1 + crop->srw) &&
|
|
|
|
mevent->y == BOUNDS (mevent->y, crop->y2 - crop->srh, crop->y2))
|
|
|
|
ctype = GDK_FLEUR;
|
|
|
|
else if (mevent->x == BOUNDS (mevent->x, crop->x2 - crop->srw, crop->x2) &&
|
|
|
|
mevent->y == BOUNDS (mevent->y, crop->y1, crop->y1 + crop->srh))
|
|
|
|
ctype = GDK_FLEUR;
|
|
|
|
else if (mevent->x > crop->x1 && mevent->x < crop->x2 &&
|
|
|
|
mevent->y > crop->y1 && mevent->y < crop->y2)
|
1999-04-08 13:20:37 +08:00
|
|
|
{
|
1999-04-27 10:09:03 +08:00
|
|
|
if ( crop_options->type == CROP_CROP )
|
|
|
|
ctype = GDK_ICON;
|
1999-04-08 13:20:37 +08:00
|
|
|
else
|
1999-04-27 10:09:03 +08:00
|
|
|
ctype = GDK_SIZING;
|
1999-04-08 13:20:37 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
ctype = GDK_CROSS;
|
|
|
|
|
|
|
|
gdisplay_install_tool_cursor (gdisp, ctype);
|
|
|
|
}
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
1997-11-25 06:05:25 +08:00
|
|
|
crop_arrow_keys_func (Tool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
gpointer gdisp_ptr)
|
|
|
|
{
|
|
|
|
int inc_x, inc_y;
|
|
|
|
GDisplay * gdisp;
|
1999-04-08 13:20:37 +08:00
|
|
|
Layer * layer;
|
1997-11-25 06:05:25 +08:00
|
|
|
Crop * crop;
|
1999-04-08 13:20:37 +08:00
|
|
|
int min_x, min_y, max_x, max_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gdisp = (GDisplay *) gdisp_ptr;
|
|
|
|
|
|
|
|
if (tool->state == ACTIVE)
|
|
|
|
{
|
|
|
|
crop = (Crop *) tool->private;
|
|
|
|
inc_x = inc_y = 0;
|
|
|
|
|
|
|
|
switch (kevent->keyval)
|
|
|
|
{
|
|
|
|
case GDK_Up : inc_y = -1; break;
|
|
|
|
case GDK_Left : inc_x = -1; break;
|
|
|
|
case GDK_Right : inc_x = 1; break;
|
|
|
|
case GDK_Down : inc_y = 1; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the shift key is down, move by an accelerated increment */
|
|
|
|
if (kevent->state & GDK_SHIFT_MASK)
|
|
|
|
{
|
|
|
|
inc_y *= ARROW_VELOCITY;
|
|
|
|
inc_x *= ARROW_VELOCITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_core_pause (crop->core, tool);
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
if (crop_options->layer_only)
|
1999-04-08 13:20:37 +08:00
|
|
|
{
|
|
|
|
layer = (gdisp->gimage)->active_layer;
|
|
|
|
drawable_offsets (GIMP_DRAWABLE(layer), &min_x, &min_y);
|
|
|
|
max_x = drawable_width (GIMP_DRAWABLE(layer)) + min_x;
|
|
|
|
max_y = drawable_height (GIMP_DRAWABLE(layer)) + min_y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
min_x = min_y = 0;
|
|
|
|
max_x = gdisp->gimage->width;
|
|
|
|
max_y = gdisp->gimage->height;
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (kevent->state & GDK_CONTROL_MASK) /* RESIZING */
|
|
|
|
{
|
1999-04-08 13:20:37 +08:00
|
|
|
crop->tx2 = crop->tx2 + inc_x;
|
|
|
|
crop->ty2 = crop->ty2 + inc_y;
|
1999-04-28 05:06:00 +08:00
|
|
|
if (!crop_options->allow_enlarge)
|
1999-04-08 13:20:37 +08:00
|
|
|
{
|
|
|
|
crop->tx2 = BOUNDS (crop->tx2, min_x, max_x);
|
|
|
|
crop->ty2 = BOUNDS (crop->ty2, min_y, max_y);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
crop->tx1 = MINIMUM (crop->tx1, crop->tx2);
|
|
|
|
crop->ty1 = MINIMUM (crop->ty1, crop->ty2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-04-28 05:06:00 +08:00
|
|
|
if (!crop_options->allow_enlarge)
|
1999-04-08 13:20:37 +08:00
|
|
|
{
|
|
|
|
inc_x = BOUNDS (inc_x, -crop->tx1, gdisp->gimage->width - crop->tx2);
|
|
|
|
inc_y = BOUNDS (inc_y, -crop->ty1, gdisp->gimage->height - crop->ty2);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
crop->tx1 += inc_x;
|
|
|
|
crop->tx2 += inc_x;
|
|
|
|
crop->ty1 += inc_y;
|
|
|
|
crop->ty2 += inc_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
crop_recalc (tool, crop);
|
|
|
|
draw_core_resume (crop->core, tool);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-27 10:09:03 +08:00
|
|
|
static void
|
1999-04-28 05:06:00 +08:00
|
|
|
crop_modifier_key_func (Tool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
gpointer gdisp_ptr)
|
1999-04-27 10:09:03 +08:00
|
|
|
{
|
1999-04-29 02:58:01 +08:00
|
|
|
switch (kevent->keyval)
|
1999-04-27 10:09:03 +08:00
|
|
|
{
|
1999-04-29 02:58:01 +08:00
|
|
|
case GDK_Alt_L: case GDK_Alt_R:
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (crop_options->allow_enlarge_w), !crop_options->allow_enlarge);
|
|
|
|
break;
|
|
|
|
case GDK_Shift_L: case GDK_Shift_R:
|
1999-06-08 06:38:20 +08:00
|
|
|
break;
|
|
|
|
case GDK_Control_L: case GDK_Control_R:
|
1999-04-29 02:58:01 +08:00
|
|
|
if (crop_options->type == CROP_CROP)
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (crop_options->type_w[RESIZE_CROP]), TRUE);
|
|
|
|
else
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (crop_options->type_w[CROP_CROP]), TRUE);
|
|
|
|
break;
|
1999-04-27 10:09:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
1999-06-22 06:12:07 +08:00
|
|
|
crop_control (Tool *tool,
|
|
|
|
ToolAction action,
|
|
|
|
gpointer gdisp_ptr)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
Crop * crop;
|
|
|
|
|
|
|
|
crop = (Crop *) tool->private;
|
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
1999-06-26 19:16:47 +08:00
|
|
|
case PAUSE:
|
1997-11-25 06:05:25 +08:00
|
|
|
draw_core_pause (crop->core, tool);
|
|
|
|
break;
|
1999-06-22 06:12:07 +08:00
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
case RESUME:
|
1997-11-25 06:05:25 +08:00
|
|
|
crop_recalc (tool, crop);
|
|
|
|
draw_core_resume (crop->core, tool);
|
|
|
|
break;
|
1999-06-22 06:12:07 +08:00
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
case HALT:
|
|
|
|
crop_close_callback (NULL, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
1999-06-22 06:12:07 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
crop_draw (Tool *tool)
|
|
|
|
{
|
|
|
|
Crop * crop;
|
|
|
|
GDisplay * gdisp;
|
|
|
|
|
|
|
|
gdisp = (GDisplay *) tool->gdisp_ptr;
|
|
|
|
crop = (Crop *) tool->private;
|
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
#define SRW 10
|
|
|
|
#define SRH 10
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
gdk_draw_line (crop->core->win, crop->core->gc,
|
|
|
|
crop->x1, crop->y1, gdisp->disp_width, crop->y1);
|
|
|
|
gdk_draw_line (crop->core->win, crop->core->gc,
|
|
|
|
crop->x1, crop->y1, crop->x1, gdisp->disp_height);
|
|
|
|
gdk_draw_line (crop->core->win, crop->core->gc,
|
|
|
|
crop->x2, crop->y2, 0, crop->y2);
|
|
|
|
gdk_draw_line (crop->core->win, crop->core->gc,
|
|
|
|
crop->x2, crop->y2, crop->x2, 0);
|
|
|
|
|
|
|
|
crop->srw = ((crop->x2 - crop->x1) < SRW) ? (crop->x2 - crop->x1) : SRW;
|
|
|
|
crop->srh = ((crop->y2 - crop->y1) < SRH) ? (crop->y2 - crop->y1) : SRH;
|
|
|
|
|
|
|
|
gdk_draw_rectangle (crop->core->win, crop->core->gc, 1,
|
|
|
|
crop->x1, crop->y1, crop->srw, crop->srh);
|
|
|
|
gdk_draw_rectangle (crop->core->win, crop->core->gc, 1,
|
|
|
|
crop->x2 - crop->srw, crop->y2-crop->srh, crop->srw, crop->srh);
|
|
|
|
gdk_draw_rectangle (crop->core->win, crop->core->gc, 1,
|
|
|
|
crop->x2 - crop->srw, crop->y1, crop->srw, crop->srh);
|
|
|
|
gdk_draw_rectangle (crop->core->win, crop->core->gc, 1,
|
|
|
|
crop->x1, crop->y2-crop->srh, crop->srw, crop->srh);
|
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
#undef SRW
|
|
|
|
#undef SRH
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
crop_info_update (tool);
|
|
|
|
}
|
|
|
|
|
|
|
|
Tool *
|
|
|
|
tools_new_crop ()
|
|
|
|
{
|
|
|
|
Tool * tool;
|
|
|
|
Crop * private;
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* The tool options */
|
1999-04-09 06:25:54 +08:00
|
|
|
if (! crop_options)
|
1999-04-13 01:55:06 +08:00
|
|
|
{
|
|
|
|
crop_options = crop_options_new ();
|
|
|
|
tools_register (CROP, (ToolOptions *) crop_options);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-09 20:24:36 +08:00
|
|
|
tool = tools_new_tool (CROP);
|
|
|
|
private = g_new (Crop, 1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
private->core = draw_core_new (crop_draw);
|
|
|
|
private->startx = private->starty = 0;
|
|
|
|
private->function = CREATING;
|
|
|
|
|
|
|
|
tool->private = (void *) private;
|
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
tool->preserve = FALSE; /* XXX Check me */
|
|
|
|
|
1999-07-09 20:24:36 +08:00
|
|
|
tool->button_press_func = crop_button_press;
|
1997-11-25 06:05:25 +08:00
|
|
|
tool->button_release_func = crop_button_release;
|
1999-07-09 20:24:36 +08:00
|
|
|
tool->motion_func = crop_motion;
|
|
|
|
tool->arrow_keys_func = crop_arrow_keys_func;
|
|
|
|
tool->modifier_key_func = crop_modifier_key_func;
|
|
|
|
tool->cursor_update_func = crop_cursor_update;
|
|
|
|
tool->control_func = crop_control;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return tool;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tools_free_crop (Tool *tool)
|
|
|
|
{
|
|
|
|
Crop * crop;
|
|
|
|
|
|
|
|
crop = (Crop *) tool->private;
|
|
|
|
|
|
|
|
if (tool->state == ACTIVE)
|
|
|
|
draw_core_stop (crop->core, tool);
|
|
|
|
|
|
|
|
if (crop_info)
|
1999-06-26 19:16:47 +08:00
|
|
|
crop_close_callback (NULL, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-14 04:53:30 +08:00
|
|
|
draw_core_free (crop->core);
|
1997-11-25 06:05:25 +08:00
|
|
|
g_free (crop);
|
|
|
|
}
|
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
void
|
1997-11-25 06:05:25 +08:00
|
|
|
crop_image (GImage *gimage,
|
|
|
|
int x1,
|
|
|
|
int y1,
|
|
|
|
int x2,
|
1999-04-08 13:20:37 +08:00
|
|
|
int y2,
|
|
|
|
int layer_only,
|
|
|
|
int crop_layers)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
Layer *layer;
|
|
|
|
Layer *floating_layer;
|
|
|
|
Channel *channel;
|
|
|
|
GList *guide_list_ptr;
|
1998-01-29 16:03:27 +08:00
|
|
|
GSList *list;
|
1997-11-25 06:05:25 +08:00
|
|
|
int width, height;
|
|
|
|
int lx1, ly1, lx2, ly2;
|
1998-01-22 15:02:57 +08:00
|
|
|
int off_x, off_y;
|
1998-12-04 14:46:52 +08:00
|
|
|
int doff_x, doff_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-01-11 07:36:29 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
width = x2 - x1;
|
|
|
|
height = y2 - y1;
|
|
|
|
|
|
|
|
/* Make sure new width and height are non-zero */
|
|
|
|
if (width && height)
|
|
|
|
{
|
1999-01-11 07:36:29 +08:00
|
|
|
gimp_add_busy_cursors();
|
|
|
|
|
1999-04-08 13:20:37 +08:00
|
|
|
if (layer_only)
|
1998-12-04 14:46:52 +08:00
|
|
|
{
|
|
|
|
undo_push_group_start (gimage, LAYER_RESIZE_UNDO);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-12-04 14:46:52 +08:00
|
|
|
layer = gimage->active_layer;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-12-04 14:46:52 +08:00
|
|
|
if (layer_is_floating_sel (layer))
|
|
|
|
floating_sel_relax (layer, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-12-04 14:46:52 +08:00
|
|
|
drawable_offsets (GIMP_DRAWABLE(layer), &doff_x, &doff_y);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-12-04 14:46:52 +08:00
|
|
|
off_x = (doff_x - x1);
|
|
|
|
off_y = (doff_y - y1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-12-04 14:46:52 +08:00
|
|
|
layer_resize (layer, width, height, off_x, off_y);
|
|
|
|
|
|
|
|
if (layer_is_floating_sel (layer))
|
|
|
|
floating_sel_rigor (layer, TRUE);
|
|
|
|
|
|
|
|
undo_push_group_end (gimage);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
floating_layer = gimage_floating_sel (gimage);
|
|
|
|
|
|
|
|
undo_push_group_start (gimage, CROP_UNDO);
|
|
|
|
|
|
|
|
/* relax the floating layer */
|
|
|
|
if (floating_layer)
|
|
|
|
floating_sel_relax (floating_layer, TRUE);
|
|
|
|
|
|
|
|
/* Push the image size to the stack */
|
|
|
|
undo_push_gimage_mod (gimage);
|
|
|
|
|
|
|
|
/* Set the new width and height */
|
|
|
|
gimage->width = width;
|
|
|
|
gimage->height = height;
|
|
|
|
|
|
|
|
/* Resize all channels */
|
|
|
|
list = gimage->channels;
|
|
|
|
while (list)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
channel = (Channel *) list->data;
|
|
|
|
channel_resize (channel, width, height, -x1, -y1);
|
1998-01-29 16:03:27 +08:00
|
|
|
list = g_slist_next (list);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-12-04 14:46:52 +08:00
|
|
|
/* Don't forget the selection mask! */
|
|
|
|
channel_resize (gimage->selection_mask, width, height, -x1, -y1);
|
|
|
|
gimage_mask_invalidate (gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-12-04 14:46:52 +08:00
|
|
|
/* crop all layers */
|
|
|
|
list = gimage->layers;
|
|
|
|
while (list)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-05-16 05:07:01 +08:00
|
|
|
GSList * next;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
layer = (Layer *) list->data;
|
1999-05-16 05:07:01 +08:00
|
|
|
next = g_slist_next (list);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
layer_translate (layer, -x1, -y1);
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
drawable_offsets (GIMP_DRAWABLE (layer), &off_x, &off_y);
|
|
|
|
|
1999-04-08 13:20:37 +08:00
|
|
|
if (crop_layers)
|
|
|
|
{
|
|
|
|
drawable_offsets (GIMP_DRAWABLE (layer), &off_x, &off_y);
|
|
|
|
|
|
|
|
lx1 = BOUNDS (off_x, 0, gimage->width);
|
|
|
|
ly1 = BOUNDS (off_y, 0, gimage->height);
|
|
|
|
lx2 = BOUNDS ((drawable_width (GIMP_DRAWABLE (layer)) + off_x), 0, gimage->width);
|
|
|
|
ly2 = BOUNDS ((drawable_height (GIMP_DRAWABLE (layer)) + off_y), 0, gimage->height);
|
|
|
|
width = lx2 - lx1;
|
|
|
|
height = ly2 - ly1;
|
|
|
|
|
|
|
|
if (width && height)
|
|
|
|
layer_resize (layer, width, height,
|
|
|
|
-(lx1 - off_x),
|
|
|
|
-(ly1 - off_y));
|
|
|
|
else
|
|
|
|
gimage_remove_layer (gimage, layer);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-05-16 05:07:01 +08:00
|
|
|
list = next;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-12-04 14:46:52 +08:00
|
|
|
/* Make sure the projection matches the gimage size */
|
|
|
|
gimage_projection_realloc (gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-12-04 14:46:52 +08:00
|
|
|
/* rigor the floating layer */
|
|
|
|
if (floating_layer)
|
|
|
|
floating_sel_rigor (floating_layer, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-12-04 14:46:52 +08:00
|
|
|
guide_list_ptr = gimage->guides;
|
|
|
|
while ( guide_list_ptr != NULL)
|
|
|
|
{
|
|
|
|
undo_push_guide (gimage, (Guide *)guide_list_ptr->data);
|
|
|
|
guide_list_ptr = guide_list_ptr->next;
|
|
|
|
}
|
|
|
|
undo_push_group_end (gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-12-04 14:46:52 +08:00
|
|
|
/* Adjust any guides we might have laying about */
|
|
|
|
crop_adjust_guides (gimage, x1, y1, x2, y2);
|
|
|
|
|
|
|
|
/* shrink wrap and update all views */
|
|
|
|
channel_invalidate_previews (gimage);
|
|
|
|
layer_invalidate_previews (gimage);
|
|
|
|
gimage_invalidate_preview (gimage);
|
|
|
|
gdisplays_update_full (gimage);
|
|
|
|
gdisplays_shrink_wrap (gimage);
|
|
|
|
}
|
1999-01-18 01:03:54 +08:00
|
|
|
gimp_remove_busy_cursors(NULL);
|
1998-12-04 14:46:52 +08:00
|
|
|
gdisplays_flush ();
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
crop_recalc (Tool *tool,
|
|
|
|
Crop *crop)
|
|
|
|
{
|
|
|
|
GDisplay * gdisp;
|
|
|
|
|
|
|
|
gdisp = (GDisplay *) tool->gdisp_ptr;
|
|
|
|
|
|
|
|
gdisplay_transform_coords (gdisp, crop->tx1, crop->ty1,
|
|
|
|
&crop->x1, &crop->y1, FALSE);
|
|
|
|
gdisplay_transform_coords (gdisp, crop->tx2, crop->ty2,
|
|
|
|
&crop->x2, &crop->y2, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
crop_start (Tool *tool,
|
|
|
|
Crop *crop)
|
|
|
|
{
|
1999-04-03 03:46:59 +08:00
|
|
|
static GDisplay * old_gdisp = NULL;
|
|
|
|
GDisplay * gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gdisp = (GDisplay *) tool->gdisp_ptr;
|
|
|
|
|
|
|
|
crop_recalc (tool, crop);
|
1999-04-06 20:13:54 +08:00
|
|
|
|
|
|
|
if (! crop_info)
|
|
|
|
crop_info_create (tool);
|
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
gtk_signal_handler_block_by_data (GTK_OBJECT (origin_sizeentry), crop_info);
|
|
|
|
gtk_signal_handler_block_by_data (GTK_OBJECT (size_sizeentry), crop_info);
|
|
|
|
|
1999-04-06 20:13:54 +08:00
|
|
|
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
|
|
|
|
gdisp->gimage->xresolution, FALSE);
|
|
|
|
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
|
|
|
|
gdisp->gimage->yresolution, FALSE);
|
1999-05-31 22:11:10 +08:00
|
|
|
|
|
|
|
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
|
|
|
|
0, gdisp->gimage->width);
|
1999-04-06 20:13:54 +08:00
|
|
|
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
|
|
|
|
0, gdisp->gimage->height);
|
|
|
|
|
|
|
|
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size_sizeentry), 0,
|
|
|
|
gdisp->gimage->xresolution, FALSE);
|
|
|
|
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size_sizeentry), 1,
|
|
|
|
gdisp->gimage->yresolution, FALSE);
|
1999-05-31 22:11:10 +08:00
|
|
|
|
|
|
|
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (size_sizeentry), 0,
|
|
|
|
0, gdisp->gimage->width);
|
1999-04-06 20:13:54 +08:00
|
|
|
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (size_sizeentry), 1,
|
|
|
|
0, gdisp->gimage->height);
|
|
|
|
|
|
|
|
if (old_gdisp != gdisp)
|
1999-04-03 03:46:59 +08:00
|
|
|
{
|
1999-04-06 20:13:54 +08:00
|
|
|
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (origin_sizeentry),
|
1999-05-31 22:11:10 +08:00
|
|
|
gdisp->gimage->unit) ;
|
1999-04-06 20:13:54 +08:00
|
|
|
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (size_sizeentry),
|
1999-05-31 22:11:10 +08:00
|
|
|
gdisp->gimage->unit);
|
|
|
|
|
|
|
|
if (gdisp->dot_for_dot)
|
|
|
|
{
|
|
|
|
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (origin_sizeentry),
|
|
|
|
UNIT_PIXEL);
|
|
|
|
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (size_sizeentry),
|
|
|
|
UNIT_PIXEL);
|
|
|
|
}
|
1999-04-03 03:46:59 +08:00
|
|
|
}
|
1999-04-06 20:13:54 +08:00
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
gtk_signal_handler_unblock_by_data (GTK_OBJECT (size_sizeentry), crop_info);
|
|
|
|
gtk_signal_handler_unblock_by_data (GTK_OBJECT (origin_sizeentry), crop_info);
|
|
|
|
|
1999-04-03 03:46:59 +08:00
|
|
|
old_gdisp = gdisp;
|
|
|
|
|
1998-07-27 05:49:42 +08:00
|
|
|
/* initialize the statusbar display */
|
1999-04-03 03:46:59 +08:00
|
|
|
crop->context_id =
|
|
|
|
gtk_statusbar_get_context_id (GTK_STATUSBAR (gdisp->statusbar), "crop");
|
|
|
|
gtk_statusbar_push (GTK_STATUSBAR (gdisp->statusbar),
|
|
|
|
crop->context_id, _("Crop: 0 x 0"));
|
1998-07-27 05:49:42 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
draw_core_start (crop->core, gdisp->canvas->window, tool);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
/***************************/
|
|
|
|
/* Crop dialog functions */
|
|
|
|
/***************************/
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
crop_info_create (Tool *tool)
|
|
|
|
{
|
1999-04-13 05:53:41 +08:00
|
|
|
GDisplay *gdisp;
|
|
|
|
GtkWidget *spinbutton;
|
|
|
|
GtkWidget *bbox;
|
|
|
|
GtkWidget *button;
|
1999-04-03 03:46:59 +08:00
|
|
|
|
|
|
|
gdisp = (GDisplay *) tool->gdisp_ptr;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* create the info dialog */
|
1999-09-28 01:58:10 +08:00
|
|
|
crop_info = info_dialog_new (_("Crop & Resize Information"),
|
|
|
|
tools_help_func, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
/* create the action area */
|
|
|
|
gimp_dialog_create_action_area (GTK_DIALOG (crop_info->shell),
|
|
|
|
|
|
|
|
_("Crop"), crop_crop_callback,
|
2000-01-07 00:40:17 +08:00
|
|
|
NULL, NULL, NULL, TRUE, FALSE,
|
1999-10-27 02:27:27 +08:00
|
|
|
_("Resize"), crop_resize_callback,
|
2000-01-07 00:40:17 +08:00
|
|
|
NULL, NULL, NULL, FALSE, FALSE,
|
1999-10-27 02:27:27 +08:00
|
|
|
_("Close"), crop_close_callback,
|
2000-01-07 00:40:17 +08:00
|
|
|
NULL, NULL, NULL, FALSE, FALSE,
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* add the information fields */
|
1999-04-06 20:13:54 +08:00
|
|
|
spinbutton = info_dialog_add_spinbutton (crop_info, _("Origin X:"), NULL,
|
1999-04-03 03:46:59 +08:00
|
|
|
-1, 1, 1, 10, 1, 1, 2, NULL, NULL);
|
1999-04-06 20:13:54 +08:00
|
|
|
origin_sizeentry =
|
1999-04-03 03:46:59 +08:00
|
|
|
info_dialog_add_sizeentry (crop_info, _("Y:"), orig_vals, 1,
|
|
|
|
gdisp->dot_for_dot ?
|
|
|
|
UNIT_PIXEL : gdisp->gimage->unit, "%a",
|
1999-04-06 20:13:54 +08:00
|
|
|
TRUE, TRUE, FALSE, GIMP_SIZE_ENTRY_UPDATE_SIZE,
|
1999-06-26 19:16:47 +08:00
|
|
|
crop_orig_changed, crop_info);
|
1999-04-06 20:13:54 +08:00
|
|
|
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (origin_sizeentry),
|
|
|
|
GTK_SPIN_BUTTON (spinbutton), NULL);
|
1999-04-03 03:46:59 +08:00
|
|
|
|
1999-05-31 22:11:10 +08:00
|
|
|
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
|
|
|
|
-65536, 65536);
|
1999-04-06 20:13:54 +08:00
|
|
|
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
|
1999-04-03 03:46:59 +08:00
|
|
|
-65536, 65536);
|
1999-05-31 22:11:10 +08:00
|
|
|
|
1999-04-06 20:13:54 +08:00
|
|
|
spinbutton = info_dialog_add_spinbutton (crop_info, _("Width:"), NULL,
|
1999-04-03 03:46:59 +08:00
|
|
|
-1, 1, 1, 10, 1, 1, 2, NULL, NULL);
|
1999-04-06 20:13:54 +08:00
|
|
|
size_sizeentry =
|
1999-04-03 03:46:59 +08:00
|
|
|
info_dialog_add_sizeentry (crop_info, _("Height:"), size_vals, 1,
|
|
|
|
gdisp->dot_for_dot ?
|
|
|
|
UNIT_PIXEL : gdisp->gimage->unit, "%a",
|
1999-04-06 20:13:54 +08:00
|
|
|
TRUE, TRUE, FALSE, GIMP_SIZE_ENTRY_UPDATE_SIZE,
|
1999-06-26 19:16:47 +08:00
|
|
|
crop_size_changed, crop_info);
|
1999-04-06 20:13:54 +08:00
|
|
|
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (size_sizeentry),
|
|
|
|
GTK_SPIN_BUTTON (spinbutton), NULL);
|
1999-04-03 03:46:59 +08:00
|
|
|
|
1999-05-31 22:11:10 +08:00
|
|
|
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (size_sizeentry), 0,
|
|
|
|
-65536, 65536);
|
1999-04-06 20:13:54 +08:00
|
|
|
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (size_sizeentry), 1,
|
1999-04-03 03:46:59 +08:00
|
|
|
-65536, 65536);
|
1999-05-31 22:11:10 +08:00
|
|
|
|
1999-04-03 03:46:59 +08:00
|
|
|
gtk_table_set_row_spacing (GTK_TABLE (crop_info->info_table), 0, 0);
|
|
|
|
gtk_table_set_row_spacing (GTK_TABLE (crop_info->info_table), 1, 6);
|
|
|
|
gtk_table_set_row_spacing (GTK_TABLE (crop_info->info_table), 2, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-13 05:53:41 +08:00
|
|
|
/* Create the area selection buttons */
|
|
|
|
bbox = gtk_hbutton_box_new ();
|
|
|
|
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_SPREAD);
|
|
|
|
gtk_button_box_set_spacing (GTK_BUTTON_BOX (bbox), 4);
|
|
|
|
|
|
|
|
button = gtk_button_new_with_label (_("From Selection"));
|
|
|
|
gtk_container_add( GTK_CONTAINER(bbox), button);
|
|
|
|
gtk_signal_connect(GTK_OBJECT (button) , "clicked",
|
|
|
|
(GtkSignalFunc) crop_selection_callback, NULL);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
1999-07-01 00:19:52 +08:00
|
|
|
button = gtk_button_new_with_label (_("Auto Shrink"));
|
1999-04-13 05:53:41 +08:00
|
|
|
gtk_container_add(GTK_CONTAINER (bbox), button);
|
|
|
|
gtk_signal_connect(GTK_OBJECT (button) , "clicked",
|
|
|
|
(GtkSignalFunc) crop_automatic_callback, NULL);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (crop_info->vbox), bbox, FALSE, FALSE, 2);
|
|
|
|
gtk_widget_show (bbox);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
crop_info_update (Tool *tool)
|
|
|
|
{
|
|
|
|
Crop * crop;
|
1999-04-27 10:09:03 +08:00
|
|
|
GDisplay * gdisp;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
crop = (Crop *) tool->private;
|
1999-04-27 10:09:03 +08:00
|
|
|
gdisp = (GDisplay *) tool->gdisp_ptr;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-03 03:46:59 +08:00
|
|
|
orig_vals[0] = crop->tx1;
|
|
|
|
orig_vals[1] = crop->ty1;
|
|
|
|
size_vals[0] = crop->tx2 - crop->tx1;
|
|
|
|
size_vals[1] = crop->ty2 - crop->ty1;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
info_dialog_update (crop_info);
|
|
|
|
info_dialog_popup (crop_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-04-29 02:58:01 +08:00
|
|
|
crop_crop_callback (GtkWidget *w,
|
|
|
|
gpointer client_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
Tool * tool;
|
|
|
|
Crop * crop;
|
|
|
|
GDisplay * gdisp;
|
|
|
|
|
|
|
|
tool = active_tool;
|
|
|
|
crop = (Crop *) tool->private;
|
|
|
|
gdisp = (GDisplay *) tool->gdisp_ptr;
|
1999-04-08 13:20:37 +08:00
|
|
|
crop_image (gdisp->gimage, crop->tx1, crop->ty1, crop->tx2, crop->ty2,
|
1999-04-09 06:25:54 +08:00
|
|
|
crop_options->layer_only, TRUE);
|
1999-04-08 13:20:37 +08:00
|
|
|
|
|
|
|
/* Finish the tool */
|
1999-06-26 19:16:47 +08:00
|
|
|
crop_close_callback (NULL, NULL);
|
1999-04-08 13:20:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
crop_resize_callback (GtkWidget *w,
|
|
|
|
gpointer client_data)
|
|
|
|
{
|
|
|
|
Tool * tool;
|
|
|
|
Crop * crop;
|
|
|
|
GDisplay * gdisp;
|
|
|
|
|
|
|
|
tool = active_tool;
|
|
|
|
crop = (Crop *) tool->private;
|
|
|
|
gdisp = (GDisplay *) tool->gdisp_ptr;
|
|
|
|
crop_image (gdisp->gimage, crop->tx1, crop->ty1, crop->tx2, crop->ty2,
|
1999-04-09 06:25:54 +08:00
|
|
|
crop_options->layer_only, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Finish the tool */
|
1999-06-26 19:16:47 +08:00
|
|
|
crop_close_callback (NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
crop_close_callback (GtkWidget *w,
|
|
|
|
gpointer client_data)
|
|
|
|
{
|
|
|
|
Tool * tool;
|
|
|
|
Crop * crop;
|
|
|
|
|
|
|
|
tool = active_tool;
|
|
|
|
crop = (Crop *) tool->private;
|
|
|
|
|
|
|
|
if (tool->state == ACTIVE)
|
|
|
|
draw_core_stop (crop->core, tool);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
info_dialog_popdown (crop_info);
|
1999-06-26 19:16:47 +08:00
|
|
|
|
|
|
|
tool->gdisp_ptr = NULL;
|
|
|
|
tool->drawable = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
tool->state = INACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
crop_selection_callback (GtkWidget *w,
|
|
|
|
gpointer client_data)
|
|
|
|
{
|
|
|
|
Tool * tool;
|
|
|
|
Crop * crop;
|
1999-04-13 05:53:41 +08:00
|
|
|
Layer * layer;
|
1997-11-25 06:05:25 +08:00
|
|
|
GDisplay * gdisp;
|
|
|
|
|
|
|
|
tool = active_tool;
|
|
|
|
crop = (Crop *) tool->private;
|
|
|
|
gdisp = (GDisplay *) tool->gdisp_ptr;
|
|
|
|
|
|
|
|
draw_core_pause (crop->core, tool);
|
|
|
|
if (! gimage_mask_bounds (gdisp->gimage, &crop->tx1, &crop->ty1, &crop->tx2, &crop->ty2))
|
|
|
|
{
|
1999-04-13 05:53:41 +08:00
|
|
|
if (crop_options->layer_only)
|
|
|
|
{
|
|
|
|
layer = (gdisp->gimage)->active_layer;
|
|
|
|
drawable_offsets (GIMP_DRAWABLE(layer), &crop->tx1, &crop->ty1);
|
|
|
|
crop->tx2 = drawable_width (GIMP_DRAWABLE(layer)) + crop->tx1;
|
|
|
|
crop->ty2 = drawable_height (GIMP_DRAWABLE(layer)) + crop->ty1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
crop->tx1 = crop->ty1 = 0;
|
|
|
|
crop->tx2 = gdisp->gimage->width;
|
|
|
|
crop->ty2 = gdisp->gimage->height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
crop_recalc (tool, crop);
|
|
|
|
draw_core_resume (crop->core, tool);
|
|
|
|
}
|
|
|
|
|
1999-04-15 07:39:12 +08:00
|
|
|
|
1999-04-13 05:53:41 +08:00
|
|
|
static void
|
|
|
|
crop_automatic_callback (GtkWidget *w,
|
|
|
|
gpointer client_data)
|
|
|
|
{
|
|
|
|
Tool * tool;
|
|
|
|
Crop * crop;
|
|
|
|
GDisplay * gdisp;
|
1999-04-21 07:23:40 +08:00
|
|
|
GimpDrawable * active_drawable = NULL;
|
1999-04-13 05:53:41 +08:00
|
|
|
GetColorFunc get_color_func;
|
1999-04-15 07:39:12 +08:00
|
|
|
ColorsEqualFunc colors_equal_func;
|
1999-04-13 05:53:41 +08:00
|
|
|
GtkObject *get_color_obj;
|
|
|
|
guchar bgcolor[4] = {0, 0, 0, 0};
|
1999-04-15 07:39:12 +08:00
|
|
|
gint has_alpha = FALSE;
|
1999-04-21 07:23:40 +08:00
|
|
|
PixelRegion PR;
|
1999-07-01 00:19:52 +08:00
|
|
|
guchar *buffer = NULL;
|
|
|
|
gint offset_x, offset_y, width, height, bytes;
|
1999-04-13 05:53:41 +08:00
|
|
|
gint x, y, abort;
|
|
|
|
gint x1, y1, x2, y2;
|
1999-04-15 07:39:12 +08:00
|
|
|
|
1999-04-13 05:53:41 +08:00
|
|
|
tool = active_tool;
|
|
|
|
crop = (Crop *) tool->private;
|
|
|
|
gdisp = (GDisplay *) tool->gdisp_ptr;
|
|
|
|
|
|
|
|
draw_core_pause (crop->core, tool);
|
|
|
|
gimp_add_busy_cursors ();
|
|
|
|
|
1999-07-01 00:19:52 +08:00
|
|
|
/* You should always keep in mind that crop->tx2 and crop->ty2 are the NOT the
|
|
|
|
coordinates of the bottomright corner of the area to be cropped. They point
|
|
|
|
at the pixel located one to the right and one to the bottom.
|
|
|
|
*/
|
|
|
|
|
1999-04-13 05:53:41 +08:00
|
|
|
if (crop_options->layer_only)
|
|
|
|
{
|
|
|
|
if (!(active_drawable = gimage_active_drawable (gdisp->gimage)))
|
|
|
|
return;
|
1999-07-01 00:19:52 +08:00
|
|
|
width = drawable_width (GIMP_DRAWABLE (active_drawable));
|
1999-04-13 05:53:41 +08:00
|
|
|
height = drawable_height (GIMP_DRAWABLE (active_drawable));
|
|
|
|
bytes = drawable_bytes (GIMP_DRAWABLE (active_drawable));
|
1999-04-15 07:39:12 +08:00
|
|
|
if (drawable_has_alpha (GIMP_DRAWABLE (active_drawable)))
|
|
|
|
has_alpha = TRUE;
|
1999-04-13 05:53:41 +08:00
|
|
|
get_color_obj = GTK_OBJECT (active_drawable);
|
|
|
|
get_color_func = (GetColorFunc) gimp_drawable_get_color_at;
|
1999-07-01 00:19:52 +08:00
|
|
|
drawable_offsets (GIMP_DRAWABLE (active_drawable), &offset_x, &offset_y);
|
1999-04-13 05:53:41 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = gdisp->gimage->width;
|
|
|
|
height = gdisp->gimage->height;
|
1999-07-01 00:19:52 +08:00
|
|
|
has_alpha = TRUE;
|
|
|
|
bytes = gimp_image_composite_bytes (gdisp->gimage);
|
1999-04-13 05:53:41 +08:00
|
|
|
get_color_obj = GTK_OBJECT (gdisp->gimage);
|
|
|
|
get_color_func = (GetColorFunc) gimp_image_get_color_at;
|
1999-07-01 00:19:52 +08:00
|
|
|
offset_x = offset_y = 0;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-01 00:19:52 +08:00
|
|
|
x1 = crop->tx1 - offset_x > 0 ? crop->tx1 - offset_x : 0;
|
|
|
|
x2 = crop->tx2 - offset_x < width ? crop->tx2 - offset_x : width;
|
|
|
|
y1 = crop->ty1 - offset_y > 0 ? crop->ty1 - offset_y : 0;
|
|
|
|
y2 = crop->ty2 - offset_y < height ? crop->ty2 - offset_y : height;
|
|
|
|
|
|
|
|
switch (crop_guess_bgcolor (get_color_obj, get_color_func, bytes, has_alpha,
|
|
|
|
bgcolor, x1, x2-1, y1, y2-1))
|
1999-04-15 07:39:12 +08:00
|
|
|
{
|
|
|
|
case AUTO_CROP_ALPHA:
|
|
|
|
colors_equal_func = (ColorsEqualFunc) crop_colors_alpha;
|
|
|
|
break;
|
|
|
|
case AUTO_CROP_COLOR:
|
|
|
|
colors_equal_func = (ColorsEqualFunc) crop_colors_equal;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto FINISH;
|
|
|
|
}
|
1999-04-13 05:53:41 +08:00
|
|
|
|
1999-07-01 00:19:52 +08:00
|
|
|
width = x2 - x1;
|
|
|
|
height = y2 - y1;
|
|
|
|
|
1999-04-21 07:23:40 +08:00
|
|
|
if (crop_options->layer_only)
|
1999-07-01 00:19:52 +08:00
|
|
|
pixel_region_init (&PR, drawable_data (active_drawable),
|
|
|
|
x1, y1, width, height, FALSE);
|
1999-04-21 07:23:40 +08:00
|
|
|
else
|
1999-07-01 00:19:52 +08:00
|
|
|
pixel_region_init (&PR, gimp_image_composite (gdisp->gimage),
|
|
|
|
x1, y1, width, height, FALSE);
|
1999-04-21 07:23:40 +08:00
|
|
|
|
1999-07-01 00:19:52 +08:00
|
|
|
/* The following could be optimized further by processing the smaller side first
|
|
|
|
instead of defaulting to width --Sven
|
|
|
|
*/
|
1999-04-21 07:23:40 +08:00
|
|
|
|
1999-07-01 00:19:52 +08:00
|
|
|
buffer = g_malloc ((width > height ? width : height) * bytes);
|
1999-04-15 07:39:12 +08:00
|
|
|
|
|
|
|
/* Check how many of the top lines are uniform/transparent. */
|
|
|
|
abort = FALSE;
|
1999-07-01 00:19:52 +08:00
|
|
|
for (y = y1; y < y2 && !abort; y++)
|
1999-04-21 07:23:40 +08:00
|
|
|
{
|
1999-07-01 00:19:52 +08:00
|
|
|
pixel_region_get_row (&PR, x1, y, width, buffer, 1);
|
1999-04-21 07:23:40 +08:00
|
|
|
for (x = 0; x < width && !abort; x++)
|
|
|
|
abort = !(colors_equal_func) (bgcolor, buffer + x * bytes, bytes);
|
|
|
|
}
|
1999-07-01 00:19:52 +08:00
|
|
|
if (y == y2 && !abort)
|
1999-04-13 05:53:41 +08:00
|
|
|
goto FINISH;
|
|
|
|
y1 = y - 1;
|
|
|
|
|
1999-04-15 07:39:12 +08:00
|
|
|
/* Check how many of the bottom lines are uniform/transparent. */
|
|
|
|
abort = FALSE;
|
1999-07-01 00:19:52 +08:00
|
|
|
for (y = y2; y > y1 && !abort; y--)
|
1999-04-21 07:23:40 +08:00
|
|
|
{
|
1999-07-01 00:19:52 +08:00
|
|
|
pixel_region_get_row (&PR, x1, y-1 , width, buffer, 1);
|
1999-04-21 07:23:40 +08:00
|
|
|
for (x = 0; x < width && !abort; x++)
|
|
|
|
abort = !(colors_equal_func) (bgcolor, buffer + x * bytes, bytes);
|
|
|
|
}
|
1999-04-13 05:53:41 +08:00
|
|
|
y2 = y + 1;
|
|
|
|
|
1999-07-01 00:19:52 +08:00
|
|
|
/* compute a new height for the next operations */
|
|
|
|
height = y2 - y1;
|
|
|
|
|
1999-04-15 07:39:12 +08:00
|
|
|
/* Check how many of the left lines are uniform/transparent. */
|
|
|
|
abort = FALSE;
|
1999-07-01 00:19:52 +08:00
|
|
|
for (x = x1; x < x2 && !abort; x++)
|
1999-04-21 07:23:40 +08:00
|
|
|
{
|
1999-07-01 00:19:52 +08:00
|
|
|
pixel_region_get_col (&PR, x, y1, height, buffer, 1);
|
|
|
|
for (y = 0; y < height && !abort; y++)
|
1999-04-21 07:23:40 +08:00
|
|
|
abort = !(colors_equal_func) (bgcolor, buffer + y * bytes, bytes);
|
|
|
|
}
|
1999-04-13 05:53:41 +08:00
|
|
|
x1 = x - 1;
|
|
|
|
|
1999-04-15 07:39:12 +08:00
|
|
|
/* Check how many of the right lines are uniform/transparent. */
|
|
|
|
abort = FALSE;
|
1999-07-01 00:19:52 +08:00
|
|
|
for (x = x2; x > x1 && !abort; x--)
|
1999-04-21 07:23:40 +08:00
|
|
|
{
|
1999-07-01 00:19:52 +08:00
|
|
|
pixel_region_get_col (&PR, x-1, y1, height, buffer, 1);
|
|
|
|
for (y = 0; y < height && !abort; y++)
|
1999-04-21 07:23:40 +08:00
|
|
|
abort = !(colors_equal_func) (bgcolor, buffer + y * bytes, bytes);
|
|
|
|
}
|
1999-04-13 05:53:41 +08:00
|
|
|
x2 = x + 1;
|
|
|
|
|
1999-07-01 00:19:52 +08:00
|
|
|
crop->tx1 = offset_x + x1;
|
|
|
|
crop->tx2 = offset_x + x2;
|
|
|
|
crop->ty1 = offset_y + y1;
|
|
|
|
crop->ty2 = offset_y + y2;
|
1999-04-21 07:23:40 +08:00
|
|
|
|
1999-07-01 00:19:52 +08:00
|
|
|
crop_recalc (tool, crop);
|
1999-04-13 05:53:41 +08:00
|
|
|
|
|
|
|
FINISH:
|
1999-07-01 00:19:52 +08:00
|
|
|
g_free (buffer);
|
1999-04-13 05:53:41 +08:00
|
|
|
gimp_remove_busy_cursors (NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
draw_core_resume (crop->core, tool);
|
1999-04-13 05:53:41 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-04-15 07:39:12 +08:00
|
|
|
static AutoCropType
|
1999-04-13 05:53:41 +08:00
|
|
|
crop_guess_bgcolor (GtkObject *get_color_obj,
|
|
|
|
GetColorFunc get_color_func,
|
1999-06-22 06:12:07 +08:00
|
|
|
int bytes,
|
|
|
|
int has_alpha,
|
1999-07-01 00:19:52 +08:00
|
|
|
guchar *color,
|
|
|
|
int x1,
|
|
|
|
int x2,
|
|
|
|
int y1,
|
|
|
|
int y2)
|
1999-04-13 05:53:41 +08:00
|
|
|
{
|
1999-04-15 07:39:12 +08:00
|
|
|
guchar *tl = NULL;
|
|
|
|
guchar *tr = NULL;
|
|
|
|
guchar *bl = NULL;
|
|
|
|
guchar *br = NULL;
|
|
|
|
gint i, alpha;
|
|
|
|
|
1999-07-01 00:19:52 +08:00
|
|
|
for (i = 0; i < bytes; i++)
|
1999-04-15 07:39:12 +08:00
|
|
|
color[i] = 0;
|
|
|
|
|
|
|
|
/* First check if there's transparency to crop. If not, guess the
|
|
|
|
* background-color to see if at least 2 corners are equal.
|
1999-04-13 05:53:41 +08:00
|
|
|
*/
|
|
|
|
|
1999-07-01 00:19:52 +08:00
|
|
|
if (!(tl = (*get_color_func) (get_color_obj, x1, y1)))
|
1999-04-15 07:39:12 +08:00
|
|
|
goto ERROR;
|
1999-07-01 00:19:52 +08:00
|
|
|
if (!(tr = (*get_color_func) (get_color_obj, x1, y2)))
|
1999-04-15 07:39:12 +08:00
|
|
|
goto ERROR;
|
1999-07-01 00:19:52 +08:00
|
|
|
if (!(bl = (*get_color_func) (get_color_obj, x2, y1)))
|
1999-04-15 07:39:12 +08:00
|
|
|
goto ERROR;
|
1999-07-01 00:19:52 +08:00
|
|
|
if (!(br = (*get_color_func) (get_color_obj, x2, y2)))
|
1999-04-15 07:39:12 +08:00
|
|
|
goto ERROR;
|
|
|
|
|
|
|
|
if (has_alpha)
|
|
|
|
{
|
|
|
|
alpha = bytes - 1;
|
|
|
|
if ((tl[alpha] == 0 && tr[alpha] == 0) ||
|
|
|
|
(tl[alpha] == 0 && bl[alpha] == 0) ||
|
|
|
|
(tr[alpha] == 0 && br[alpha] == 0) ||
|
|
|
|
(bl[alpha] == 0 && br[alpha] == 0))
|
|
|
|
{
|
|
|
|
g_free (tl);
|
|
|
|
g_free (tr);
|
|
|
|
g_free (bl);
|
|
|
|
g_free (br);
|
|
|
|
return AUTO_CROP_ALPHA;
|
|
|
|
}
|
|
|
|
}
|
1999-04-13 05:53:41 +08:00
|
|
|
|
1999-04-15 07:39:12 +08:00
|
|
|
if (crop_colors_equal (tl, tr, bytes) || crop_colors_equal (tl, bl, bytes))
|
|
|
|
memcpy (color, tl, bytes);
|
|
|
|
else if (crop_colors_equal (br, bl, bytes) || crop_colors_equal (br, tr, bytes))
|
|
|
|
memcpy (color, br, bytes);
|
1999-04-13 05:53:41 +08:00
|
|
|
else
|
1999-04-15 07:39:12 +08:00
|
|
|
goto ERROR;
|
1999-04-13 05:53:41 +08:00
|
|
|
|
|
|
|
g_free (tl);
|
|
|
|
g_free (tr);
|
|
|
|
g_free (bl);
|
|
|
|
g_free (br);
|
1999-04-15 07:39:12 +08:00
|
|
|
return AUTO_CROP_COLOR;
|
1999-04-13 05:53:41 +08:00
|
|
|
|
1999-04-15 07:39:12 +08:00
|
|
|
ERROR:
|
|
|
|
g_free (tl);
|
|
|
|
g_free (tr);
|
|
|
|
g_free (bl);
|
|
|
|
g_free (br);
|
|
|
|
return AUTO_CROP_NOTHING;
|
1999-04-13 05:53:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
crop_colors_equal (guchar *col1,
|
|
|
|
guchar *col2,
|
1999-06-22 06:12:07 +08:00
|
|
|
int bytes)
|
1999-04-13 05:53:41 +08:00
|
|
|
{
|
1999-04-15 07:39:12 +08:00
|
|
|
int equal = TRUE;
|
1999-04-13 05:53:41 +08:00
|
|
|
int b;
|
|
|
|
|
|
|
|
for (b = 0; b < bytes; b++) {
|
|
|
|
if (col1[b] != col2[b]) {
|
1999-04-15 07:39:12 +08:00
|
|
|
equal = FALSE;
|
1999-04-13 05:53:41 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return equal;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-04-15 07:39:12 +08:00
|
|
|
static int
|
|
|
|
crop_colors_alpha (guchar *dummy,
|
|
|
|
guchar *col,
|
1999-06-22 06:12:07 +08:00
|
|
|
int bytes)
|
1999-04-15 07:39:12 +08:00
|
|
|
{
|
|
|
|
if (col[bytes-1] == 0)
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1998-08-15 21:34:54 +08:00
|
|
|
static void
|
1999-04-03 03:46:59 +08:00
|
|
|
crop_orig_changed (GtkWidget *w,
|
|
|
|
gpointer data)
|
1998-08-15 21:34:54 +08:00
|
|
|
{
|
1999-04-03 03:46:59 +08:00
|
|
|
Tool *tool;
|
|
|
|
Crop *crop;
|
|
|
|
GDisplay *gdisp;
|
|
|
|
int ox;
|
|
|
|
int oy;
|
1998-08-15 21:34:54 +08:00
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
tool = active_tool;
|
1998-08-15 21:34:54 +08:00
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
if (tool && active_tool->type == CROP)
|
1998-08-15 21:34:54 +08:00
|
|
|
{
|
|
|
|
gdisp = (GDisplay *) tool->gdisp_ptr;
|
|
|
|
crop = (Crop *) tool->private;
|
1999-04-03 03:46:59 +08:00
|
|
|
ox = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (w), 0);
|
|
|
|
oy = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (w), 1);
|
1998-08-15 21:34:54 +08:00
|
|
|
|
1999-04-03 03:46:59 +08:00
|
|
|
if ((ox != crop->tx1) ||
|
|
|
|
(oy != crop->ty1))
|
1998-08-15 21:34:54 +08:00
|
|
|
{
|
|
|
|
draw_core_pause (crop->core, tool);
|
1999-04-03 03:46:59 +08:00
|
|
|
crop->tx2 = crop->tx2 + (ox - crop->tx1);
|
|
|
|
crop->tx1 = ox;
|
|
|
|
crop->ty2 = crop->ty2 + (oy - crop->ty1);
|
|
|
|
crop->ty1 = oy;
|
1998-08-15 21:34:54 +08:00
|
|
|
crop_recalc (tool, crop);
|
|
|
|
draw_core_resume (crop->core, tool);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-04-03 03:46:59 +08:00
|
|
|
crop_size_changed (GtkWidget *w,
|
|
|
|
gpointer data)
|
1998-08-15 21:34:54 +08:00
|
|
|
{
|
1999-04-03 03:46:59 +08:00
|
|
|
Tool *tool;
|
|
|
|
Crop *crop;
|
|
|
|
GDisplay *gdisp;
|
|
|
|
int sx;
|
|
|
|
int sy;
|
1998-08-15 21:34:54 +08:00
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
tool = active_tool;
|
1998-08-15 21:34:54 +08:00
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
if (tool && active_tool->type == CROP)
|
1998-08-15 21:34:54 +08:00
|
|
|
{
|
|
|
|
gdisp = (GDisplay *) tool->gdisp_ptr;
|
|
|
|
crop = (Crop *) tool->private;
|
1999-04-03 03:46:59 +08:00
|
|
|
sx = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (w), 0);
|
|
|
|
sy = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (w), 1);
|
1998-08-15 21:34:54 +08:00
|
|
|
|
1999-04-03 03:46:59 +08:00
|
|
|
if ((sx != (crop->tx2 - crop->tx1)) ||
|
|
|
|
(sy != (crop->ty2 - crop->ty1)))
|
1998-08-15 21:34:54 +08:00
|
|
|
{
|
|
|
|
draw_core_pause (crop->core, tool);
|
1999-04-03 03:46:59 +08:00
|
|
|
crop->tx2 = sx + crop->tx1;
|
|
|
|
crop->ty2 = sy + crop->ty1;
|
1998-08-15 21:34:54 +08:00
|
|
|
crop_recalc (tool, crop);
|
|
|
|
draw_core_resume (crop->core, tool);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|