~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/tools/gimptransformtool.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995-2001 Spencer Kimball, Peter Mattis, and others
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
24
24
#include <gdk/gdkkeysyms.h>
25
25
 
26
26
#include "libgimpmath/gimpmath.h"
 
27
#include "libgimpconfig/gimpconfig.h"
27
28
#include "libgimpwidgets/gimpwidgets.h"
28
29
 
29
30
#include "tools-types.h"
30
31
 
 
32
#include "base/boundary.h"
31
33
#include "base/tile-manager.h"
32
34
 
33
35
#include "core/gimp.h"
34
 
#include "core/gimpchannel.h"
35
36
#include "core/gimpcontext.h"
36
37
#include "core/gimpdrawable-transform.h"
37
38
#include "core/gimpimage.h"
40
41
#include "core/gimpitem-linked.h"
41
42
#include "core/gimplayer.h"
42
43
#include "core/gimplayermask.h"
 
44
#include "core/gimppickable.h"
43
45
#include "core/gimpprogress.h"
44
46
#include "core/gimptoolinfo.h"
45
47
 
47
49
#include "vectors/gimpstroke.h"
48
50
 
49
51
#include "widgets/gimpdialogfactory.h"
50
 
#include "widgets/gimpviewabledialog.h"
 
52
#include "widgets/gimptooldialog.h"
51
53
 
52
54
#include "display/gimpdisplay.h"
53
55
#include "display/gimpdisplayshell.h"
54
56
#include "display/gimpdisplayshell-appearance.h"
55
57
#include "display/gimpdisplayshell-transform.h"
56
58
 
57
 
#ifdef __GNUC__
58
 
#warning FIXME #include "dialogs/dialogs-types.h"
59
 
#endif
60
 
#include "dialogs/dialogs-types.h"
61
 
#include "dialogs/info-dialog.h"
62
 
 
63
59
#include "gimptoolcontrol.h"
64
60
#include "gimptransformoptions.h"
65
61
#include "gimptransformtool.h"
66
 
#include "gimptransformtool-undo.h"
 
62
#include "gimptransformtoolundo.h"
67
63
 
68
64
#include "gimp-intl.h"
69
65
 
70
66
 
71
 
#define HANDLE_SIZE 10
 
67
#define HANDLE_SIZE     25
 
68
#define MIN_HANDLE_SIZE  6
72
69
 
73
70
 
74
71
/*  local function prototypes  */
75
72
 
76
 
static void   gimp_transform_tool_init        (GimpTransformTool      *tool);
77
 
static void   gimp_transform_tool_class_init  (GimpTransformToolClass *tool);
78
 
 
79
 
static GObject * gimp_transform_tool_constructor   (GType              type,
80
 
                                                    guint              n_params,
81
 
                                                    GObjectConstructParam *params);
82
 
static void     gimp_transform_tool_finalize       (GObject           *object);
83
 
 
84
 
static gboolean gimp_transform_tool_initialize     (GimpTool          *tool,
85
 
                                                    GimpDisplay       *gdisp);
86
 
static void     gimp_transform_tool_control        (GimpTool          *tool,
87
 
                                                    GimpToolAction     action,
88
 
                                                    GimpDisplay       *gdisp);
89
 
static void     gimp_transform_tool_button_press   (GimpTool          *tool,
90
 
                                                    GimpCoords        *coords,
91
 
                                                    guint32            time,
92
 
                                                    GdkModifierType    state,
93
 
                                                    GimpDisplay       *gdisp);
94
 
static void     gimp_transform_tool_button_release (GimpTool          *tool,
95
 
                                                    GimpCoords        *coords,
96
 
                                                    guint32            time,
97
 
                                                    GdkModifierType    state,
98
 
                                                    GimpDisplay       *gdisp);
99
 
static void     gimp_transform_tool_motion         (GimpTool          *tool,
100
 
                                                    GimpCoords        *coords,
101
 
                                                    guint32            time,
102
 
                                                    GdkModifierType    state,
103
 
                                                    GimpDisplay       *gdisp);
104
 
static gboolean gimp_transform_tool_key_press      (GimpTool          *tool,
105
 
                                                    GdkEventKey       *kevent,
106
 
                                                    GimpDisplay       *gdisp);
107
 
static void     gimp_transform_tool_modifier_key   (GimpTool          *tool,
108
 
                                                    GdkModifierType    key,
109
 
                                                    gboolean           press,
110
 
                                                    GdkModifierType    state,
111
 
                                                    GimpDisplay       *gdisp);
112
 
static void     gimp_transform_tool_oper_update    (GimpTool          *tool,
113
 
                                                    GimpCoords        *coords,
114
 
                                                    GdkModifierType    state,
115
 
                                                    GimpDisplay       *gdisp);
116
 
static void     gimp_transform_tool_cursor_update  (GimpTool          *tool,
117
 
                                                    GimpCoords        *coords,
118
 
                                                    GdkModifierType    state,
119
 
                                                    GimpDisplay       *gdisp);
120
 
 
121
 
static void     gimp_transform_tool_draw           (GimpDrawTool      *draw_tool);
 
73
static GObject * gimp_transform_tool_constructor (GType                  type,
 
74
                                                  guint                  n_params,
 
75
                                                  GObjectConstructParam *params);
 
76
static void   gimp_transform_tool_finalize       (GObject               *object);
 
77
 
 
78
static gboolean gimp_transform_tool_initialize   (GimpTool              *tool,
 
79
                                                  GimpDisplay           *display,
 
80
                                                  GError               **error);
 
81
static void   gimp_transform_tool_control        (GimpTool              *tool,
 
82
                                                  GimpToolAction         action,
 
83
                                                  GimpDisplay           *display);
 
84
static void   gimp_transform_tool_button_press   (GimpTool              *tool,
 
85
                                                  GimpCoords            *coords,
 
86
                                                  guint32                time,
 
87
                                                  GdkModifierType        state,
 
88
                                                  GimpDisplay           *display);
 
89
static void   gimp_transform_tool_button_release (GimpTool              *tool,
 
90
                                                  GimpCoords            *coords,
 
91
                                                  guint32                time,
 
92
                                                  GdkModifierType        state,
 
93
                                                  GimpButtonReleaseType  release_type,
 
94
                                                  GimpDisplay           *display);
 
95
static void   gimp_transform_tool_motion         (GimpTool              *tool,
 
96
                                                  GimpCoords            *coords,
 
97
                                                  guint32                time,
 
98
                                                  GdkModifierType        state,
 
99
                                                  GimpDisplay           *display);
 
100
static gboolean gimp_transform_tool_key_press    (GimpTool              *tool,
 
101
                                                  GdkEventKey           *kevent,
 
102
                                                  GimpDisplay           *display);
 
103
static void   gimp_transform_tool_modifier_key   (GimpTool              *tool,
 
104
                                                  GdkModifierType        key,
 
105
                                                  gboolean               press,
 
106
                                                  GdkModifierType        state,
 
107
                                                  GimpDisplay           *display);
 
108
static void   gimp_transform_tool_oper_update    (GimpTool              *tool,
 
109
                                                  GimpCoords            *coords,
 
110
                                                  GdkModifierType        state,
 
111
                                                  gboolean               proximity,
 
112
                                                  GimpDisplay           *display);
 
113
static void   gimp_transform_tool_cursor_update  (GimpTool              *tool,
 
114
                                                  GimpCoords            *coords,
 
115
                                                  GdkModifierType        state,
 
116
                                                  GimpDisplay           *display);
 
117
 
 
118
static void   gimp_transform_tool_draw           (GimpDrawTool          *draw_tool);
 
119
 
 
120
static void   gimp_transform_tool_dialog_update  (GimpTransformTool     *tr_tool);
122
121
 
123
122
static TileManager *
124
 
                gimp_transform_tool_real_transform (GimpTransformTool *tr_tool,
125
 
                                                    GimpItem          *item,
126
 
                                                    gboolean           mask_empty,
127
 
                                                    GimpDisplay       *gdisp);
128
 
 
129
 
static void     gimp_transform_tool_halt           (GimpTransformTool *tr_tool);
130
 
static void     gimp_transform_tool_bounds         (GimpTransformTool *tr_tool,
131
 
                                                    GimpDisplay       *gdisp);
132
 
static void     gimp_transform_tool_dialog         (GimpTransformTool *tr_tool);
133
 
static void     gimp_transform_tool_prepare        (GimpTransformTool *tr_tool,
134
 
                                                    GimpDisplay       *gdisp);
135
 
static void     gimp_transform_tool_doit           (GimpTransformTool *tr_tool,
136
 
                                                    GimpDisplay       *gdisp);
137
 
static void     gimp_transform_tool_transform_bounding_box (GimpTransformTool *tr_tool);
138
 
static void     gimp_transform_tool_grid_recalc    (GimpTransformTool *tr_tool);
139
 
 
140
 
static void     gimp_transform_tool_force_expose_preview (GimpTransformTool *tr_tool);
141
 
 
142
 
static void     gimp_transform_tool_response       (GtkWidget         *widget,
143
 
                                                    gint               response_id,
144
 
                                                    GimpTransformTool *tr_tool);
145
 
 
146
 
static void     gimp_transform_tool_notify_type    (GimpTransformOptions *options,
147
 
                                                    GParamSpec           *pspec,
148
 
                                                    GimpTransformTool    *tr_tool);
149
 
static void     gimp_transform_tool_notify_preview (GimpTransformOptions *options,
150
 
                                                    GParamSpec           *pspec,
151
 
                                                    GimpTransformTool    *tr_tool);
152
 
 
153
 
static GimpDrawToolClass *parent_class = NULL;
154
 
 
155
 
 
156
 
GType
157
 
gimp_transform_tool_get_type (void)
158
 
{
159
 
  static GType tool_type = 0;
160
 
 
161
 
  if (! tool_type)
162
 
    {
163
 
      static const GTypeInfo tool_info =
164
 
      {
165
 
        sizeof (GimpTransformToolClass),
166
 
        (GBaseInitFunc) NULL,
167
 
        (GBaseFinalizeFunc) NULL,
168
 
        (GClassInitFunc) gimp_transform_tool_class_init,
169
 
        NULL,           /* class_finalize */
170
 
        NULL,           /* class_data     */
171
 
        sizeof (GimpTransformTool),
172
 
        0,              /* n_preallocs    */
173
 
        (GInstanceInitFunc) gimp_transform_tool_init,
174
 
      };
175
 
 
176
 
      tool_type = g_type_register_static (GIMP_TYPE_DRAW_TOOL,
177
 
                                          "GimpTransformTool",
178
 
                                          &tool_info, 0);
179
 
    }
180
 
 
181
 
  return tool_type;
182
 
}
 
123
              gimp_transform_tool_real_transform (GimpTransformTool     *tr_tool,
 
124
                                                  GimpItem              *item,
 
125
                                                  gboolean               mask_empty,
 
126
                                                  GimpDisplay           *display);
 
127
 
 
128
static void   gimp_transform_tool_halt           (GimpTransformTool     *tr_tool);
 
129
static void   gimp_transform_tool_bounds         (GimpTransformTool     *tr_tool,
 
130
                                                  GimpDisplay           *display);
 
131
static void   gimp_transform_tool_dialog         (GimpTransformTool     *tr_tool);
 
132
static void   gimp_transform_tool_prepare        (GimpTransformTool     *tr_tool,
 
133
                                                  GimpDisplay           *display);
 
134
static void   gimp_transform_tool_doit           (GimpTransformTool     *tr_tool,
 
135
                                                  GimpDisplay           *display);
 
136
static void   gimp_transform_tool_transform_bounding_box (GimpTransformTool *tr_tool);
 
137
static void   gimp_transform_tool_grid_recalc    (GimpTransformTool     *tr_tool);
 
138
 
 
139
static void   gimp_transform_tool_handles_recalc (GimpTransformTool     *tr_tool,
 
140
                                                  GimpDisplay           *display);
 
141
static void   gimp_transform_tool_force_expose_preview (GimpTransformTool *tr_tool);
 
142
 
 
143
static void   gimp_transform_tool_response       (GtkWidget             *widget,
 
144
                                                  gint                   response_id,
 
145
                                                  GimpTransformTool     *tr_tool);
 
146
 
 
147
static void   gimp_transform_tool_notify_type    (GimpTransformOptions  *options,
 
148
                                                  GParamSpec            *pspec,
 
149
                                                  GimpTransformTool     *tr_tool);
 
150
static void   gimp_transform_tool_notify_preview (GimpTransformOptions  *options,
 
151
                                                  GParamSpec            *pspec,
 
152
                                                  GimpTransformTool     *tr_tool);
 
153
 
 
154
 
 
155
G_DEFINE_TYPE (GimpTransformTool, gimp_transform_tool, GIMP_TYPE_DRAW_TOOL)
 
156
 
 
157
#define parent_class gimp_transform_tool_parent_class
 
158
 
183
159
 
184
160
static void
185
161
gimp_transform_tool_class_init (GimpTransformToolClass *klass)
188
164
  GimpToolClass     *tool_class   = GIMP_TOOL_CLASS (klass);
189
165
  GimpDrawToolClass *draw_class   = GIMP_DRAW_TOOL_CLASS (klass);
190
166
 
191
 
  parent_class = g_type_class_peek_parent (klass);
192
 
 
193
 
  object_class->constructor  = gimp_transform_tool_constructor;
194
 
  object_class->finalize     = gimp_transform_tool_finalize;
195
 
 
196
 
  tool_class->initialize     = gimp_transform_tool_initialize;
197
 
  tool_class->control        = gimp_transform_tool_control;
198
 
  tool_class->button_press   = gimp_transform_tool_button_press;
199
 
  tool_class->button_release = gimp_transform_tool_button_release;
200
 
  tool_class->motion         = gimp_transform_tool_motion;
201
 
  tool_class->key_press      = gimp_transform_tool_key_press;
202
 
  tool_class->modifier_key   = gimp_transform_tool_modifier_key;
203
 
  tool_class->oper_update    = gimp_transform_tool_oper_update;
204
 
  tool_class->cursor_update  = gimp_transform_tool_cursor_update;
205
 
 
206
 
  draw_class->draw           = gimp_transform_tool_draw;
207
 
 
208
 
  klass->dialog              = NULL;
209
 
  klass->dialog_update       = NULL;
210
 
  klass->prepare             = NULL;
211
 
  klass->motion              = NULL;
212
 
  klass->recalc              = NULL;
213
 
  klass->transform           = gimp_transform_tool_real_transform;
 
167
  object_class->constructor       = gimp_transform_tool_constructor;
 
168
  object_class->finalize          = gimp_transform_tool_finalize;
 
169
 
 
170
  tool_class->initialize          = gimp_transform_tool_initialize;
 
171
  tool_class->control             = gimp_transform_tool_control;
 
172
  tool_class->button_press        = gimp_transform_tool_button_press;
 
173
  tool_class->button_release      = gimp_transform_tool_button_release;
 
174
  tool_class->motion              = gimp_transform_tool_motion;
 
175
  tool_class->key_press           = gimp_transform_tool_key_press;
 
176
  tool_class->modifier_key        = gimp_transform_tool_modifier_key;
 
177
  tool_class->active_modifier_key = gimp_transform_tool_modifier_key;
 
178
  tool_class->oper_update         = gimp_transform_tool_oper_update;
 
179
  tool_class->cursor_update       = gimp_transform_tool_cursor_update;
 
180
 
 
181
  draw_class->draw                = gimp_transform_tool_draw;
 
182
 
 
183
  klass->dialog                   = NULL;
 
184
  klass->dialog_update            = NULL;
 
185
  klass->prepare                  = NULL;
 
186
  klass->motion                   = NULL;
 
187
  klass->recalc                   = NULL;
 
188
  klass->transform                = gimp_transform_tool_real_transform;
214
189
}
215
190
 
216
191
static void
231
206
  tr_tool->function = TRANSFORM_CREATING;
232
207
  tr_tool->original = NULL;
233
208
 
234
 
  for (i = 0; i < TRAN_INFO_SIZE; i++)
 
209
  for (i = 0; i < TRANS_INFO_SIZE; i++)
235
210
    {
236
211
      tr_tool->trans_info[i]     = 0.0;
237
212
      tr_tool->old_trans_info[i] = 0.0;
239
214
 
240
215
  gimp_matrix3_identity (&tr_tool->transform);
241
216
 
242
 
  tr_tool->use_grid         = TRUE;
243
 
  tr_tool->use_center       = TRUE;
 
217
  tr_tool->use_grid         = FALSE;
 
218
  tr_tool->use_handles      = FALSE;
 
219
  tr_tool->use_center       = FALSE;
 
220
  tr_tool->use_mid_handles  = FALSE;
 
221
 
 
222
  tr_tool->handle_w         = HANDLE_SIZE;
 
223
  tr_tool->handle_h         = HANDLE_SIZE;
 
224
 
244
225
  tr_tool->ngx              = 0;
245
226
  tr_tool->ngy              = 0;
246
227
  tr_tool->grid_coords      = NULL;
249
230
  tr_tool->type             = GIMP_TRANSFORM_TYPE_LAYER;
250
231
  tr_tool->direction        = GIMP_TRANSFORM_FORWARD;
251
232
 
252
 
  tr_tool->shell_desc       = NULL;
253
 
  tr_tool->progress_text    = _("Transforming...");
254
 
  tr_tool->info_dialog      = NULL;
 
233
  tr_tool->undo_desc        = NULL;
 
234
 
 
235
  tr_tool->progress_text    = _("Transforming");
 
236
  tr_tool->dialog           = NULL;
255
237
}
256
238
 
257
239
static GObject *
259
241
                                 guint                  n_params,
260
242
                                 GObjectConstructParam *params)
261
243
{
262
 
  GObject           *object;
263
 
  GimpTool          *tool;
264
 
  GimpTransformTool *tr_tool;
 
244
  GObject              *object;
 
245
  GimpTool             *tool;
 
246
  GimpTransformTool    *tr_tool;
 
247
  GimpTransformOptions *options;
265
248
 
266
249
  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
267
250
 
268
251
  tool    = GIMP_TOOL (object);
269
252
  tr_tool = GIMP_TRANSFORM_TOOL (object);
270
 
 
271
 
  g_assert (GIMP_IS_TOOL_INFO (tool->tool_info));
 
253
  options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tool);
272
254
 
273
255
  if (tr_tool->use_grid)
274
256
    {
275
 
      tr_tool->type =
276
 
        GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options)->type;
277
 
      tr_tool->direction =
278
 
        GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options)->direction;
279
 
 
280
 
      g_signal_connect_object (tool->tool_info->tool_options,
281
 
                               "notify::type",
282
 
                               G_CALLBACK (gimp_transform_tool_notify_type),
283
 
                               tr_tool, 0);
284
 
      g_signal_connect_object (tool->tool_info->tool_options,
285
 
                               "notify::type",
286
 
                               G_CALLBACK (gimp_transform_tool_notify_preview),
287
 
                               tr_tool, 0);
288
 
      g_signal_connect_object (tool->tool_info->tool_options,
289
 
                               "notify::direction",
290
 
                               G_CALLBACK (gimp_transform_tool_notify_type),
291
 
                               tr_tool, 0);
292
 
      g_signal_connect_object (tool->tool_info->tool_options,
293
 
                               "notify::direction",
294
 
                               G_CALLBACK (gimp_transform_tool_notify_preview),
295
 
                               tr_tool, 0);
296
 
      g_signal_connect_object (tool->tool_info->tool_options,
297
 
                               "notify::preview-type",
298
 
                               G_CALLBACK (gimp_transform_tool_notify_preview),
299
 
                               tr_tool, 0);
300
 
      g_signal_connect_object (tool->tool_info->tool_options,
301
 
                               "notify::grid-type",
302
 
                               G_CALLBACK (gimp_transform_tool_notify_preview),
303
 
                               tr_tool, 0);
304
 
      g_signal_connect_object (tool->tool_info->tool_options,
305
 
                               "notify::grid-size",
 
257
      tr_tool->type      = options->type;
 
258
      tr_tool->direction = options->direction;
 
259
 
 
260
      g_signal_connect_object (options, "notify::type",
 
261
                               G_CALLBACK (gimp_transform_tool_notify_type),
 
262
                               tr_tool, 0);
 
263
      g_signal_connect_object (options, "notify::type",
 
264
                               G_CALLBACK (gimp_transform_tool_notify_preview),
 
265
                               tr_tool, 0);
 
266
 
 
267
      g_signal_connect_object (options, "notify::direction",
 
268
                               G_CALLBACK (gimp_transform_tool_notify_type),
 
269
                               tr_tool, 0);
 
270
      g_signal_connect_object (options, "notify::direction",
 
271
                               G_CALLBACK (gimp_transform_tool_notify_preview),
 
272
                               tr_tool, 0);
 
273
 
 
274
      g_signal_connect_object (options, "notify::preview-type",
 
275
                               G_CALLBACK (gimp_transform_tool_notify_preview),
 
276
                               tr_tool, 0);
 
277
      g_signal_connect_object (options, "notify::grid-type",
 
278
                               G_CALLBACK (gimp_transform_tool_notify_preview),
 
279
                               tr_tool, 0);
 
280
      g_signal_connect_object (options, "notify::grid-size",
306
281
                               G_CALLBACK (gimp_transform_tool_notify_preview),
307
282
                               tr_tool, 0);
308
283
    }
309
284
 
 
285
  g_signal_connect_object (options, "notify::constrain",
 
286
                           G_CALLBACK (gimp_transform_tool_dialog_update),
 
287
                           tr_tool, G_CONNECT_SWAPPED);
 
288
 
310
289
  return object;
311
290
}
312
291
 
321
300
      tr_tool->original = NULL;
322
301
    }
323
302
 
324
 
  if (tr_tool->info_dialog)
 
303
  if (tr_tool->dialog)
325
304
    {
326
 
      info_dialog_free (tr_tool->info_dialog);
327
 
      tr_tool->info_dialog = NULL;
 
305
      gtk_widget_destroy (tr_tool->dialog);
 
306
      tr_tool->dialog = NULL;
328
307
    }
329
308
 
330
309
  if (tr_tool->grid_coords)
343
322
}
344
323
 
345
324
static gboolean
346
 
gimp_transform_tool_initialize (GimpTool    *tool,
347
 
                                GimpDisplay *gdisp)
 
325
gimp_transform_tool_initialize (GimpTool     *tool,
 
326
                                GimpDisplay  *display,
 
327
                                GError      **error)
348
328
{
349
329
  GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
350
330
 
351
 
  if (gdisp != tool->gdisp)
 
331
  if (display != tool->display)
352
332
    {
353
333
      gint i;
354
334
 
355
335
      /*  Set the pointer to the active display  */
356
 
      tool->gdisp    = gdisp;
357
 
      tool->drawable = gimp_image_active_drawable (gdisp->gimage);
 
336
      tool->display  = display;
 
337
      tool->drawable = gimp_image_active_drawable (display->image);
358
338
 
359
339
      /*  Initialize the transform tool dialog */
360
 
      if (! tr_tool->info_dialog)
 
340
      if (! tr_tool->dialog)
361
341
        gimp_transform_tool_dialog (tr_tool);
362
342
 
363
343
      /*  Find the transform bounds for some tools (like scale,
364
344
       *  perspective) that actually need the bounds for
365
345
       *  initializing
366
346
       */
367
 
      gimp_transform_tool_bounds (tr_tool, gdisp);
 
347
      gimp_transform_tool_bounds (tr_tool, display);
368
348
 
369
 
      gimp_transform_tool_prepare (tr_tool, gdisp);
 
349
      gimp_transform_tool_prepare (tr_tool, display);
370
350
 
371
351
      /*  Recalculate the transform tool  */
372
 
      gimp_transform_tool_recalc (tr_tool, gdisp);
 
352
      gimp_transform_tool_recalc (tr_tool, display);
373
353
 
374
354
      /*  start drawing the bounding box and handles...  */
375
 
      gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), gdisp);
 
355
      gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
376
356
 
377
357
      tr_tool->function = TRANSFORM_CREATING;
378
358
 
379
359
      /*  Save the current transformation info  */
380
 
      for (i = 0; i < TRAN_INFO_SIZE; i++)
 
360
      for (i = 0; i < TRANS_INFO_SIZE; i++)
381
361
        tr_tool->old_trans_info[i] = tr_tool->trans_info[i];
382
362
    }
383
363
 
387
367
static void
388
368
gimp_transform_tool_control (GimpTool       *tool,
389
369
                             GimpToolAction  action,
390
 
                             GimpDisplay    *gdisp)
 
370
                             GimpDisplay    *display)
391
371
{
392
372
  GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
393
373
 
394
374
  switch (action)
395
375
    {
396
 
    case PAUSE:
397
 
      break;
398
 
 
399
 
    case RESUME:
400
 
      gimp_transform_tool_bounds (tr_tool, gdisp);
401
 
      gimp_transform_tool_recalc (tr_tool, gdisp);
402
 
      break;
403
 
 
404
 
    case HALT:
 
376
    case GIMP_TOOL_ACTION_PAUSE:
 
377
      break;
 
378
 
 
379
    case GIMP_TOOL_ACTION_RESUME:
 
380
      gimp_transform_tool_bounds (tr_tool, display);
 
381
      gimp_transform_tool_recalc (tr_tool, display);
 
382
      break;
 
383
 
 
384
    case GIMP_TOOL_ACTION_HALT:
405
385
      gimp_transform_tool_halt (tr_tool);
406
 
      return; /* don't upchain */
407
 
      break;
408
 
 
409
 
    default:
410
386
      break;
411
387
    }
412
388
 
413
 
  GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
 
389
  GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
414
390
}
415
391
 
416
392
static void
418
394
                                  GimpCoords      *coords,
419
395
                                  guint32          time,
420
396
                                  GdkModifierType  state,
421
 
                                  GimpDisplay     *gdisp)
 
397
                                  GimpDisplay     *display)
422
398
{
423
399
  GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
424
400
 
425
 
  if (tr_tool->function == TRANSFORM_CREATING && tr_tool->use_grid)
426
 
    gimp_transform_tool_oper_update (tool, coords, state, gdisp);
 
401
  if (tr_tool->function == TRANSFORM_CREATING)
 
402
    gimp_transform_tool_oper_update (tool, coords, state, TRUE, display);
427
403
 
428
404
  tr_tool->lastx = tr_tool->startx = coords->x;
429
405
  tr_tool->lasty = tr_tool->starty = coords->y;
432
408
}
433
409
 
434
410
static void
435
 
gimp_transform_tool_button_release (GimpTool        *tool,
436
 
                                    GimpCoords      *coords,
437
 
                                    guint32          time,
438
 
                                    GdkModifierType  state,
439
 
                                    GimpDisplay     *gdisp)
 
411
gimp_transform_tool_button_release (GimpTool              *tool,
 
412
                                    GimpCoords            *coords,
 
413
                                    guint32                time,
 
414
                                    GdkModifierType        state,
 
415
                                    GimpButtonReleaseType  release_type,
 
416
                                    GimpDisplay           *display)
440
417
{
441
418
  GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
442
419
  gint               i;
445
422
  if (tr_tool->function == TRANSFORM_CREATING && tr_tool->use_grid)
446
423
    return;
447
424
 
448
 
  /*  if the 3rd button isn't pressed, transform the selected mask  */
449
 
  if (! (state & GDK_BUTTON3_MASK))
 
425
  if (release_type != GIMP_BUTTON_RELEASE_CANCEL)
450
426
    {
451
427
      /* Shift-clicking is another way to approve the transform  */
452
428
      if ((state & GDK_SHIFT_MASK) || ! tr_tool->use_grid)
453
429
        {
454
 
          gimp_transform_tool_doit (tr_tool, gdisp);
 
430
          gimp_transform_tool_response (NULL, GTK_RESPONSE_OK, tr_tool);
455
431
        }
456
432
    }
457
433
  else
462
438
      gimp_transform_tool_expose_preview (tr_tool);
463
439
 
464
440
      /*  Restore the previous transformation info  */
465
 
      for (i = 0; i < TRAN_INFO_SIZE; i++)
 
441
      for (i = 0; i < TRANS_INFO_SIZE; i++)
466
442
        tr_tool->trans_info[i] = tr_tool->old_trans_info[i];
467
443
 
468
444
      /*  reget the selection bounds  */
469
 
      gimp_transform_tool_bounds (tr_tool, gdisp);
 
445
      gimp_transform_tool_bounds (tr_tool, display);
470
446
 
471
447
      /*  recalculate the tool's transformation matrix  */
472
 
      gimp_transform_tool_recalc (tr_tool, gdisp);
 
448
      gimp_transform_tool_recalc (tr_tool, display);
473
449
 
474
450
      gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
475
451
    }
482
458
                            GimpCoords      *coords,
483
459
                            guint32          time,
484
460
                            GdkModifierType  state,
485
 
                            GimpDisplay     *gdisp)
 
461
                            GimpDisplay     *display)
486
462
{
487
463
  GimpTransformTool      *tr_tool = GIMP_TRANSFORM_TOOL (tool);
488
464
  GimpTransformToolClass *tr_tool_class;
502
478
 
503
479
  if (tr_tool_class->motion)
504
480
    {
505
 
      tr_tool_class->motion (tr_tool, gdisp);
 
481
      tr_tool_class->motion (tr_tool, display);
506
482
 
507
483
      gimp_transform_tool_expose_preview (tr_tool);
508
484
 
509
 
      gimp_transform_tool_recalc (tr_tool, gdisp);
 
485
      gimp_transform_tool_recalc (tr_tool, display);
510
486
    }
511
487
 
512
488
  tr_tool->lastx = tr_tool->curx;
520
496
static gboolean
521
497
gimp_transform_tool_key_press (GimpTool    *tool,
522
498
                               GdkEventKey *kevent,
523
 
                               GimpDisplay *gdisp)
 
499
                               GimpDisplay *display)
524
500
{
525
501
  GimpTransformTool *trans_tool = GIMP_TRANSFORM_TOOL (tool);
526
502
  GimpDrawTool      *draw_tool  = GIMP_DRAW_TOOL (tool);
527
503
 
528
 
  if (gdisp == draw_tool->gdisp)
 
504
  if (display == draw_tool->display)
529
505
    {
530
506
      switch (kevent->keyval)
531
507
        {
553
529
                                  GdkModifierType  key,
554
530
                                  gboolean         press,
555
531
                                  GdkModifierType  state,
556
 
                                  GimpDisplay     *gdisp)
 
532
                                  GimpDisplay     *display)
557
533
{
558
 
  GimpTransformOptions *options;
559
 
 
560
 
  options = GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options);
 
534
  GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tool);
561
535
 
562
536
  if (key == GDK_CONTROL_MASK)
563
 
    {
564
 
      g_object_set (options,
565
 
                    "constrain-1", ! options->constrain_1,
566
 
                    NULL);
567
 
    }
568
 
  else if (key == GDK_MOD1_MASK)
569
 
    {
570
 
      g_object_set (options,
571
 
                    "constrain-2", ! options->constrain_2,
572
 
                    NULL);
573
 
    }
 
537
    g_object_set (options,
 
538
                  "constrain", ! options->constrain,
 
539
                  NULL);
574
540
}
575
541
 
576
542
static void
577
543
gimp_transform_tool_oper_update (GimpTool        *tool,
578
544
                                 GimpCoords      *coords,
579
545
                                 GdkModifierType  state,
580
 
                                 GimpDisplay     *gdisp)
 
546
                                 gboolean         proximity,
 
547
                                 GimpDisplay     *display)
581
548
{
582
549
  GimpTransformTool *tr_tool   = GIMP_TRANSFORM_TOOL (tool);
583
550
  GimpDrawTool      *draw_tool = GIMP_DRAW_TOOL (tool);
584
551
 
585
 
  if (! tr_tool->use_grid)
 
552
  tr_tool->function = TRANSFORM_HANDLE_NONE;
 
553
 
 
554
  if (display != tool->display)
586
555
    return;
587
556
 
588
 
  if (gdisp == tool->gdisp)
 
557
  if (tr_tool->use_handles)
589
558
    {
590
559
      gdouble closest_dist;
591
560
      gdouble dist;
592
561
 
593
 
      closest_dist = gimp_draw_tool_calc_distance (draw_tool, gdisp,
594
 
                                                   coords->x, coords->y,
595
 
                                                   tr_tool->tx1, tr_tool->ty1);
596
 
      tr_tool->function = TRANSFORM_HANDLE_1;
597
 
 
598
 
      dist = gimp_draw_tool_calc_distance (draw_tool, gdisp,
599
 
                                           coords->x, coords->y,
600
 
                                           tr_tool->tx2, tr_tool->ty2);
601
 
      if (dist < closest_dist)
602
 
        {
603
 
          closest_dist = dist;
604
 
          tr_tool->function = TRANSFORM_HANDLE_2;
605
 
        }
606
 
 
607
 
      dist = gimp_draw_tool_calc_distance (draw_tool, gdisp,
608
 
                                           coords->x, coords->y,
609
 
                                           tr_tool->tx3, tr_tool->ty3);
610
 
      if (dist < closest_dist)
611
 
        {
612
 
          closest_dist = dist;
613
 
          tr_tool->function = TRANSFORM_HANDLE_3;
614
 
        }
615
 
 
616
 
      dist = gimp_draw_tool_calc_distance (draw_tool, gdisp,
617
 
                                           coords->x, coords->y,
618
 
                                           tr_tool->tx4, tr_tool->ty4);
619
 
      if (dist < closest_dist)
620
 
        {
621
 
          closest_dist = dist;
622
 
          tr_tool->function = TRANSFORM_HANDLE_4;
623
 
        }
624
 
 
625
 
      if (gimp_draw_tool_on_handle (draw_tool, gdisp,
626
 
                                    coords->x, coords->y,
627
 
                                    GIMP_HANDLE_CIRCLE,
628
 
                                    tr_tool->tcx, tr_tool->tcy,
629
 
                                    HANDLE_SIZE, HANDLE_SIZE,
630
 
                                    GTK_ANCHOR_CENTER,
631
 
                                    FALSE))
632
 
        {
633
 
          tr_tool->function = TRANSFORM_HANDLE_CENTER;
634
 
        }
 
562
      dist = gimp_draw_tool_calc_distance_square (draw_tool, display,
 
563
                                                  coords->x, coords->y,
 
564
                                                  tr_tool->tx1, tr_tool->ty1);
 
565
      closest_dist = dist;
 
566
      tr_tool->function = TRANSFORM_HANDLE_NW;
 
567
 
 
568
      dist = gimp_draw_tool_calc_distance_square (draw_tool, display,
 
569
                                                  coords->x, coords->y,
 
570
                                                  tr_tool->tx2, tr_tool->ty2);
 
571
      if (dist < closest_dist)
 
572
        {
 
573
          closest_dist = dist;
 
574
          tr_tool->function = TRANSFORM_HANDLE_NE;
 
575
        }
 
576
 
 
577
      dist = gimp_draw_tool_calc_distance_square (draw_tool, display,
 
578
                                                  coords->x, coords->y,
 
579
                                                  tr_tool->tx3, tr_tool->ty3);
 
580
      if (dist < closest_dist)
 
581
        {
 
582
          closest_dist = dist;
 
583
          tr_tool->function = TRANSFORM_HANDLE_SW;
 
584
        }
 
585
 
 
586
      dist = gimp_draw_tool_calc_distance_square (draw_tool, display,
 
587
                                                  coords->x, coords->y,
 
588
                                                  tr_tool->tx4, tr_tool->ty4);
 
589
      if (dist < closest_dist)
 
590
        {
 
591
          closest_dist = dist;
 
592
          tr_tool->function = TRANSFORM_HANDLE_SE;
 
593
        }
 
594
 
 
595
      if (tr_tool->use_mid_handles)
 
596
        {
 
597
          gdouble x, y;
 
598
 
 
599
          x = (tr_tool->tx1 + tr_tool->tx2) / 2.0;
 
600
          y = (tr_tool->ty1 + tr_tool->ty2) / 2.0;
 
601
 
 
602
          if (gimp_draw_tool_on_handle (draw_tool, display,
 
603
                                        coords->x, coords->y,
 
604
                                        GIMP_HANDLE_SQUARE,
 
605
                                        x, y,
 
606
                                        tr_tool->handle_w, tr_tool->handle_h,
 
607
                                        GTK_ANCHOR_CENTER,
 
608
                                        FALSE))
 
609
            {
 
610
              tr_tool->function = TRANSFORM_HANDLE_N;
 
611
            }
 
612
 
 
613
          x = (tr_tool->tx2 + tr_tool->tx4) / 2.0;
 
614
          y = (tr_tool->ty2 + tr_tool->ty4) / 2.0;
 
615
 
 
616
          if (gimp_draw_tool_on_handle (draw_tool, display,
 
617
                                        coords->x, coords->y,
 
618
                                        GIMP_HANDLE_SQUARE,
 
619
                                        x, y,
 
620
                                        tr_tool->handle_w, tr_tool->handle_h,
 
621
                                        GTK_ANCHOR_CENTER,
 
622
                                        FALSE))
 
623
            {
 
624
              tr_tool->function = TRANSFORM_HANDLE_E;
 
625
            }
 
626
 
 
627
          x = (tr_tool->tx3 + tr_tool->tx4) / 2.0;
 
628
          y = (tr_tool->ty3 + tr_tool->ty4) / 2.0;
 
629
 
 
630
          if (gimp_draw_tool_on_handle (draw_tool, display,
 
631
                                        coords->x, coords->y,
 
632
                                        GIMP_HANDLE_SQUARE,
 
633
                                        x, y,
 
634
                                        tr_tool->handle_w, tr_tool->handle_h,
 
635
                                        GTK_ANCHOR_CENTER,
 
636
                                        FALSE))
 
637
            {
 
638
              tr_tool->function = TRANSFORM_HANDLE_S;
 
639
            }
 
640
 
 
641
          x = (tr_tool->tx3 + tr_tool->tx1) / 2.0;
 
642
          y = (tr_tool->ty3 + tr_tool->ty1) / 2.0;
 
643
 
 
644
          if (gimp_draw_tool_on_handle (draw_tool, display,
 
645
                                        coords->x, coords->y,
 
646
                                        GIMP_HANDLE_SQUARE,
 
647
                                        x, y,
 
648
                                        tr_tool->handle_w, tr_tool->handle_h,
 
649
                                        GTK_ANCHOR_CENTER,
 
650
                                        FALSE))
 
651
            {
 
652
              tr_tool->function = TRANSFORM_HANDLE_W;
 
653
            }
 
654
        }
 
655
    }
 
656
 
 
657
  if (tr_tool->use_center &&
 
658
      gimp_draw_tool_on_handle (draw_tool, display,
 
659
                                coords->x, coords->y,
 
660
                                GIMP_HANDLE_CIRCLE,
 
661
                                tr_tool->tcx, tr_tool->tcy,
 
662
                                MIN (tr_tool->handle_w, tr_tool->handle_h),
 
663
                                MIN (tr_tool->handle_w, tr_tool->handle_h),
 
664
                                GTK_ANCHOR_CENTER,
 
665
                                FALSE))
 
666
    {
 
667
      tr_tool->function = TRANSFORM_HANDLE_CENTER;
635
668
    }
636
669
}
637
670
 
639
672
gimp_transform_tool_cursor_update (GimpTool        *tool,
640
673
                                   GimpCoords      *coords,
641
674
                                   GdkModifierType  state,
642
 
                                   GimpDisplay     *gdisp)
 
675
                                   GimpDisplay     *display)
643
676
{
644
677
  GimpTransformTool    *tr_tool = GIMP_TRANSFORM_TOOL (tool);
645
 
  GimpTransformOptions *options;
646
 
 
647
 
  options = GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options);
648
 
 
649
 
  if (tr_tool->use_grid)
650
 
    {
651
 
      GimpChannel        *selection = gimp_image_get_mask (gdisp->gimage);
652
 
      GimpCursorType      cursor    = GDK_TOP_LEFT_ARROW;
653
 
      GimpCursorModifier  modifier  = GIMP_CURSOR_MODIFIER_NONE;
654
 
 
655
 
      switch (options->type)
656
 
        {
657
 
        case GIMP_TRANSFORM_TYPE_LAYER:
658
 
          if (gimp_image_coords_in_active_drawable (gdisp->gimage, coords))
659
 
            {
660
 
              if (gimp_channel_is_empty (selection) ||
661
 
                  gimp_channel_value (selection, coords->x, coords->y))
662
 
                {
663
 
                  cursor = GIMP_CURSOR_MOUSE;
664
 
                }
665
 
            }
666
 
          break;
667
 
 
668
 
        case GIMP_TRANSFORM_TYPE_SELECTION:
669
 
          if (gimp_channel_is_empty (selection) ||
670
 
              gimp_channel_value (selection, coords->x, coords->y))
671
 
            {
672
 
              cursor = GIMP_CURSOR_MOUSE;
673
 
            }
674
 
          break;
675
 
 
676
 
        case GIMP_TRANSFORM_TYPE_PATH:
677
 
          if (gimp_image_get_active_vectors (gdisp->gimage))
678
 
            cursor = GIMP_CURSOR_MOUSE;
679
 
          else
680
 
            cursor = GIMP_CURSOR_BAD;
681
 
          break;
682
 
        }
683
 
 
684
 
      if (tr_tool->use_center && tr_tool->function == TRANSFORM_HANDLE_CENTER)
685
 
        {
686
 
          modifier = GIMP_CURSOR_MODIFIER_MOVE;
687
 
        }
688
 
 
689
 
      gimp_tool_control_set_cursor          (tool->control, cursor);
690
 
      gimp_tool_control_set_cursor_modifier (tool->control, modifier);
691
 
    }
692
 
 
693
 
  GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, gdisp);
 
678
  GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tool);
 
679
  GimpCursorType        cursor;
 
680
  GimpCursorModifier    modifier = GIMP_CURSOR_MODIFIER_NONE;
 
681
 
 
682
  cursor = gimp_tool_control_get_cursor (tool->control);
 
683
 
 
684
  if (tr_tool->use_handles)
 
685
    {
 
686
      switch (tr_tool->function)
 
687
        {
 
688
        case TRANSFORM_HANDLE_NW:
 
689
          cursor = GIMP_CURSOR_CORNER_TOP_LEFT;
 
690
          break;
 
691
 
 
692
        case TRANSFORM_HANDLE_NE:
 
693
          cursor = GIMP_CURSOR_CORNER_TOP_RIGHT;
 
694
          break;
 
695
 
 
696
        case TRANSFORM_HANDLE_SW:
 
697
          cursor = GIMP_CURSOR_CORNER_BOTTOM_LEFT;
 
698
          break;
 
699
 
 
700
        case TRANSFORM_HANDLE_SE:
 
701
          cursor = GIMP_CURSOR_CORNER_BOTTOM_RIGHT;
 
702
          break;
 
703
 
 
704
        case TRANSFORM_HANDLE_N:
 
705
          cursor = GIMP_CURSOR_SIDE_TOP;
 
706
          break;
 
707
 
 
708
        case TRANSFORM_HANDLE_E:
 
709
          cursor = GIMP_CURSOR_SIDE_RIGHT;
 
710
          break;
 
711
 
 
712
        case TRANSFORM_HANDLE_S:
 
713
          cursor = GIMP_CURSOR_SIDE_BOTTOM;
 
714
          break;
 
715
 
 
716
        case TRANSFORM_HANDLE_W:
 
717
          cursor = GIMP_CURSOR_SIDE_LEFT;
 
718
          break;
 
719
 
 
720
        default:
 
721
          cursor = GIMP_CURSOR_CROSSHAIR_SMALL;
 
722
          break;
 
723
        }
 
724
    }
 
725
 
 
726
  if (tr_tool->use_center && tr_tool->function == TRANSFORM_HANDLE_CENTER)
 
727
    {
 
728
      modifier = GIMP_CURSOR_MODIFIER_MOVE;
 
729
    }
 
730
 
 
731
  switch (options->type)
 
732
    {
 
733
    case GIMP_TRANSFORM_TYPE_LAYER:
 
734
    case GIMP_TRANSFORM_TYPE_SELECTION:
 
735
      break;
 
736
 
 
737
    case GIMP_TRANSFORM_TYPE_PATH:
 
738
      if (! gimp_image_get_active_vectors (display->image))
 
739
        modifier = GIMP_CURSOR_MODIFIER_BAD;
 
740
      break;
 
741
    }
 
742
 
 
743
  gimp_tool_control_set_cursor          (tool->control, cursor);
 
744
  gimp_tool_control_set_cursor_modifier (tool->control, modifier);
 
745
 
 
746
  GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
694
747
}
695
748
 
696
749
static void
697
750
gimp_transform_tool_draw (GimpDrawTool *draw_tool)
698
751
{
699
 
  GimpTool             *tool    = GIMP_TOOL (draw_tool);
700
 
  GimpTransformTool    *tr_tool = GIMP_TRANSFORM_TOOL (draw_tool);
701
 
  GimpTransformOptions *options;
702
 
  gdouble               z1, z2, z3, z4;
703
 
 
704
 
  if (! tr_tool->use_grid)
705
 
    return;
706
 
 
707
 
  options = GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options);
708
 
 
709
 
  /*  draw the bounding box  */
710
 
  gimp_draw_tool_draw_line (draw_tool,
711
 
                            tr_tool->tx1, tr_tool->ty1,
712
 
                            tr_tool->tx2, tr_tool->ty2,
713
 
                            FALSE);
714
 
  gimp_draw_tool_draw_line (draw_tool,
715
 
                            tr_tool->tx2, tr_tool->ty2,
716
 
                            tr_tool->tx4, tr_tool->ty4,
717
 
                            FALSE);
718
 
  gimp_draw_tool_draw_line (draw_tool,
719
 
                            tr_tool->tx3, tr_tool->ty3,
720
 
                            tr_tool->tx4, tr_tool->ty4,
721
 
                            FALSE);
722
 
  gimp_draw_tool_draw_line (draw_tool,
723
 
                            tr_tool->tx3, tr_tool->ty3,
724
 
                            tr_tool->tx1, tr_tool->ty1,
725
 
                            FALSE);
726
 
 
727
 
  /* We test if the transformed polygon is convex.
728
 
   * if z1 and z2 have the same sign as well as z3 and z4
729
 
   * the polygon is convex.
730
 
   */
731
 
  z1 = ((tr_tool->tx2 - tr_tool->tx1) * (tr_tool->ty4 - tr_tool->ty1) -
732
 
        (tr_tool->tx4 - tr_tool->tx1) * (tr_tool->ty2 - tr_tool->ty1));
733
 
  z2 = ((tr_tool->tx4 - tr_tool->tx1) * (tr_tool->ty3 - tr_tool->ty1) -
734
 
        (tr_tool->tx3 - tr_tool->tx1) * (tr_tool->ty4 - tr_tool->ty1));
735
 
  z3 = ((tr_tool->tx4 - tr_tool->tx2) * (tr_tool->ty3 - tr_tool->ty2) -
736
 
        (tr_tool->tx3 - tr_tool->tx2) * (tr_tool->ty4 - tr_tool->ty2));
737
 
  z4 = ((tr_tool->tx3 - tr_tool->tx2) * (tr_tool->ty1 - tr_tool->ty2) -
738
 
        (tr_tool->tx1 - tr_tool->tx2) * (tr_tool->ty3 - tr_tool->ty2));
739
 
 
740
 
  /*  Draw the grid (not for path transform since it looks ugly)  */
741
 
 
742
 
  if (tr_tool->type != GIMP_TRANSFORM_TYPE_PATH &&
743
 
      tr_tool->grid_coords                      &&
744
 
      tr_tool->tgrid_coords                     &&
745
 
      z1 * z2 > 0                               &&
746
 
      z3 * z4 > 0)
747
 
    {
748
 
      gint gci, i, k;
749
 
 
750
 
      k = tr_tool->ngx + tr_tool->ngy;
751
 
 
752
 
      for (i = 0, gci = 0; i < k; i++, gci += 4)
753
 
        {
754
 
          gimp_draw_tool_draw_line (draw_tool,
755
 
                                    tr_tool->tgrid_coords[gci],
756
 
                                    tr_tool->tgrid_coords[gci + 1],
757
 
                                    tr_tool->tgrid_coords[gci + 2],
758
 
                                    tr_tool->tgrid_coords[gci + 3],
759
 
                                    FALSE);
760
 
        }
761
 
    }
762
 
 
763
 
  /*  draw the tool handles  */
764
 
  gimp_draw_tool_draw_handle (draw_tool,
765
 
                              GIMP_HANDLE_SQUARE,
766
 
                              tr_tool->tx1, tr_tool->ty1,
767
 
                              HANDLE_SIZE, HANDLE_SIZE,
768
 
                              GTK_ANCHOR_CENTER,
769
 
                              FALSE);
770
 
  gimp_draw_tool_draw_handle (draw_tool,
771
 
                              GIMP_HANDLE_SQUARE,
772
 
                              tr_tool->tx2, tr_tool->ty2,
773
 
                              HANDLE_SIZE, HANDLE_SIZE,
774
 
                              GTK_ANCHOR_CENTER,
775
 
                              FALSE);
776
 
  gimp_draw_tool_draw_handle (draw_tool,
777
 
                              GIMP_HANDLE_SQUARE,
778
 
                              tr_tool->tx3, tr_tool->ty3,
779
 
                              HANDLE_SIZE, HANDLE_SIZE,
780
 
                              GTK_ANCHOR_CENTER,
781
 
                              FALSE);
782
 
  gimp_draw_tool_draw_handle (draw_tool,
783
 
                              GIMP_HANDLE_SQUARE,
784
 
                              tr_tool->tx4, tr_tool->ty4,
785
 
                              HANDLE_SIZE, HANDLE_SIZE,
786
 
                              GTK_ANCHOR_CENTER,
787
 
                              FALSE);
 
752
  GimpTool          *tool    = GIMP_TOOL (draw_tool);
 
753
  GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (draw_tool);
 
754
  gdouble            z1, z2, z3, z4;
 
755
 
 
756
  if (tr_tool->use_grid)
 
757
    {
 
758
      /*  draw the bounding box  */
 
759
      gimp_draw_tool_draw_line (draw_tool,
 
760
                                tr_tool->tx1, tr_tool->ty1,
 
761
                                tr_tool->tx2, tr_tool->ty2,
 
762
                                FALSE);
 
763
      gimp_draw_tool_draw_line (draw_tool,
 
764
                                tr_tool->tx2, tr_tool->ty2,
 
765
                                tr_tool->tx4, tr_tool->ty4,
 
766
                                FALSE);
 
767
      gimp_draw_tool_draw_line (draw_tool,
 
768
                                tr_tool->tx3, tr_tool->ty3,
 
769
                                tr_tool->tx4, tr_tool->ty4,
 
770
                                FALSE);
 
771
      gimp_draw_tool_draw_line (draw_tool,
 
772
                                tr_tool->tx3, tr_tool->ty3,
 
773
                                tr_tool->tx1, tr_tool->ty1,
 
774
                                FALSE);
 
775
 
 
776
      /* We test if the transformed polygon is convex.
 
777
       * if z1 and z2 have the same sign as well as z3 and z4
 
778
       * the polygon is convex.
 
779
       */
 
780
      z1 = ((tr_tool->tx2 - tr_tool->tx1) * (tr_tool->ty4 - tr_tool->ty1) -
 
781
            (tr_tool->tx4 - tr_tool->tx1) * (tr_tool->ty2 - tr_tool->ty1));
 
782
      z2 = ((tr_tool->tx4 - tr_tool->tx1) * (tr_tool->ty3 - tr_tool->ty1) -
 
783
            (tr_tool->tx3 - tr_tool->tx1) * (tr_tool->ty4 - tr_tool->ty1));
 
784
      z3 = ((tr_tool->tx4 - tr_tool->tx2) * (tr_tool->ty3 - tr_tool->ty2) -
 
785
            (tr_tool->tx3 - tr_tool->tx2) * (tr_tool->ty4 - tr_tool->ty2));
 
786
      z4 = ((tr_tool->tx3 - tr_tool->tx2) * (tr_tool->ty1 - tr_tool->ty2) -
 
787
            (tr_tool->tx1 - tr_tool->tx2) * (tr_tool->ty3 - tr_tool->ty2));
 
788
 
 
789
      /*  draw the grid  */
 
790
      if (tr_tool->grid_coords  &&
 
791
          tr_tool->tgrid_coords &&
 
792
          z1 * z2 > 0           &&
 
793
          z3 * z4 > 0)
 
794
        {
 
795
          gint gci, i, k;
 
796
 
 
797
          k = tr_tool->ngx + tr_tool->ngy;
 
798
 
 
799
          for (i = 0, gci = 0; i < k; i++, gci += 4)
 
800
            {
 
801
              gimp_draw_tool_draw_line (draw_tool,
 
802
                                        tr_tool->tgrid_coords[gci],
 
803
                                        tr_tool->tgrid_coords[gci + 1],
 
804
                                        tr_tool->tgrid_coords[gci + 2],
 
805
                                        tr_tool->tgrid_coords[gci + 3],
 
806
                                        FALSE);
 
807
            }
 
808
        }
 
809
    }
 
810
 
 
811
  gimp_transform_tool_handles_recalc (tr_tool, tool->display);
 
812
 
 
813
  if (tr_tool->use_handles)
 
814
    {
 
815
      /*  draw the tool handles  */
 
816
      gimp_draw_tool_draw_handle (draw_tool,
 
817
                                  GIMP_HANDLE_SQUARE,
 
818
                                  tr_tool->tx1, tr_tool->ty1,
 
819
                                  tr_tool->handle_w, tr_tool->handle_h,
 
820
                                  GTK_ANCHOR_CENTER,
 
821
                                  FALSE);
 
822
      gimp_draw_tool_draw_handle (draw_tool,
 
823
                                  GIMP_HANDLE_SQUARE,
 
824
                                  tr_tool->tx2, tr_tool->ty2,
 
825
                                  tr_tool->handle_w, tr_tool->handle_h,
 
826
                                  GTK_ANCHOR_CENTER,
 
827
                                  FALSE);
 
828
      gimp_draw_tool_draw_handle (draw_tool,
 
829
                                  GIMP_HANDLE_SQUARE,
 
830
                                  tr_tool->tx3, tr_tool->ty3,
 
831
                                  tr_tool->handle_w, tr_tool->handle_h,
 
832
                                  GTK_ANCHOR_CENTER,
 
833
                                  FALSE);
 
834
      gimp_draw_tool_draw_handle (draw_tool,
 
835
                                  GIMP_HANDLE_SQUARE,
 
836
                                  tr_tool->tx4, tr_tool->ty4,
 
837
                                  tr_tool->handle_w, tr_tool->handle_h,
 
838
                                  GTK_ANCHOR_CENTER,
 
839
                                  FALSE);
 
840
 
 
841
      if (tr_tool->use_mid_handles)
 
842
        {
 
843
          gdouble x, y;
 
844
 
 
845
          x = (tr_tool->tx1 + tr_tool->tx2) / 2.0;
 
846
          y = (tr_tool->ty1 + tr_tool->ty2) / 2.0;
 
847
 
 
848
          gimp_draw_tool_draw_handle (draw_tool,
 
849
                                      GIMP_HANDLE_SQUARE,
 
850
                                      x, y,
 
851
                                      tr_tool->handle_w, tr_tool->handle_h,
 
852
                                      GTK_ANCHOR_CENTER,
 
853
                                      FALSE);
 
854
 
 
855
          x = (tr_tool->tx2 + tr_tool->tx4) / 2.0;
 
856
          y = (tr_tool->ty2 + tr_tool->ty4) / 2.0;
 
857
 
 
858
          gimp_draw_tool_draw_handle (draw_tool,
 
859
                                      GIMP_HANDLE_SQUARE,
 
860
                                      x, y,
 
861
                                      tr_tool->handle_w, tr_tool->handle_h,
 
862
                                      GTK_ANCHOR_CENTER,
 
863
                                      FALSE);
 
864
 
 
865
          x = (tr_tool->tx3 + tr_tool->tx4) / 2.0;
 
866
          y = (tr_tool->ty3 + tr_tool->ty4) / 2.0;
 
867
 
 
868
          gimp_draw_tool_draw_handle (draw_tool,
 
869
                                      GIMP_HANDLE_SQUARE,
 
870
                                      x, y,
 
871
                                      tr_tool->handle_w, tr_tool->handle_h,
 
872
                                      GTK_ANCHOR_CENTER,
 
873
                                      FALSE);
 
874
 
 
875
          x = (tr_tool->tx3 + tr_tool->tx1) / 2.0;
 
876
          y = (tr_tool->ty3 + tr_tool->ty1) / 2.0;
 
877
 
 
878
          gimp_draw_tool_draw_handle (draw_tool,
 
879
                                      GIMP_HANDLE_SQUARE,
 
880
                                      x, y,
 
881
                                      tr_tool->handle_w, tr_tool->handle_h,
 
882
                                      GTK_ANCHOR_CENTER,
 
883
                                      FALSE);
 
884
        }
 
885
    }
788
886
 
789
887
  /*  draw the center  */
790
888
  if (tr_tool->use_center)
791
889
    {
792
 
      gimp_draw_tool_draw_handle (draw_tool,
793
 
                                  GIMP_HANDLE_FILLED_CIRCLE,
794
 
                                  tr_tool->tcx, tr_tool->tcy,
795
 
                                  HANDLE_SIZE, HANDLE_SIZE,
796
 
                                  GTK_ANCHOR_CENTER,
797
 
                                  FALSE);
798
 
    }
799
 
 
800
 
  if (tr_tool->type == GIMP_TRANSFORM_TYPE_PATH)
 
890
      gint d = MIN (tr_tool->handle_w, tr_tool->handle_h);
 
891
 
 
892
      gimp_draw_tool_draw_handle (draw_tool,
 
893
                                  GIMP_HANDLE_CIRCLE,
 
894
                                  tr_tool->tcx, tr_tool->tcy,
 
895
                                  d, d,
 
896
                                  GTK_ANCHOR_CENTER,
 
897
                                  FALSE);
 
898
      gimp_draw_tool_draw_handle (draw_tool,
 
899
                                  GIMP_HANDLE_CROSS,
 
900
                                  tr_tool->tcx, tr_tool->tcy,
 
901
                                  d, d,
 
902
                                  GTK_ANCHOR_CENTER,
 
903
                                  FALSE);
 
904
    }
 
905
 
 
906
  if (tr_tool->type == GIMP_TRANSFORM_TYPE_SELECTION)
 
907
    {
 
908
      GimpMatrix3     matrix = tr_tool->transform;
 
909
      const BoundSeg *orig_in;
 
910
      const BoundSeg *orig_out;
 
911
      BoundSeg       *segs_in;
 
912
      BoundSeg       *segs_out;
 
913
      gint            num_segs_in;
 
914
      gint            num_segs_out;
 
915
      gint            num_groups;
 
916
      gint            i;
 
917
 
 
918
      gimp_channel_boundary (gimp_image_get_mask (tool->display->image),
 
919
                             &orig_in, &orig_out,
 
920
                             &num_segs_in, &num_segs_out,
 
921
                             0, 0, 0, 0);
 
922
 
 
923
      segs_in = boundary_sort (orig_in, num_segs_in, &num_groups);
 
924
      num_segs_in += num_groups;
 
925
 
 
926
      segs_out = boundary_sort (orig_out, num_segs_out, &num_groups);
 
927
      num_segs_out += num_groups;
 
928
 
 
929
      if (segs_in)
 
930
        {
 
931
          for (i = 0; i < num_segs_in; i++)
 
932
            {
 
933
              gdouble tx, ty;
 
934
 
 
935
              if (segs_in[i].x1 != -1 &&
 
936
                  segs_in[i].y1 != -1 &&
 
937
                  segs_in[i].x2 != -1 &&
 
938
                  segs_in[i].y2 != -1)
 
939
                {
 
940
                  gimp_matrix3_transform_point (&matrix,
 
941
                                                segs_in[i].x1, segs_in[i].y1,
 
942
                                                &tx, &ty);
 
943
                  segs_in[i].x1 = RINT (tx);
 
944
                  segs_in[i].y1 = RINT (ty);
 
945
 
 
946
                  gimp_matrix3_transform_point (&matrix,
 
947
                                                segs_in[i].x2, segs_in[i].y2,
 
948
                                                &tx, &ty);
 
949
                  segs_in[i].x2 = RINT (tx);
 
950
                  segs_in[i].y2 = RINT (ty);
 
951
                }
 
952
            }
 
953
 
 
954
          gimp_draw_tool_draw_boundary (draw_tool,
 
955
                                        segs_in, num_segs_in,
 
956
                                        0, 0,
 
957
                                        FALSE);
 
958
          g_free (segs_in);
 
959
        }
 
960
 
 
961
      if (segs_out)
 
962
        {
 
963
          for (i = 0; i < num_segs_out; i++)
 
964
            {
 
965
              gdouble tx, ty;
 
966
 
 
967
              if (segs_out[i].x1 != -1 &&
 
968
                  segs_out[i].y1 != -1 &&
 
969
                  segs_out[i].x2 != -1 &&
 
970
                  segs_out[i].y2 != -1)
 
971
                {
 
972
                  gimp_matrix3_transform_point (&matrix,
 
973
                                                segs_out[i].x1, segs_out[i].y1,
 
974
                                                &tx, &ty);
 
975
                  segs_out[i].x1 = RINT (tx);
 
976
                  segs_out[i].y1 = RINT (ty);
 
977
 
 
978
                  gimp_matrix3_transform_point (&matrix,
 
979
                                                segs_out[i].x2, segs_out[i].y2,
 
980
                                                &tx, &ty);
 
981
                  segs_out[i].x2 = RINT (tx);
 
982
                  segs_out[i].y2 = RINT (ty);
 
983
                }
 
984
            }
 
985
 
 
986
          gimp_draw_tool_draw_boundary (draw_tool,
 
987
                                        segs_out, num_segs_out,
 
988
                                        0, 0,
 
989
                                        FALSE);
 
990
          g_free (segs_out);
 
991
        }
 
992
    }
 
993
  else if (tr_tool->type == GIMP_TRANSFORM_TYPE_PATH)
801
994
    {
802
995
      GimpVectors *vectors;
803
996
      GimpStroke  *stroke = NULL;
804
997
      GimpMatrix3  matrix = tr_tool->transform;
805
998
 
806
 
      vectors = gimp_image_get_active_vectors (tool->gdisp->gimage);
 
999
      vectors = gimp_image_get_active_vectors (tool->display->image);
807
1000
 
808
1001
      if (vectors)
809
1002
        {
843
1036
    }
844
1037
}
845
1038
 
 
1039
static void
 
1040
gimp_transform_tool_dialog_update (GimpTransformTool *tr_tool)
 
1041
{
 
1042
  if (tr_tool->dialog &&
 
1043
      GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->dialog_update)
 
1044
    {
 
1045
      GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->dialog_update (tr_tool);
 
1046
    }
 
1047
}
 
1048
 
846
1049
static TileManager *
847
1050
gimp_transform_tool_real_transform (GimpTransformTool *tr_tool,
848
1051
                                    GimpItem          *active_item,
849
1052
                                    gboolean           mask_empty,
850
 
                                    GimpDisplay       *gdisp)
 
1053
                                    GimpDisplay       *display)
851
1054
{
852
 
  GimpTool             *tool = GIMP_TOOL (tr_tool);
853
 
  GimpTransformOptions *options;
854
 
  GimpContext          *context;
 
1055
  GimpTool             *tool    = GIMP_TOOL (tr_tool);
 
1056
  GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tool);
 
1057
  GimpContext          *context = GIMP_CONTEXT (options);
855
1058
  GimpProgress         *progress;
856
1059
  TileManager          *ret  = NULL;
857
1060
 
858
 
  options = GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options);
859
 
  context = GIMP_CONTEXT (options);
860
 
 
861
 
  if (tr_tool->info_dialog)
862
 
    gtk_widget_set_sensitive (GTK_WIDGET (tr_tool->info_dialog->shell), FALSE);
863
 
 
864
 
  progress = gimp_progress_start (GIMP_PROGRESS (gdisp),
 
1061
  if (tr_tool->dialog)
 
1062
    gtk_widget_set_sensitive (tr_tool->dialog, FALSE);
 
1063
 
 
1064
  progress = gimp_progress_start (GIMP_PROGRESS (display),
865
1065
                                  tr_tool->progress_text, FALSE);
866
1066
 
867
1067
  if (gimp_item_get_linked (active_item))
895
1095
    case GIMP_TRANSFORM_TYPE_LAYER:
896
1096
    case GIMP_TRANSFORM_TYPE_SELECTION:
897
1097
      {
898
 
        gboolean clip_result = options->clip;
 
1098
        GimpTransformResize clip_result = options->clip;
899
1099
 
900
1100
        /*  always clip the selction and unfloated channels
901
1101
         *  so they keep their size
902
1102
         */
903
 
        if (GIMP_IS_CHANNEL (active_item) &&
904
 
            tile_manager_bpp (tr_tool->original) == 1)
905
 
          clip_result = TRUE;
 
1103
        if (tr_tool->original)
 
1104
          {
 
1105
            if (GIMP_IS_CHANNEL (active_item) &&
 
1106
                tile_manager_bpp (tr_tool->original) == 1)
 
1107
              clip_result = GIMP_TRANSFORM_RESIZE_CLIP;
906
1108
 
907
 
        ret =
908
 
          gimp_drawable_transform_tiles_affine (GIMP_DRAWABLE (active_item),
909
 
                                                context,
910
 
                                                tr_tool->original,
911
 
                                                &tr_tool->transform,
912
 
                                                options->direction,
913
 
                                                options->interpolation,
914
 
                                                options->supersample,
915
 
                                                options->recursion_level,
916
 
                                                clip_result,
917
 
                                                progress);
 
1109
            ret =
 
1110
              gimp_drawable_transform_tiles_affine (GIMP_DRAWABLE (active_item),
 
1111
                                                    context,
 
1112
                                                    tr_tool->original,
 
1113
                                                    &tr_tool->transform,
 
1114
                                                    options->direction,
 
1115
                                                    options->interpolation,
 
1116
                                                    options->supersample,
 
1117
                                                    options->recursion_level,
 
1118
                                                    clip_result,
 
1119
                                                    progress);
 
1120
          }
918
1121
      }
919
1122
      break;
920
1123
 
938
1141
 
939
1142
static void
940
1143
gimp_transform_tool_doit (GimpTransformTool *tr_tool,
941
 
                          GimpDisplay       *gdisp)
 
1144
                          GimpDisplay       *display)
942
1145
{
943
1146
  GimpTool             *tool        = GIMP_TOOL (tr_tool);
944
 
  GimpTransformOptions *options;
945
 
  GimpContext          *context;
 
1147
  GimpTransformOptions *options     = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tool);
 
1148
  GimpContext          *context     = GIMP_CONTEXT (options);
 
1149
  GimpDisplayShell     *shell       = GIMP_DISPLAY_SHELL (display->shell);
946
1150
  GimpItem             *active_item = NULL;
947
1151
  TileManager          *new_tiles;
 
1152
  const gchar          *message     = NULL;
948
1153
  gboolean              new_layer;
949
1154
  gboolean              mask_empty;
950
1155
 
951
 
  options = GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options);
952
 
  context = GIMP_CONTEXT (options);
953
 
 
954
1156
  switch (options->type)
955
1157
    {
956
1158
    case GIMP_TRANSFORM_TYPE_LAYER:
957
 
      active_item = (GimpItem *) gimp_image_active_drawable (gdisp->gimage);
 
1159
      active_item = (GimpItem *) gimp_image_active_drawable (display->image);
 
1160
      message = _("There is no layer to transform.");
958
1161
      break;
959
1162
 
960
1163
    case GIMP_TRANSFORM_TYPE_SELECTION:
961
 
      active_item = (GimpItem *) gimp_image_get_mask (gdisp->gimage);
 
1164
      active_item = (GimpItem *) gimp_image_get_mask (display->image);
 
1165
      /* cannot happen, so don't translate this message */
 
1166
      message = "There is no selection to transform.";
962
1167
      break;
963
1168
 
964
1169
    case GIMP_TRANSFORM_TYPE_PATH:
965
 
      active_item = (GimpItem *) gimp_image_get_active_vectors (gdisp->gimage);
 
1170
      active_item = (GimpItem *) gimp_image_get_active_vectors (display->image);
 
1171
      message = _("There is no path to transform.");
966
1172
      break;
967
1173
    }
968
1174
 
969
1175
  if (! active_item)
970
 
    return;
971
 
 
972
 
  mask_empty = gimp_channel_is_empty (gimp_image_get_mask (gdisp->gimage));
973
 
 
974
 
  if (gimp_display_shell_get_show_transform (GIMP_DISPLAY_SHELL (gdisp->shell)))
975
 
    {
976
 
      gimp_display_shell_set_show_transform (GIMP_DISPLAY_SHELL (gdisp->shell),
977
 
                                             FALSE);
 
1176
    {
 
1177
      gimp_tool_message (tool, display, message);
 
1178
      return;
 
1179
    }
 
1180
 
 
1181
  mask_empty = gimp_channel_is_empty (gimp_image_get_mask (display->image));
 
1182
 
 
1183
  if (gimp_display_shell_get_show_transform (shell))
 
1184
    {
 
1185
      gimp_display_shell_set_show_transform (shell, FALSE);
978
1186
 
979
1187
      /* get rid of preview artifacts left outside the drawable's area */
980
 
      gimp_transform_tool_expose_preview (tr_tool);
 
1188
      gtk_widget_queue_draw (shell->canvas);
981
1189
    }
982
1190
 
983
 
  gimp_set_busy (gdisp->gimage->gimp);
 
1191
  gimp_set_busy (display->image->gimp);
984
1192
 
985
1193
  /* undraw the tool before we muck around with the transform matrix */
986
1194
  gimp_draw_tool_stop (GIMP_DRAW_TOOL (tr_tool));
989
1197
  gimp_tool_control_set_preserve (tool->control, TRUE);
990
1198
 
991
1199
  /*  Start a transform undo group  */
992
 
  gimp_image_undo_group_start (gdisp->gimage, GIMP_UNDO_GROUP_TRANSFORM,
993
 
                               tool->tool_info->blurb);
 
1200
  gimp_image_undo_group_start (display->image, GIMP_UNDO_GROUP_TRANSFORM,
 
1201
                               tr_tool->undo_desc);
994
1202
 
995
1203
  /* With the old UI, if original is NULL, then this is the
996
1204
   * first transformation. In the new UI, it is always so, right?
1001
1209
   *  selection pointer, so that the original source can be repeatedly
1002
1210
   *  modified.
1003
1211
   */
1004
 
  tool->drawable = gimp_image_active_drawable (gdisp->gimage);
 
1212
  tool->drawable = gimp_image_active_drawable (display->image);
1005
1213
 
1006
1214
  switch (options->type)
1007
1215
    {
1026
1234
  new_tiles = GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->transform (tr_tool,
1027
1235
                                                                  active_item,
1028
1236
                                                                  mask_empty,
1029
 
                                                                  gdisp);
 
1237
                                                                  display);
1030
1238
 
1031
 
  gimp_transform_tool_prepare (tr_tool, gdisp);
1032
 
  gimp_transform_tool_bounds (tr_tool, gdisp);
1033
 
  gimp_transform_tool_recalc (tr_tool, gdisp);
 
1239
  gimp_transform_tool_bounds (tr_tool, display);
 
1240
  gimp_transform_tool_prepare (tr_tool, display);
 
1241
  gimp_transform_tool_recalc (tr_tool, display);
1034
1242
 
1035
1243
  switch (options->type)
1036
1244
    {
1037
1245
    case GIMP_TRANSFORM_TYPE_LAYER:
1038
1246
      if (new_tiles)
1039
1247
        {
1040
 
          /*  paste the new transformed image to the gimage...also implement
 
1248
          /*  paste the new transformed image to the image...also implement
1041
1249
           *  undo...
1042
1250
           */
1043
1251
          gimp_drawable_transform_paste (tool->drawable,
1069
1277
  /*  Make a note of the new current drawable (since we may have
1070
1278
   *  a floating selection, etc now.
1071
1279
   */
1072
 
  tool->drawable = gimp_image_active_drawable (gdisp->gimage);
 
1280
  tool->drawable = gimp_image_active_drawable (display->image);
1073
1281
 
1074
 
  gimp_transform_tool_push_undo (gdisp->gimage, NULL,
1075
 
                                 tool->ID,
1076
 
                                 G_TYPE_FROM_INSTANCE (tool),
1077
 
                                 tr_tool->old_trans_info,
1078
 
                                 NULL);
 
1282
  gimp_image_undo_push (display->image, GIMP_TYPE_TRANSFORM_TOOL_UNDO,
 
1283
                        GIMP_UNDO_TRANSFORM, NULL,
 
1284
                        0,
 
1285
                        "transform-tool", tr_tool,
 
1286
                        NULL);
1079
1287
 
1080
1288
  /*  push the undo group end  */
1081
 
  gimp_image_undo_group_end (gdisp->gimage);
 
1289
  gimp_image_undo_group_end (display->image);
1082
1290
 
1083
1291
  /*  We're done dirtying the image, and would like to be restarted
1084
1292
   *  if the image gets dirty while the tool exists
1085
1293
   */
1086
1294
  gimp_tool_control_set_preserve (tool->control, FALSE);
1087
1295
 
1088
 
  gimp_unset_busy (gdisp->gimage->gimp);
 
1296
  gimp_unset_busy (display->image->gimp);
1089
1297
 
1090
 
  gimp_image_flush (gdisp->gimage);
 
1298
  gimp_image_flush (display->image);
1091
1299
 
1092
1300
  gimp_transform_tool_halt (tr_tool);
1093
1301
}
1137
1345
void
1138
1346
gimp_transform_tool_expose_preview (GimpTransformTool *tr_tool)
1139
1347
{
1140
 
  GimpTransformOptions *options;
1141
 
 
1142
 
  options =
1143
 
    GIMP_TRANSFORM_OPTIONS (GIMP_TOOL (tr_tool)->tool_info->tool_options);
 
1348
  GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
1144
1349
 
1145
1350
  if ((options->preview_type == GIMP_TRANSFORM_PREVIEW_TYPE_IMAGE ||
1146
1351
       options->preview_type == GIMP_TRANSFORM_PREVIEW_TYPE_IMAGE_GRID) &&
1174
1379
  if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tr_tool)))
1175
1380
    return;
1176
1381
 
1177
 
  shell = GIMP_DISPLAY_SHELL (GIMP_DRAW_TOOL (tr_tool)->gdisp->shell);
 
1382
  shell = GIMP_DISPLAY_SHELL (GIMP_DRAW_TOOL (tr_tool)->display->shell);
1178
1383
 
1179
1384
  gimp_display_shell_transform_xy_f (shell, tr_tool->tx1, tr_tool->ty1,
1180
1385
                                     dx + 0, dy + 0, FALSE);
1227
1432
    {
1228
1433
      GimpDisplayShell *shell;
1229
1434
 
1230
 
      shell = GIMP_DISPLAY_SHELL (GIMP_DRAW_TOOL (tr_tool)->gdisp->shell);
 
1435
      shell = GIMP_DISPLAY_SHELL (GIMP_DRAW_TOOL (tr_tool)->display->shell);
1231
1436
 
1232
1437
      if (gimp_display_shell_get_show_transform (shell))
1233
1438
        {
1250
1455
  if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tr_tool)))
1251
1456
    gimp_draw_tool_stop (GIMP_DRAW_TOOL (tr_tool));
1252
1457
 
1253
 
  if (tr_tool->info_dialog)
1254
 
    info_dialog_hide (tr_tool->info_dialog);
 
1458
  if (tr_tool->dialog)
 
1459
    gimp_dialog_factory_hide_dialog (tr_tool->dialog);
1255
1460
 
1256
 
  tool->gdisp    = NULL;
 
1461
  tool->display  = NULL;
1257
1462
  tool->drawable = NULL;
1258
1463
}
1259
1464
 
1260
1465
static void
1261
1466
gimp_transform_tool_bounds (GimpTransformTool *tr_tool,
1262
 
                            GimpDisplay       *gdisp)
 
1467
                            GimpDisplay       *display)
1263
1468
{
1264
 
  GimpTransformOptions *options;
 
1469
  GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
1265
1470
 
1266
 
  options =
1267
 
    GIMP_TRANSFORM_OPTIONS (GIMP_TOOL (tr_tool)->tool_info->tool_options);
 
1471
  g_return_if_fail (GIMP_IS_DISPLAY (display));
1268
1472
 
1269
1473
  /*  find the boundaries  */
1270
1474
  if (tr_tool->original)
1280
1484
        {
1281
1485
        case GIMP_TRANSFORM_TYPE_LAYER:
1282
1486
          {
1283
 
            GimpDrawable *drawable = gimp_image_active_drawable (gdisp->gimage);
 
1487
            GimpDrawable *drawable = gimp_image_active_drawable (display->image);
1284
1488
            gint          offset_x;
1285
1489
            gint          offset_y;
1286
1490
 
1298
1502
 
1299
1503
        case GIMP_TRANSFORM_TYPE_SELECTION:
1300
1504
        case GIMP_TRANSFORM_TYPE_PATH:
1301
 
          gimp_channel_bounds (gimp_image_get_mask (gdisp->gimage),
 
1505
          gimp_channel_bounds (gimp_image_get_mask (display->image),
1302
1506
                               &tr_tool->x1, &tr_tool->y1,
1303
1507
                               &tr_tool->x2, &tr_tool->y2);
1304
1508
          break;
1308
1512
  tr_tool->cx = (gdouble) (tr_tool->x1 + tr_tool->x2) / 2.0;
1309
1513
  tr_tool->cy = (gdouble) (tr_tool->y1 + tr_tool->y2) / 2.0;
1310
1514
 
 
1515
  tr_tool->aspect = ((gdouble) (tr_tool->x2 - tr_tool->x1) /
 
1516
                     (gdouble) (tr_tool->y2 - tr_tool->y1));
 
1517
 
1311
1518
  /*  changing the bounds invalidates any grid we may have  */
1312
1519
  if (tr_tool->use_grid)
1313
1520
    gimp_transform_tool_grid_recalc (tr_tool);
1316
1523
static void
1317
1524
gimp_transform_tool_grid_recalc (GimpTransformTool *tr_tool)
1318
1525
{
1319
 
  GimpTransformOptions *options;
1320
 
 
1321
 
  options =
1322
 
    GIMP_TRANSFORM_OPTIONS (GIMP_TOOL (tr_tool)->tool_info->tool_options);
 
1526
  GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
1323
1527
 
1324
1528
  if (tr_tool->grid_coords != NULL)
1325
1529
    {
1410
1614
}
1411
1615
 
1412
1616
static void
 
1617
gimp_transform_tool_handles_recalc (GimpTransformTool *tr_tool,
 
1618
                                    GimpDisplay       *display)
 
1619
{
 
1620
  gint dx1, dy1;
 
1621
  gint dx2, dy2;
 
1622
  gint dx3, dy3;
 
1623
  gint dx4, dy4;
 
1624
  gint x1, y1;
 
1625
  gint x2, y2;
 
1626
 
 
1627
  gimp_display_shell_transform_xy (GIMP_DISPLAY_SHELL (display->shell),
 
1628
                                   tr_tool->tx1, tr_tool->ty1,
 
1629
                                   &dx1, &dy1,
 
1630
                                   FALSE);
 
1631
  gimp_display_shell_transform_xy (GIMP_DISPLAY_SHELL (display->shell),
 
1632
                                   tr_tool->tx2, tr_tool->ty2,
 
1633
                                   &dx2, &dy2,
 
1634
                                   FALSE);
 
1635
  gimp_display_shell_transform_xy (GIMP_DISPLAY_SHELL (display->shell),
 
1636
                                   tr_tool->tx3, tr_tool->ty3,
 
1637
                                   &dx3, &dy3,
 
1638
                                   FALSE);
 
1639
  gimp_display_shell_transform_xy (GIMP_DISPLAY_SHELL (display->shell),
 
1640
                                   tr_tool->tx4, tr_tool->ty4,
 
1641
                                   &dx4, &dy4,
 
1642
                                   FALSE);
 
1643
 
 
1644
  x1 = MIN (MIN (dx1, dx2), MIN (dx3, dx4));
 
1645
  y1 = MIN (MIN (dy1, dy2), MIN (dy3, dy4));
 
1646
  x2 = MAX (MAX (dx1, dx2), MAX (dx3, dx4));
 
1647
  y2 = MAX (MAX (dy1, dy2), MAX (dy3, dy4));
 
1648
 
 
1649
  tr_tool->handle_w = CLAMP ((x2 - x1) / 3, MIN_HANDLE_SIZE, HANDLE_SIZE);
 
1650
  tr_tool->handle_h = CLAMP ((y2 - y1) / 3, MIN_HANDLE_SIZE, HANDLE_SIZE);
 
1651
}
 
1652
 
 
1653
static void
1413
1654
gimp_transform_tool_dialog (GimpTransformTool *tr_tool)
1414
1655
{
1415
 
  GimpTool     *tool = GIMP_TOOL (tr_tool);
1416
 
  GimpToolInfo *tool_info;
 
1656
  GimpTool     *tool      = GIMP_TOOL (tr_tool);
 
1657
  GimpToolInfo *tool_info = tool->tool_info;
1417
1658
  const gchar  *stock_id;
1418
 
  gchar        *identifier;
1419
1659
 
1420
1660
  if (! GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->dialog)
1421
1661
    return;
1422
1662
 
1423
 
  tool_info = tool->tool_info;
1424
 
 
1425
1663
  stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info));
1426
1664
 
1427
 
  tr_tool->info_dialog = info_dialog_new (NULL,
 
1665
  tr_tool->dialog = gimp_tool_dialog_new (tool_info,
 
1666
                                          NULL /* tool->display->shell */,
1428
1667
                                          tool_info->blurb,
1429
 
                                          GIMP_OBJECT (tool_info)->name,
1430
 
                                          stock_id,
1431
 
                                          tr_tool->shell_desc,
1432
 
                                          NULL /* tool->gdisp->shell */,
1433
 
                                          gimp_standard_help_func,
1434
 
                                          tool_info->help_id);
1435
 
 
1436
 
  gtk_dialog_add_buttons (GTK_DIALOG (tr_tool->info_dialog->shell),
1437
 
                          GIMP_STOCK_RESET, RESPONSE_RESET,
1438
 
                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1439
 
                          stock_id,         GTK_RESPONSE_OK,
1440
 
                          NULL);
1441
 
  gtk_dialog_set_default_response (GTK_DIALOG (tr_tool->info_dialog->shell),
 
1668
                                          GIMP_STOCK_RESET, RESPONSE_RESET,
 
1669
                                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
1670
                                          stock_id,         GTK_RESPONSE_OK,
 
1671
                                          NULL);
 
1672
  gtk_dialog_set_default_response (GTK_DIALOG (tr_tool->dialog),
1442
1673
                                   GTK_RESPONSE_OK);
 
1674
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (tr_tool->dialog),
 
1675
                                           RESPONSE_RESET,
 
1676
                                           GTK_RESPONSE_OK,
 
1677
                                           GTK_RESPONSE_CANCEL,
 
1678
                                           -1);
1443
1679
 
1444
 
  g_signal_connect (tr_tool->info_dialog->shell, "response",
 
1680
  g_signal_connect (tr_tool->dialog, "response",
1445
1681
                    G_CALLBACK (gimp_transform_tool_response),
1446
1682
                    tr_tool);
1447
1683
 
1448
1684
  GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->dialog (tr_tool);
1449
 
 
1450
 
  identifier = g_strconcat (GIMP_OBJECT (tool_info)->name, "-dialog", NULL);
1451
 
 
1452
 
  gimp_dialog_factory_add_foreign (gimp_dialog_factory_from_name ("toplevel"),
1453
 
                                   identifier,
1454
 
                                   tr_tool->info_dialog->shell);
1455
 
 
1456
 
  g_free (identifier);
1457
1685
}
1458
1686
 
1459
1687
static void
1460
1688
gimp_transform_tool_prepare (GimpTransformTool *tr_tool,
1461
 
                             GimpDisplay       *gdisp)
 
1689
                             GimpDisplay       *display)
1462
1690
{
1463
 
  GimpTransformOptions *options;
1464
 
 
1465
 
  options =
1466
 
    GIMP_TRANSFORM_OPTIONS (GIMP_TOOL (tr_tool)->tool_info->tool_options);
 
1691
  GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
1467
1692
 
1468
1693
  if ((options->preview_type == GIMP_TRANSFORM_PREVIEW_TYPE_IMAGE ||
1469
1694
       options->preview_type == GIMP_TRANSFORM_PREVIEW_TYPE_IMAGE_GRID) &&
1470
1695
      options->type         == GIMP_TRANSFORM_TYPE_LAYER &&
1471
1696
      options->direction    == GIMP_TRANSFORM_FORWARD)
1472
 
    gimp_display_shell_set_show_transform (GIMP_DISPLAY_SHELL (gdisp->shell),
 
1697
    gimp_display_shell_set_show_transform (GIMP_DISPLAY_SHELL (display->shell),
1473
1698
                                           TRUE);
1474
1699
  else
1475
 
    gimp_display_shell_set_show_transform (GIMP_DISPLAY_SHELL (gdisp->shell),
 
1700
    gimp_display_shell_set_show_transform (GIMP_DISPLAY_SHELL (display->shell),
1476
1701
                                           FALSE);
1477
1702
 
1478
 
  if (tr_tool->info_dialog)
 
1703
  if (tr_tool->dialog)
1479
1704
    {
1480
 
      gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (tr_tool->info_dialog->shell),
1481
 
                                         GIMP_VIEWABLE (gimp_image_active_drawable (gdisp->gimage)));
 
1705
      gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (tr_tool->dialog),
 
1706
                                         GIMP_VIEWABLE (gimp_image_active_drawable (display->image)),
 
1707
                                         GIMP_CONTEXT (options));
1482
1708
 
1483
 
      gtk_widget_set_sensitive (GTK_WIDGET (tr_tool->info_dialog->shell), TRUE);
 
1709
      gtk_widget_set_sensitive (tr_tool->dialog, TRUE);
1484
1710
    }
1485
1711
 
1486
1712
  if (GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->prepare)
1487
 
    GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->prepare (tr_tool, gdisp);
 
1713
    GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->prepare (tr_tool, display);
1488
1714
}
1489
1715
 
1490
1716
void
1491
1717
gimp_transform_tool_recalc (GimpTransformTool *tr_tool,
1492
 
                            GimpDisplay       *gdisp)
 
1718
                            GimpDisplay       *display)
1493
1719
{
 
1720
  g_return_if_fail (GIMP_IS_DISPLAY (display));
 
1721
 
1494
1722
  if (GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->recalc)
1495
 
    GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->recalc (tr_tool, gdisp);
 
1723
    GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->recalc (tr_tool, display);
1496
1724
 
1497
1725
  gimp_transform_tool_transform_bounding_box (tr_tool);
1498
1726
 
1499
 
  if (GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->dialog_update)
1500
 
    GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->dialog_update (tr_tool);
 
1727
  gimp_transform_tool_dialog_update (tr_tool);
 
1728
 
 
1729
  if (tr_tool->dialog)
 
1730
    gtk_widget_show (tr_tool->dialog);
1501
1731
}
1502
1732
 
1503
1733
static void
1505
1735
                              gint               response_id,
1506
1736
                              GimpTransformTool *tr_tool)
1507
1737
{
 
1738
  GimpTool *tool = GIMP_TOOL (tr_tool);
 
1739
 
1508
1740
  switch (response_id)
1509
1741
    {
1510
1742
    case RESPONSE_RESET:
1511
1743
      {
1512
 
        GimpTool *tool;
1513
 
        gint      i;
1514
 
 
1515
 
        tool = GIMP_TOOL (tr_tool);
 
1744
        gint i;
1516
1745
 
1517
1746
        gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
1518
1747
 
1519
1748
        /*  Restore the previous transformation info  */
1520
 
        for (i = 0; i < TRAN_INFO_SIZE; i++)
 
1749
        for (i = 0; i < TRANS_INFO_SIZE; i++)
1521
1750
          tr_tool->trans_info[i] = tr_tool->old_trans_info[i];
1522
1751
 
1523
1752
        /*  reget the selection bounds  */
1524
 
        gimp_transform_tool_bounds (tr_tool, tool->gdisp);
 
1753
        gimp_transform_tool_bounds (tr_tool, tool->display);
1525
1754
 
1526
1755
        /*  recalculate the tool's transformation matrix  */
1527
 
        gimp_transform_tool_recalc (tr_tool, tool->gdisp);
 
1756
        gimp_transform_tool_recalc (tr_tool, tool->display);
1528
1757
 
1529
1758
        /* update preview */
1530
1759
        gimp_transform_tool_expose_preview (tr_tool);
1534
1763
      break;
1535
1764
 
1536
1765
    case GTK_RESPONSE_OK:
1537
 
      gimp_transform_tool_doit (tr_tool, GIMP_TOOL (tr_tool)->gdisp);
 
1766
      g_return_if_fail (tool->display != NULL);
 
1767
      gimp_transform_tool_doit (tr_tool, tool->display);
1538
1768
      break;
1539
1769
 
1540
1770
    default:
1548
1778
                                 GParamSpec           *pspec,
1549
1779
                                 GimpTransformTool    *tr_tool)
1550
1780
{
 
1781
  GimpDisplay *display = GIMP_TOOL (tr_tool)->display;
 
1782
 
1551
1783
  if (tr_tool->function != TRANSFORM_CREATING)
1552
1784
    gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
1553
1785
 
1556
1788
 
1557
1789
  if (tr_tool->function != TRANSFORM_CREATING)
1558
1790
    {
1559
 
      /*  reget the selection bounds  */
1560
 
      gimp_transform_tool_bounds (tr_tool, GIMP_TOOL (tr_tool)->gdisp);
 
1791
      if (display)
 
1792
        {
 
1793
          /*  reget the selection bounds  */
 
1794
          gimp_transform_tool_bounds (tr_tool, display);
1561
1795
 
1562
 
      /*  recalculate the tool's transformation matrix  */
1563
 
      gimp_transform_tool_recalc (tr_tool, GIMP_TOOL (tr_tool)->gdisp);
 
1796
          /*  recalculate the tool's transformation matrix  */
 
1797
          gimp_transform_tool_recalc (tr_tool, display);
 
1798
        }
1564
1799
 
1565
1800
      gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
1566
1801
    }
1574
1809
  GimpDisplayShell *shell = NULL;
1575
1810
 
1576
1811
  if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tr_tool)))
1577
 
    shell = GIMP_DISPLAY_SHELL (GIMP_DRAW_TOOL (tr_tool)->gdisp->shell);
 
1812
    shell = GIMP_DISPLAY_SHELL (GIMP_DRAW_TOOL (tr_tool)->display->shell);
1578
1813
 
1579
1814
  switch (options->preview_type)
1580
1815
    {