Index: app/tools/gimpscaletool.c
===================================================================
RCS file: /cvs/gnome/gimp/app/tools/gimpscaletool.c,v
retrieving revision 1.92
diff -u -p -r1.92 gimpscaletool.c
--- app/tools/gimpscaletool.c	21 Jan 2004 11:16:57 -0000	1.92
+++ app/tools/gimpscaletool.c	15 Apr 2004 15:06:43 -0000
@@ -70,6 +70,8 @@ static void   gimp_scale_tool_size_chang
                                             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  */
@@ -166,6 +168,8 @@ static void
 gimp_scale_tool_dialog (GimpTransformTool *tr_tool)
 {
   GtkWidget *spinbutton;
+  GtkWidget *widget;
+
 
   info_dialog_add_label (tr_tool->info_dialog,
                          _("Original Width:"),
@@ -199,6 +203,13 @@ gimp_scale_tool_dialog (GimpTransformToo
   info_dialog_add_label (tr_tool->info_dialog,
                          _("Y:"),
                          y_ratio_buf);
+  widget = 
+      info_dialog_add_spinbutton (tr_tool->info_dialog, _("Aspect Ratio:"),
+                                  &(tr_tool->aspect_ratio),
+                                  0, 65536, 0.01, 0.1, 1, 1, 2,
+                                  G_CALLBACK (gimp_scale_tool_aspect_changed),
+                                  tr_tool);
+  gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (widget), TRUE);
 
   gtk_table_set_row_spacing (GTK_TABLE (tr_tool->info_dialog->info_table),
                              1, 4);
@@ -368,8 +379,7 @@ gimp_scale_tool_motion (GimpTransformToo
    */
   if (options->constrain_1 && options->constrain_2)
     {
-      ratio = ((gdouble) (tr_tool->x2 - tr_tool->x1) /
-               (gdouble) (tr_tool->y2 - tr_tool->y1));
+      ratio = tr_tool->aspect_ratio;
 
       w = ABS ((*x2 - *x1));
       h = ABS ((*y2 - *y1));
@@ -415,10 +425,12 @@ gimp_scale_tool_info_update (GimpTransfo
   GimpUnit  unit;
   gdouble   unit_factor;
   gchar     format_buf[16];
+  GimpTransformOptions *options;
 
   static GimpUnit  label_unit = GIMP_UNIT_PIXEL;
 
   tool = GIMP_TOOL (tr_tool);
+  options = GIMP_TRANSFORM_OPTIONS (GIMP_TOOL (tr_tool)->tool_info->tool_options);
 
   unit = gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (sizeentry));
 
@@ -467,6 +479,18 @@ gimp_scale_tool_info_update (GimpTransfo
   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);
 
@@ -480,6 +504,10 @@ gimp_scale_tool_size_changed (GtkWidget 
 {
   gint width;
   gint height;
+  gdouble ratio;
+  GimpTransformOptions *options;
+
+  options = GIMP_TRANSFORM_OPTIONS (GIMP_TOOL (tr_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));
@@ -491,6 +519,19 @@ gimp_scale_tool_size_changed (GtkWidget 
     {
       gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
 
+      /* Only recalculate height & width if both options are selected ctrl & mod1 */
+      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;
 
@@ -506,3 +547,22 @@ gimp_scale_tool_unit_changed (GtkWidget 
 {
   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));
+}
+
+
