app/tools/gimpscaletool.c applied patch from Jordi Gay (attached to bug

2004-08-05  Michael Natterer  <mitch@gimp.org>

	* app/tools/gimpscaletool.c
	* app/tools/gimptransformtool.h: applied patch from Jordi Gay
	(attached to bug #131111) which adds an aspect ratio spinbutton to
	the scale dialog and keeps the aspect ratio intact when with or
	height are changed using the dialog. Fixes bug #132274.

	* app/tools/gimpcroptool.c
	* app/tools/gimpscaletool.c: don't set the aspect spinbuttons to
	"wrap" and decrease their climb_rate.
This commit is contained in:
Michael Natterer
2004-08-05 11:12:58 +00:00
committed by Michael Natterer
parent f3d3a3a6b9
commit 8db70a4c79
4 changed files with 128 additions and 57 deletions

View File

@ -1,3 +1,15 @@
2004-08-05 Michael Natterer <mitch@gimp.org>
* app/tools/gimpscaletool.c
* app/tools/gimptransformtool.h: applied patch from Jordi Gay
(attached to bug #131111) which adds an aspect ratio spinbutton to
the scale dialog and keeps the aspect ratio intact when with or
height are changed using the dialog. Fixes bug #132274.
* app/tools/gimpcroptool.c
* app/tools/gimpscaletool.c: don't set the aspect spinbuttons to
"wrap" and decrease their climb_rate.
2004-08-05 Michael Natterer <mitch@gimp.org> 2004-08-05 Michael Natterer <mitch@gimp.org>
* app/actions/context-actions.c * app/actions/context-actions.c

View File

@ -966,7 +966,6 @@ crop_info_create (GimpCropTool *crop)
GtkWidget *spinbutton; GtkWidget *spinbutton;
GtkWidget *bbox; GtkWidget *bbox;
GtkWidget *button; GtkWidget *button;
GtkWidget *widget;
const gchar *stock_id; const gchar *stock_id;
stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool->tool_info)); stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool->tool_info));
@ -1036,14 +1035,11 @@ crop_info_create (GimpCropTool *crop)
gtk_table_set_row_spacing (GTK_TABLE (crop->crop_info->info_table), 1, 6); gtk_table_set_row_spacing (GTK_TABLE (crop->crop_info->info_table), 1, 6);
gtk_table_set_row_spacing (GTK_TABLE (crop->crop_info->info_table), 2, 0); gtk_table_set_row_spacing (GTK_TABLE (crop->crop_info->info_table), 2, 0);
widget = spinbutton = info_dialog_add_spinbutton (crop->crop_info, _("Aspect ratio:"),
info_dialog_add_spinbutton (crop->crop_info, _("Aspect ratio:"), &(crop->aspect_ratio),
&(crop->aspect_ratio), 0, 65536, 0.01, 0.1, 1, 0.5, 2,
0, 65536, 0.01, 0.1, 1, 1, 2, G_CALLBACK (crop_aspect_changed),
G_CALLBACK (crop_aspect_changed), crop);
crop);
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (widget), TRUE);
/* Create the area selection buttons */ /* Create the area selection buttons */
bbox = gtk_hbutton_box_new (); bbox = gtk_hbutton_box_new ();

View File

@ -52,24 +52,25 @@
/* local function prototypes */ /* local function prototypes */
static void gimp_scale_tool_class_init (GimpScaleToolClass *klass); static void gimp_scale_tool_class_init (GimpScaleToolClass *klass);
static void gimp_scale_tool_init (GimpScaleTool *sc_tool);
static void gimp_scale_tool_init (GimpScaleTool *sc_tool); static void gimp_scale_tool_dialog (GimpTransformTool *tr_tool);
static void gimp_scale_tool_prepare (GimpTransformTool *tr_tool,
GimpDisplay *gdisp);
static void gimp_scale_tool_motion (GimpTransformTool *tr_tool,
GimpDisplay *gdisp);
static void gimp_scale_tool_recalc (GimpTransformTool *tr_tool,
GimpDisplay *gdisp);
static void gimp_scale_tool_dialog (GimpTransformTool *tr_tool); static void gimp_scale_tool_info_update (GimpTransformTool *tr_tool);
static void gimp_scale_tool_prepare (GimpTransformTool *tr_tool,
GimpDisplay *gdisp);
static void gimp_scale_tool_motion (GimpTransformTool *tr_tool,
GimpDisplay *gdisp);
static void gimp_scale_tool_recalc (GimpTransformTool *tr_tool,
GimpDisplay *gdisp);
static void gimp_scale_tool_info_update (GimpTransformTool *tr_tool); static void gimp_scale_tool_size_changed (GtkWidget *widget,
GimpTransformTool *tr_tool);
static void gimp_scale_tool_size_changed (GtkWidget *widget, static void gimp_scale_tool_unit_changed (GtkWidget *widget,
GimpTransformTool *tr_tool); GimpTransformTool *tr_tool);
static void gimp_scale_tool_unit_changed (GtkWidget *widget, static void gimp_scale_tool_aspect_changed (GtkWidget *widget,
GimpTransformTool *tr_tool); GimpTransformTool *tr_tool);
/* storage for information dialog fields */ /* storage for information dialog fields */
@ -198,6 +199,13 @@ gimp_scale_tool_dialog (GimpTransformTool *tr_tool)
_("Scale ratio Y:"), _("Scale ratio Y:"),
y_ratio_buf); y_ratio_buf);
spinbutton = info_dialog_add_spinbutton (tr_tool->info_dialog,
_("Aspect Ratio:"),
&tr_tool->aspect_ratio,
0, 65536, 0.01, 0.1, 1, 0.5, 2,
G_CALLBACK (gimp_scale_tool_aspect_changed),
tr_tool);
gtk_table_set_row_spacing (GTK_TABLE (tr_tool->info_dialog->info_table), gtk_table_set_row_spacing (GTK_TABLE (tr_tool->info_dialog->info_table),
1, 4); 1, 4);
gtk_table_set_row_spacing (GTK_TABLE (tr_tool->info_dialog->info_table), gtk_table_set_row_spacing (GTK_TABLE (tr_tool->info_dialog->info_table),
@ -258,7 +266,7 @@ gimp_scale_tool_prepare (GimpTransformTool *tr_tool,
static void static void
gimp_scale_tool_motion (GimpTransformTool *tr_tool, gimp_scale_tool_motion (GimpTransformTool *tr_tool,
GimpDisplay *gdisp) GimpDisplay *gdisp)
{ {
GimpTransformOptions *options; GimpTransformOptions *options;
gdouble *x1; gdouble *x1;
@ -340,19 +348,21 @@ gimp_scale_tool_motion (GimpTransformTool *tr_tool,
/* if control and mod1 are both down, constrain the aspect ratio */ /* if control and mod1 are both down, constrain the aspect ratio */
else if (options->constrain_1 && options->constrain_2) else if (options->constrain_1 && options->constrain_2)
{ {
mag = hypot ((gdouble)(tr_tool->x2 - tr_tool->x1), mag = hypot ((gdouble) (tr_tool->x2 - tr_tool->x1),
(gdouble)(tr_tool->y2 - tr_tool->y1)); (gdouble) (tr_tool->y2 - tr_tool->y1));
dot = dir_x * diff_x * (tr_tool->x2 - tr_tool->x1) dot = (dir_x * diff_x * (tr_tool->x2 - tr_tool->x1) +
+ dir_y * diff_y * (tr_tool->y2 - tr_tool->y1); dir_y * diff_y * (tr_tool->y2 - tr_tool->y1));
if (mag > 0.) if (mag > 0.0)
{ {
diff_x = dir_x * (tr_tool->x2 - tr_tool->x1) * dot / (mag*mag); diff_x = dir_x * (tr_tool->x2 - tr_tool->x1) * dot / (mag * mag);
diff_y = dir_y * (tr_tool->y2 - tr_tool->y1) * dot / (mag*mag); diff_y = dir_y * (tr_tool->y2 - tr_tool->y1) * dot / (mag * mag);
} }
else else
diff_x = diff_y = 0; {
diff_x = diff_y = 0;
}
} }
*x1 += diff_x; *x1 += diff_x;
@ -379,7 +389,7 @@ gimp_scale_tool_motion (GimpTransformTool *tr_tool,
static void static void
gimp_scale_tool_recalc (GimpTransformTool *tr_tool, gimp_scale_tool_recalc (GimpTransformTool *tr_tool,
GimpDisplay *gdisp) GimpDisplay *gdisp)
{ {
gimp_transform_matrix_scale (tr_tool->x1, gimp_transform_matrix_scale (tr_tool->x1,
tr_tool->y1, tr_tool->y1,
@ -401,17 +411,18 @@ gimp_scale_tool_recalc (GimpTransformTool *tr_tool,
static void static void
gimp_scale_tool_info_update (GimpTransformTool *tr_tool) gimp_scale_tool_info_update (GimpTransformTool *tr_tool)
{ {
Gimp *gimp; GimpTool *tool = GIMP_TOOL (tr_tool);
GimpTool *tool; GimpTransformOptions *options;
gdouble ratio_x, ratio_y; Gimp *gimp;
gint x1, y1, x2, y2, x3, y3, x4, y4; gdouble ratio_x, ratio_y;
GimpUnit unit; gint x1, y1, x2, y2, x3, y3, x4, y4;
gdouble unit_factor; GimpUnit unit;
gchar format_buf[16]; gdouble unit_factor;
gchar format_buf[16];
static GimpUnit label_unit = GIMP_UNIT_PIXEL; static GimpUnit label_unit = GIMP_UNIT_PIXEL;
tool = GIMP_TOOL (tr_tool); options = GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options);
unit = gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (sizeentry)); unit = gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (sizeentry));
@ -431,12 +442,12 @@ gimp_scale_tool_info_update (GimpTransformTool *tr_tool)
if (label_unit) /* unit != GIMP_UNIT_PIXEL */ if (label_unit) /* unit != GIMP_UNIT_PIXEL */
{ {
g_snprintf (format_buf, sizeof (format_buf), "%%.%df %s", g_snprintf (format_buf, sizeof (format_buf), "%%.%df %s",
_gimp_unit_get_digits (gimp, label_unit) + 1, _gimp_unit_get_digits (gimp, label_unit) + 1,
_gimp_unit_get_symbol (gimp, label_unit)); _gimp_unit_get_symbol (gimp, label_unit));
g_snprintf (orig_width_buf, MAX_INFO_BUF, format_buf, g_snprintf (orig_width_buf, MAX_INFO_BUF, format_buf,
(x2 - x1) * unit_factor / tool->gdisp->gimage->xresolution); (x2 - x1) * unit_factor / tool->gdisp->gimage->xresolution);
g_snprintf (orig_height_buf, MAX_INFO_BUF, format_buf, g_snprintf (orig_height_buf, MAX_INFO_BUF, format_buf,
(y2 - y1) * unit_factor / tool->gdisp->gimage->yresolution); (y2 - y1) * unit_factor / tool->gdisp->gimage->yresolution);
} }
else /* unit == GIMP_UNIT_PIXEL */ else /* unit == GIMP_UNIT_PIXEL */
{ {
@ -460,6 +471,22 @@ gimp_scale_tool_info_update (GimpTransformTool *tr_tool)
if (y2 - y1) if (y2 - y1)
ratio_y = (double) (y4 - y3) / (double) (y2 - y1); ratio_y = (double) (y4 - y3) / (double) (y2 - y1);
/* Detecting initial update, aspect_ratio reset */
if ((ratio_x == 1) && (ratio_y == 1))
tr_tool->aspect_ratio = 0;
/* Only when one or the two options are disabled, is necessary to
* update the value Taking care of the initial update too
*/
if (! options->constrain_1 ||
! options->constrain_2 ||
tr_tool->aspect_ratio == 0 )
{
tr_tool->aspect_ratio =
((tr_tool->trans_info[X1] - tr_tool->trans_info[X0]) /
(tr_tool->trans_info[Y1] - tr_tool->trans_info[Y0]));
}
g_snprintf (x_ratio_buf, sizeof (x_ratio_buf), "%0.2f", ratio_x); g_snprintf (x_ratio_buf, sizeof (x_ratio_buf), "%0.2f", ratio_x);
g_snprintf (y_ratio_buf, sizeof (y_ratio_buf), "%0.2f", ratio_y); g_snprintf (y_ratio_buf, sizeof (y_ratio_buf), "%0.2f", ratio_y);
@ -471,8 +498,13 @@ static void
gimp_scale_tool_size_changed (GtkWidget *widget, gimp_scale_tool_size_changed (GtkWidget *widget,
GimpTransformTool *tr_tool) GimpTransformTool *tr_tool)
{ {
gint width; GimpTool *tool = GIMP_TOOL (tr_tool);
gint height; GimpTransformOptions *options;
gint width;
gint height;
gdouble ratio;
options = GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options);
width = RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0)); width = RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0));
height = RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1)); height = RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1));
@ -484,6 +516,17 @@ gimp_scale_tool_size_changed (GtkWidget *widget,
{ {
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool)); gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
if (options->constrain_1 && options->constrain_2)
{
ratio = tr_tool->aspect_ratio;
/* Calculating height and width taking into account the aspect ratio*/
if (width != (tr_tool->trans_info[X1] - tr_tool->trans_info[X0]))
height = width / ratio;
else
width = height * ratio;
}
tr_tool->trans_info[X1] = tr_tool->trans_info[X0] + width; tr_tool->trans_info[X1] = tr_tool->trans_info[X0] + width;
tr_tool->trans_info[Y1] = tr_tool->trans_info[Y0] + height; tr_tool->trans_info[Y1] = tr_tool->trans_info[Y0] + height;
@ -497,7 +540,25 @@ gimp_scale_tool_size_changed (GtkWidget *widget,
static void static void
gimp_scale_tool_unit_changed (GtkWidget *widget, gimp_scale_tool_unit_changed (GtkWidget *widget,
GimpTransformTool *tr_tool) GimpTransformTool *tr_tool)
{ {
gimp_scale_tool_info_update (tr_tool); gimp_scale_tool_info_update (tr_tool);
} }
static void
gimp_scale_tool_aspect_changed (GtkWidget *widget,
GimpTransformTool *tr_tool)
{
tr_tool->aspect_ratio = GTK_ADJUSTMENT (widget)->value;
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
tr_tool->trans_info[Y1] =
((gdouble) (tr_tool->trans_info[X1] - tr_tool->trans_info[X0]) /
tr_tool->aspect_ratio) +
tr_tool->trans_info[Y0];
gimp_scale_tool_recalc (tr_tool, GIMP_TOOL (tr_tool)->gdisp);
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
}

View File

@ -60,13 +60,14 @@ struct _GimpTransformTool
gint x1, y1; /* upper left hand coordinate */ gint x1, y1; /* upper left hand coordinate */
gint x2, y2; /* lower right hand coords */ gint x2, y2; /* lower right hand coords */
gdouble cx, cy; /* center point (for rotation) */ gdouble cx, cy; /* center point (for rotation) */
gdouble aspect_ratio; /* aspect ratio (for scaling) */
gdouble tx1, ty1; /* transformed coords */ gdouble tx1, ty1; /* transformed coords */
gdouble tx2, ty2; gdouble tx2, ty2;
gdouble tx3, ty3; gdouble tx3, ty3;
gdouble tx4, ty4; gdouble tx4, ty4;
gdouble tcx, tcy; gdouble tcx, tcy;
GimpMatrix3 transform; /* transformation matrix */ GimpMatrix3 transform; /* transformation matrix */
TransInfo trans_info; /* transformation info */ TransInfo trans_info; /* transformation info */
@ -80,14 +81,14 @@ struct _GimpTransformTool
gboolean use_grid; /* does the tool use the grid */ gboolean use_grid; /* does the tool use the grid */
gboolean use_center; /* use the center handle */ gboolean use_center; /* use the center handle */
gint ngx, ngy; /* number of grid lines in original gint ngx, ngy; /* number of grid lines in original
* x and y directions * x and y directions
*/ */
gdouble *grid_coords; /* x and y coordinates of the grid gdouble *grid_coords; /* x and y coordinates of the grid
* endpoints (a total of (ngx+ngy)*2 * endpoints (a total of (ngx+ngy)*2
* coordinate pairs) * coordinate pairs)
*/ */
gdouble *tgrid_coords; /* transformed grid_coords */ gdouble *tgrid_coords; /* transformed grid_coords */
GimpTransformType type; GimpTransformType type;
GimpTransformDirection direction; GimpTransformDirection direction;
@ -122,4 +123,5 @@ GType gimp_transform_tool_get_type (void) G_GNUC_CONST;
void gimp_transform_tool_transform_bounding_box (GimpTransformTool *tr_tool); void gimp_transform_tool_transform_bounding_box (GimpTransformTool *tr_tool);
void gimp_transform_tool_expose_preview (GimpTransformTool *tr_tool); void gimp_transform_tool_expose_preview (GimpTransformTool *tr_tool);
#endif /* __GIMP_TRANSFORM_TOOL_H__ */ #endif /* __GIMP_TRANSFORM_TOOL_H__ */