2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-25 06:05:25 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
app/appenv.h New file. Includes <math.h>. Move G_PI, RINT(), ROUND() etc
1999-09-01 Tor Lillqvist <tml@iki.fi>
* app/appenv.h
* libgimp/gimpmath.h: New file. Includes <math.h>. Move G_PI,
RINT(), ROUND() etc from app/appenv.h here, so plug-ins can
use them, too. Remove some commented-out old stuff in appenv.h.
* libgimp/gimp.h: Include gimpmath.h.
* libgimp/gimp.c (gimp_main): Win32: Don't install signal
handlers, we can't do anything useful in the handler ourselves
anyway (it would be nice to print out a backtrace, but that seems
pretty hard to do, even if not impossible). Let Windows inform the
user about the crash. If the plug-in was compiled with MSVC, and
the user also has it, she is offered a chance to start the
debugger automatically anyway.
* app/*several*.c: Include gimpmath.h for G_PI etc. Don't include
<math.h>, as gimpmath.h includes it.
* plug-ins/*/*many*.c: Include config.h. Don't include <math.h>.
Remove all the duplicated definitions of G_PI and rint(). Use
RINT() instead of rint().
* app/app_procs.[ch]: app_exit() takes a gboolean.
* app/batch.c
* app/commands.c
* app/interface.c: Call app_exit() with FALSE or TRUE.
* app/main.c (on_error): Call gimp_fatal_error. (main): Don't
install any signal handler on Win32 here, either.
* app/errors.c (gimp_fatal_error, gimp_terminate): Win32: Format
the message and call MessageBox with it. g_on_error_query doesn't
do anything useful on Win32, and printf'ing a message to stdout or
stderr doesn't do anything, either, in a windowing application.
1999-09-02 04:30:56 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2008-05-23 22:09:55 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <gtk/gtk.h>
|
2008-06-01 01:51:52 +08:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2007-03-09 21:00:01 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2001-01-24 07:56:18 +08:00
|
|
|
|
2002-05-03 20:45:22 +08:00
|
|
|
#include "tools-types.h"
|
|
|
|
|
2003-09-16 01:41:18 +08:00
|
|
|
#include "core/gimp-transform-utils.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
2001-04-25 02:43:31 +08:00
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2002-08-31 05:00:42 +08:00
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
2002-06-27 06:16:59 +08:00
|
|
|
#include "display/gimpdisplayshell.h"
|
2013-06-07 17:52:48 +08:00
|
|
|
#include "display/gimptoolgui.h"
|
2001-01-23 21:01:48 +08:00
|
|
|
|
2001-04-25 02:43:31 +08:00
|
|
|
#include "gimprotatetool.h"
|
2003-04-16 00:05:52 +08:00
|
|
|
#include "gimptoolcontrol.h"
|
2003-02-09 05:12:03 +08:00
|
|
|
#include "gimptransformoptions.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* index into trans_info array */
|
2011-03-28 06:50:46 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ANGLE,
|
|
|
|
REAL_ANGLE,
|
2011-08-12 02:11:09 +08:00
|
|
|
PIVOT_X,
|
|
|
|
PIVOT_Y
|
2011-03-28 06:50:46 +08:00
|
|
|
};
|
1998-08-14 04:19:09 +08:00
|
|
|
|
1999-08-05 07:22:29 +08:00
|
|
|
#define FIFTEEN_DEG (G_PI / 12.0)
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-03-31 21:36:34 +08:00
|
|
|
#define SB_WIDTH 10
|
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2001-11-20 02:23:43 +08:00
|
|
|
/* local function prototypes */
|
2001-04-25 02:43:31 +08:00
|
|
|
|
2011-08-27 14:37:30 +08:00
|
|
|
static gboolean gimp_rotate_tool_key_press (GimpTool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GimpDisplay *display);
|
|
|
|
|
|
|
|
static void gimp_rotate_tool_dialog (GimpTransformTool *tr_tool);
|
|
|
|
static void gimp_rotate_tool_dialog_update (GimpTransformTool *tr_tool);
|
|
|
|
static void gimp_rotate_tool_prepare (GimpTransformTool *tr_tool);
|
|
|
|
static void gimp_rotate_tool_motion (GimpTransformTool *tr_tool);
|
|
|
|
static void gimp_rotate_tool_recalc_matrix (GimpTransformTool *tr_tool);
|
|
|
|
static gchar * gimp_rotate_tool_get_undo_desc (GimpTransformTool *tr_tool);
|
|
|
|
|
|
|
|
static void rotate_angle_changed (GtkAdjustment *adj,
|
|
|
|
GimpTransformTool *tr_tool);
|
|
|
|
static void rotate_center_changed (GtkWidget *entry,
|
2008-06-01 01:51:52 +08:00
|
|
|
GimpTransformTool *tr_tool);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpRotateTool, gimp_rotate_tool, GIMP_TYPE_TRANSFORM_TOOL)
|
2001-04-25 02:43:31 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
#define parent_class gimp_rotate_tool_parent_class
|
2001-07-07 20:17:23 +08:00
|
|
|
|
2001-04-25 02:43:31 +08:00
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
void
|
2002-03-29 11:50:29 +08:00
|
|
|
gimp_rotate_tool_register (GimpToolRegisterCallback callback,
|
2002-05-03 19:31:08 +08:00
|
|
|
gpointer data)
|
2001-04-25 02:43:31 +08:00
|
|
|
{
|
2002-03-29 11:50:29 +08:00
|
|
|
(* callback) (GIMP_TYPE_ROTATE_TOOL,
|
2003-02-05 22:39:40 +08:00
|
|
|
GIMP_TYPE_TRANSFORM_OPTIONS,
|
|
|
|
gimp_transform_options_gui,
|
2015-09-09 03:18:49 +08:00
|
|
|
GIMP_CONTEXT_PROP_MASK_BACKGROUND,
|
2002-03-21 20:17:17 +08:00
|
|
|
"gimp-rotate-tool",
|
GimpViewableDialogs everywhere, cleanup:
2002-09-01 Michael Natterer <mitch@gimp.org>
GimpViewableDialogs everywhere, cleanup:
* libgimpwidgets/gimpstock.c: added texts for the RESIZE, SCALE
and CROP stock items.
* app/widgets/gimpviewabledialog.c: update the title when the
viewable's name changes.
* app/gui/color-notebook.[ch]: added color_notebook_viewable_new()
which creates a GimpViewableDialog.
* app/widgets/gimpgradienteditor.[ch]
* app/gui/colormap-editor-commands.c
* app/gui/file-new-dialog.c
* app/gui/gradient-editor-commands.c
* app/gui/palette-editor-commands.c
* app/undo_history.c: use GimpViewableDialogs and the new
color_notebook constructor.
* app/gui/convert-dialog.c: #include "widgets/gimpviewabledialog.h"
* app/gui/image-commands.c
* app/gui/info-dialog.c
* app/gui/resize-dialog.c: minor cleanups.
* app/gui/info-window.c: cleaned up the whole thing, esp. the
"Extended" page. Added HSV color display to the color picker
frame. Set the icons as frame titles, stuff...
* app/tools/gimpimagemaptool.[ch]: removed "shell_title",
"shell_name" and "stock_id" from the GimpImageMapTool struct
because they can be obtained from the tool's GimpToolInfo object.
* app/tools/gimpbrightnesscontrasttool.c
* app/tools/gimpcolorbalancetool.c
* app/tools/gimpcurvestool.c
* app/tools/gimphuesaturationtool.c
* app/tools/gimplevelstool.c
* app/tools/gimpposterizetool.c
* app/tools/gimpthresholdtool.c: changed accordingly.
* app/tools/gimphistogramtool.c: same here: take values from
tool->tool_info instead of hardcoding them.
* app/tools/gimpcroptool.[ch]: removed the static crop dialog
variables and added them to the GimpCropTool struct. Feels safer
and makes the callback code much simpler. Use stock items for the
dialog's "Resize" and "Crop" buttons.
* app/tools/gimpmeasuretool.c
* app/tools/gimprotatetool.c: for consistency don't name the tools
"Blah Tool", also the dialog titles need to match the menu
entries.
Unrelated:
* libgimpwidgets/gimpwidgets.c: the recently changed, gtk-doc
comment was correct, as gtk-doc takes the parameter names from
the header, not the .c file.
* app/tools/gimptransformtool.c: set the transform tool's state to
TRANSFORM_CREATING after changing displays, so the initial matrix
components are saved correctly for the "Reset" function.
2002-09-01 16:44:57 +08:00
|
|
|
_("Rotate"),
|
2006-10-17 17:38:51 +08:00
|
|
|
_("Rotate Tool: Rotate the layer, selection or path"),
|
2004-04-29 21:19:28 +08:00
|
|
|
N_("_Rotate"), "<shift>R",
|
2003-08-22 09:42:57 +08:00
|
|
|
NULL, GIMP_HELP_TOOL_ROTATE,
|
2002-03-29 11:50:29 +08:00
|
|
|
GIMP_STOCK_TOOL_ROTATE,
|
2002-05-03 19:31:08 +08:00
|
|
|
data);
|
2001-04-25 02:43:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_rotate_tool_class_init (GimpRotateToolClass *klass)
|
|
|
|
{
|
2008-06-01 01:51:52 +08:00
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
2004-06-05 07:08:29 +08:00
|
|
|
GimpTransformToolClass *trans_class = GIMP_TRANSFORM_TOOL_CLASS (klass);
|
2001-04-25 02:43:31 +08:00
|
|
|
|
2008-06-01 01:51:52 +08:00
|
|
|
tool_class->key_press = gimp_rotate_tool_key_press;
|
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
trans_class->dialog = gimp_rotate_tool_dialog;
|
|
|
|
trans_class->dialog_update = gimp_rotate_tool_dialog_update;
|
|
|
|
trans_class->prepare = gimp_rotate_tool_prepare;
|
|
|
|
trans_class->motion = gimp_rotate_tool_motion;
|
2011-03-28 05:12:11 +08:00
|
|
|
trans_class->recalc_matrix = gimp_rotate_tool_recalc_matrix;
|
2011-08-27 14:37:30 +08:00
|
|
|
trans_class->get_undo_desc = gimp_rotate_tool_get_undo_desc;
|
2001-04-25 02:43:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_rotate_tool_init (GimpRotateTool *rotate_tool)
|
|
|
|
{
|
2003-10-21 05:27:34 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (rotate_tool);
|
|
|
|
GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (rotate_tool);
|
2001-04-29 04:14:32 +08:00
|
|
|
|
2004-06-05 07:08:29 +08:00
|
|
|
gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_ROTATE);
|
2002-11-14 19:54:57 +08:00
|
|
|
|
2015-03-24 06:18:28 +08:00
|
|
|
tr_tool->progress_text = _("Rotating");
|
2006-06-20 16:22:39 +08:00
|
|
|
|
2015-03-24 06:18:28 +08:00
|
|
|
tr_tool->use_grid = TRUE;
|
|
|
|
tr_tool->use_pivot_handle = TRUE;
|
2001-04-25 02:43:31 +08:00
|
|
|
}
|
1998-08-15 21:34:54 +08:00
|
|
|
|
2008-06-01 01:51:52 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_rotate_tool_key_press (GimpTool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
2008-07-12 03:38:28 +08:00
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
2008-06-01 01:51:52 +08:00
|
|
|
|
|
|
|
if (display == draw_tool->display)
|
|
|
|
{
|
2008-07-12 03:38:28 +08:00
|
|
|
GimpRotateTool *rotate = GIMP_ROTATE_TOOL (tool);
|
|
|
|
GtkSpinButton *angle_spin = GTK_SPIN_BUTTON (rotate->angle_spin_button);
|
|
|
|
|
2008-06-01 01:51:52 +08:00
|
|
|
switch (kevent->keyval)
|
|
|
|
{
|
2011-03-29 21:27:25 +08:00
|
|
|
case GDK_KEY_Up:
|
2008-06-01 01:51:52 +08:00
|
|
|
gtk_spin_button_spin (angle_spin, GTK_SPIN_STEP_FORWARD, 0.0);
|
2008-07-12 03:38:28 +08:00
|
|
|
return TRUE;
|
2008-06-01 01:51:52 +08:00
|
|
|
|
2011-03-29 21:27:25 +08:00
|
|
|
case GDK_KEY_Down:
|
2008-06-01 01:51:52 +08:00
|
|
|
gtk_spin_button_spin (angle_spin, GTK_SPIN_STEP_BACKWARD, 0.0);
|
2008-07-12 03:38:28 +08:00
|
|
|
return TRUE;
|
2008-06-01 01:51:52 +08:00
|
|
|
|
2012-01-23 03:45:42 +08:00
|
|
|
case GDK_KEY_Right:
|
2008-06-01 01:51:52 +08:00
|
|
|
gtk_spin_button_spin (angle_spin, GTK_SPIN_PAGE_FORWARD, 0.0);
|
2008-07-12 03:38:28 +08:00
|
|
|
return TRUE;
|
2008-06-01 01:51:52 +08:00
|
|
|
|
2012-01-23 03:45:42 +08:00
|
|
|
case GDK_KEY_Left:
|
2008-06-01 01:51:52 +08:00
|
|
|
gtk_spin_button_spin (angle_spin, GTK_SPIN_PAGE_BACKWARD, 0.0);
|
2008-07-12 03:38:28 +08:00
|
|
|
return TRUE;
|
2008-06-01 01:51:52 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-12 03:38:28 +08:00
|
|
|
return GIMP_TOOL_CLASS (parent_class)->key_press (tool, kevent, display);
|
2008-06-01 01:51:52 +08:00
|
|
|
}
|
|
|
|
|
2002-11-14 19:54:57 +08:00
|
|
|
static void
|
|
|
|
gimp_rotate_tool_dialog (GimpTransformTool *tr_tool)
|
|
|
|
{
|
2004-08-07 00:27:13 +08:00
|
|
|
GimpRotateTool *rotate = GIMP_ROTATE_TOOL (tr_tool);
|
2006-03-31 21:36:34 +08:00
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *scale;
|
2014-06-22 04:39:37 +08:00
|
|
|
GtkAdjustment *adj;
|
2006-03-31 21:36:34 +08:00
|
|
|
|
|
|
|
table = gtk_table_new (4, 2, FALSE);
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
|
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
|
|
|
|
gtk_table_set_row_spacing (GTK_TABLE (table), 1, 6);
|
2013-06-07 17:52:48 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (gimp_tool_gui_get_vbox (tr_tool->gui)), table,
|
|
|
|
FALSE, FALSE, 0);
|
2006-03-31 21:36:34 +08:00
|
|
|
gtk_widget_show (table);
|
|
|
|
|
2014-06-22 04:39:37 +08:00
|
|
|
rotate->angle_adj = (GtkAdjustment *)
|
|
|
|
gtk_adjustment_new (0, -180, 180, 0.1, 15, 0);
|
|
|
|
button = gtk_spin_button_new (rotate->angle_adj, 1.0, 2);
|
|
|
|
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (button), TRUE);
|
2006-03-31 21:36:34 +08:00
|
|
|
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (button), TRUE);
|
|
|
|
gtk_entry_set_width_chars (GTK_ENTRY (button), SB_WIDTH);
|
2006-10-18 18:29:16 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0, _("_Angle:"),
|
2006-03-31 21:36:34 +08:00
|
|
|
0.0, 0.5, button, 1, TRUE);
|
2008-06-01 01:51:52 +08:00
|
|
|
rotate->angle_spin_button = button;
|
2006-03-31 21:36:34 +08:00
|
|
|
|
|
|
|
g_signal_connect (rotate->angle_adj, "value-changed",
|
2006-04-12 20:49:29 +08:00
|
|
|
G_CALLBACK (rotate_angle_changed),
|
2006-03-31 21:36:34 +08:00
|
|
|
tr_tool);
|
|
|
|
|
2011-10-02 20:09:45 +08:00
|
|
|
scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, rotate->angle_adj);
|
2006-03-31 21:36:34 +08:00
|
|
|
gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
|
|
|
|
gtk_table_attach (GTK_TABLE (table), scale, 1, 2, 1, 2,
|
|
|
|
GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
|
|
|
|
gtk_widget_show (scale);
|
|
|
|
|
2014-06-22 04:39:37 +08:00
|
|
|
adj = (GtkAdjustment *) gtk_adjustment_new (0, -1, 1, 1, 10, 0);
|
|
|
|
button = gtk_spin_button_new (adj, 1.0, 2);
|
|
|
|
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (button), TRUE);
|
2006-03-31 21:36:34 +08:00
|
|
|
gtk_entry_set_width_chars (GTK_ENTRY (button), SB_WIDTH);
|
2006-10-18 18:29:16 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 2, _("Center _X:"),
|
2006-03-31 21:36:34 +08:00
|
|
|
0.0, 0.5, button, 1, TRUE);
|
|
|
|
|
|
|
|
rotate->sizeentry = gimp_size_entry_new (1, GIMP_UNIT_PIXEL, "%a",
|
|
|
|
TRUE, TRUE, FALSE, SB_WIDTH,
|
|
|
|
GIMP_SIZE_ENTRY_UPDATE_SIZE);
|
2004-08-07 00:27:13 +08:00
|
|
|
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (rotate->sizeentry),
|
2006-03-31 21:36:34 +08:00
|
|
|
GTK_SPIN_BUTTON (button), NULL);
|
2006-10-24 06:36:45 +08:00
|
|
|
gimp_size_entry_set_pixel_digits (GIMP_SIZE_ENTRY (rotate->sizeentry), 2);
|
2006-10-18 18:29:16 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 3, _("Center _Y:"),
|
2006-03-31 21:36:34 +08:00
|
|
|
0.0, 0.5, rotate->sizeentry, 1, TRUE);
|
2002-11-14 19:54:57 +08:00
|
|
|
|
2006-03-31 21:36:34 +08:00
|
|
|
g_signal_connect (rotate->sizeentry, "value-changed",
|
|
|
|
G_CALLBACK (rotate_center_changed),
|
|
|
|
tr_tool);
|
2002-11-14 19:54:57 +08:00
|
|
|
}
|
|
|
|
|
2004-08-07 00:27:13 +08:00
|
|
|
static void
|
|
|
|
gimp_rotate_tool_dialog_update (GimpTransformTool *tr_tool)
|
|
|
|
{
|
|
|
|
GimpRotateTool *rotate = GIMP_ROTATE_TOOL (tr_tool);
|
|
|
|
|
2010-10-19 18:27:33 +08:00
|
|
|
gtk_adjustment_set_value (rotate->angle_adj,
|
2006-03-31 21:36:34 +08:00
|
|
|
gimp_rad_to_deg (tr_tool->trans_info[ANGLE]));
|
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (rotate->sizeentry,
|
|
|
|
rotate_center_changed,
|
|
|
|
tr_tool);
|
|
|
|
|
|
|
|
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (rotate->sizeentry), 0,
|
2011-08-12 02:11:09 +08:00
|
|
|
tr_tool->trans_info[PIVOT_X]);
|
2006-03-31 21:36:34 +08:00
|
|
|
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (rotate->sizeentry), 1,
|
2011-08-12 02:11:09 +08:00
|
|
|
tr_tool->trans_info[PIVOT_Y]);
|
2006-03-31 21:36:34 +08:00
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (rotate->sizeentry,
|
|
|
|
rotate_center_changed,
|
|
|
|
tr_tool);
|
2004-08-07 00:27:13 +08:00
|
|
|
}
|
|
|
|
|
2002-11-14 19:54:57 +08:00
|
|
|
static void
|
2011-03-28 04:39:31 +08:00
|
|
|
gimp_rotate_tool_prepare (GimpTransformTool *tr_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2011-03-28 04:39:31 +08:00
|
|
|
GimpRotateTool *rotate = GIMP_ROTATE_TOOL (tr_tool);
|
|
|
|
GimpDisplay *display = GIMP_TOOL (tr_tool)->display;
|
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
2007-12-27 01:33:41 +08:00
|
|
|
gdouble xres;
|
|
|
|
gdouble yres;
|
2002-11-14 19:54:57 +08:00
|
|
|
|
2011-08-12 02:11:09 +08:00
|
|
|
tr_tool->px = (gdouble) (tr_tool->x1 + tr_tool->x2) / 2.0;
|
|
|
|
tr_tool->py = (gdouble) (tr_tool->y1 + tr_tool->y2) / 2.0;
|
|
|
|
|
2006-03-31 21:36:34 +08:00
|
|
|
tr_tool->trans_info[ANGLE] = 0.0;
|
|
|
|
tr_tool->trans_info[REAL_ANGLE] = 0.0;
|
2011-08-12 02:11:09 +08:00
|
|
|
tr_tool->trans_info[PIVOT_X] = tr_tool->px;
|
|
|
|
tr_tool->trans_info[PIVOT_Y] = tr_tool->py;
|
2004-08-07 00:27:13 +08:00
|
|
|
|
2009-10-07 01:20:44 +08:00
|
|
|
gimp_image_get_resolution (image, &xres, &yres);
|
2007-12-27 01:33:41 +08:00
|
|
|
|
2004-08-07 00:27:13 +08:00
|
|
|
g_signal_handlers_block_by_func (rotate->sizeentry,
|
2002-11-14 19:54:57 +08:00
|
|
|
rotate_center_changed,
|
|
|
|
tr_tool);
|
|
|
|
|
2004-08-07 00:27:13 +08:00
|
|
|
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (rotate->sizeentry),
|
2009-10-05 01:56:39 +08:00
|
|
|
gimp_display_get_shell (display)->unit);
|
2002-11-14 19:54:57 +08:00
|
|
|
|
2004-08-07 00:27:13 +08:00
|
|
|
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (rotate->sizeentry), 0,
|
2007-12-27 01:33:41 +08:00
|
|
|
xres, FALSE);
|
2004-08-07 00:27:13 +08:00
|
|
|
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (rotate->sizeentry), 1,
|
2007-12-27 01:33:41 +08:00
|
|
|
yres, FALSE);
|
2002-11-14 19:54:57 +08:00
|
|
|
|
2004-08-07 00:27:13 +08:00
|
|
|
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (rotate->sizeentry), 0,
|
2002-11-14 19:54:57 +08:00
|
|
|
-65536,
|
2007-12-26 00:21:40 +08:00
|
|
|
65536 +
|
2009-10-07 01:20:44 +08:00
|
|
|
gimp_image_get_width (image));
|
2004-08-07 00:27:13 +08:00
|
|
|
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (rotate->sizeentry), 1,
|
2002-11-14 19:54:57 +08:00
|
|
|
-65536,
|
2007-12-26 00:21:40 +08:00
|
|
|
65536 +
|
2009-10-07 01:20:44 +08:00
|
|
|
gimp_image_get_height (image));
|
2002-11-14 19:54:57 +08:00
|
|
|
|
2004-08-07 00:27:13 +08:00
|
|
|
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (rotate->sizeentry), 0,
|
2002-11-14 19:54:57 +08:00
|
|
|
tr_tool->x1, tr_tool->x2);
|
2004-08-07 00:27:13 +08:00
|
|
|
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (rotate->sizeentry), 1,
|
2002-11-14 19:54:57 +08:00
|
|
|
tr_tool->y1, tr_tool->y2);
|
|
|
|
|
2004-08-07 00:27:13 +08:00
|
|
|
g_signal_handlers_unblock_by_func (rotate->sizeentry,
|
2002-11-14 19:54:57 +08:00
|
|
|
rotate_center_changed,
|
|
|
|
tr_tool);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-28 04:39:31 +08:00
|
|
|
gimp_rotate_tool_motion (GimpTransformTool *tr_tool)
|
2002-11-14 19:54:57 +08:00
|
|
|
{
|
2006-09-06 02:25:31 +08:00
|
|
|
GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
|
2003-02-05 22:39:40 +08:00
|
|
|
gdouble angle1, angle2, angle;
|
2011-08-12 02:11:09 +08:00
|
|
|
gdouble px, py;
|
2003-02-05 22:39:40 +08:00
|
|
|
gdouble x1, y1, x2, y2;
|
2002-11-14 19:54:57 +08:00
|
|
|
|
2011-08-12 02:11:09 +08:00
|
|
|
if (tr_tool->function == TRANSFORM_HANDLE_PIVOT)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2011-08-12 02:11:09 +08:00
|
|
|
tr_tool->trans_info[PIVOT_X] = tr_tool->curx;
|
|
|
|
tr_tool->trans_info[PIVOT_Y] = tr_tool->cury;
|
2002-11-14 19:54:57 +08:00
|
|
|
|
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2011-08-12 02:11:09 +08:00
|
|
|
px = tr_tool->trans_info[PIVOT_X];
|
|
|
|
py = tr_tool->trans_info[PIVOT_Y];
|
2002-11-14 19:54:57 +08:00
|
|
|
|
2011-08-12 02:11:09 +08:00
|
|
|
x1 = tr_tool->curx - px;
|
|
|
|
x2 = tr_tool->lastx - px;
|
|
|
|
y1 = py - tr_tool->cury;
|
|
|
|
y2 = py - tr_tool->lasty;
|
2002-11-14 19:54:57 +08:00
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
tr_tool->trans_info[REAL_ANGLE] += angle;
|
|
|
|
|
2006-08-22 20:20:12 +08:00
|
|
|
/* limit the angle to between -180 and 180 degrees */
|
2002-11-14 19:54:57 +08:00
|
|
|
if (tr_tool->trans_info[REAL_ANGLE] < - G_PI)
|
2006-08-22 20:20:12 +08:00
|
|
|
{
|
2008-01-04 17:01:55 +08:00
|
|
|
tr_tool->trans_info[REAL_ANGLE] += 2.0 * G_PI;
|
2006-08-22 20:20:12 +08:00
|
|
|
}
|
2002-11-14 19:54:57 +08:00
|
|
|
else if (tr_tool->trans_info[REAL_ANGLE] > G_PI)
|
2006-08-22 20:20:12 +08:00
|
|
|
{
|
2008-01-04 17:01:55 +08:00
|
|
|
tr_tool->trans_info[REAL_ANGLE] -= 2.0 * G_PI;
|
2006-08-22 20:20:12 +08:00
|
|
|
}
|
2002-11-14 19:54:57 +08:00
|
|
|
|
|
|
|
/* constrain the angle to 15-degree multiples if ctrl is held down */
|
2012-08-11 20:42:39 +08:00
|
|
|
if (options->constrain_rotate)
|
2002-11-14 19:54:57 +08:00
|
|
|
{
|
|
|
|
tr_tool->trans_info[ANGLE] =
|
2008-01-04 17:01:55 +08:00
|
|
|
FIFTEEN_DEG * (gint) ((tr_tool->trans_info[REAL_ANGLE] +
|
|
|
|
FIFTEEN_DEG / 2.0) / FIFTEEN_DEG);
|
2002-11-14 19:54:57 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tr_tool->trans_info[ANGLE] = tr_tool->trans_info[REAL_ANGLE];
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-28 05:12:11 +08:00
|
|
|
gimp_rotate_tool_recalc_matrix (GimpTransformTool *tr_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2011-08-12 02:11:09 +08:00
|
|
|
tr_tool->px = tr_tool->trans_info[PIVOT_X];
|
|
|
|
tr_tool->py = tr_tool->trans_info[PIVOT_Y];
|
2002-11-14 19:54:57 +08:00
|
|
|
|
2005-03-22 03:10:11 +08:00
|
|
|
gimp_matrix3_identity (&tr_tool->transform);
|
|
|
|
gimp_transform_matrix_rotate_center (&tr_tool->transform,
|
2011-08-12 02:11:09 +08:00
|
|
|
tr_tool->px,
|
|
|
|
tr_tool->py,
|
2005-03-22 03:10:11 +08:00
|
|
|
tr_tool->trans_info[ANGLE]);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2011-08-27 14:37:30 +08:00
|
|
|
static gchar *
|
|
|
|
gimp_rotate_tool_get_undo_desc (GimpTransformTool *tr_tool)
|
|
|
|
{
|
|
|
|
return g_strdup_printf (C_("undo-type",
|
|
|
|
"Rotate by %-3.3g° around (%g, %g)"),
|
|
|
|
gimp_rad_to_deg (tr_tool->trans_info[ANGLE]),
|
2011-08-12 02:11:09 +08:00
|
|
|
tr_tool->trans_info[PIVOT_X],
|
|
|
|
tr_tool->trans_info[PIVOT_Y]);
|
2011-08-27 14:37:30 +08:00
|
|
|
}
|
|
|
|
|
1998-08-15 21:34:54 +08:00
|
|
|
static void
|
2006-03-31 21:36:34 +08:00
|
|
|
rotate_angle_changed (GtkAdjustment *adj,
|
2002-11-18 21:10:04 +08:00
|
|
|
GimpTransformTool *tr_tool)
|
1998-08-15 21:34:54 +08:00
|
|
|
{
|
2006-03-31 21:36:34 +08:00
|
|
|
gdouble value = gimp_deg_to_rad (gtk_adjustment_get_value (adj));
|
1998-08-15 21:34:54 +08:00
|
|
|
|
2002-11-18 07:56:13 +08:00
|
|
|
#define ANGLE_EPSILON 0.0001
|
|
|
|
|
2002-11-18 21:10:04 +08:00
|
|
|
if (ABS (value - tr_tool->trans_info[ANGLE]) > ANGLE_EPSILON)
|
1998-08-15 21:34:54 +08:00
|
|
|
{
|
2002-11-18 21:10:04 +08:00
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
|
1998-08-15 21:34:54 +08:00
|
|
|
|
2008-01-04 17:01:55 +08:00
|
|
|
tr_tool->trans_info[REAL_ANGLE] = tr_tool->trans_info[ANGLE] = value;
|
1998-08-15 21:34:54 +08:00
|
|
|
|
2011-08-13 23:42:41 +08:00
|
|
|
gimp_transform_tool_push_internal_undo (tr_tool);
|
|
|
|
|
2011-03-28 05:12:11 +08:00
|
|
|
gimp_transform_tool_recalc_matrix (tr_tool);
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2002-11-18 21:10:04 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
|
1998-08-15 21:34:54 +08:00
|
|
|
}
|
2002-11-18 07:56:13 +08:00
|
|
|
|
|
|
|
#undef ANGLE_EPSILON
|
1998-08-15 21:34:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-11-18 21:10:04 +08:00
|
|
|
rotate_center_changed (GtkWidget *widget,
|
|
|
|
GimpTransformTool *tr_tool)
|
1998-08-15 21:34:54 +08:00
|
|
|
{
|
2011-08-12 02:11:09 +08:00
|
|
|
gdouble px = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0);
|
|
|
|
gdouble py = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1);
|
1998-08-15 21:34:54 +08:00
|
|
|
|
2011-08-12 02:11:09 +08:00
|
|
|
if ((px != tr_tool->trans_info[PIVOT_X]) ||
|
|
|
|
(py != tr_tool->trans_info[PIVOT_Y]))
|
2001-11-20 02:23:43 +08:00
|
|
|
{
|
2002-11-18 21:10:04 +08:00
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
|
2001-11-09 03:14:51 +08:00
|
|
|
|
2011-08-12 02:11:09 +08:00
|
|
|
tr_tool->trans_info[PIVOT_X] = px;
|
|
|
|
tr_tool->trans_info[PIVOT_Y] = py;
|
|
|
|
tr_tool->px = px;
|
|
|
|
tr_tool->py = py;
|
2001-11-09 03:14:51 +08:00
|
|
|
|
2011-08-13 23:42:41 +08:00
|
|
|
gimp_transform_tool_push_internal_undo (tr_tool);
|
|
|
|
|
2011-03-28 05:12:11 +08:00
|
|
|
gimp_transform_tool_recalc_matrix (tr_tool);
|
2001-11-09 03:14:51 +08:00
|
|
|
|
2002-11-18 21:10:04 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
|
1998-08-15 21:34:54 +08:00
|
|
|
}
|
|
|
|
}
|