Commit a5f38085 authored by Michael Natterer's avatar Michael Natterer 😴

app: use the newly added tool widgets in the transform tools

parent 457f6bf9
......@@ -105,7 +105,8 @@ static void gimp_handle_transform_tool_dialog (GimpTransformTool *tr_
static void gimp_handle_transform_tool_dialog_update (GimpTransformTool *tr_tool);
static void gimp_handle_transform_tool_prepare (GimpTransformTool *tr_tool);
static void gimp_handle_transform_tool_motion (GimpTransformTool *tr_tool);
static void gimp_handle_transform_tool_recalc_matrix (GimpTransformTool *tr_tool);
static void gimp_handle_transform_tool_recalc_matrix (GimpTransformTool *tr_tool,
GimpToolWidget *widget);
static gchar *gimp_handle_transform_tool_get_undo_desc (GimpTransformTool *tr_tool);
static TransformAction
gimp_handle_transform_tool_pick_function (GimpTransformTool *tr_tool,
......@@ -115,9 +116,7 @@ static TransformAction
static void gimp_handle_transform_tool_cursor_update (GimpTransformTool *tr_tool,
GimpCursorType *cursor,
GimpCursorModifier *modifier);
static void gimp_handle_transform_tool_draw_gui (GimpTransformTool *tr_tool,
gint handle_w,
gint handle_h);
static void gimp_handle_transform_tool_draw_gui (GimpTransformTool *tr_tool);
static gboolean is_handle_position_valid (GimpTransformTool *tr_tool,
gint active_handle);
......@@ -606,7 +605,8 @@ gimp_handle_transform_tool_motion (GimpTransformTool *tr_tool)
}
static void
gimp_handle_transform_tool_recalc_matrix (GimpTransformTool *tr_tool)
gimp_handle_transform_tool_recalc_matrix (GimpTransformTool *tr_tool,
GimpToolWidget *widget)
{
GimpHandleTransformTool *ht_tool = GIMP_HANDLE_TRANSFORM_TOOL (tr_tool);
gdouble coeff[8 * 9];
......@@ -765,9 +765,7 @@ gimp_handle_transform_tool_cursor_update (GimpTransformTool *tr_tool,
}
static void
gimp_handle_transform_tool_draw_gui (GimpTransformTool *tr_tool,
gint handle_w,
gint handle_h)
gimp_handle_transform_tool_draw_gui (GimpTransformTool *tr_tool)
{
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tr_tool);
gint i;
......
......@@ -17,8 +17,6 @@
#include "config.h"
#include <string.h>
#include <gegl.h>
#include <gtk/gtk.h>
......@@ -29,12 +27,12 @@
#include "core/gimp-transform-utils.h"
#include "core/gimpimage.h"
#include "core/gimpdrawable-transform.h"
#include "widgets/gimphelp-ids.h"
#include "display/gimpdisplay.h"
#include "display/gimptoolgui.h"
#include "display/gimptooltransformgrid.h"
#include "gimpperspectivetool.h"
#include "gimptoolcontrol.h"
......@@ -59,12 +57,16 @@ enum
/* local function prototypes */
static void gimp_perspective_tool_dialog (GimpTransformTool *tr_tool);
static void gimp_perspective_tool_dialog_update (GimpTransformTool *tr_tool);
static void gimp_perspective_tool_prepare (GimpTransformTool *tr_tool);
static void gimp_perspective_tool_motion (GimpTransformTool *tr_tool);
static void gimp_perspective_tool_recalc_matrix (GimpTransformTool *tr_tool);
static gchar * gimp_perspective_tool_get_undo_desc (GimpTransformTool *tr_tool);
static void gimp_perspective_tool_dialog (GimpTransformTool *tr_tool);
static void gimp_perspective_tool_dialog_update (GimpTransformTool *tr_tool);
static void gimp_perspective_tool_prepare (GimpTransformTool *tr_tool);
static GimpToolWidget * gimp_perspective_tool_get_widget (GimpTransformTool *tr_tool);
static void gimp_perspective_tool_recalc_matrix (GimpTransformTool *tr_tool,
GimpToolWidget *widget);
static gchar * gimp_perspective_tool_get_undo_desc (GimpTransformTool *tr_tool);
static void gimp_perspective_tool_widget_changed (GimpToolWidget *widget,
GimpTransformTool *tr_tool);
G_DEFINE_TYPE (GimpPerspectiveTool, gimp_perspective_tool,
......@@ -97,7 +99,7 @@ gimp_perspective_tool_class_init (GimpPerspectiveToolClass *klass)
trans_class->dialog = gimp_perspective_tool_dialog;
trans_class->dialog_update = gimp_perspective_tool_dialog_update;
trans_class->prepare = gimp_perspective_tool_prepare;
trans_class->motion = gimp_perspective_tool_motion;
trans_class->get_widget = gimp_perspective_tool_get_widget;
trans_class->recalc_matrix = gimp_perspective_tool_recalc_matrix;
trans_class->get_undo_desc = gimp_perspective_tool_get_undo_desc;
}
......@@ -111,13 +113,9 @@ gimp_perspective_tool_init (GimpPerspectiveTool *perspective_tool)
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_PERSPECTIVE);
tr_tool->progress_text = _("Perspective transformation");
tr_tool->use_grid = TRUE;
tr_tool->use_corner_handles = TRUE;
tr_tool->use_center_handle = TRUE;
tr_tool->does_perspective = TRUE;
tr_tool->progress_text = _("Perspective transformation");
tr_tool->use_grid = TRUE;
tr_tool->does_perspective = TRUE;
}
static void
......@@ -185,54 +183,50 @@ gimp_perspective_tool_prepare (GimpTransformTool *tr_tool)
tr_tool->trans_info[Y3] = (gdouble) tr_tool->y2;
}
static void
gimp_perspective_tool_motion (GimpTransformTool *transform_tool)
static GimpToolWidget *
gimp_perspective_tool_get_widget (GimpTransformTool *tr_tool)
{
gdouble diff_x, diff_y;
diff_x = transform_tool->curx - transform_tool->lastx;
diff_y = transform_tool->cury - transform_tool->lasty;
switch (transform_tool->function)
{
case TRANSFORM_HANDLE_NW:
transform_tool->trans_info[X0] += diff_x;
transform_tool->trans_info[Y0] += diff_y;
break;
case TRANSFORM_HANDLE_NE:
transform_tool->trans_info[X1] += diff_x;
transform_tool->trans_info[Y1] += diff_y;
break;
case TRANSFORM_HANDLE_SW:
transform_tool->trans_info[X2] += diff_x;
transform_tool->trans_info[Y2] += diff_y;
break;
case TRANSFORM_HANDLE_SE:
transform_tool->trans_info[X3] += diff_x;
transform_tool->trans_info[Y3] += diff_y;
break;
case TRANSFORM_HANDLE_CENTER:
transform_tool->trans_info[X0] += diff_x;
transform_tool->trans_info[Y0] += diff_y;
transform_tool->trans_info[X1] += diff_x;
transform_tool->trans_info[Y1] += diff_y;
transform_tool->trans_info[X2] += diff_x;
transform_tool->trans_info[Y2] += diff_y;
transform_tool->trans_info[X3] += diff_x;
transform_tool->trans_info[Y3] += diff_y;
break;
default:
break;
}
GimpTool *tool = GIMP_TOOL (tr_tool);
GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
GimpToolWidget *widget;
widget = gimp_tool_transform_grid_new (shell,
&tr_tool->transform,
tr_tool->x1,
tr_tool->y1,
tr_tool->x2,
tr_tool->y2,
options->grid_type,
options->grid_size);
g_object_set (widget,
"inside-function", GIMP_TRANSFORM_FUNCTION_PERSPECTIVE,
"outside-function", GIMP_TRANSFORM_FUNCTION_PERSPECTIVE,
"use-perspective-handles", TRUE,
"use-center-handle", TRUE,
"constrain-move", options->constrain_move,
"constrain-scale", options->constrain_scale,
"constrain-rotate", options->constrain_rotate,
"constrain-shear", options->constrain_shear,
"constrain-perspective", options->constrain_perspective,
"frompivot-scale", options->frompivot_scale,
"frompivot-shear", options->frompivot_shear,
"frompivot-perspective", options->frompivot_perspective,
"cornersnap", options->cornersnap,
"fixedpivot", options->fixedpivot,
NULL);
g_signal_connect (widget, "changed",
G_CALLBACK (gimp_perspective_tool_widget_changed),
tr_tool);
return widget;
}
static void
gimp_perspective_tool_recalc_matrix (GimpTransformTool *tr_tool)
gimp_perspective_tool_recalc_matrix (GimpTransformTool *tr_tool,
GimpToolWidget *widget)
{
gimp_matrix3_identity (&tr_tool->transform);
gimp_transform_matrix_perspective (&tr_tool->transform,
......@@ -248,6 +242,15 @@ gimp_perspective_tool_recalc_matrix (GimpTransformTool *tr_tool)
tr_tool->trans_info[Y2],
tr_tool->trans_info[X3],
tr_tool->trans_info[Y3]);
if (widget)
g_object_set (widget,
"transform", &tr_tool->transform,
"x1", (gdouble) tr_tool->x1,
"y1", (gdouble) tr_tool->y1,
"x2", (gdouble) tr_tool->x2,
"y2", (gdouble) tr_tool->y2,
NULL);
}
static gchar *
......@@ -255,3 +258,35 @@ gimp_perspective_tool_get_undo_desc (GimpTransformTool *tr_tool)
{
return g_strdup (C_("undo-type", "Perspective"));
}
static void
gimp_perspective_tool_widget_changed (GimpToolWidget *widget,
GimpTransformTool *tr_tool)
{
GimpMatrix3 *transform;
g_object_get (widget,
"transform", &transform,
NULL);
gimp_matrix3_transform_point (transform,
tr_tool->x1, tr_tool->y1,
&tr_tool->trans_info[X0],
&tr_tool->trans_info[Y0]);
gimp_matrix3_transform_point (transform,
tr_tool->x2, tr_tool->y1,
&tr_tool->trans_info[X1],
&tr_tool->trans_info[Y1]);
gimp_matrix3_transform_point (transform,
tr_tool->x1, tr_tool->y2,
&tr_tool->trans_info[X2],
&tr_tool->trans_info[Y2]);
gimp_matrix3_transform_point (transform,
tr_tool->x2, tr_tool->y2,
&tr_tool->trans_info[X3],
&tr_tool->trans_info[Y3]);
g_free (transform);
gimp_transform_tool_recalc_matrix (tr_tool, NULL);
}
......@@ -17,8 +17,6 @@
#include "config.h"
#include <string.h>
#include <gegl.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
......@@ -36,6 +34,7 @@
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "display/gimptoolgui.h"
#include "display/gimptoolrotategrid.h"
#include "gimprotatetool.h"
#include "gimptoolcontrol.h"
......@@ -48,33 +47,35 @@
enum
{
ANGLE,
REAL_ANGLE,
PIVOT_X,
PIVOT_Y
};
#define FIFTEEN_DEG (G_PI / 12.0)
#define SB_WIDTH 10
#define SB_WIDTH 10
/* local function prototypes */
static gboolean gimp_rotate_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *display);
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 GimpToolWidget * gimp_rotate_tool_get_widget (GimpTransformTool *tr_tool);
static void gimp_rotate_tool_recalc_matrix (GimpTransformTool *tr_tool,
GimpToolWidget *widget);
static gchar * gimp_rotate_tool_get_undo_desc (GimpTransformTool *tr_tool);
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 gimp_rotate_tool_widget_changed (GimpToolWidget *widget,
GimpTransformTool *tr_tool);
static void rotate_angle_changed (GtkAdjustment *adj,
GimpTransformTool *tr_tool);
static void rotate_center_changed (GtkWidget *entry,
GimpTransformTool *tr_tool);
static void rotate_angle_changed (GtkAdjustment *adj,
GimpTransformTool *tr_tool);
static void rotate_center_changed (GtkWidget *entry,
GimpTransformTool *tr_tool);
G_DEFINE_TYPE (GimpRotateTool, gimp_rotate_tool, GIMP_TYPE_TRANSFORM_TOOL)
......@@ -110,7 +111,7 @@ gimp_rotate_tool_class_init (GimpRotateToolClass *klass)
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;
trans_class->get_widget = gimp_rotate_tool_get_widget;
trans_class->recalc_matrix = gimp_rotate_tool_recalc_matrix;
trans_class->get_undo_desc = gimp_rotate_tool_get_undo_desc;
......@@ -125,10 +126,8 @@ gimp_rotate_tool_init (GimpRotateTool *rotate_tool)
gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_ROTATE);
tr_tool->progress_text = _("Rotating");
tr_tool->use_grid = TRUE;
tr_tool->use_pivot_handle = TRUE;
tr_tool->progress_text = _("Rotating");
tr_tool->use_grid = TRUE;
}
static gboolean
......@@ -258,13 +257,9 @@ gimp_rotate_tool_prepare (GimpTransformTool *tr_tool)
gdouble xres;
gdouble yres;
tr_tool->px = (gdouble) (tr_tool->x1 + tr_tool->x2) / 2.0;
tr_tool->py = (gdouble) (tr_tool->y1 + tr_tool->y2) / 2.0;
tr_tool->trans_info[ANGLE] = 0.0;
tr_tool->trans_info[REAL_ANGLE] = 0.0;
tr_tool->trans_info[PIVOT_X] = tr_tool->px;
tr_tool->trans_info[PIVOT_Y] = tr_tool->py;
tr_tool->trans_info[ANGLE] = 0.0;
tr_tool->trans_info[PIVOT_X] = (gdouble) (tr_tool->x1 + tr_tool->x2) / 2.0;
tr_tool->trans_info[PIVOT_Y] = (gdouble) (tr_tool->y1 + tr_tool->y2) / 2.0;
gimp_image_get_resolution (image, &xres, &yres);
......@@ -299,78 +294,65 @@ gimp_rotate_tool_prepare (GimpTransformTool *tr_tool)
tr_tool);
}
static void
gimp_rotate_tool_motion (GimpTransformTool *tr_tool)
static GimpToolWidget *
gimp_rotate_tool_get_widget (GimpTransformTool *tr_tool)
{
GimpTool *tool = GIMP_TOOL (tr_tool);
GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
gdouble angle1, angle2, angle;
gdouble px, py;
gdouble x1, y1, x2, y2;
if (tr_tool->function == TRANSFORM_HANDLE_PIVOT)
{
tr_tool->trans_info[PIVOT_X] = tr_tool->curx;
tr_tool->trans_info[PIVOT_Y] = tr_tool->cury;
return;
}
px = tr_tool->trans_info[PIVOT_X];
py = tr_tool->trans_info[PIVOT_Y];
x1 = tr_tool->curx - px;
x2 = tr_tool->lastx - px;
y1 = py - tr_tool->cury;
y2 = py - tr_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 */
tr_tool->trans_info[REAL_ANGLE] += angle;
/* limit the angle to between -180 and 180 degrees */
if (tr_tool->trans_info[REAL_ANGLE] < - G_PI)
{
tr_tool->trans_info[REAL_ANGLE] += 2.0 * G_PI;
}
else if (tr_tool->trans_info[REAL_ANGLE] > G_PI)
{
tr_tool->trans_info[REAL_ANGLE] -= 2.0 * G_PI;
}
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
GimpToolWidget *widget;
widget = gimp_tool_rotate_grid_new (shell,
tr_tool->x1,
tr_tool->y1,
tr_tool->x2,
tr_tool->y2,
tr_tool->trans_info[PIVOT_X],
tr_tool->trans_info[PIVOT_Y],
tr_tool->trans_info[ANGLE]);
g_object_set (widget,
"guide-type", options->grid_type,
"n-guides", options->grid_size,
"inside-function", GIMP_TRANSFORM_FUNCTION_ROTATE,
"outside-function", GIMP_TRANSFORM_FUNCTION_ROTATE,
"use-pivot-handle", TRUE,
"constrain-move", options->constrain_move,
"constrain-scale", options->constrain_scale,
"constrain-rotate", options->constrain_rotate,
"constrain-shear", options->constrain_shear,
"constrain-perspective", options->constrain_perspective,
"frompivot-scale", options->frompivot_scale,
"frompivot-shear", options->frompivot_shear,
"frompivot-perspective", options->frompivot_perspective,
"cornersnap", options->cornersnap,
"fixedpivot", options->fixedpivot,
NULL);
g_signal_connect (widget, "changed",
G_CALLBACK (gimp_rotate_tool_widget_changed),
tr_tool);
/* constrain the angle to 15-degree multiples if ctrl is held down */
if (options->constrain_rotate)
{
tr_tool->trans_info[ANGLE] =
FIFTEEN_DEG * (gint) ((tr_tool->trans_info[REAL_ANGLE] +
FIFTEEN_DEG / 2.0) / FIFTEEN_DEG);
}
else
{
tr_tool->trans_info[ANGLE] = tr_tool->trans_info[REAL_ANGLE];
}
return widget;
}
static void
gimp_rotate_tool_recalc_matrix (GimpTransformTool *tr_tool)
gimp_rotate_tool_recalc_matrix (GimpTransformTool *tr_tool,
GimpToolWidget *widget)
{
tr_tool->px = tr_tool->trans_info[PIVOT_X];
tr_tool->py = tr_tool->trans_info[PIVOT_Y];
gimp_matrix3_identity (&tr_tool->transform);
gimp_transform_matrix_rotate_center (&tr_tool->transform,
tr_tool->px,
tr_tool->py,
tr_tool->trans_info[PIVOT_X],
tr_tool->trans_info[PIVOT_Y],
tr_tool->trans_info[ANGLE]);
if (widget)
g_object_set (widget,
"transform", &tr_tool->transform,
"angle", tr_tool->trans_info[ANGLE],
"pivot-x", tr_tool->trans_info[PIVOT_X],
"pivot-y", tr_tool->trans_info[PIVOT_Y],
NULL);
}
static gchar *
......@@ -383,6 +365,19 @@ gimp_rotate_tool_get_undo_desc (GimpTransformTool *tr_tool)
tr_tool->trans_info[PIVOT_Y]);
}
static void
gimp_rotate_tool_widget_changed (GimpToolWidget *widget,
GimpTransformTool *tr_tool)
{
g_object_get (widget,
"angle", &tr_tool->trans_info[ANGLE],
"pivot-x", &tr_tool->trans_info[PIVOT_X],
"pivot-y", &tr_tool->trans_info[PIVOT_Y],
NULL);
gimp_transform_tool_recalc_matrix (tr_tool, NULL);
}
static void
rotate_angle_changed (GtkAdjustment *adj,
GimpTransformTool *tr_tool)
......@@ -393,15 +388,11 @@ rotate_angle_changed (GtkAdjustment *adj,
if (ABS (value - tr_tool->trans_info[ANGLE]) > ANGLE_EPSILON)
{
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
tr_tool->trans_info[REAL_ANGLE] = tr_tool->trans_info[ANGLE] = value;
tr_tool->trans_info[ANGLE] = value;
gimp_transform_tool_push_internal_undo (tr_tool);
gimp_transform_tool_recalc_matrix (tr_tool);
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
gimp_transform_tool_recalc_matrix (tr_tool, tr_tool->widget);
}
#undef ANGLE_EPSILON
......@@ -417,17 +408,11 @@ rotate_center_changed (GtkWidget *widget,
if ((px != tr_tool->trans_info[PIVOT_X]) ||
(py != tr_tool->trans_info[PIVOT_Y]))
{
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
tr_tool->trans_info[PIVOT_X] = px;
tr_tool->trans_info[PIVOT_Y] = py;
tr_tool->px = px;
tr_tool->py = py;
gimp_transform_tool_push_internal_undo (tr_tool);
gimp_transform_tool_recalc_matrix (tr_tool);
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
gimp_transform_tool_recalc_matrix (tr_tool, tr_tool->widget);
}
}
......@@ -29,7 +29,6 @@
#include "core/gimp-transform-utils.h"
#include "core/gimpimage.h"
#include "core/gimpdrawable-transform.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpsizebox.h"
......@@ -37,6 +36,7 @@
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "display/gimptoolgui.h"
#include "display/gimptooltransformgrid.h"
#include "gimpscaletool.h"
#include "gimptoolcontrol.h"
......@@ -51,26 +51,26 @@ enum
X0,
Y0,
X1,
Y1,
X2,
Y2,
X3,
Y3
Y1
};
/* local function prototypes */
static void gimp_scale_tool_dialog (GimpTransformTool *tr_tool);
static void gimp_scale_tool_dialog_update (GimpTransformTool *tr_tool);
static void gimp_scale_tool_prepare (GimpTransformTool *tr_tool);
static void gimp_scale_tool_motion (GimpTransformTool *tr_tool);
static void gimp_scale_tool_recalc_matrix (GimpTransformTool *tr_tool);
static gchar * gimp_scale_tool_get_undo_desc (GimpTransformTool *tr_tool);
static void gimp_scale_tool_dialog (GimpTransformTool *tr_tool);
static void gimp_scale_tool_dialog_update (GimpTransformTool *tr_tool);
static void gimp_scale_tool_prepare (GimpTransformTool *tr_tool);
static GimpToolWidget * gimp_scale_tool_get_widget (GimpTransformTool *tr_tool);
static void gimp_scale_tool_recalc_matrix (GimpTransformTool *tr_tool,
GimpToolWidget *widget);
static gchar * gimp_scale_tool_get_undo_desc (GimpTransformTool *tr_tool);
static void gimp_scale_tool_size_notify (GtkWidget *box,
GParamSpec *pspec,
GimpTransformTool *tr_tool);
static void gimp_scale_tool_widget_changed (GimpToolWidget *widget,
GimpTransformTool *tr_tool);
static void gimp_scale_tool_size_notify (GtkWidget *box,
GParamSpec *pspec,
GimpTransformTool *tr_tool);
G_DEFINE_TYPE (GimpScaleTool, gimp_scale_tool, GIMP_TYPE_TRANSFORM_TOOL)
......@@ -103,7 +103,7 @@ gimp_scale_tool_class_init (GimpScaleToolClass *klass)
trans_class->dialog = gimp_scale_tool_dialog;
trans_class->dialog_update = gimp_scale_tool_dialog_update;
trans_class->prepare = gimp_scale_tool_prepare;
trans_class->motion = gimp_scale_tool_motion;
trans_class->get_widget = gimp_scale_tool_get_widget;
trans_class->recalc_matrix = gimp_scale_tool_recalc_matrix;
trans_class->get_undo_desc = gimp_scale_tool_get_undo_desc;
......@@ -118,12 +118,8 @@ gimp_scale_tool_init (GimpScaleTool *scale_tool)
gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_RESIZE);
tr_tool->progress_text = _("Scaling");
tr_tool->use_grid = TRUE;
tr_tool->use_corner_handles = TRUE;
tr_tool->use_side_handles = TRUE;
tr_tool->use_center_handle = TRUE;
tr_tool->progress_text = _("Scaling");
tr_tool->use_grid = TRUE;
}
static void
......@@ -135,9 +131,11 @@ static void
gimp_scale_tool_dialog_update (GimpTransformTool *tr_tool)
{
GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
gint width;
gint height;
gint width = ROUND (tr_tool->trans_info[X1] - tr_tool->trans_info[X0]);
gint height = ROUND (tr_tool->trans_info[Y1] - tr_tool->trans_info[Y0]);
width = ROUND (tr_tool->trans_info[X1] - tr_tool->trans_info[X0]);
height = ROUND (tr_tool->trans_info[Y1] - tr_tool->trans_info[Y0]);
g_object_set (GIMP_SCALE_TOOL (tr_tool)->box,
"width", width,
......@@ -193,131 +191,51 @@ gimp_scale_tool_prepare (GimpTransformTool *tr_tool)
tr_tool);
}
static void
gimp_scale_tool_motion (GimpTransformTool *tr_tool)
static GimpToolWidget *
gimp_scale_tool_get_widget (GimpTransformTool *tr_tool)
{
GimpTool *tool = GIMP_TOOL (tr_tool);
GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
gdouble *x1;
gdouble *y1;
gdouble *x2;
gdouble *y2;
gint dir_x;
gint dir_y;
gdouble diff_x = tr_tool->curx - tr_tool->lastx;
gdouble diff_y = tr_tool->cury - tr_tool->lasty;
switch (tr_tool->function)
{
case TRANSFORM_HANDLE_N:
diff_x = 0; /* and fall through */
case TRANSFORM_HANDLE_NW:
x1 = &tr_tool->trans_info[X0];
y1 = &tr_tool->trans_info[Y0];
x2 = &tr_tool->trans_info[X1];
y2 = &tr_tool->trans_info[Y1];
dir_x = dir_y = 1;
break;
case TRANSFORM_HANDLE_E:
diff_y = 0; /* and fall through */
case TRANSFORM_HANDLE_NE:
x1 = &tr_tool->trans_info[X1];
y1 = &tr_tool->trans_info[Y0];
x2 = &tr_tool->trans_info[X0];
y2 = &tr_tool->trans_info[Y1];
dir_x = -1;
dir_y = 1;
break;
case TRANSFORM_HANDLE_W:
diff_y = 0; /* and fall through */
case TRANSFORM_HANDLE_SW:
x1 = &tr_tool->trans_info[X0];
y1 = &tr_tool->trans_info[Y1];
x2 = &tr_tool->trans_info[X1];
y2 = &tr_tool->trans_info[Y0];
dir_x = 1;
dir_y = -1;
break;
case TRANSFORM_HANDLE_S:
diff_x = 0; /* and fall through */
case TRANSFORM_HANDLE_SE:
x1 = &tr_tool->trans_info[X1];
y1 = &tr_tool->trans_info[Y1];
x2 = &tr_tool->trans_info[X0];
y2 = &tr_tool->trans_info[Y0];
dir_x = dir_y = -1;
break;
case TRANSFORM_HANDLE_CENTER:
tr_tool->trans_info[X0] += diff_x;
tr_tool->trans_info[Y0] += diff_y;
tr_tool->trans_info[X1] += diff_x;
tr_tool->trans_info[Y1] += diff_y;
tr_tool->trans_info[X2] += diff_x;
tr_tool->trans_info[Y2] += diff_y;
tr_tool->trans_info[X3] += diff_x;
tr_tool->trans_info[Y3] += diff_y;
return;
default:
return;
}
*x1 += diff_x;
*y1 += diff_y;
/* if control is being held, constrain the aspect ratio */
if (options->constrain_scale)
{
/* FIXME: improve this */
gdouble h = tr_tool->trans_info[Y1] - tr_tool->trans_info[Y0];
switch (tr_tool->function)
{
case TRANSFORM_HANDLE_NW:
case TRANSFORM_HANDLE_SW: