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

« back to all changes in this revision

Viewing changes to app/tools/gimpfreeselecttool.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
18
18
 
19
19
#include "config.h"
20
20
 
21
 
#include <stdlib.h>
22
 
#include <string.h>
23
 
 
24
21
#include <gtk/gtk.h>
25
22
 
 
23
#include "libgimpmath/gimpmath.h"
26
24
#include "libgimpwidgets/gimpwidgets.h"
27
25
 
28
 
#include "libgimpmath/gimpmath.h"
29
 
 
30
26
#include "tools-types.h"
31
27
 
32
28
#include "core/gimpchannel.h"
33
29
#include "core/gimpchannel-select.h"
34
30
#include "core/gimpimage.h"
35
31
#include "core/gimplayer-floating-sel.h"
36
 
#include "core/gimptoolinfo.h"
37
32
 
38
33
#include "widgets/gimphelp-ids.h"
39
34
 
49
44
#define DEFAULT_MAX_INC 1024
50
45
 
51
46
 
52
 
static void   gimp_free_select_tool_class_init (GimpFreeSelectToolClass *klass);
53
 
static void   gimp_free_select_tool_init       (GimpFreeSelectTool      *free_select);
54
 
static void   gimp_free_select_tool_finalize       (GObject         *object);
55
 
 
56
 
static void   gimp_free_select_tool_button_press   (GimpTool        *tool,
57
 
                                                    GimpCoords      *coords,
58
 
                                                    guint32          time,
59
 
                                                    GdkModifierType  state,
60
 
                                                    GimpDisplay     *gdisp);
61
 
static void   gimp_free_select_tool_button_release (GimpTool        *tool,
62
 
                                                    GimpCoords      *coords,
63
 
                                                    guint32          time,
64
 
                                                    GdkModifierType  state,
65
 
                                                    GimpDisplay     *gdisp);
66
 
static void   gimp_free_select_tool_motion         (GimpTool        *tool,
67
 
                                                    GimpCoords      *coords,
68
 
                                                    guint32          time,
69
 
                                                    GdkModifierType  state,
70
 
                                                    GimpDisplay     *gdisp);
71
 
 
72
 
static void   gimp_free_select_tool_draw           (GimpDrawTool    *draw_tool);
 
47
static void   gimp_free_select_tool_finalize       (GObject            *object);
 
48
 
 
49
static void   gimp_free_select_tool_control        (GimpTool           *tool,
 
50
                                                    GimpToolAction      action,
 
51
                                                    GimpDisplay        *display);
 
52
static void   gimp_free_select_tool_button_press   (GimpTool           *tool,
 
53
                                                    GimpCoords         *coords,
 
54
                                                    guint32             time,
 
55
                                                    GdkModifierType     state,
 
56
                                                    GimpDisplay        *display);
 
57
static void   gimp_free_select_tool_button_release (GimpTool           *tool,
 
58
                                                    GimpCoords         *coords,
 
59
                                                    guint32             time,
 
60
                                                    GdkModifierType     state,
 
61
                                                    GimpButtonReleaseType release_type,
 
62
                                                    GimpDisplay        *display);
 
63
static void   gimp_free_select_tool_motion         (GimpTool           *tool,
 
64
                                                    GimpCoords         *coords,
 
65
                                                    guint32             time,
 
66
                                                    GdkModifierType     state,
 
67
                                                    GimpDisplay        *display);
 
68
 
 
69
static void   gimp_free_select_tool_draw           (GimpDrawTool       *draw_tool);
 
70
 
 
71
static void   gimp_free_select_tool_real_select    (GimpFreeSelectTool *free_sel,
 
72
                                                    GimpDisplay        *display);
73
73
 
74
74
static void   gimp_free_select_tool_add_point      (GimpFreeSelectTool *free_sel,
75
75
                                                    gdouble             x,
79
79
                                                    gdouble             dy);
80
80
 
81
81
 
82
 
static GimpSelectionToolClass *parent_class = NULL;
83
 
 
84
 
 
85
 
/*  public functions  */
 
82
G_DEFINE_TYPE (GimpFreeSelectTool, gimp_free_select_tool,
 
83
               GIMP_TYPE_SELECTION_TOOL);
 
84
 
 
85
#define parent_class gimp_free_select_tool_parent_class
 
86
 
86
87
 
87
88
void
88
89
gimp_free_select_tool_register (GimpToolRegisterCallback  callback,
94
95
                0,
95
96
                "gimp-free-select-tool",
96
97
                _("Free Select"),
97
 
                _("Select hand-drawn regions"),
 
98
                _("Free Select Tool: Select a hand-drawn region"),
98
99
                N_("_Free Select"), "F",
99
100
                NULL, GIMP_HELP_TOOL_FREE_SELECT,
100
101
                GIMP_STOCK_TOOL_FREE_SELECT,
101
102
                data);
102
103
}
103
104
 
104
 
GType
105
 
gimp_free_select_tool_get_type (void)
106
 
{
107
 
  static GType tool_type = 0;
108
 
 
109
 
  if (! tool_type)
110
 
    {
111
 
      static const GTypeInfo tool_info =
112
 
      {
113
 
        sizeof (GimpFreeSelectToolClass),
114
 
        (GBaseInitFunc) NULL,
115
 
        (GBaseFinalizeFunc) NULL,
116
 
        (GClassInitFunc) gimp_free_select_tool_class_init,
117
 
        NULL,           /* class_finalize */
118
 
        NULL,           /* class_data     */
119
 
        sizeof (GimpFreeSelectTool),
120
 
        0,              /* n_preallocs    */
121
 
        (GInstanceInitFunc) gimp_free_select_tool_init,
122
 
      };
123
 
 
124
 
      tool_type = g_type_register_static (GIMP_TYPE_SELECTION_TOOL,
125
 
                                          "GimpFreeSelectTool",
126
 
                                          &tool_info, 0);
127
 
    }
128
 
 
129
 
  return tool_type;
130
 
}
131
 
 
132
 
/*  private functions  */
133
 
 
134
105
static void
135
106
gimp_free_select_tool_class_init (GimpFreeSelectToolClass *klass)
136
107
{
138
109
  GimpToolClass     *tool_class      = GIMP_TOOL_CLASS (klass);
139
110
  GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
140
111
 
141
 
  parent_class = g_type_class_peek_parent (klass);
142
 
 
143
112
  object_class->finalize     = gimp_free_select_tool_finalize;
144
113
 
 
114
  tool_class->control        = gimp_free_select_tool_control;
145
115
  tool_class->button_press   = gimp_free_select_tool_button_press;
146
116
  tool_class->button_release = gimp_free_select_tool_button_release;
147
117
  tool_class->motion         = gimp_free_select_tool_motion;
148
118
 
149
119
  draw_tool_class->draw      = gimp_free_select_tool_draw;
 
120
 
 
121
  klass->select              = gimp_free_select_tool_real_select;
150
122
}
151
123
 
152
124
static void
154
126
{
155
127
  GimpTool *tool = GIMP_TOOL (free_select);
156
128
 
157
 
  gimp_tool_control_set_scroll_lock (tool->control, TRUE);
 
129
  gimp_tool_control_set_scroll_lock (tool->control, FALSE);
 
130
  gimp_tool_control_set_wants_click (tool->control, TRUE);
158
131
  gimp_tool_control_set_tool_cursor (tool->control,
159
132
                                     GIMP_TOOL_CURSOR_FREE_SELECT);
160
133
 
178
151
}
179
152
 
180
153
static void
 
154
gimp_free_select_tool_control (GimpTool       *tool,
 
155
                               GimpToolAction  action,
 
156
                               GimpDisplay    *display)
 
157
{
 
158
  switch (action)
 
159
    {
 
160
    case GIMP_TOOL_ACTION_PAUSE:
 
161
    case GIMP_TOOL_ACTION_RESUME:
 
162
      break;
 
163
 
 
164
    case GIMP_TOOL_ACTION_HALT:
 
165
      GIMP_FREE_SELECT_TOOL (tool)->num_points = 0;
 
166
      break;
 
167
    }
 
168
 
 
169
  GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
 
170
}
 
171
 
 
172
static void
181
173
gimp_free_select_tool_button_press (GimpTool        *tool,
182
174
                                    GimpCoords      *coords,
183
175
                                    guint32          time,
184
176
                                    GdkModifierType  state,
185
 
                                    GimpDisplay     *gdisp)
 
177
                                    GimpDisplay     *display)
186
178
{
187
179
  GimpFreeSelectTool *free_sel = GIMP_FREE_SELECT_TOOL (tool);
188
180
 
189
181
  gimp_tool_control_activate (tool->control);
190
 
  tool->gdisp = gdisp;
 
182
  tool->display = display;
191
183
 
192
184
  if (gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (free_sel), coords))
193
185
    return;
197
189
 
198
190
  gimp_free_select_tool_add_point (free_sel, coords->x, coords->y);
199
191
 
200
 
  gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), gdisp);
 
192
  gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
201
193
}
202
194
 
203
195
static void
204
 
gimp_free_select_tool_button_release (GimpTool        *tool,
205
 
                                      GimpCoords      *coords,
206
 
                                      guint32          time,
207
 
                                      GdkModifierType  state,
208
 
                                      GimpDisplay     *gdisp)
 
196
gimp_free_select_tool_button_release (GimpTool              *tool,
 
197
                                      GimpCoords            *coords,
 
198
                                      guint32                time,
 
199
                                      GdkModifierType        state,
 
200
                                      GimpButtonReleaseType  release_type,
 
201
                                      GimpDisplay           *display)
209
202
{
210
 
  GimpFreeSelectTool   *free_sel = GIMP_FREE_SELECT_TOOL (tool);
211
 
  GimpSelectionOptions *options;
212
 
 
213
 
  options  = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
 
203
  GimpFreeSelectTool *free_sel = GIMP_FREE_SELECT_TOOL (tool);
214
204
 
215
205
  gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
216
206
 
217
207
  gimp_tool_control_halt (tool->control);
218
208
 
219
 
  /*  First take care of the case where the user "cancels" the action  */
220
 
  if (! (state & GDK_BUTTON3_MASK))
 
209
  switch (release_type)
221
210
    {
222
 
      if (free_sel->num_points == 1)
 
211
    case GIMP_BUTTON_RELEASE_NORMAL:
 
212
      GIMP_FREE_SELECT_TOOL_GET_CLASS (free_sel)->select (free_sel, display);
 
213
      break;
 
214
 
 
215
    case GIMP_BUTTON_RELEASE_CANCEL:
 
216
      return;
 
217
 
 
218
    case GIMP_BUTTON_RELEASE_CLICK:
 
219
    case GIMP_BUTTON_RELEASE_NO_MOTION:
 
220
      if (gimp_image_floating_sel (display->image))
223
221
        {
224
222
          /*  If there is a floating selection, anchor it  */
225
 
          if (gimp_image_floating_sel (gdisp->gimage))
226
 
            floating_sel_anchor (gimp_image_floating_sel (gdisp->gimage));
 
223
          floating_sel_anchor (gimp_image_floating_sel (display->image));
 
224
        }
 
225
      else
 
226
        {
227
227
          /*  Otherwise, clear the selection mask  */
228
 
          else
229
 
            gimp_channel_clear (gimp_image_get_mask (gdisp->gimage), NULL,
230
 
                                TRUE);
231
 
 
232
 
          gimp_image_flush (gdisp->gimage);
233
 
          return;
 
228
          gimp_channel_clear (gimp_image_get_mask (display->image), NULL, TRUE);
234
229
        }
235
 
 
236
 
      gimp_channel_select_polygon (gimp_image_get_mask (gdisp->gimage),
237
 
                                   tool->tool_info->blurb,
238
 
                                   free_sel->num_points,
239
 
                                   free_sel->points,
240
 
                                   GIMP_SELECTION_TOOL (tool)->op,
241
 
                                   options->antialias,
242
 
                                   options->feather,
243
 
                                   options->feather_radius,
244
 
                                   options->feather_radius);
245
 
 
246
 
      gimp_image_flush (gdisp->gimage);
 
230
      break;
247
231
    }
 
232
 
 
233
  gimp_image_flush (display->image);
248
234
}
249
235
 
250
236
static void
252
238
                              GimpCoords      *coords,
253
239
                              guint32          time,
254
240
                              GdkModifierType  state,
255
 
                              GimpDisplay     *gdisp)
 
241
                              GimpDisplay     *display)
256
242
{
257
243
  GimpFreeSelectTool *free_sel = GIMP_FREE_SELECT_TOOL (tool);
258
244
  GimpSelectionTool  *sel_tool = GIMP_SELECTION_TOOL (tool);
259
245
 
260
 
  if (sel_tool->op == SELECTION_ANCHOR)
 
246
  if (sel_tool->function == SELECTION_ANCHOR)
261
247
    {
262
 
      sel_tool->op = SELECTION_REPLACE;
 
248
      sel_tool->function = SELECTION_SELECT;
263
249
 
264
 
      gimp_tool_cursor_update (tool, coords, state, gdisp);
 
250
      gimp_tool_cursor_update (tool, coords, state, display);
265
251
    }
266
252
 
267
253
  if (state & GDK_MOD1_MASK)
293
279
gimp_free_select_tool_draw (GimpDrawTool *draw_tool)
294
280
{
295
281
  GimpFreeSelectTool *free_sel = GIMP_FREE_SELECT_TOOL (draw_tool);
296
 
  gint                i;
297
 
 
298
 
  for (i = 1; i < free_sel->num_points; i++)
299
 
    {
300
 
      gimp_draw_tool_draw_line (draw_tool,
301
 
                                free_sel->points[i - 1].x,
302
 
                                free_sel->points[i - 1].y,
303
 
                                free_sel->points[i].x,
304
 
                                free_sel->points[i].y,
305
 
                                FALSE);
306
 
    }
 
282
 
 
283
  gimp_draw_tool_draw_lines (draw_tool,
 
284
                             (const gdouble *) free_sel->points,
 
285
                             free_sel->num_points,
 
286
                             FALSE, FALSE);
 
287
}
 
288
 
 
289
 
 
290
/*  public functions  */
 
291
 
 
292
void
 
293
gimp_free_select_tool_select (GimpFreeSelectTool *free_sel,
 
294
                              GimpDisplay        *display)
 
295
{
 
296
  g_return_if_fail (GIMP_IS_FREE_SELECT_TOOL (free_sel));
 
297
  g_return_if_fail (GIMP_IS_DISPLAY (display));
 
298
 
 
299
  GIMP_FREE_SELECT_TOOL_GET_CLASS (free_sel)->select (free_sel, display);
 
300
}
 
301
 
 
302
 
 
303
/*  private functions  */
 
304
 
 
305
static void
 
306
gimp_free_select_tool_real_select (GimpFreeSelectTool *free_sel,
 
307
                                   GimpDisplay        *display)
 
308
{
 
309
  GimpSelectionOptions *options = GIMP_SELECTION_TOOL_GET_OPTIONS (free_sel);
 
310
 
 
311
  gimp_channel_select_polygon (gimp_image_get_mask (display->image),
 
312
                               Q_("command|Free Select"),
 
313
                               free_sel->num_points,
 
314
                               free_sel->points,
 
315
                               options->operation,
 
316
                               options->antialias,
 
317
                               options->feather,
 
318
                               options->feather_radius,
 
319
                               options->feather_radius,
 
320
                               TRUE);
307
321
}
308
322
 
309
323
static void