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

« back to all changes in this revision

Viewing changes to app/tools/gimpsheartool.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
22
22
 
23
23
#include <gtk/gtk.h>
24
24
 
25
 
#include "libgimpmath/gimpmath.h"
26
25
#include "libgimpwidgets/gimpwidgets.h"
27
26
 
28
27
#include "tools-types.h"
29
28
 
30
29
#include "core/gimp-transform-utils.h"
31
 
#include "core/gimpimage.h"
32
 
#include "core/gimpdrawable-transform.h"
33
 
#include "core/gimptoolinfo.h"
34
30
 
35
31
#include "widgets/gimphelp-ids.h"
36
32
 
37
 
#include "display/gimpdisplay.h"
38
 
 
39
 
#ifdef __GNUC__
40
 
#warning FIXME #include "dialogs/dialogs-types.h"
41
 
#endif
42
 
#include "dialogs/dialogs-types.h"
43
 
#include "dialogs/info-dialog.h"
44
 
 
45
33
#include "gimpsheartool.h"
46
34
#include "gimptoolcontrol.h"
47
35
#include "gimptransformoptions.h"
57
45
/*  the minimum movement before direction of shear can be determined (pixels) */
58
46
#define MIN_MOVE     5
59
47
 
 
48
#define SB_WIDTH     10
 
49
 
60
50
 
61
51
/*  local function prototypes  */
62
52
 
63
 
static void   gimp_shear_tool_class_init    (GimpShearToolClass *klass);
64
 
static void   gimp_shear_tool_init          (GimpShearTool      *shear_tool);
65
 
 
66
53
static void   gimp_shear_tool_dialog        (GimpTransformTool  *tr_tool);
67
54
static void   gimp_shear_tool_dialog_update (GimpTransformTool  *tr_tool);
68
55
 
69
56
static void   gimp_shear_tool_prepare       (GimpTransformTool  *tr_tool,
70
 
                                             GimpDisplay        *gdisp);
 
57
                                             GimpDisplay        *display);
71
58
static void   gimp_shear_tool_motion        (GimpTransformTool  *tr_tool,
72
 
                                             GimpDisplay        *gdisp);
 
59
                                             GimpDisplay        *display);
73
60
static void   gimp_shear_tool_recalc        (GimpTransformTool  *tr_tool,
74
 
                                             GimpDisplay        *gdisp);
75
 
 
76
 
static void   shear_x_mag_changed           (GtkWidget          *widget,
77
 
                                             GimpTransformTool  *tr_tool);
78
 
static void   shear_y_mag_changed           (GtkWidget          *widget,
79
 
                                             GimpTransformTool  *tr_tool);
80
 
 
81
 
 
82
 
/*  private variables  */
83
 
 
84
 
static GimpTransformToolClass *parent_class = NULL;
85
 
 
86
 
 
87
 
/*  public functions  */
 
61
                                             GimpDisplay        *display);
 
62
 
 
63
static void   shear_x_mag_changed           (GtkAdjustment      *adj,
 
64
                                             GimpTransformTool  *tr_tool);
 
65
static void   shear_y_mag_changed           (GtkAdjustment      *adj,
 
66
                                             GimpTransformTool  *tr_tool);
 
67
 
 
68
 
 
69
G_DEFINE_TYPE (GimpShearTool, gimp_shear_tool, GIMP_TYPE_TRANSFORM_TOOL)
 
70
 
88
71
 
89
72
void
90
73
gimp_shear_tool_register (GimpToolRegisterCallback  callback,
96
79
                0,
97
80
                "gimp-shear-tool",
98
81
                _("Shear"),
99
 
                _("Shear the layer or selection"),
 
82
                _("Shear Tool: Shear the layer, selection or path"),
100
83
                N_("S_hear"), "<shift>S",
101
84
                NULL, GIMP_HELP_TOOL_SHEAR,
102
85
                GIMP_STOCK_TOOL_SHEAR,
103
86
                data);
104
87
}
105
88
 
106
 
GType
107
 
gimp_shear_tool_get_type (void)
108
 
{
109
 
  static GType tool_type = 0;
110
 
 
111
 
  if (! tool_type)
112
 
    {
113
 
      static const GTypeInfo tool_info =
114
 
      {
115
 
        sizeof (GimpShearToolClass),
116
 
        (GBaseInitFunc) NULL,
117
 
        (GBaseFinalizeFunc) NULL,
118
 
        (GClassInitFunc) gimp_shear_tool_class_init,
119
 
        NULL,           /* class_finalize */
120
 
        NULL,           /* class_data     */
121
 
        sizeof (GimpShearTool),
122
 
        0,              /* n_preallocs    */
123
 
        (GInstanceInitFunc) gimp_shear_tool_init,
124
 
      };
125
 
 
126
 
      tool_type = g_type_register_static (GIMP_TYPE_TRANSFORM_TOOL,
127
 
                                          "GimpShearTool",
128
 
                                          &tool_info, 0);
129
 
    }
130
 
 
131
 
  return tool_type;
132
 
}
133
 
 
134
89
static void
135
90
gimp_shear_tool_class_init (GimpShearToolClass *klass)
136
91
{
137
92
  GimpTransformToolClass *trans_class = GIMP_TRANSFORM_TOOL_CLASS (klass);
138
93
 
139
 
  parent_class = g_type_class_peek_parent (klass);
140
 
 
141
94
  trans_class->dialog        = gimp_shear_tool_dialog;
142
95
  trans_class->dialog_update = gimp_shear_tool_dialog_update;
143
96
  trans_class->prepare       = gimp_shear_tool_prepare;
153
106
 
154
107
  gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_SHEAR);
155
108
 
156
 
  tr_tool->use_center    = FALSE;
157
 
  tr_tool->shell_desc    = _("Shearing Information");
158
 
  tr_tool->progress_text = _("Shearing...");
 
109
  tr_tool->undo_desc     = Q_("command|Shear");
 
110
  tr_tool->progress_text = _("Shearing");
 
111
 
 
112
  tr_tool->use_grid      = TRUE;
159
113
}
160
114
 
161
115
static void
162
116
gimp_shear_tool_dialog (GimpTransformTool *tr_tool)
163
117
{
164
118
  GimpShearTool *shear = GIMP_SHEAR_TOOL (tr_tool);
165
 
 
166
 
  info_dialog_add_spinbutton (tr_tool->info_dialog,
167
 
                              _("Shear magnitude X:"),
168
 
                              &shear->xshear_val,
169
 
                              -65536, 65536, 1, 15, 1, 1, 0,
170
 
                              G_CALLBACK (shear_x_mag_changed),
171
 
                              tr_tool);
172
 
 
173
 
  info_dialog_add_spinbutton (tr_tool->info_dialog,
174
 
                              _("Shear magnitude Y:"),
175
 
                              &shear->yshear_val,
176
 
                              -65536, 65536, 1, 15, 1, 1, 0,
177
 
                              G_CALLBACK (shear_y_mag_changed),
178
 
                              tr_tool);
 
119
  GtkWidget     *table;
 
120
  GtkWidget     *button;
 
121
 
 
122
  table = gtk_table_new (2, 2, FALSE);
 
123
  gtk_container_set_border_width (GTK_CONTAINER (table), 6);
 
124
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
 
125
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
 
126
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (tr_tool->dialog)->vbox), table,
 
127
                      FALSE, FALSE, 0);
 
128
  gtk_widget_show (table);
 
129
 
 
130
  button = gimp_spin_button_new (&shear->x_adj,
 
131
                                 0, -65536, 65536, 1, 15, 1, 1, 0);
 
132
  gtk_entry_set_width_chars (GTK_ENTRY (button), SB_WIDTH);
 
133
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 0, _("Shear magnitude _X:"),
 
134
                             0.0, 0.5, button, 1, TRUE);
 
135
 
 
136
  g_signal_connect (shear->x_adj, "value-changed",
 
137
                    G_CALLBACK (shear_x_mag_changed),
 
138
                    tr_tool);
 
139
 
 
140
  button = gimp_spin_button_new (&shear->y_adj,
 
141
                                 0, -65536, 65536, 1, 15, 1, 1, 0);
 
142
  gtk_entry_set_width_chars (GTK_ENTRY (button), SB_WIDTH);
 
143
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 1, _("Shear magnitude _Y:"),
 
144
                             0.0, 0.5, button, 1, TRUE);
 
145
 
 
146
  g_signal_connect (shear->y_adj, "value-changed",
 
147
                    G_CALLBACK (shear_y_mag_changed),
 
148
                    tr_tool);
179
149
}
180
150
 
181
151
static void
183
153
{
184
154
  GimpShearTool *shear = GIMP_SHEAR_TOOL (tr_tool);
185
155
 
186
 
  shear->xshear_val = tr_tool->trans_info[XSHEAR];
187
 
  shear->yshear_val = tr_tool->trans_info[YSHEAR];
188
 
 
189
 
  info_dialog_update (tr_tool->info_dialog);
190
 
  info_dialog_show (tr_tool->info_dialog);
 
156
  gtk_adjustment_set_value (GTK_ADJUSTMENT (shear->x_adj),
 
157
                            tr_tool->trans_info[XSHEAR]);
 
158
  gtk_adjustment_set_value (GTK_ADJUSTMENT (shear->y_adj),
 
159
                            tr_tool->trans_info[YSHEAR]);
191
160
}
192
161
 
193
162
static void
194
163
gimp_shear_tool_prepare (GimpTransformTool *tr_tool,
195
 
                         GimpDisplay       *gdisp)
 
164
                         GimpDisplay       *display)
196
165
{
197
166
  tr_tool->trans_info[HORZ_OR_VERT] = GIMP_ORIENTATION_UNKNOWN;
198
167
  tr_tool->trans_info[XSHEAR]       = 0.0;
201
170
 
202
171
static void
203
172
gimp_shear_tool_motion (GimpTransformTool *tr_tool,
204
 
                        GimpDisplay       *gdisp)
 
173
                        GimpDisplay       *display)
205
174
{
206
 
  gdouble diffx, diffy;
207
 
  gint    dir;
208
 
 
209
 
  diffx = tr_tool->curx - tr_tool->lastx;
210
 
  diffy = tr_tool->cury - tr_tool->lasty;
 
175
  gdouble diffx = tr_tool->curx - tr_tool->lastx;
 
176
  gdouble diffy = tr_tool->cury - tr_tool->lasty;
211
177
 
212
178
  /*  If we haven't yet decided on which way to control shearing
213
179
   *  decide using the maximum differential
237
203
    }
238
204
 
239
205
  /*  if the direction is known, keep track of the magnitude  */
240
 
  if (tr_tool->trans_info[HORZ_OR_VERT] != GIMP_ORIENTATION_UNKNOWN)
241
 
    {
242
 
      dir = tr_tool->trans_info[HORZ_OR_VERT];
243
 
 
244
 
      switch (tr_tool->function)
245
 
        {
246
 
        case TRANSFORM_HANDLE_1:
247
 
          if (dir == GIMP_ORIENTATION_HORIZONTAL)
248
 
            tr_tool->trans_info[XSHEAR] -= diffx;
249
 
          else
250
 
            tr_tool->trans_info[YSHEAR] -= diffy;
251
 
          break;
252
 
 
253
 
        case TRANSFORM_HANDLE_2:
254
 
          if (dir == GIMP_ORIENTATION_HORIZONTAL)
255
 
            tr_tool->trans_info[XSHEAR] -= diffx;
256
 
          else
257
 
            tr_tool->trans_info[YSHEAR] += diffy;
258
 
          break;
259
 
 
260
 
        case TRANSFORM_HANDLE_3:
261
 
          if (dir == GIMP_ORIENTATION_HORIZONTAL)
262
 
            tr_tool->trans_info[XSHEAR] += diffx;
263
 
          else
264
 
            tr_tool->trans_info[YSHEAR] -= diffy;
265
 
          break;
266
 
 
267
 
        case TRANSFORM_HANDLE_4:
268
 
          if (dir == GIMP_ORIENTATION_HORIZONTAL)
269
 
            tr_tool->trans_info[XSHEAR] += diffx;
270
 
          else
271
 
            tr_tool->trans_info[YSHEAR] += diffy;
272
 
          break;
273
 
 
274
 
        default:
275
 
          break;
276
 
        }
 
206
  if (tr_tool->trans_info[HORZ_OR_VERT] == GIMP_ORIENTATION_HORIZONTAL)
 
207
    {
 
208
      if (tr_tool->cury > (tr_tool->ty1 + tr_tool->ty3) / 2)
 
209
        tr_tool->trans_info[XSHEAR] += diffx;
 
210
      else
 
211
        tr_tool->trans_info[XSHEAR] -= diffx;
 
212
    }
 
213
  else if (tr_tool->trans_info[HORZ_OR_VERT] == GIMP_ORIENTATION_VERTICAL)
 
214
    {
 
215
      if (tr_tool->curx > (tr_tool->tx1 + tr_tool->tx2) / 2)
 
216
        tr_tool->trans_info[YSHEAR] += diffy;
 
217
      else
 
218
        tr_tool->trans_info[YSHEAR] -= diffy;
277
219
    }
278
220
}
279
221
 
280
222
static void
281
223
gimp_shear_tool_recalc (GimpTransformTool *tr_tool,
282
 
                        GimpDisplay       *gdisp)
 
224
                        GimpDisplay       *display)
283
225
{
284
226
  gdouble amount;
285
227
 
286
228
  if (tr_tool->trans_info[XSHEAR] == 0.0 &&
287
229
      tr_tool->trans_info[YSHEAR] == 0.0)
288
 
    tr_tool->trans_info[HORZ_OR_VERT] = GIMP_ORIENTATION_UNKNOWN;
 
230
    {
 
231
      tr_tool->trans_info[HORZ_OR_VERT] = GIMP_ORIENTATION_UNKNOWN;
 
232
    }
289
233
 
290
234
  if (tr_tool->trans_info[HORZ_OR_VERT] == GIMP_ORIENTATION_HORIZONTAL)
291
235
    amount = tr_tool->trans_info[XSHEAR];
292
236
  else
293
237
    amount = tr_tool->trans_info[YSHEAR];
294
238
 
295
 
  gimp_transform_matrix_shear (tr_tool->x1,
 
239
  gimp_matrix3_identity (&tr_tool->transform);
 
240
  gimp_transform_matrix_shear (&tr_tool->transform,
 
241
                               tr_tool->x1,
296
242
                               tr_tool->y1,
297
243
                               tr_tool->x2 - tr_tool->x1,
298
244
                               tr_tool->y2 - tr_tool->y1,
299
245
                               tr_tool->trans_info[HORZ_OR_VERT],
300
 
                               amount,
301
 
                               &tr_tool->transform);
 
246
                               amount);
302
247
}
303
248
 
304
249
static void
305
 
shear_x_mag_changed (GtkWidget         *widget,
 
250
shear_x_mag_changed (GtkAdjustment     *adj,
306
251
                     GimpTransformTool *tr_tool)
307
252
{
308
 
  gdouble value;
309
 
 
310
 
  value = GTK_ADJUSTMENT (widget)->value;
 
253
  gdouble value = gtk_adjustment_get_value (adj);
311
254
 
312
255
  if (value != tr_tool->trans_info[XSHEAR])
313
256
    {
318
261
 
319
262
      tr_tool->trans_info[XSHEAR] = value;
320
263
 
321
 
      gimp_transform_tool_recalc (tr_tool, GIMP_TOOL (tr_tool)->gdisp);
 
264
      gimp_transform_tool_recalc (tr_tool, GIMP_TOOL (tr_tool)->display);
322
265
 
323
266
      gimp_transform_tool_expose_preview (tr_tool);
324
267
 
327
270
}
328
271
 
329
272
static void
330
 
shear_y_mag_changed (GtkWidget         *widget,
 
273
shear_y_mag_changed (GtkAdjustment     *adj,
331
274
                     GimpTransformTool *tr_tool)
332
275
{
333
 
  gdouble value;
334
 
 
335
 
  value = GTK_ADJUSTMENT (widget)->value;
 
276
  gdouble value = gtk_adjustment_get_value (adj);
336
277
 
337
278
  if (value != tr_tool->trans_info[YSHEAR])
338
279
    {
343
284
 
344
285
      tr_tool->trans_info[YSHEAR] = value;
345
286
 
346
 
      gimp_transform_tool_recalc (tr_tool, GIMP_TOOL (tr_tool)->gdisp);
 
287
      gimp_transform_tool_recalc (tr_tool, GIMP_TOOL (tr_tool)->display);
347
288
 
348
289
      gimp_transform_tool_expose_preview (tr_tool);
349
290