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>
* app/actions/context-actions.c

View File

@ -966,7 +966,6 @@ crop_info_create (GimpCropTool *crop)
GtkWidget *spinbutton;
GtkWidget *bbox;
GtkWidget *button;
GtkWidget *widget;
const gchar *stock_id;
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), 2, 0);
widget =
info_dialog_add_spinbutton (crop->crop_info, _("Aspect ratio:"),
spinbutton = info_dialog_add_spinbutton (crop->crop_info, _("Aspect ratio:"),
&(crop->aspect_ratio),
0, 65536, 0.01, 0.1, 1, 1, 2,
0, 65536, 0.01, 0.1, 1, 0.5, 2,
G_CALLBACK (crop_aspect_changed),
crop);
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (widget), TRUE);
/* Create the area selection buttons */
bbox = gtk_hbutton_box_new ();

View File

@ -53,7 +53,6 @@
/* local function prototypes */
static void gimp_scale_tool_class_init (GimpScaleToolClass *klass);
static void gimp_scale_tool_init (GimpScaleTool *sc_tool);
static void gimp_scale_tool_dialog (GimpTransformTool *tr_tool);
@ -70,6 +69,8 @@ static void gimp_scale_tool_size_changed (GtkWidget *widget,
GimpTransformTool *tr_tool);
static void gimp_scale_tool_unit_changed (GtkWidget *widget,
GimpTransformTool *tr_tool);
static void gimp_scale_tool_aspect_changed (GtkWidget *widget,
GimpTransformTool *tr_tool);
/* storage for information dialog fields */
@ -198,6 +199,13 @@ gimp_scale_tool_dialog (GimpTransformTool *tr_tool)
_("Scale ratio Y:"),
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),
1, 4);
gtk_table_set_row_spacing (GTK_TABLE (tr_tool->info_dialog->info_table),
@ -340,20 +348,22 @@ gimp_scale_tool_motion (GimpTransformTool *tr_tool,
/* if control and mod1 are both down, constrain the aspect ratio */
else if (options->constrain_1 && options->constrain_2)
{
mag = hypot ((gdouble)(tr_tool->x2 - tr_tool->x1),
(gdouble)(tr_tool->y2 - tr_tool->y1));
mag = hypot ((gdouble) (tr_tool->x2 - tr_tool->x1),
(gdouble) (tr_tool->y2 - tr_tool->y1));
dot = dir_x * diff_x * (tr_tool->x2 - tr_tool->x1)
+ dir_y * diff_y * (tr_tool->y2 - tr_tool->y1);
dot = (dir_x * diff_x * (tr_tool->x2 - tr_tool->x1) +
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_y = dir_y * (tr_tool->y2 - tr_tool->y1) * 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);
}
else
{
diff_x = diff_y = 0;
}
}
*x1 += diff_x;
*y1 += diff_y;
@ -401,8 +411,9 @@ gimp_scale_tool_recalc (GimpTransformTool *tr_tool,
static void
gimp_scale_tool_info_update (GimpTransformTool *tr_tool)
{
GimpTool *tool = GIMP_TOOL (tr_tool);
GimpTransformOptions *options;
Gimp *gimp;
GimpTool *tool;
gdouble ratio_x, ratio_y;
gint x1, y1, x2, y2, x3, y3, x4, y4;
GimpUnit unit;
@ -411,7 +422,7 @@ gimp_scale_tool_info_update (GimpTransformTool *tr_tool)
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));
@ -460,6 +471,22 @@ gimp_scale_tool_info_update (GimpTransformTool *tr_tool)
if (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 (y_ratio_buf, sizeof (y_ratio_buf), "%0.2f", ratio_y);
@ -471,8 +498,13 @@ static void
gimp_scale_tool_size_changed (GtkWidget *widget,
GimpTransformTool *tr_tool)
{
GimpTool *tool = GIMP_TOOL (tr_tool);
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));
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));
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[Y1] = tr_tool->trans_info[Y0] + height;
@ -501,3 +544,21 @@ gimp_scale_tool_unit_changed (GtkWidget *widget,
{
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

@ -61,6 +61,7 @@ struct _GimpTransformTool
gint x1, y1; /* upper left hand coordinate */
gint x2, y2; /* lower right hand coords */
gdouble cx, cy; /* center point (for rotation) */
gdouble aspect_ratio; /* aspect ratio (for scaling) */
gdouble tx1, ty1; /* transformed coords */
gdouble tx2, ty2;
@ -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_expose_preview (GimpTransformTool *tr_tool);
#endif /* __GIMP_TRANSFORM_TOOL_H__ */