gimp/app/tools/gimprotatetool.c
Michael Natterer 02fde14c95 build display/ before tools/.
2001-11-08  Michael Natterer  <mitch@gimp.org>

	* app/Makefile.am: build display/ before tools/.

	* app/devices.c: devices_check_change(): added all events
	which have a GdkDevice pointer.

	* app/gimpprogress.c: include "display-types.h" instead of
	"core-types.h".

	* app/core/Makefile.am
	* app/core/gimpdrawable-bucket-fill.[ch]: new files: the bucket_fill
	stuff taken from tools/gimpbucketfilltool.[ch].

	* app/core/core-types.h: added "BucketFillMode".

	* app/core/gimpimage-mask-select.[ch]: cleanup.

	* app/core/gimpmarshal.list: added more marshallers for GimpTool's
	new signal signatures.

	* app/core/gimpmarshal.[ch]: regenerated.

	* app/display/Makefile.am
	* app/display/gimpdisplayshell-dnd.[ch]
	* app/display/gimpdisplayshell-layer-select.[ch]: new files: the
	canvas drop callbacks from gimpdisplayshell-callbacks.[ch] and
	the stuff formerly knows as gui/layer-select.[ch].

	* app/display/gimpdisplay.h: don't include "gui/gui-types.h".

	* app/display/gximage.c: include "display-types.h".

	* app/display/gimpdisplay-foreach.c
	* app/display/gimpdisplayshell.[ch]: call gdsplay_delete(), don't
	destroy the shell widget.

	* app/gui/Makefile.am
	* app/gui/layer-select.[ch]: removed.

	* app/gui/gradients-commands.c: fixed "Save as POV" fprintf()s.

	* app/gui/preferences-dialog.c: removed the layer_select stuff
	because it is useless with the new preview system.

	* app/gui/tool-options-dialog.c: send the correct data to the
	close_callback.

	* app/gui/tools-commands.c: changed to follow the new
	gimp_tool_initialize() semantics (see below).

	Tool & canvas event handling chainsawing:

	* app/tools/tools-types.h: new struct GimpCoords which contains
	x, y, pressure, tilt etc.

	* app/display/gimpdisplayshell-callbacks.[ch]: added utility
	functions which transparently retreive the current event's
	GimpCoords or take it from the device directly if the event has
	none. Pass GimpCoords _in_image_coordinates_ to all tool
	functions.

	Most important: don't pass GdkEvents and display coordinates to
	tools any more.

	* app/tools/gimptool.[ch]: changed virtual functions to take
	GimpCoords, time and state separately instead of GdkEvents.

	* app/tools/gimpbezierselecttool.c
	* app/tools/gimpblendtool.c
	* app/tools/gimpbucketfilltool.[ch]
	* app/tools/gimpbycolorselecttool.c
	* app/tools/gimpclonetool.c
	* app/tools/gimpcolorpickertool.c
	* app/tools/gimpconvolvetool.c
	* app/tools/gimpcroptool.[ch]
	* app/tools/gimpcurvestool.c
	* app/tools/gimpdodgeburntool.c
	* app/tools/gimpdrawtool.c
	* app/tools/gimpeditselectiontool.[ch]
	* app/tools/gimperasertool.c
	* app/tools/gimpfliptool.c
	* app/tools/gimpfreeselecttool.[ch]
	* app/tools/gimpfuzzyselecttool.c
	* app/tools/gimpinktool.c
	* app/tools/gimpiscissorstool.c
	* app/tools/gimpmagnifytool.c
	* app/tools/gimpmeasuretool.c
	* app/tools/gimpmovetool.c
	* app/tools/gimppainttool.c
	* app/tools/gimppathtool.[ch]
	* app/tools/gimprectselecttool.c
	* app/tools/gimprotatetool.c
	* app/tools/gimpselectiontool.[ch]
	* app/tools/gimpsmudgetool.c
	* app/tools/gimptexttool.c
	* app/tools/gimptransformtool.[ch]
	* app/tools/path_tool.[ch]
	* app/tools/selection_options.c: tons and tons of changes:

	- changed to use the new virtual function parameters.
	- removed zillions of gdisplay_untransform_coords().
	- get the active drawable's offsets manually in many cases.
	  (questionable, but IMHO ok because it's obvious and not simply a
	  "TRUE" passed to some function)
	- reordered some functions to be consistent across tools.
	- some tools had to be changed to work on image coords, not
	  display ones (esp. crop).
	- fixed strange rotate tool behaviour which should be backported
	  to stable.
	- some stuff i came across.
	- indentation and other paranoia.
	- rounding of coordinated may be broken in some tools.
	- new bugs guaranteed.

	* app/tools/tool_manager.[ch]: new semantic of
	tool_manager_initialize_active() (looked at the places where it
	was used from and put common code together). Should be a bit
	better now :)

	* app/tools/gimpblendtool.c
	* app/tools/transform_options.c: use the new GTK+ feature that a
	widget (toggle button) can be a frame's title for this tools' tool
	options.

	* app/widgets/widgets-types.h: stuff.

	* themes/Default/gtkrc: s/GtkDialog/GimpDialog/.

	* tools/pdbgen/Makefile.am: don't scan tools/gimpbucketfilltool.h
	any more.

	* tools/pdbgen/enums.pl: regenerated.

	* tools/pdbgen/pdb/tools.pdb: changed bucket_fill wrapper.

	* app/pdb/tools_cmds.c: regenerated.
2001-11-08 19:14:51 +00:00

500 lines
14 KiB
C

/* 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "libgimpmath/gimpmath.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
#include "gui/gui-types.h"
#include "paint-funcs/paint-funcs.h"
#include "core/gimpimage.h"
#include "gui/info-dialog.h"
#include "display/gimpdisplay.h"
#include "gimprotatetool.h"
#include "tool_manager.h"
#include "tool_options.h"
#include "transform_options.h"
#include "gimpprogress.h"
#include "undo.h"
#include "path_transform.h"
#include "libgimp/gimpintl.h"
/* index into trans_info array */
#define ANGLE 0
#define REAL_ANGLE 1
#define CENTER_X 2
#define CENTER_Y 3
#define EPSILON 0.018 /* ~ 1 degree */
#define FIFTEEN_DEG (G_PI / 12.0)
/* local function declarations */
static void gimp_rotate_tool_class_init (GimpRotateToolClass *klass);
static void gimp_rotate_tool_init (GimpRotateTool *rotate_tool);
static TileManager * gimp_rotate_tool_transform (GimpTransformTool *transform_tool,
GimpDisplay *gdisp,
TransformState state);
static void rotate_tool_recalc (GimpTool *tool,
GimpDisplay *gdisp);
static void rotate_tool_motion (GimpTool *tool,
GimpDisplay *gdisp);
static void rotate_info_update (GimpTool *tool);
static void rotate_angle_changed (GtkWidget *entry,
gpointer data);
static void rotate_center_changed (GtkWidget *entry,
gpointer data);
/* variables local to this file */
static gdouble angle_val;
static gdouble center_vals[2];
/* needed for size update */
static GtkWidget *sizeentry = NULL;
static GimpTransformToolClass *parent_class = NULL;
static TransformOptions *rotate_options = NULL;
/* public functions */
void
gimp_rotate_tool_register (Gimp *gimp)
{
tool_manager_register_tool (gimp,
GIMP_TYPE_ROTATE_TOOL,
FALSE,
"gimp:rotate_tool",
_("Rotate Tool"),
_("Rotate the layer or selection"),
N_("/Tools/Transform Tools/Rotate"), "<shift>R",
NULL, "tools/rotate.html",
GIMP_STOCK_TOOL_ROTATE);
}
GType
gimp_rotate_tool_get_type (void)
{
static GType tool_type = 0;
if (! tool_type)
{
static const GTypeInfo tool_info =
{
sizeof (GimpRotateToolClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_rotate_tool_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpRotateTool),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_rotate_tool_init,
};
tool_type = g_type_register_static (GIMP_TYPE_TRANSFORM_TOOL,
"GimpRotateTool",
&tool_info, 0);
}
return tool_type;
}
static void
gimp_rotate_tool_class_init (GimpRotateToolClass *klass)
{
GimpTransformToolClass *trans_class;
trans_class = GIMP_TRANSFORM_TOOL_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
trans_class->transform = gimp_rotate_tool_transform;
}
static void
gimp_rotate_tool_init (GimpRotateTool *rotate_tool)
{
GimpTool *tool;
GimpTransformTool *tr_tool;
tool = GIMP_TOOL (rotate_tool);
tr_tool = GIMP_TRANSFORM_TOOL (rotate_tool);
if (! rotate_options)
{
rotate_options = transform_options_new (GIMP_TYPE_ROTATE_TOOL,
transform_options_reset);
tool_manager_register_tool_options (GIMP_TYPE_ROTATE_TOOL,
(GimpToolOptions *) rotate_options);
}
tool->tool_cursor = GIMP_ROTATE_TOOL_CURSOR;
tr_tool->trans_info[ANGLE] = 0.0;
tr_tool->trans_info[REAL_ANGLE] = 0.0;
tr_tool->trans_info[CENTER_X] = 0.0;
tr_tool->trans_info[CENTER_Y] = 0.0;
/* assemble the transformation matrix */
gimp_matrix3_identity (tr_tool->transform);
}
TileManager *
gimp_rotate_tool_rotate (GimpImage *gimage,
GimpDrawable *drawable,
GimpDisplay *gdisp,
gdouble angle,
TileManager *float_tiles,
gboolean interpolation,
GimpMatrix3 matrix)
{
GimpProgress *progress;
TileManager *ret;
progress = progress_start (gdisp, _("Rotating..."), FALSE, NULL, NULL);
ret = gimp_transform_tool_do (gimage, drawable, float_tiles,
interpolation, matrix,
progress ? progress_update_and_flush :
(GimpProgressFunc) NULL,
progress);
if (progress)
progress_end (progress);
return ret;
}
static TileManager *
gimp_rotate_tool_transform (GimpTransformTool *transform_tool,
GimpDisplay *gdisp,
TransformState state)
{
GimpTool *tool;
GtkWidget *widget;
GtkWidget *spinbutton2;
tool = GIMP_TOOL (transform_tool);
switch (state)
{
case TRANSFORM_INIT:
angle_val = 0.0;
center_vals[0] = transform_tool->cx;
center_vals[1] = transform_tool->cy;
if (!transform_info)
{
transform_info = info_dialog_new (_("Rotation Information"),
gimp_standard_help_func,
"tools/transform_rotate.html");
widget =
info_dialog_add_spinbutton (transform_info, _("Angle:"),
&angle_val,
-180, 180, 1, 15, 1, 1, 2,
G_CALLBACK (rotate_angle_changed),
tool);
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (widget), TRUE);
/* this looks strange (-180, 181), but it works */
widget = info_dialog_add_scale (transform_info, "", &angle_val,
-180, 181, 0.01, 0.1, 1, -1,
G_CALLBACK (rotate_angle_changed),
tool);
gtk_widget_set_usize (widget, 180, 0);
spinbutton2 =
info_dialog_add_spinbutton (transform_info, _("Center X:"), NULL,
-1, 1, 1, 10, 1, 1, 2, NULL, NULL);
sizeentry =
info_dialog_add_sizeentry (transform_info, _("Y:"),
center_vals, 1,
gdisp->gimage->unit, "%a",
TRUE, TRUE, FALSE,
GIMP_SIZE_ENTRY_UPDATE_SIZE,
G_CALLBACK (rotate_center_changed),
tool);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (sizeentry),
GTK_SPIN_BUTTON (spinbutton2), NULL);
gtk_table_set_row_spacing (GTK_TABLE (transform_info->info_table),
1, 6);
gtk_table_set_row_spacing (GTK_TABLE (transform_info->info_table),
2, 0);
}
g_signal_handlers_block_by_func (G_OBJECT (sizeentry),
rotate_center_changed,
tool);
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (sizeentry),
gdisp->gimage->unit);
if (gdisp->dot_for_dot)
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (sizeentry), GIMP_UNIT_PIXEL);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0,
gdisp->gimage->xresolution, FALSE);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 1,
gdisp->gimage->yresolution, FALSE);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 0,
-65536,
65536 + gdisp->gimage->width);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 1,
-65536,
65536 + gdisp->gimage->height);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (sizeentry), 0,
transform_tool->x1, transform_tool->x2);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (sizeentry), 1,
transform_tool->y1, transform_tool->y2);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 0,
center_vals[0]);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 1,
center_vals[1]);
gtk_widget_set_sensitive (transform_info->shell, TRUE);
g_signal_handlers_unblock_by_func (G_OBJECT (sizeentry),
rotate_center_changed,
tool);
transform_tool->trans_info[ANGLE] = angle_val;
transform_tool->trans_info[REAL_ANGLE] = angle_val;
transform_tool->trans_info[CENTER_X] = center_vals[0];
transform_tool->trans_info[CENTER_Y] = center_vals[1];
return NULL;
break;
case TRANSFORM_MOTION:
rotate_tool_motion (tool, gdisp);
rotate_tool_recalc (tool, gdisp);
break;
case TRANSFORM_RECALC:
rotate_tool_recalc (tool, gdisp);
break;
case TRANSFORM_FINISH:
gtk_widget_set_sensitive (GTK_WIDGET (transform_info->shell), FALSE);
return gimp_rotate_tool_rotate (gdisp->gimage,
gimp_image_active_drawable (gdisp->gimage),
gdisp,
transform_tool->trans_info[ANGLE],
transform_tool->original,
gimp_transform_tool_smoothing (),
transform_tool->transform);
break;
}
return NULL;
}
static void
rotate_info_update (GimpTool *tool)
{
GimpTransformTool *transform_tool;
transform_tool = GIMP_TRANSFORM_TOOL (tool);
angle_val = gimp_rad_to_deg (transform_tool->trans_info[ANGLE]);
center_vals[0] = transform_tool->trans_info[CENTER_X];
center_vals[1] = transform_tool->trans_info[CENTER_Y];
info_dialog_update (transform_info);
info_dialog_popup (transform_info);
}
static void
rotate_angle_changed (GtkWidget *widget,
gpointer data)
{
GimpTool *tool;
GimpDrawTool *draw_tool;
GimpTransformTool *transform_tool;
gdouble value;
tool = (GimpTool *) data;
if (tool)
{
transform_tool = GIMP_TRANSFORM_TOOL (tool);
draw_tool = GIMP_DRAW_TOOL (tool);
value = gimp_deg_to_rad (GTK_ADJUSTMENT (widget)->value);
if (value != transform_tool->trans_info[ANGLE])
{
gimp_draw_tool_pause (draw_tool);
transform_tool->trans_info[ANGLE] = value;
rotate_tool_recalc (tool, tool->gdisp);
gimp_draw_tool_resume (draw_tool);
}
}
}
static void
rotate_center_changed (GtkWidget *widget,
gpointer data)
{
GimpTool *tool;
GimpDrawTool *draw_tool;
GimpTransformTool *transform_tool;
gint cx;
gint cy;
tool = (GimpTool *) data;
if (tool)
{
transform_tool = GIMP_TRANSFORM_TOOL (tool);
draw_tool = GIMP_DRAW_TOOL (tool);
cx = RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0));
cy = RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1));
if ((cx != transform_tool->trans_info[CENTER_X]) ||
(cy != transform_tool->trans_info[CENTER_Y]))
{
gimp_draw_tool_pause (draw_tool);
transform_tool->trans_info[CENTER_X] = cx;
transform_tool->trans_info[CENTER_Y] = cy;
transform_tool->cx = cx;
transform_tool->cy = cy;
rotate_tool_recalc (tool, tool->gdisp);
gimp_draw_tool_resume (draw_tool);
}
}
}
static void
rotate_tool_motion (GimpTool *tool,
GimpDisplay *gdisp)
{
GimpTransformTool *transform_tool;
gdouble angle1, angle2, angle;
gdouble cx, cy;
gdouble x1, y1, x2, y2;
transform_tool = GIMP_TRANSFORM_TOOL (tool);
if (transform_tool->function == TRANSFORM_HANDLE_CENTER)
{
transform_tool->trans_info[CENTER_X] = transform_tool->curx;
transform_tool->trans_info[CENTER_Y] = transform_tool->cury;
transform_tool->cx = transform_tool->curx;
transform_tool->cy = transform_tool->cury;
return;
}
cx = transform_tool->trans_info[CENTER_X];
cy = transform_tool->trans_info[CENTER_Y];
x1 = transform_tool->curx - cx;
x2 = transform_tool->lastx - cx;
y1 = cy - transform_tool->cury;
y2 = cy - transform_tool->lasty;
/* find the first angle */
angle1 = atan2 (y1, x1);
/* find the angle */
angle2 = atan2 (y2, x2);
angle = angle2 - angle1;
if (angle > G_PI || angle < -G_PI)
angle = angle2 - ((angle1 < 0) ? 2.0 * G_PI + angle1 : angle1 - 2.0 * G_PI);
/* increment the transform tool's angle */
transform_tool->trans_info[REAL_ANGLE] += angle;
/* limit the angle to between 0 and 360 degrees */
if (transform_tool->trans_info[REAL_ANGLE] < - G_PI)
transform_tool->trans_info[REAL_ANGLE] =
2.0 * G_PI - transform_tool->trans_info[REAL_ANGLE];
else if (transform_tool->trans_info[REAL_ANGLE] > G_PI)
transform_tool->trans_info[REAL_ANGLE] =
transform_tool->trans_info[REAL_ANGLE] - 2.0 * G_PI;
/* constrain the angle to 15-degree multiples if ctrl is held down */
if (transform_tool->state & GDK_CONTROL_MASK)
transform_tool->trans_info[ANGLE] =
FIFTEEN_DEG * (int) ((transform_tool->trans_info[REAL_ANGLE] +
FIFTEEN_DEG / 2.0) /
FIFTEEN_DEG);
else
transform_tool->trans_info[ANGLE] = transform_tool->trans_info[REAL_ANGLE];
}
static void
rotate_tool_recalc (GimpTool *tool,
GimpDisplay *gdisp)
{
GimpTransformTool *transform_tool;
gdouble cx, cy;
transform_tool = GIMP_TRANSFORM_TOOL (tool);
cx = transform_tool->trans_info[CENTER_X];
cy = transform_tool->trans_info[CENTER_Y];
transform_tool->cx = cx;
transform_tool->cy = cy;
/* assemble the transformation matrix */
gimp_matrix3_identity (transform_tool->transform);
gimp_matrix3_translate (transform_tool->transform, -cx, -cy);
gimp_matrix3_rotate (transform_tool->transform,
transform_tool->trans_info[ANGLE]);
gimp_matrix3_translate (transform_tool->transform, +cx, +cy);
/* transform the bounding box */
gimp_transform_tool_transform_bounding_box (transform_tool);
/* update the information dialog */
rotate_info_update (tool);
}