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

« back to all changes in this revision

Viewing changes to app/tools/gimprotatetool.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 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
27
27
 
28
28
#include "core/gimp-transform-utils.h"
29
29
#include "core/gimpimage.h"
30
 
#include "core/gimpdrawable-transform.h"
31
 
#include "core/gimptoolinfo.h"
32
30
 
33
31
#include "widgets/gimphelp-ids.h"
34
32
 
35
33
#include "display/gimpdisplay.h"
36
34
#include "display/gimpdisplayshell.h"
37
35
 
38
 
#ifdef __GNUC__
39
 
#warning FIXME #include "dialogs/dialogs-types.h"
40
 
#endif
41
 
#include "dialogs/dialogs-types.h"
42
 
#include "dialogs/info-dialog.h"
43
 
 
44
36
#include "gimprotatetool.h"
45
37
#include "gimptoolcontrol.h"
46
38
#include "gimptransformoptions.h"
54
46
#define CENTER_X     2
55
47
#define CENTER_Y     3
56
48
 
57
 
#define EPSILON      0.018  /*  ~ 1 degree  */
58
49
#define FIFTEEN_DEG  (G_PI / 12.0)
59
50
 
 
51
#define SB_WIDTH     10
 
52
 
60
53
 
61
54
/*  local function prototypes  */
62
55
 
63
 
static void   gimp_rotate_tool_class_init    (GimpRotateToolClass *klass);
64
 
static void   gimp_rotate_tool_init          (GimpRotateTool      *rotate_tool);
65
 
 
66
56
static void   gimp_rotate_tool_dialog        (GimpTransformTool   *tr_tool);
67
57
static void   gimp_rotate_tool_dialog_update (GimpTransformTool   *tr_tool);
68
58
static void   gimp_rotate_tool_prepare       (GimpTransformTool   *tr_tool,
69
 
                                              GimpDisplay         *gdisp);
 
59
                                              GimpDisplay         *display);
70
60
static void   gimp_rotate_tool_motion        (GimpTransformTool   *tr_tool,
71
 
                                              GimpDisplay         *gdisp);
 
61
                                              GimpDisplay         *display);
72
62
static void   gimp_rotate_tool_recalc        (GimpTransformTool   *tr_tool,
73
 
                                              GimpDisplay         *gdisp);
 
63
                                              GimpDisplay         *display);
74
64
 
75
 
static void   rotate_angle_changed           (GtkWidget           *entry,
 
65
static void   rotate_angle_changed           (GtkAdjustment       *adj,
76
66
                                              GimpTransformTool   *tr_tool);
77
67
static void   rotate_center_changed          (GtkWidget           *entry,
78
68
                                              GimpTransformTool   *tr_tool);
79
69
 
80
70
 
81
 
/*  private variables  */
82
 
 
83
 
static GimpTransformToolClass *parent_class = NULL;
84
 
 
85
 
 
86
 
/*  public functions  */
 
71
G_DEFINE_TYPE (GimpRotateTool, gimp_rotate_tool, GIMP_TYPE_TRANSFORM_TOOL)
 
72
 
 
73
#define parent_class gimp_rotate_tool_parent_class
 
74
 
87
75
 
88
76
void
89
77
gimp_rotate_tool_register (GimpToolRegisterCallback  callback,
95
83
                0,
96
84
                "gimp-rotate-tool",
97
85
                _("Rotate"),
98
 
                _("Rotate the layer or selection"),
 
86
                _("Rotate Tool: Rotate the layer, selection or path"),
99
87
                N_("_Rotate"), "<shift>R",
100
88
                NULL, GIMP_HELP_TOOL_ROTATE,
101
89
                GIMP_STOCK_TOOL_ROTATE,
102
90
                data);
103
91
}
104
92
 
105
 
GType
106
 
gimp_rotate_tool_get_type (void)
107
 
{
108
 
  static GType tool_type = 0;
109
 
 
110
 
  if (! tool_type)
111
 
    {
112
 
      static const GTypeInfo tool_info =
113
 
      {
114
 
        sizeof (GimpRotateToolClass),
115
 
        (GBaseInitFunc) NULL,
116
 
        (GBaseFinalizeFunc) NULL,
117
 
        (GClassInitFunc) gimp_rotate_tool_class_init,
118
 
        NULL,           /* class_finalize */
119
 
        NULL,           /* class_data     */
120
 
        sizeof (GimpRotateTool),
121
 
        0,              /* n_preallocs    */
122
 
        (GInstanceInitFunc) gimp_rotate_tool_init,
123
 
      };
124
 
 
125
 
      tool_type = g_type_register_static (GIMP_TYPE_TRANSFORM_TOOL,
126
 
                                          "GimpRotateTool",
127
 
                                          &tool_info, 0);
128
 
    }
129
 
 
130
 
  return tool_type;
131
 
}
132
 
 
133
 
 
134
 
/*  private functions  */
135
 
 
136
93
static void
137
94
gimp_rotate_tool_class_init (GimpRotateToolClass *klass)
138
95
{
139
96
  GimpTransformToolClass *trans_class = GIMP_TRANSFORM_TOOL_CLASS (klass);
140
97
 
141
 
  parent_class = g_type_class_peek_parent (klass);
142
 
 
143
 
  trans_class->dialog         = gimp_rotate_tool_dialog;
144
 
  trans_class->dialog_update  = gimp_rotate_tool_dialog_update;
145
 
  trans_class->prepare        = gimp_rotate_tool_prepare;
146
 
  trans_class->motion         = gimp_rotate_tool_motion;
147
 
  trans_class->recalc         = gimp_rotate_tool_recalc;
 
98
  trans_class->dialog        = gimp_rotate_tool_dialog;
 
99
  trans_class->dialog_update = gimp_rotate_tool_dialog_update;
 
100
  trans_class->prepare       = gimp_rotate_tool_prepare;
 
101
  trans_class->motion        = gimp_rotate_tool_motion;
 
102
  trans_class->recalc        = gimp_rotate_tool_recalc;
148
103
}
149
104
 
150
105
static void
155
110
 
156
111
  gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_ROTATE);
157
112
 
158
 
  tr_tool->shell_desc    = _("Rotation Information");
159
 
  tr_tool->progress_text = _("Rotating...");
 
113
  tr_tool->undo_desc     = Q_("command|Rotate");
 
114
  tr_tool->progress_text = _("Rotating");
 
115
 
 
116
  tr_tool->use_grid      = TRUE;
 
117
  tr_tool->use_center    = TRUE;
160
118
}
161
119
 
162
120
static void
163
121
gimp_rotate_tool_dialog (GimpTransformTool *tr_tool)
164
122
{
165
123
  GimpRotateTool *rotate = GIMP_ROTATE_TOOL (tr_tool);
166
 
  GtkWidget      *widget;
167
 
  GtkWidget      *spinbutton2;
168
 
 
169
 
  widget = info_dialog_add_spinbutton (tr_tool->info_dialog, _("Angle:"),
170
 
                                       &rotate->angle_val,
171
 
                                       -180, 180, 1, 15, 1, 1, 2,
172
 
                                       G_CALLBACK (rotate_angle_changed),
173
 
                                       tr_tool);
174
 
  gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (widget), TRUE);
175
 
 
176
 
  /*  this looks strange (-180, 181), but it works  */
177
 
  widget = info_dialog_add_scale (tr_tool->info_dialog, "",
178
 
                                  &rotate->angle_val,
179
 
                                  -180, 181, 0.01, 0.1, 1, -1,
180
 
                                  G_CALLBACK (rotate_angle_changed),
181
 
                                  tr_tool);
182
 
  gtk_widget_set_size_request (widget, 180, -1);
183
 
 
184
 
  spinbutton2 = info_dialog_add_spinbutton (tr_tool->info_dialog,
185
 
                                            _("Center X:"),
186
 
                                            NULL,
187
 
                                            -1, 1, 1, 10, 1, 1, 2,
188
 
                                            NULL, NULL);
189
 
  rotate->sizeentry = info_dialog_add_sizeentry (tr_tool->info_dialog,
190
 
                                                 _("Center Y:"),
191
 
                                                 rotate->center_vals, 1,
192
 
                                                 GIMP_UNIT_PIXEL, "%a",
193
 
                                                 TRUE, TRUE, FALSE,
194
 
                                                 GIMP_SIZE_ENTRY_UPDATE_SIZE,
195
 
                                                 G_CALLBACK (rotate_center_changed),
196
 
                                                 tr_tool);
197
 
 
 
124
  GtkWidget      *table;
 
125
  GtkWidget      *button;
 
126
  GtkWidget      *scale;
 
127
  GtkObject      *adj;
 
128
 
 
129
  table = gtk_table_new (4, 2, FALSE);
 
130
  gtk_container_set_border_width (GTK_CONTAINER (table), 6);
 
131
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
 
132
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
 
133
  gtk_table_set_row_spacing (GTK_TABLE (table), 1, 6);
 
134
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (tr_tool->dialog)->vbox), table,
 
135
                      FALSE, FALSE, 0);
 
136
  gtk_widget_show (table);
 
137
 
 
138
  button = gimp_spin_button_new (&rotate->angle_adj,
 
139
                                 0, -180, 180, 0.1, 15, 0, 2, 2);
 
140
  gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (button), TRUE);
 
141
  gtk_entry_set_width_chars (GTK_ENTRY (button), SB_WIDTH);
 
142
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 0, _("_Angle:"),
 
143
                             0.0, 0.5, button, 1, TRUE);
 
144
 
 
145
  g_signal_connect (rotate->angle_adj, "value-changed",
 
146
                    G_CALLBACK (rotate_angle_changed),
 
147
                    tr_tool);
 
148
 
 
149
  scale = gtk_hscale_new (GTK_ADJUSTMENT (rotate->angle_adj));
 
150
  gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
 
151
  gtk_table_attach (GTK_TABLE (table), scale, 1, 2, 1, 2,
 
152
                    GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
 
153
  gtk_widget_show (scale);
 
154
 
 
155
  button = gimp_spin_button_new (&adj, 0, -1, 1, 1, 10, 1, 1, 2);
 
156
  gtk_entry_set_width_chars (GTK_ENTRY (button), SB_WIDTH);
 
157
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 2, _("Center _X:"),
 
158
                             0.0, 0.5, button, 1, TRUE);
 
159
 
 
160
  rotate->sizeentry = gimp_size_entry_new (1, GIMP_UNIT_PIXEL, "%a",
 
161
                                           TRUE, TRUE, FALSE, SB_WIDTH,
 
162
                                           GIMP_SIZE_ENTRY_UPDATE_SIZE);
198
163
  gimp_size_entry_add_field (GIMP_SIZE_ENTRY (rotate->sizeentry),
199
 
                             GTK_SPIN_BUTTON (spinbutton2), NULL);
 
164
                             GTK_SPIN_BUTTON (button), NULL);
 
165
  gimp_size_entry_set_pixel_digits (GIMP_SIZE_ENTRY (rotate->sizeentry), 2);
 
166
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 3, _("Center _Y:"),
 
167
                             0.0, 0.5, rotate->sizeentry, 1, TRUE);
200
168
 
201
 
  gtk_table_set_row_spacing (GTK_TABLE (tr_tool->info_dialog->info_table),
202
 
                             1, 6);
203
 
  gtk_table_set_row_spacing (GTK_TABLE (tr_tool->info_dialog->info_table),
204
 
                             2, 0);
 
169
  g_signal_connect (rotate->sizeentry, "value-changed",
 
170
                    G_CALLBACK (rotate_center_changed),
 
171
                    tr_tool);
205
172
}
206
173
 
207
174
static void
209
176
{
210
177
  GimpRotateTool *rotate = GIMP_ROTATE_TOOL (tr_tool);
211
178
 
212
 
  rotate->angle_val      = gimp_rad_to_deg (tr_tool->trans_info[ANGLE]);
213
 
  rotate->center_vals[0] = tr_tool->trans_info[CENTER_X];
214
 
  rotate->center_vals[1] = tr_tool->trans_info[CENTER_Y];
215
 
 
216
 
  info_dialog_update (tr_tool->info_dialog);
217
 
  info_dialog_show (tr_tool->info_dialog);
 
179
  gtk_adjustment_set_value (GTK_ADJUSTMENT (rotate->angle_adj),
 
180
                            gimp_rad_to_deg (tr_tool->trans_info[ANGLE]));
 
181
 
 
182
  g_signal_handlers_block_by_func (rotate->sizeentry,
 
183
                                   rotate_center_changed,
 
184
                                   tr_tool);
 
185
 
 
186
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (rotate->sizeentry), 0,
 
187
                              tr_tool->trans_info[CENTER_X]);
 
188
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (rotate->sizeentry), 1,
 
189
                              tr_tool->trans_info[CENTER_Y]);
 
190
 
 
191
  g_signal_handlers_unblock_by_func (rotate->sizeentry,
 
192
                                     rotate_center_changed,
 
193
                                     tr_tool);
218
194
}
219
195
 
220
196
static void
221
197
gimp_rotate_tool_prepare (GimpTransformTool *tr_tool,
222
 
                          GimpDisplay       *gdisp)
 
198
                          GimpDisplay       *display)
223
199
{
224
200
  GimpRotateTool *rotate = GIMP_ROTATE_TOOL (tr_tool);
225
201
 
226
 
  rotate->angle_val      = 0.0;
227
 
  rotate->center_vals[0] = tr_tool->cx;
228
 
  rotate->center_vals[1] = tr_tool->cy;
 
202
  tr_tool->trans_info[ANGLE]      = 0.0;
 
203
  tr_tool->trans_info[REAL_ANGLE] = 0.0;
 
204
  tr_tool->trans_info[CENTER_X]   = tr_tool->cx;
 
205
  tr_tool->trans_info[CENTER_Y]   = tr_tool->cy;
229
206
 
230
207
  g_signal_handlers_block_by_func (rotate->sizeentry,
231
208
                                   rotate_center_changed,
232
209
                                   tr_tool);
233
210
 
234
211
  gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (rotate->sizeentry),
235
 
                            GIMP_DISPLAY_SHELL (gdisp->shell)->unit);
 
212
                            GIMP_DISPLAY_SHELL (display->shell)->unit);
236
213
 
237
214
  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (rotate->sizeentry), 0,
238
 
                                  gdisp->gimage->xresolution, FALSE);
 
215
                                  display->image->xresolution, FALSE);
239
216
  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (rotate->sizeentry), 1,
240
 
                                  gdisp->gimage->yresolution, FALSE);
 
217
                                  display->image->yresolution, FALSE);
241
218
 
242
219
  gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (rotate->sizeentry), 0,
243
220
                                         -65536,
244
 
                                         65536 + gdisp->gimage->width);
 
221
                                         65536 + display->image->width);
245
222
  gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (rotate->sizeentry), 1,
246
223
                                         -65536,
247
 
                                         65536 + gdisp->gimage->height);
 
224
                                         65536 + display->image->height);
248
225
 
249
226
  gimp_size_entry_set_size (GIMP_SIZE_ENTRY (rotate->sizeentry), 0,
250
227
                            tr_tool->x1, tr_tool->x2);
251
228
  gimp_size_entry_set_size (GIMP_SIZE_ENTRY (rotate->sizeentry), 1,
252
229
                            tr_tool->y1, tr_tool->y2);
253
230
 
254
 
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (rotate->sizeentry), 0,
255
 
                              rotate->center_vals[0]);
256
 
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (rotate->sizeentry), 1,
257
 
                              rotate->center_vals[1]);
258
 
 
259
231
  g_signal_handlers_unblock_by_func (rotate->sizeentry,
260
232
                                     rotate_center_changed,
261
233
                                     tr_tool);
262
 
 
263
 
  tr_tool->trans_info[ANGLE]      = rotate->angle_val;
264
 
  tr_tool->trans_info[REAL_ANGLE] = rotate->angle_val;
265
 
  tr_tool->trans_info[CENTER_X]   = rotate->center_vals[0];
266
 
  tr_tool->trans_info[CENTER_Y]   = rotate->center_vals[1];
267
234
}
268
235
 
269
236
static void
270
237
gimp_rotate_tool_motion (GimpTransformTool *tr_tool,
271
 
                         GimpDisplay       *gdisp)
 
238
                         GimpDisplay       *display)
272
239
{
273
 
  GimpTransformOptions *options;
 
240
  GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
274
241
  gdouble               angle1, angle2, angle;
275
242
  gdouble               cx, cy;
276
243
  gdouble               x1, y1, x2, y2;
285
252
      return;
286
253
    }
287
254
 
288
 
  options =
289
 
    GIMP_TRANSFORM_OPTIONS (GIMP_TOOL (tr_tool)->tool_info->tool_options);
290
 
 
291
255
  cx = tr_tool->trans_info[CENTER_X];
292
256
  cy = tr_tool->trans_info[CENTER_Y];
293
257
 
310
274
  /*  increment the transform tool's angle  */
311
275
  tr_tool->trans_info[REAL_ANGLE] += angle;
312
276
 
313
 
  /*  limit the angle to between 0 and 360 degrees  */
 
277
  /*  limit the angle to between -180 and 180 degrees  */
314
278
  if (tr_tool->trans_info[REAL_ANGLE] < - G_PI)
315
 
    tr_tool->trans_info[REAL_ANGLE] =
316
 
      2.0 * G_PI - tr_tool->trans_info[REAL_ANGLE];
 
279
    {
 
280
      tr_tool->trans_info[REAL_ANGLE] =
 
281
        2.0 * G_PI + tr_tool->trans_info[REAL_ANGLE];
 
282
    }
317
283
  else if (tr_tool->trans_info[REAL_ANGLE] > G_PI)
318
 
    tr_tool->trans_info[REAL_ANGLE] =
319
 
      tr_tool->trans_info[REAL_ANGLE] - 2.0 * G_PI;
 
284
    {
 
285
      tr_tool->trans_info[REAL_ANGLE] =
 
286
        tr_tool->trans_info[REAL_ANGLE] - 2.0 * G_PI;
 
287
    }
320
288
 
321
289
  /*  constrain the angle to 15-degree multiples if ctrl is held down  */
322
 
  if (options->constrain_1)
 
290
  if (options->constrain)
323
291
    {
324
292
      tr_tool->trans_info[ANGLE] =
325
293
        FIFTEEN_DEG * (int) ((tr_tool->trans_info[REAL_ANGLE] +
326
 
                              FIFTEEN_DEG / 2.0) /
327
 
                             FIFTEEN_DEG);
 
294
                              FIFTEEN_DEG / 2.0) / FIFTEEN_DEG);
328
295
    }
329
296
  else
330
297
    {
334
301
 
335
302
static void
336
303
gimp_rotate_tool_recalc (GimpTransformTool *tr_tool,
337
 
                         GimpDisplay       *gdisp)
 
304
                         GimpDisplay       *display)
338
305
{
339
306
  tr_tool->cx = tr_tool->trans_info[CENTER_X];
340
307
  tr_tool->cy = tr_tool->trans_info[CENTER_Y];
341
308
 
342
 
  gimp_transform_matrix_rotate_center (tr_tool->cx,
 
309
  gimp_matrix3_identity (&tr_tool->transform);
 
310
  gimp_transform_matrix_rotate_center (&tr_tool->transform,
 
311
                                       tr_tool->cx,
343
312
                                       tr_tool->cy,
344
 
                                       tr_tool->trans_info[ANGLE],
345
 
                                       &tr_tool->transform);
 
313
                                       tr_tool->trans_info[ANGLE]);
346
314
}
347
315
 
348
316
static void
349
 
rotate_angle_changed (GtkWidget         *widget,
 
317
rotate_angle_changed (GtkAdjustment     *adj,
350
318
                      GimpTransformTool *tr_tool)
351
319
{
352
 
  gdouble value = gimp_deg_to_rad (GTK_ADJUSTMENT (widget)->value);
 
320
  gdouble value = gimp_deg_to_rad (gtk_adjustment_get_value (adj));
353
321
 
354
322
#define ANGLE_EPSILON 0.0001
355
323
 
359
327
 
360
328
      tr_tool->trans_info[ANGLE] = value;
361
329
 
362
 
      gimp_transform_tool_recalc (tr_tool, GIMP_TOOL (tr_tool)->gdisp);
 
330
      gimp_transform_tool_recalc (tr_tool, GIMP_TOOL (tr_tool)->display);
363
331
 
364
332
      gimp_transform_tool_expose_preview (tr_tool);
365
333
 
386
354
      tr_tool->cx = cx;
387
355
      tr_tool->cy = cy;
388
356
 
389
 
      gimp_transform_tool_recalc (tr_tool, GIMP_TOOL (tr_tool)->gdisp);
 
357
      gimp_transform_tool_recalc (tr_tool, GIMP_TOOL (tr_tool)->display);
390
358
 
391
359
      gimp_transform_tool_expose_preview (tr_tool);
392
360