~ubuntu-branches/ubuntu/hoary/gimp/hoary

« back to all changes in this revision

Viewing changes to app/tools/gimpscaletool.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-04-04 14:51:23 UTC
  • Revision ID: james.westby@ubuntu.com-20050404145123-9py049eeelfymur8
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The GIMP -- an image manipulation program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 */
 
18
 
 
19
#include "config.h"
 
20
 
 
21
#include <gtk/gtk.h>
 
22
 
 
23
#include "libgimpbase/gimpbase.h"
 
24
#include "libgimpmath/gimpmath.h"
 
25
#include "libgimpwidgets/gimpwidgets.h"
 
26
 
 
27
#include "tools-types.h"
 
28
 
 
29
#include "core/gimp-transform-utils.h"
 
30
#include "core/gimpimage.h"
 
31
#include "core/gimpdrawable-transform.h"
 
32
#include "core/gimptoolinfo.h"
 
33
#include "core/gimpunit.h"
 
34
 
 
35
#include "widgets/gimphelp-ids.h"
 
36
 
 
37
#include "display/gimpdisplay.h"
 
38
#include "display/gimpdisplayshell.h"
 
39
 
 
40
#ifdef __GNUC__
 
41
#warning FIXME #include "dialogs/dialogs-types.h"
 
42
#endif
 
43
#include "dialogs/dialogs-types.h"
 
44
#include "dialogs/info-dialog.h"
 
45
 
 
46
#include "gimpscaletool.h"
 
47
#include "gimptoolcontrol.h"
 
48
#include "gimptransformoptions.h"
 
49
 
 
50
#include "gimp-intl.h"
 
51
 
 
52
 
 
53
/*  local function prototypes  */
 
54
 
 
55
static void   gimp_scale_tool_class_init     (GimpScaleToolClass *klass);
 
56
static void   gimp_scale_tool_init           (GimpScaleTool      *sc_tool);
 
57
 
 
58
static void   gimp_scale_tool_dialog         (GimpTransformTool  *tr_tool);
 
59
static void   gimp_scale_tool_dialog_update  (GimpTransformTool  *tr_tool);
 
60
static void   gimp_scale_tool_prepare        (GimpTransformTool  *tr_tool,
 
61
                                              GimpDisplay        *gdisp);
 
62
static void   gimp_scale_tool_motion         (GimpTransformTool  *tr_tool,
 
63
                                              GimpDisplay        *gdisp);
 
64
static void   gimp_scale_tool_recalc         (GimpTransformTool  *tr_tool,
 
65
                                              GimpDisplay        *gdisp);
 
66
 
 
67
static void   gimp_scale_tool_size_changed   (GtkWidget          *widget,
 
68
                                              GimpTransformTool  *tr_tool);
 
69
static void   gimp_scale_tool_unit_changed   (GtkWidget          *widget,
 
70
                                              GimpTransformTool  *tr_tool);
 
71
static void   gimp_scale_tool_aspect_changed (GtkWidget          *widget,
 
72
                                              GimpTransformTool  *tr_tool);
 
73
 
 
74
 
 
75
/*  private variables  */
 
76
 
 
77
static GimpTransformToolClass *parent_class = NULL;
 
78
 
 
79
 
 
80
/*  public functions  */
 
81
 
 
82
void
 
83
gimp_scale_tool_register (GimpToolRegisterCallback  callback,
 
84
                          gpointer                  data)
 
85
{
 
86
  (* callback) (GIMP_TYPE_SCALE_TOOL,
 
87
                GIMP_TYPE_TRANSFORM_OPTIONS,
 
88
                gimp_transform_options_gui,
 
89
                0,
 
90
                "gimp-scale-tool",
 
91
                _("Scale"),
 
92
                _("Scale the layer or selection"),
 
93
                N_("_Scale"), "<shift>T",
 
94
                NULL, GIMP_HELP_TOOL_SCALE,
 
95
                GIMP_STOCK_TOOL_SCALE,
 
96
                data);
 
97
}
 
98
 
 
99
GType
 
100
gimp_scale_tool_get_type (void)
 
101
{
 
102
  static GType tool_type = 0;
 
103
 
 
104
  if (! tool_type)
 
105
    {
 
106
      static const GTypeInfo tool_info =
 
107
      {
 
108
        sizeof (GimpScaleToolClass),
 
109
        (GBaseInitFunc) NULL,
 
110
        (GBaseFinalizeFunc) NULL,
 
111
        (GClassInitFunc) gimp_scale_tool_class_init,
 
112
        NULL,           /* class_finalize */
 
113
        NULL,           /* class_data     */
 
114
        sizeof (GimpScaleTool),
 
115
        0,              /* n_preallocs    */
 
116
        (GInstanceInitFunc) gimp_scale_tool_init,
 
117
      };
 
118
 
 
119
      tool_type = g_type_register_static (GIMP_TYPE_TRANSFORM_TOOL,
 
120
                                          "GimpScaleTool",
 
121
                                          &tool_info, 0);
 
122
    }
 
123
 
 
124
  return tool_type;
 
125
}
 
126
 
 
127
 
 
128
/*  private functions  */
 
129
 
 
130
static void
 
131
gimp_scale_tool_class_init (GimpScaleToolClass *klass)
 
132
{
 
133
  GimpTransformToolClass *trans_class = GIMP_TRANSFORM_TOOL_CLASS (klass);
 
134
 
 
135
  parent_class = g_type_class_peek_parent (klass);
 
136
 
 
137
  trans_class->dialog         = gimp_scale_tool_dialog;
 
138
  trans_class->dialog_update  = gimp_scale_tool_dialog_update;
 
139
  trans_class->prepare        = gimp_scale_tool_prepare;
 
140
  trans_class->motion         = gimp_scale_tool_motion;
 
141
  trans_class->recalc         = gimp_scale_tool_recalc;
 
142
}
 
143
 
 
144
static void
 
145
gimp_scale_tool_init (GimpScaleTool *scale_tool)
 
146
{
 
147
  GimpTool          *tool    = GIMP_TOOL (scale_tool);
 
148
  GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (scale_tool);
 
149
 
 
150
  gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_RESIZE);
 
151
 
 
152
  tr_tool->shell_desc    = _("Scaling information");
 
153
  tr_tool->progress_text = _("Scaling...");
 
154
}
 
155
 
 
156
static void
 
157
gimp_scale_tool_dialog (GimpTransformTool *tr_tool)
 
158
{
 
159
  GimpScaleTool *scale = GIMP_SCALE_TOOL (tr_tool);
 
160
  GtkWidget     *spinbutton;
 
161
 
 
162
  info_dialog_add_label (tr_tool->info_dialog,
 
163
                         _("Original Width:"),
 
164
                         scale->orig_width_buf);
 
165
  info_dialog_add_label (tr_tool->info_dialog,
 
166
                         _("Height:"),
 
167
                         scale->orig_height_buf);
 
168
 
 
169
  spinbutton = info_dialog_add_spinbutton (tr_tool->info_dialog,
 
170
                                           _("Current width:"),
 
171
                                           NULL, -1, 1, 1, 10, 1, 1, 2,
 
172
                                           NULL, NULL);
 
173
  scale->sizeentry = info_dialog_add_sizeentry (tr_tool->info_dialog,
 
174
                                                _("Current height:"),
 
175
                                                scale->size_vals, 1,
 
176
                                                GIMP_UNIT_PIXEL, "%a",
 
177
                                                TRUE, TRUE, FALSE,
 
178
                                                GIMP_SIZE_ENTRY_UPDATE_SIZE,
 
179
                                                G_CALLBACK (gimp_scale_tool_size_changed),
 
180
                                                tr_tool);
 
181
  g_signal_connect (scale->sizeentry, "unit_changed",
 
182
                    G_CALLBACK (gimp_scale_tool_unit_changed),
 
183
                    tr_tool);
 
184
 
 
185
  gimp_size_entry_add_field (GIMP_SIZE_ENTRY (scale->sizeentry),
 
186
                             GTK_SPIN_BUTTON (spinbutton), NULL);
 
187
 
 
188
  info_dialog_add_label (tr_tool->info_dialog,
 
189
                         _("Scale ratio X:"),
 
190
                         scale->x_ratio_buf);
 
191
  info_dialog_add_label (tr_tool->info_dialog,
 
192
                         _("Scale ratio Y:"),
 
193
                         scale->y_ratio_buf);
 
194
 
 
195
  spinbutton = info_dialog_add_spinbutton (tr_tool->info_dialog,
 
196
                                           _("Aspect Ratio:"),
 
197
                                           &scale->aspect_ratio_val,
 
198
                                           0, 65536, 0.01, 0.1, 1, 0.5, 2,
 
199
                                           G_CALLBACK (gimp_scale_tool_aspect_changed),
 
200
                                           tr_tool);
 
201
 
 
202
  gtk_table_set_row_spacing (GTK_TABLE (tr_tool->info_dialog->info_table),
 
203
                             1, 4);
 
204
  gtk_table_set_row_spacing (GTK_TABLE (tr_tool->info_dialog->info_table),
 
205
                             2, 0);
 
206
}
 
207
 
 
208
static void
 
209
gimp_scale_tool_dialog_update (GimpTransformTool *tr_tool)
 
210
{
 
211
  GimpTool             *tool  = GIMP_TOOL (tr_tool);
 
212
  GimpScaleTool        *scale = GIMP_SCALE_TOOL (tr_tool);
 
213
  GimpTransformOptions *options;
 
214
  Gimp                 *gimp;
 
215
  gdouble               ratio_x, ratio_y;
 
216
  gint                  x1, y1, x2, y2, x3, y3, x4, y4;
 
217
  GimpUnit              unit;
 
218
  gdouble               unit_factor;
 
219
  gchar                 format_buf[16];
 
220
 
 
221
  static GimpUnit       label_unit = GIMP_UNIT_PIXEL;
 
222
 
 
223
  options = GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options);
 
224
 
 
225
  unit = gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (scale->sizeentry));
 
226
 
 
227
  /*  Find original sizes  */
 
228
  x1 = tr_tool->x1;
 
229
  y1 = tr_tool->y1;
 
230
  x2 = tr_tool->x2;
 
231
  y2 = tr_tool->y2;
 
232
 
 
233
  if (unit != GIMP_UNIT_PERCENT)
 
234
    label_unit = unit;
 
235
 
 
236
  gimp = tool->tool_info->gimp;
 
237
 
 
238
  unit_factor = _gimp_unit_get_factor (gimp, label_unit);
 
239
 
 
240
  if (label_unit) /* unit != GIMP_UNIT_PIXEL */
 
241
    {
 
242
      g_snprintf (format_buf, sizeof (format_buf), "%%.%df %s",
 
243
                  _gimp_unit_get_digits (gimp, label_unit) + 1,
 
244
                  _gimp_unit_get_symbol (gimp, label_unit));
 
245
      g_snprintf (scale->orig_width_buf, MAX_INFO_BUF, format_buf,
 
246
                  (x2 - x1) * unit_factor / tool->gdisp->gimage->xresolution);
 
247
      g_snprintf (scale->orig_height_buf, MAX_INFO_BUF, format_buf,
 
248
                  (y2 - y1) * unit_factor / tool->gdisp->gimage->yresolution);
 
249
    }
 
250
  else /* unit == GIMP_UNIT_PIXEL */
 
251
    {
 
252
      g_snprintf (scale->orig_width_buf, MAX_INFO_BUF, "%d", x2 - x1);
 
253
      g_snprintf (scale->orig_height_buf, MAX_INFO_BUF, "%d", y2 - y1);
 
254
    }
 
255
 
 
256
  /*  Find current sizes  */
 
257
  x3 = (gint) tr_tool->trans_info[X0];
 
258
  y3 = (gint) tr_tool->trans_info[Y0];
 
259
  x4 = (gint) tr_tool->trans_info[X1];
 
260
  y4 = (gint) tr_tool->trans_info[Y1];
 
261
 
 
262
  scale->size_vals[0] = x4 - x3;
 
263
  scale->size_vals[1] = y4 - y3;
 
264
 
 
265
  ratio_x = ratio_y = 0.0;
 
266
 
 
267
  if (x2 - x1)
 
268
    ratio_x = (double) (x4 - x3) / (double) (x2 - x1);
 
269
  if (y2 - y1)
 
270
    ratio_y = (double) (y4 - y3) / (double) (y2 - y1);
 
271
 
 
272
  /* Detecting initial update, aspect_ratio reset */
 
273
  if (ratio_x == 1 && ratio_y == 1)
 
274
    scale->aspect_ratio_val = 0.0;
 
275
 
 
276
  /* Only when one or the two options are disabled, is necessary to
 
277
   * update the value Taking care of the initial update too
 
278
   */
 
279
  if (! options->constrain_1 ||
 
280
      ! options->constrain_2 ||
 
281
      scale->aspect_ratio_val == 0 )
 
282
    {
 
283
      scale->aspect_ratio_val =
 
284
        ((tr_tool->trans_info[X1] - tr_tool->trans_info[X0]) /
 
285
         (tr_tool->trans_info[Y1] - tr_tool->trans_info[Y0]));
 
286
    }
 
287
 
 
288
  g_snprintf (scale->x_ratio_buf, sizeof (scale->x_ratio_buf),
 
289
              "%0.2f", ratio_x);
 
290
  g_snprintf (scale->y_ratio_buf, sizeof (scale->y_ratio_buf),
 
291
              "%0.2f", ratio_y);
 
292
 
 
293
  info_dialog_update (tr_tool->info_dialog);
 
294
  info_dialog_show (tr_tool->info_dialog);
 
295
}
 
296
 
 
297
static void
 
298
gimp_scale_tool_prepare (GimpTransformTool *tr_tool,
 
299
                         GimpDisplay       *gdisp)
 
300
{
 
301
  GimpScaleTool *scale = GIMP_SCALE_TOOL (tr_tool);
 
302
 
 
303
  scale->size_vals[0] = tr_tool->x2 - tr_tool->x1;
 
304
  scale->size_vals[1] = tr_tool->y2 - tr_tool->y1;
 
305
 
 
306
  g_signal_handlers_block_by_func (scale->sizeentry,
 
307
                                   gimp_scale_tool_size_changed,
 
308
                                   tr_tool);
 
309
  g_signal_handlers_block_by_func (scale->sizeentry,
 
310
                                   gimp_scale_tool_unit_changed,
 
311
                                   tr_tool);
 
312
 
 
313
  gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (scale->sizeentry),
 
314
                            GIMP_DISPLAY_SHELL (gdisp->shell)->unit);
 
315
 
 
316
  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (scale->sizeentry), 0,
 
317
                                  gdisp->gimage->xresolution, FALSE);
 
318
  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (scale->sizeentry), 1,
 
319
                                  gdisp->gimage->yresolution, FALSE);
 
320
 
 
321
  gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (scale->sizeentry), 0,
 
322
                                         GIMP_MIN_IMAGE_SIZE,
 
323
                                         GIMP_MAX_IMAGE_SIZE);
 
324
  gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (scale->sizeentry), 1,
 
325
                                         GIMP_MIN_IMAGE_SIZE,
 
326
                                         GIMP_MAX_IMAGE_SIZE);
 
327
 
 
328
  gimp_size_entry_set_size (GIMP_SIZE_ENTRY (scale->sizeentry), 0,
 
329
                            0, scale->size_vals[0]);
 
330
  gimp_size_entry_set_size (GIMP_SIZE_ENTRY (scale->sizeentry), 1,
 
331
                            0, scale->size_vals[1]);
 
332
 
 
333
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (scale->sizeentry), 0,
 
334
                              scale->size_vals[0]);
 
335
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (scale->sizeentry), 1,
 
336
                              scale->size_vals[1]);
 
337
 
 
338
  g_signal_handlers_unblock_by_func (scale->sizeentry,
 
339
                                     gimp_scale_tool_size_changed,
 
340
                                     tr_tool);
 
341
  g_signal_handlers_unblock_by_func (scale->sizeentry,
 
342
                                     gimp_scale_tool_unit_changed,
 
343
                                     tr_tool);
 
344
 
 
345
  tr_tool->trans_info[X0] = (gdouble) tr_tool->x1;
 
346
  tr_tool->trans_info[Y0] = (gdouble) tr_tool->y1;
 
347
  tr_tool->trans_info[X1] = (gdouble) tr_tool->x2;
 
348
  tr_tool->trans_info[Y1] = (gdouble) tr_tool->y2;
 
349
}
 
350
 
 
351
static void
 
352
gimp_scale_tool_motion (GimpTransformTool *tr_tool,
 
353
                        GimpDisplay       *gdisp)
 
354
{
 
355
  GimpTransformOptions *options;
 
356
  gdouble              *x1;
 
357
  gdouble              *y1;
 
358
  gdouble              *x2;
 
359
  gdouble              *y2;
 
360
  gdouble               mag;
 
361
  gdouble               dot;
 
362
  gint                  dir_x, dir_y;
 
363
  gdouble               diff_x, diff_y;
 
364
 
 
365
  options = GIMP_TRANSFORM_OPTIONS (GIMP_TOOL (tr_tool)->tool_info->tool_options);
 
366
 
 
367
  diff_x = tr_tool->curx - tr_tool->lastx;
 
368
  diff_y = tr_tool->cury - tr_tool->lasty;
 
369
 
 
370
  switch (tr_tool->function)
 
371
    {
 
372
    case TRANSFORM_HANDLE_1:
 
373
      x1 = &tr_tool->trans_info[X0];
 
374
      y1 = &tr_tool->trans_info[Y0];
 
375
      x2 = &tr_tool->trans_info[X1];
 
376
      y2 = &tr_tool->trans_info[Y1];
 
377
      dir_x = dir_y = 1;
 
378
      break;
 
379
 
 
380
    case TRANSFORM_HANDLE_2:
 
381
      x1 = &tr_tool->trans_info[X1];
 
382
      y1 = &tr_tool->trans_info[Y0];
 
383
      x2 = &tr_tool->trans_info[X0];
 
384
      y2 = &tr_tool->trans_info[Y1];
 
385
      dir_x = -1;
 
386
      dir_y = 1;
 
387
      break;
 
388
 
 
389
    case TRANSFORM_HANDLE_3:
 
390
      x1 = &tr_tool->trans_info[X0];
 
391
      y1 = &tr_tool->trans_info[Y1];
 
392
      x2 = &tr_tool->trans_info[X1];
 
393
      y2 = &tr_tool->trans_info[Y0];
 
394
      dir_x = 1;
 
395
      dir_y = -1;
 
396
      break;
 
397
 
 
398
    case TRANSFORM_HANDLE_4:
 
399
      x1 = &tr_tool->trans_info[X1];
 
400
      y1 = &tr_tool->trans_info[Y1];
 
401
      x2 = &tr_tool->trans_info[X0];
 
402
      y2 = &tr_tool->trans_info[Y0];
 
403
      dir_x = dir_y = -1;
 
404
      break;
 
405
 
 
406
    case TRANSFORM_HANDLE_CENTER:
 
407
      tr_tool->trans_info[X0] += diff_x;
 
408
      tr_tool->trans_info[Y0] += diff_y;
 
409
      tr_tool->trans_info[X1] += diff_x;
 
410
      tr_tool->trans_info[Y1] += diff_y;
 
411
      tr_tool->trans_info[X2] += diff_x;
 
412
      tr_tool->trans_info[Y2] += diff_y;
 
413
      tr_tool->trans_info[X3] += diff_x;
 
414
      tr_tool->trans_info[Y3] += diff_y;
 
415
 
 
416
      return;
 
417
 
 
418
    default:
 
419
      return;
 
420
    }
 
421
 
 
422
  /*  if just the mod1 key is down, affect only the height  */
 
423
  if (options->constrain_2 && ! options->constrain_1)
 
424
    {
 
425
      diff_x = 0;
 
426
    }
 
427
  /*  if just the control key is down, affect only the width  */
 
428
  else if (options->constrain_1 && ! options->constrain_2)
 
429
    {
 
430
      diff_y = 0;
 
431
    }
 
432
  /*  if control and mod1 are both down, constrain the aspect ratio  */
 
433
  else if (options->constrain_1 && options->constrain_2)
 
434
    {
 
435
      mag = hypot ((gdouble) (tr_tool->x2 - tr_tool->x1),
 
436
                   (gdouble) (tr_tool->y2 - tr_tool->y1));
 
437
 
 
438
      dot = (dir_x * diff_x * (tr_tool->x2 - tr_tool->x1) +
 
439
             dir_y * diff_y * (tr_tool->y2 - tr_tool->y1));
 
440
 
 
441
      if (mag > 0.0)
 
442
        {
 
443
          diff_x = dir_x * (tr_tool->x2 - tr_tool->x1) * dot / (mag * mag);
 
444
          diff_y = dir_y * (tr_tool->y2 - tr_tool->y1) * dot / (mag * mag);
 
445
        }
 
446
      else
 
447
        {
 
448
          diff_x = diff_y = 0;
 
449
        }
 
450
    }
 
451
 
 
452
  *x1 += diff_x;
 
453
  *y1 += diff_y;
 
454
 
 
455
  if (dir_x > 0)
 
456
    {
 
457
      if (*x1 >= *x2) *x1 = *x2 - 1;
 
458
    }
 
459
  else
 
460
    {
 
461
      if (*x1 <= *x2) *x1 = *x2 + 1;
 
462
    }
 
463
 
 
464
  if (dir_y > 0)
 
465
    {
 
466
      if (*y1 >= *y2) *y1 = *y2 - 1;
 
467
    }
 
468
  else
 
469
    {
 
470
      if (*y1 <= *y2) *y1 = *y2 + 1;
 
471
    }
 
472
}
 
473
 
 
474
static void
 
475
gimp_scale_tool_recalc (GimpTransformTool *tr_tool,
 
476
                        GimpDisplay       *gdisp)
 
477
{
 
478
  gimp_transform_matrix_scale (tr_tool->x1,
 
479
                               tr_tool->y1,
 
480
                               tr_tool->x2 - tr_tool->x1,
 
481
                               tr_tool->y2 - tr_tool->y1,
 
482
                               tr_tool->trans_info[X0],
 
483
                               tr_tool->trans_info[Y0],
 
484
                               tr_tool->trans_info[X1] - tr_tool->trans_info[X0],
 
485
                               tr_tool->trans_info[Y1] - tr_tool->trans_info[Y0],
 
486
                               &tr_tool->transform);
 
487
}
 
488
 
 
489
static void
 
490
gimp_scale_tool_size_changed (GtkWidget         *widget,
 
491
                              GimpTransformTool *tr_tool)
 
492
{
 
493
  GimpTool             *tool  = GIMP_TOOL (tr_tool);
 
494
  GimpScaleTool        *scale = GIMP_SCALE_TOOL (tr_tool);
 
495
  GimpTransformOptions *options;
 
496
  gint                  width;
 
497
  gint                  height;
 
498
 
 
499
  options = GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options);
 
500
 
 
501
  width  = RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0));
 
502
  height = RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1));
 
503
 
 
504
  if ((width  != (tr_tool->trans_info[X1] -
 
505
                  tr_tool->trans_info[X0])) ||
 
506
      (height != (tr_tool->trans_info[Y1] -
 
507
                  tr_tool->trans_info[Y0])))
 
508
    {
 
509
      gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
 
510
 
 
511
      if (options->constrain_1 && options->constrain_2)
 
512
        {
 
513
          gdouble ratio = scale->aspect_ratio_val;
 
514
 
 
515
          /* Calculating height and width taking into account the aspect ratio*/
 
516
          if (width != (tr_tool->trans_info[X1] - tr_tool->trans_info[X0]))
 
517
            height = width / ratio;
 
518
          else
 
519
            width = height * ratio;
 
520
        }
 
521
 
 
522
      tr_tool->trans_info[X1] = tr_tool->trans_info[X0] + width;
 
523
      tr_tool->trans_info[Y1] = tr_tool->trans_info[Y0] + height;
 
524
 
 
525
      gimp_transform_tool_recalc (tr_tool, GIMP_TOOL (tr_tool)->gdisp);
 
526
 
 
527
      gimp_transform_tool_expose_preview (tr_tool);
 
528
 
 
529
      gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
 
530
    }
 
531
}
 
532
 
 
533
static void
 
534
gimp_scale_tool_unit_changed (GtkWidget         *widget,
 
535
                              GimpTransformTool *tr_tool)
 
536
{
 
537
  gimp_scale_tool_dialog_update (tr_tool);
 
538
}
 
539
 
 
540
static void
 
541
gimp_scale_tool_aspect_changed (GtkWidget         *widget,
 
542
                                GimpTransformTool *tr_tool)
 
543
{
 
544
  GimpScaleTool *scale = GIMP_SCALE_TOOL (tr_tool);
 
545
 
 
546
  scale->aspect_ratio_val = GTK_ADJUSTMENT (widget)->value;
 
547
 
 
548
  gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
 
549
 
 
550
  tr_tool->trans_info[Y1] =
 
551
    ((gdouble) (tr_tool->trans_info[X1] - tr_tool->trans_info[X0]) /
 
552
     scale->aspect_ratio_val) +
 
553
    tr_tool->trans_info[Y0];
 
554
 
 
555
  gimp_transform_tool_recalc (tr_tool, GIMP_TOOL (tr_tool)->gdisp);
 
556
 
 
557
  gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
 
558
}