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

« back to all changes in this revision

Viewing changes to app/tools/gimppainttool.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
19
19
#include "config.h"
20
20
 
21
21
#include <gtk/gtk.h>
22
 
#include <gdk/gdkkeysyms.h>
 
22
 
 
23
#include "libgimpmath/gimpmath.h"
23
24
 
24
25
#include "tools-types.h"
25
26
 
26
 
#include "config/gimpdisplayconfig.h"
27
 
 
28
 
#include "base/boundary.h"
29
 
#include "base/pixel-region.h"
30
 
#include "base/temp-buf.h"
31
 
 
32
27
#include "core/gimp.h"
33
 
#include "core/gimpbrush.h"
34
 
#include "core/gimpcontainer.h"
35
28
#include "core/gimpdrawable.h"
36
29
#include "core/gimpimage.h"
37
30
#include "core/gimppaintinfo.h"
39
32
#include "core/gimptoolinfo.h"
40
33
#include "core/gimpunit.h"
41
34
 
42
 
#include "paint/gimpbrushcore.h"
43
35
#include "paint/gimppaintcore.h"
44
36
#include "paint/gimppaintoptions.h"
45
37
 
46
38
#include "widgets/gimpdevices.h"
 
39
#include "widgets/gimpwidgets-utils.h"
47
40
 
48
41
#include "display/gimpdisplay.h"
49
42
#include "display/gimpdisplayshell.h"
50
 
#include "display/gimpstatusbar.h"
51
43
 
52
44
#include "gimpcoloroptions.h"
53
 
#include "gimpcolorpickertool.h"
54
45
#include "gimppainttool.h"
55
46
#include "gimptoolcontrol.h"
56
47
#include "tools-utils.h"
58
49
#include "gimp-intl.h"
59
50
 
60
51
 
61
 
#define TARGET_SIZE    15
62
 
#define STATUSBAR_SIZE 128
63
 
 
64
 
 
65
 
static void   gimp_paint_tool_class_init     (GimpPaintToolClass  *klass);
66
 
static void   gimp_paint_tool_init           (GimpPaintTool       *paint_tool);
67
 
 
68
 
static GObject * gimp_paint_tool_constructor (GType                type,
69
 
                                              guint                n_params,
 
52
#define HANDLE_SIZE    15
 
53
#define STATUSBAR_SIZE 200
 
54
 
 
55
 
 
56
static GObject * gimp_paint_tool_constructor (GType                  type,
 
57
                                              guint                  n_params,
70
58
                                              GObjectConstructParam *params);
71
 
static void   gimp_paint_tool_finalize       (GObject             *object);
72
 
 
73
 
static void   gimp_paint_tool_control        (GimpTool            *tool,
74
 
                                              GimpToolAction       action,
75
 
                                              GimpDisplay         *gdisp);
76
 
static void   gimp_paint_tool_button_press   (GimpTool            *tool,
77
 
                                              GimpCoords          *coords,
78
 
                                              guint32              time,
79
 
                                              GdkModifierType      state,
80
 
                                              GimpDisplay         *gdisp);
81
 
static void   gimp_paint_tool_button_release (GimpTool            *tool,
82
 
                                              GimpCoords          *coords,
83
 
                                              guint32              time,
84
 
                                              GdkModifierType      state,
85
 
                                              GimpDisplay         *gdisp);
86
 
static void   gimp_paint_tool_motion         (GimpTool            *tool,
87
 
                                              GimpCoords          *coords,
88
 
                                              guint32              time,
89
 
                                              GdkModifierType      state,
90
 
                                              GimpDisplay         *gdisp);
91
 
static void   gimp_paint_tool_modifier_key   (GimpTool            *tool,
92
 
                                              GdkModifierType      key,
93
 
                                              gboolean             press,
94
 
                                              GdkModifierType      state,
95
 
                                              GimpDisplay         *gdisp);
96
 
static void   gimp_paint_tool_oper_update    (GimpTool            *tool,
97
 
                                              GimpCoords          *coords,
98
 
                                              GdkModifierType      state,
99
 
                                              GimpDisplay         *gdisp);
100
 
static void   gimp_paint_tool_cursor_update  (GimpTool            *tool,
101
 
                                              GimpCoords          *coords,
102
 
                                              GdkModifierType      state,
103
 
                                              GimpDisplay         *gdisp);
104
 
 
105
 
static void   gimp_paint_tool_draw           (GimpDrawTool        *draw_tool);
106
 
 
107
 
static void   gimp_paint_tool_color_picked   (GimpColorTool       *color_tool,
108
 
                                              GimpColorPickState   pick_state,
109
 
                                              GimpImageType        sample_type,
110
 
                                              GimpRGB             *color,
111
 
                                              gint                 color_index);
112
 
 
113
 
static void   gimp_paint_tool_set_brush      (GimpBrushCore       *brush_core,
114
 
                                              GimpBrush           *brush,
115
 
                                              GimpPaintTool       *paint_tool);
116
 
static void   gimp_paint_tool_set_brush_after(GimpBrushCore       *brush_core,
117
 
                                              GimpBrush           *brush,
118
 
                                              GimpPaintTool       *paint_tool);
119
 
static void   gimp_paint_tool_notify_brush   (GimpDisplayConfig   *config,
120
 
                                              GParamSpec          *pspec,
121
 
                                              GimpPaintTool       *paint_tool);
122
 
 
123
 
 
124
 
static GimpColorToolClass *parent_class = NULL;
125
 
 
126
 
 
127
 
GType
128
 
gimp_paint_tool_get_type (void)
129
 
{
130
 
  static GType tool_type = 0;
131
 
 
132
 
  if (! tool_type)
133
 
    {
134
 
      static const GTypeInfo tool_info =
135
 
      {
136
 
        sizeof (GimpPaintToolClass),
137
 
        (GBaseInitFunc) NULL,
138
 
        (GBaseFinalizeFunc) NULL,
139
 
        (GClassInitFunc) gimp_paint_tool_class_init,
140
 
        NULL,           /* class_finalize */
141
 
        NULL,           /* class_data     */
142
 
        sizeof (GimpPaintTool),
143
 
        0,              /* n_preallocs    */
144
 
        (GInstanceInitFunc) gimp_paint_tool_init,
145
 
      };
146
 
 
147
 
      tool_type = g_type_register_static (GIMP_TYPE_COLOR_TOOL,
148
 
                                          "GimpPaintTool",
149
 
                                          &tool_info, 0);
150
 
    }
151
 
 
152
 
  return tool_type;
153
 
}
 
59
static void   gimp_paint_tool_finalize       (GObject               *object);
 
60
 
 
61
static void   gimp_paint_tool_control        (GimpTool              *tool,
 
62
                                              GimpToolAction         action,
 
63
                                              GimpDisplay           *display);
 
64
static void   gimp_paint_tool_button_press   (GimpTool              *tool,
 
65
                                              GimpCoords            *coords,
 
66
                                              guint32                time,
 
67
                                              GdkModifierType        state,
 
68
                                              GimpDisplay           *display);
 
69
static void   gimp_paint_tool_button_release (GimpTool              *tool,
 
70
                                              GimpCoords            *coords,
 
71
                                              guint32                time,
 
72
                                              GdkModifierType        state,
 
73
                                              GimpButtonReleaseType  release_type,
 
74
                                              GimpDisplay           *display);
 
75
static void   gimp_paint_tool_motion         (GimpTool              *tool,
 
76
                                              GimpCoords            *coords,
 
77
                                              guint32                time,
 
78
                                              GdkModifierType        state,
 
79
                                              GimpDisplay           *display);
 
80
static void   gimp_paint_tool_modifier_key   (GimpTool              *tool,
 
81
                                              GdkModifierType        key,
 
82
                                              gboolean               press,
 
83
                                              GdkModifierType        state,
 
84
                                              GimpDisplay           *display);
 
85
static void   gimp_paint_tool_oper_update    (GimpTool              *tool,
 
86
                                              GimpCoords            *coords,
 
87
                                              GdkModifierType        state,
 
88
                                              gboolean               proximity,
 
89
                                              GimpDisplay           *display);
 
90
 
 
91
static void   gimp_paint_tool_draw           (GimpDrawTool          *draw_tool);
 
92
 
 
93
 
 
94
G_DEFINE_TYPE (GimpPaintTool, gimp_paint_tool, GIMP_TYPE_COLOR_TOOL)
 
95
 
 
96
#define parent_class gimp_paint_tool_parent_class
 
97
 
154
98
 
155
99
static void
156
100
gimp_paint_tool_class_init (GimpPaintToolClass *klass)
157
101
{
158
 
  GObjectClass       *object_class     = G_OBJECT_CLASS (klass);
159
 
  GimpToolClass      *tool_class       = GIMP_TOOL_CLASS (klass);
160
 
  GimpDrawToolClass  *draw_tool_class  = GIMP_DRAW_TOOL_CLASS (klass);
161
 
  GimpColorToolClass *color_tool_class = GIMP_COLOR_TOOL_CLASS (klass);
162
 
 
163
 
  parent_class = g_type_class_peek_parent (klass);
 
102
  GObjectClass      *object_class    = G_OBJECT_CLASS (klass);
 
103
  GimpToolClass     *tool_class      = GIMP_TOOL_CLASS (klass);
 
104
  GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
164
105
 
165
106
  object_class->constructor  = gimp_paint_tool_constructor;
166
107
  object_class->finalize     = gimp_paint_tool_finalize;
171
112
  tool_class->motion         = gimp_paint_tool_motion;
172
113
  tool_class->modifier_key   = gimp_paint_tool_modifier_key;
173
114
  tool_class->oper_update    = gimp_paint_tool_oper_update;
174
 
  tool_class->cursor_update  = gimp_paint_tool_cursor_update;
175
115
 
176
116
  draw_tool_class->draw      = gimp_paint_tool_draw;
177
 
 
178
 
  color_tool_class->picked   = gimp_paint_tool_color_picked;
179
117
}
180
118
 
181
119
static void
184
122
  GimpTool *tool = GIMP_TOOL (paint_tool);
185
123
 
186
124
  gimp_tool_control_set_motion_mode (tool->control, GIMP_MOTION_MODE_EXACT);
 
125
  gimp_tool_control_set_scroll_lock (tool->control, TRUE);
 
126
  gimp_tool_control_set_action_value_1 (tool->control,
 
127
                                        "context/context-opacity-set");
187
128
 
188
129
  paint_tool->pick_colors = FALSE;
189
130
  paint_tool->draw_line   = FALSE;
190
131
 
191
 
  paint_tool->show_cursor = TRUE;
192
 
  paint_tool->draw_brush  = TRUE;
193
 
  paint_tool->brush_x     = 0.0;
194
 
  paint_tool->brush_y     = 0.0;
 
132
  paint_tool->status      = _("Click to paint");
 
133
  paint_tool->status_line = _("Click to draw the line");
 
134
  paint_tool->status_ctrl = _("%s to pick a color");
195
135
 
196
136
  paint_tool->core        = NULL;
197
137
}
203
143
{
204
144
  GObject       *object;
205
145
  GimpTool      *tool;
 
146
  GimpPaintInfo *paint_info;
206
147
  GimpPaintTool *paint_tool;
207
148
 
208
149
  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
211
152
  paint_tool = GIMP_PAINT_TOOL (object);
212
153
 
213
154
  g_assert (GIMP_IS_TOOL_INFO (tool->tool_info));
214
 
 
215
 
  paint_tool->show_cursor =
216
 
    GIMP_DISPLAY_CONFIG (tool->tool_info->gimp->config)->show_paint_tool_cursor;
217
 
  paint_tool->draw_brush =
218
 
    GIMP_DISPLAY_CONFIG (tool->tool_info->gimp->config)->show_brush_outline;
219
 
 
220
 
  g_signal_connect_object (tool->tool_info->gimp->config,
221
 
                           "notify::show-paint-tool-cursor",
222
 
                           G_CALLBACK (gimp_paint_tool_notify_brush),
223
 
                           paint_tool, 0);
224
 
  g_signal_connect_object (tool->tool_info->gimp->config,
225
 
                           "notify::show-brush-outline",
226
 
                           G_CALLBACK (gimp_paint_tool_notify_brush),
227
 
                           paint_tool, 0);
228
 
 
229
 
  paint_tool->core = g_object_new (tool->tool_info->paint_info->paint_type,
 
155
  g_assert (GIMP_IS_PAINT_INFO (tool->tool_info->paint_info));
 
156
 
 
157
  paint_info = tool->tool_info->paint_info;
 
158
 
 
159
  g_assert (g_type_is_a (paint_info->paint_type, GIMP_TYPE_PAINT_CORE));
 
160
 
 
161
  paint_tool->core = g_object_new (paint_info->paint_type,
 
162
                                   "undo-desc", paint_info->blurb,
230
163
                                   NULL);
231
164
 
232
 
  if (GIMP_IS_BRUSH_CORE (paint_tool->core))
233
 
    {
234
 
      g_signal_connect       (paint_tool->core, "set-brush",
235
 
                              G_CALLBACK (gimp_paint_tool_set_brush),
236
 
                              paint_tool);
237
 
      g_signal_connect_after (paint_tool->core, "set-brush",
238
 
                              G_CALLBACK (gimp_paint_tool_set_brush_after),
239
 
                              paint_tool);
240
 
   }
241
 
 
242
165
  return object;
243
166
}
244
167
 
277
200
  GIMP_COLOR_TOOL (tool)->pick_mode = mode;
278
201
}
279
202
 
280
 
 
281
203
static void
282
204
gimp_paint_tool_control (GimpTool       *tool,
283
 
                         GimpToolAction  action,
284
 
                         GimpDisplay    *gdisp)
 
205
                         GimpToolAction  action,
 
206
                         GimpDisplay    *display)
285
207
{
286
208
  GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
287
209
  GimpDrawable  *drawable;
288
210
 
289
 
  drawable = gimp_image_active_drawable (gdisp->gimage);
 
211
  drawable = gimp_image_active_drawable (display->image);
290
212
 
291
213
  switch (action)
292
214
    {
293
 
    case HALT:
 
215
    case GIMP_TOOL_ACTION_PAUSE:
 
216
    case GIMP_TOOL_ACTION_RESUME:
 
217
      break;
 
218
 
 
219
    case GIMP_TOOL_ACTION_HALT:
294
220
      gimp_paint_core_paint (paint_tool->core,
295
221
                             drawable,
296
 
                             GIMP_PAINT_OPTIONS (tool->tool_info->tool_options),
 
222
                             GIMP_PAINT_TOOL_GET_OPTIONS (tool),
297
223
                             GIMP_PAINT_STATE_FINISH, 0);
298
224
      gimp_paint_core_cleanup (paint_tool->core);
299
 
 
300
 
#if 0
301
 
      /*  evil hack i'm thinking about...  --mitch  */
302
 
      {
303
 
        /*  HALT means the current display is going to go away (TM),
304
 
         *  so try to find another display of the same image to make
305
 
         *  straight line drawing continue to work...
306
 
         */
307
 
 
308
 
        GSList *list;
309
 
 
310
 
        for (list = display_list; list; list = g_slist_next (list))
311
 
          {
312
 
            GimpDisplay *tmp_disp;
313
 
 
314
 
            tmp_disp = (GimpDisplay *) list->data;
315
 
 
316
 
            if (tmp_disp != gdisp && tmp_disp->gimage == gdisp->gimage)
317
 
              {
318
 
                tool->gdisp = tmp_disp;
319
 
                break;
320
 
              }
321
 
          }
322
 
      }
323
 
#endif
324
 
      break;
325
 
 
326
 
    default:
327
225
      break;
328
226
    }
329
227
 
330
 
  GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
 
228
  GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
331
229
}
332
230
 
333
231
/**
367
265
gimp_paint_tool_button_press (GimpTool        *tool,
368
266
                              GimpCoords      *coords,
369
267
                              guint32          time,
370
 
                              GdkModifierType  state,
371
 
                              GimpDisplay     *gdisp)
 
268
                              GdkModifierType  state,
 
269
                              GimpDisplay     *display)
372
270
{
373
 
  GimpDrawTool     *draw_tool  = GIMP_DRAW_TOOL (tool);
374
 
  GimpPaintTool    *paint_tool = GIMP_PAINT_TOOL (tool);
375
 
  GimpPaintOptions *paint_options;
376
 
  GimpPaintCore    *core;
 
271
  GimpDrawTool     *draw_tool     = GIMP_DRAW_TOOL (tool);
 
272
  GimpPaintTool    *paint_tool    = GIMP_PAINT_TOOL (tool);
 
273
  GimpPaintOptions *paint_options = GIMP_PAINT_TOOL_GET_OPTIONS (tool);
 
274
  GimpPaintCore    *core          = paint_tool->core;
377
275
  GimpDrawable     *drawable;
378
276
  GdkDisplay       *gdk_display;
379
277
  GimpCoords        curr_coords;
380
278
  gint              off_x, off_y;
381
 
 
382
 
  paint_options = GIMP_PAINT_OPTIONS (tool->tool_info->tool_options);
383
 
 
384
 
  core = paint_tool->core;
385
 
 
386
 
  drawable = gimp_image_active_drawable (gdisp->gimage);
 
279
  GError           *error = NULL;
 
280
 
 
281
  if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
 
282
    {
 
283
      GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state,
 
284
                                                    display);
 
285
      return;
 
286
    }
 
287
 
 
288
  drawable = gimp_image_active_drawable (display->image);
387
289
 
388
290
  curr_coords = *coords;
389
291
 
395
297
  if (gimp_draw_tool_is_active (draw_tool))
396
298
    gimp_draw_tool_stop (draw_tool);
397
299
 
398
 
  if (tool->gdisp          &&
399
 
      tool->gdisp != gdisp &&
400
 
      tool->gdisp->gimage == gdisp->gimage)
 
300
  if (tool->display          &&
 
301
      tool->display != display &&
 
302
      tool->display->image == display->image)
401
303
    {
402
304
      /*  if this is a different display, but the same image, HACK around
403
305
       *  in tool internals AFTER stopping the current draw_tool, so
405
307
       *  same image.
406
308
       */
407
309
 
408
 
      tool->gdisp = gdisp;
 
310
      tool->display = display;
409
311
    }
410
312
 
411
 
  gdk_display = gtk_widget_get_display (gdisp->shell);
 
313
  gdk_display = gtk_widget_get_display (display->shell);
412
314
 
413
 
  core->use_pressure = (gimp_devices_get_current (gdisp->gimage->gimp) !=
 
315
  core->use_pressure = (gimp_devices_get_current (display->image->gimp) !=
414
316
                        gdk_display_get_core_pointer (gdk_display));
415
317
 
416
 
  if (! gimp_paint_core_start (core, drawable, paint_options, &curr_coords))
417
 
    return;
 
318
  if (! gimp_paint_core_start (core, drawable, paint_options, &curr_coords,
 
319
                               &error))
 
320
    {
 
321
      gimp_tool_message (tool, display, error->message);
 
322
      g_clear_error (&error);
 
323
      return;
 
324
    }
418
325
 
419
 
  if ((gdisp != tool->gdisp) || ! paint_tool->draw_line)
 
326
  if ((display != tool->display) || ! paint_tool->draw_line)
420
327
    {
421
328
      /*  if this is a new image, reinit the core vals  */
422
329
 
440
347
      gimp_paint_tool_round_line (core, hard, state);
441
348
    }
442
349
 
443
 
  /*  let the parent class activate the tool  */
444
 
  GIMP_TOOL_CLASS (parent_class)->button_press (tool,
445
 
                                                coords, time, state, gdisp);
446
 
 
447
 
  if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
448
 
    return;
 
350
  /*  chain up to activate the tool  */
 
351
  GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state,
 
352
                                                display);
449
353
 
450
354
  /*  pause the current selection  */
451
 
  gimp_image_selection_control (gdisp->gimage, GIMP_SELECTION_PAUSE);
 
355
  gimp_image_selection_control (display->image, GIMP_SELECTION_PAUSE);
452
356
 
453
357
  /*  Let the specific painting function initialize itself  */
454
358
  gimp_paint_core_paint (core, drawable, paint_options,
465
369
                             GIMP_PAINT_STATE_MOTION, time);
466
370
    }
467
371
 
468
 
  gimp_projection_flush_now (gdisp->gimage->projection);
469
 
  gimp_display_flush_now (gdisp);
 
372
  gimp_projection_flush_now (display->image->projection);
 
373
  gimp_display_flush_now (display);
470
374
 
471
 
  gimp_draw_tool_start (draw_tool, gdisp);
 
375
  gimp_draw_tool_start (draw_tool, display);
472
376
}
473
377
 
474
378
static void
475
 
gimp_paint_tool_button_release (GimpTool        *tool,
476
 
                                GimpCoords      *coords,
477
 
                                guint32          time,
478
 
                                GdkModifierType  state,
479
 
                                GimpDisplay     *gdisp)
 
379
gimp_paint_tool_button_release (GimpTool              *tool,
 
380
                                GimpCoords            *coords,
 
381
                                guint32                time,
 
382
                                GdkModifierType        state,
 
383
                                GimpButtonReleaseType  release_type,
 
384
                                GimpDisplay           *display)
480
385
{
481
 
  GimpPaintTool    *paint_tool = GIMP_PAINT_TOOL (tool);
482
 
  GimpPaintOptions *paint_options;
483
 
  GimpPaintCore    *core;
 
386
  GimpPaintTool    *paint_tool    = GIMP_PAINT_TOOL (tool);
 
387
  GimpPaintOptions *paint_options = GIMP_PAINT_TOOL_GET_OPTIONS (tool);
 
388
  GimpPaintCore    *core          = paint_tool->core;
484
389
  GimpDrawable     *drawable;
485
390
 
486
 
  paint_options = GIMP_PAINT_OPTIONS (tool->tool_info->tool_options);
487
 
 
488
 
  core = paint_tool->core;
489
 
 
490
 
  drawable = gimp_image_active_drawable (gdisp->gimage);
 
391
  if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
 
392
    {
 
393
      GIMP_TOOL_CLASS (parent_class)->button_release (tool, coords, time,
 
394
                                                      state, release_type,
 
395
                                                      display);
 
396
      return;
 
397
    }
 
398
 
 
399
  drawable = gimp_image_active_drawable (display->image);
491
400
 
492
401
  gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
493
402
 
496
405
                         GIMP_PAINT_STATE_FINISH, time);
497
406
 
498
407
  /*  resume the current selection  */
499
 
  gimp_image_selection_control (gdisp->gimage, GIMP_SELECTION_RESUME);
 
408
  gimp_image_selection_control (display->image, GIMP_SELECTION_RESUME);
500
409
 
501
410
  /*  chain up to halt the tool */
502
 
  GIMP_TOOL_CLASS (parent_class)->button_release (tool,
503
 
                                                  coords, time, state, gdisp);
 
411
  GIMP_TOOL_CLASS (parent_class)->button_release (tool, coords, time, state,
 
412
                                                  release_type, display);
504
413
 
505
 
  if (state & GDK_BUTTON3_MASK)
 
414
  if (release_type == GIMP_BUTTON_RELEASE_CANCEL)
506
415
    gimp_paint_core_cancel (core, drawable);
507
416
  else
508
417
    gimp_paint_core_finish (core, drawable);
509
418
 
510
 
  gimp_image_flush (gdisp->gimage);
 
419
  gimp_image_flush (display->image);
511
420
 
512
421
  gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
513
422
}
516
425
gimp_paint_tool_motion (GimpTool        *tool,
517
426
                        GimpCoords      *coords,
518
427
                        guint32          time,
519
 
                        GdkModifierType  state,
520
 
                        GimpDisplay     *gdisp)
 
428
                        GdkModifierType  state,
 
429
                        GimpDisplay     *display)
521
430
{
522
 
  GimpPaintTool    *paint_tool = GIMP_PAINT_TOOL (tool);
523
 
  GimpPaintOptions *paint_options;
524
 
  GimpPaintCore    *core;
 
431
  GimpPaintTool    *paint_tool    = GIMP_PAINT_TOOL (tool);
 
432
  GimpPaintOptions *paint_options = GIMP_PAINT_TOOL_GET_OPTIONS (tool);
 
433
  GimpPaintCore    *core          = paint_tool->core;
525
434
  GimpDrawable     *drawable;
526
435
  gint              off_x, off_y;
527
436
 
528
 
  paint_options = GIMP_PAINT_OPTIONS (tool->tool_info->tool_options);
529
 
 
530
 
  core = paint_tool->core;
531
 
 
532
 
  drawable = gimp_image_active_drawable (gdisp->gimage);
 
437
  if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
 
438
    {
 
439
      GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state,
 
440
                                              display);
 
441
      return;
 
442
    }
 
443
 
 
444
  drawable = gimp_image_active_drawable (display->image);
533
445
 
534
446
  core->cur_coords = *coords;
535
447
 
538
450
  core->cur_coords.x -= off_x;
539
451
  core->cur_coords.y -= off_y;
540
452
 
541
 
  GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state, gdisp);
542
 
 
543
 
  if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
544
 
    return;
 
453
  GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state,
 
454
                                          display);
545
455
 
546
456
  gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
547
457
 
548
458
  gimp_paint_core_interpolate (core, drawable, paint_options, time);
549
459
 
550
 
  gimp_projection_flush_now (gdisp->gimage->projection);
551
 
  gimp_display_flush_now (gdisp);
552
 
 
553
 
  paint_tool->brush_x = coords->x;
554
 
  paint_tool->brush_y = coords->y;
 
460
  gimp_projection_flush_now (display->image->projection);
 
461
  gimp_display_flush_now (display);
555
462
 
556
463
  gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
557
464
}
561
468
                              GdkModifierType  key,
562
469
                              gboolean         press,
563
470
                              GdkModifierType  state,
564
 
                              GimpDisplay     *gdisp)
 
471
                              GimpDisplay     *display)
565
472
{
566
473
  GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
567
474
  GimpDrawTool  *draw_tool  = GIMP_DRAW_TOOL (tool);
573
480
    {
574
481
      if (press)
575
482
        {
576
 
          GimpContainer *tool_info_list;
577
 
          GimpToolInfo  *info;
578
 
 
579
 
          tool_info_list = gdisp->gimage->gimp->tool_info_list;
580
 
 
581
 
          info = (GimpToolInfo *)
582
 
            gimp_container_get_child_by_name (tool_info_list,
583
 
                                              "gimp-color-picker-tool");
 
483
          GimpToolInfo *info = gimp_get_tool_info (display->image->gimp,
 
484
                                                   "gimp-color-picker-tool");
584
485
 
585
486
          if (GIMP_IS_TOOL_INFO (info))
586
487
            {
589
490
 
590
491
              gimp_color_tool_enable (GIMP_COLOR_TOOL (tool),
591
492
                                      GIMP_COLOR_OPTIONS (info->tool_options));
 
493
 
 
494
              switch (GIMP_COLOR_TOOL (tool)->pick_mode)
 
495
                {
 
496
                case GIMP_COLOR_PICK_MODE_FOREGROUND:
 
497
                  gimp_tool_push_status (tool, display,
 
498
                                         _("Click in any image to pick the "
 
499
                                           "foreground color"));
 
500
                  break;
 
501
 
 
502
                case GIMP_COLOR_PICK_MODE_BACKGROUND:
 
503
                  gimp_tool_push_status (tool, display,
 
504
                                         _("Click in any image to pick the "
 
505
                                           "background color"));
 
506
                  break;
 
507
 
 
508
                default:
 
509
                  break;
 
510
                }
592
511
            }
593
512
        }
594
513
      else
595
514
        {
596
515
          if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
597
 
            gimp_color_tool_disable (GIMP_COLOR_TOOL (tool));
 
516
            {
 
517
              gimp_tool_pop_status (tool, display);
 
518
              gimp_color_tool_disable (GIMP_COLOR_TOOL (tool));
 
519
            }
598
520
        }
599
521
    }
600
522
}
603
525
gimp_paint_tool_oper_update (GimpTool        *tool,
604
526
                             GimpCoords      *coords,
605
527
                             GdkModifierType  state,
606
 
                             GimpDisplay     *gdisp)
 
528
                             gboolean         proximity,
 
529
                             GimpDisplay     *display)
607
530
{
608
 
  GimpPaintTool    *paint_tool = GIMP_PAINT_TOOL (tool);
609
 
  GimpDrawTool     *draw_tool  = GIMP_DRAW_TOOL (tool);
610
 
  GimpPaintOptions *paint_options;
611
 
  GimpPaintCore    *core;
612
 
  GimpDisplayShell *shell;
 
531
  GimpPaintTool    *paint_tool    = GIMP_PAINT_TOOL (tool);
 
532
  GimpDrawTool     *draw_tool     = GIMP_DRAW_TOOL (tool);
 
533
  GimpPaintOptions *paint_options = GIMP_PAINT_TOOL_GET_OPTIONS (tool);
 
534
  GimpPaintCore    *core          = paint_tool->core;
 
535
  GimpDisplayShell *shell         = GIMP_DISPLAY_SHELL (display->shell);
613
536
  GimpDrawable     *drawable;
614
537
 
615
 
  paint_options = GIMP_PAINT_OPTIONS (tool->tool_info->tool_options);
616
 
 
617
 
  if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (draw_tool)))
 
538
  if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
618
539
    {
619
 
      GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, gdisp);
 
540
      GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state,
 
541
                                                   proximity, display);
620
542
      return;
621
543
    }
622
544
 
623
 
  core = paint_tool->core;
624
 
 
625
 
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);
626
 
 
627
545
  if (gimp_draw_tool_is_active (draw_tool))
628
546
    gimp_draw_tool_stop (draw_tool);
629
547
 
630
 
  gimp_statusbar_pop (GIMP_STATUSBAR (shell->statusbar),
631
 
                      g_type_name (G_TYPE_FROM_INSTANCE (tool)));
 
548
  gimp_tool_pop_status (tool, display);
632
549
 
633
 
  if (tool->gdisp          &&
634
 
      tool->gdisp != gdisp &&
635
 
      tool->gdisp->gimage == gdisp->gimage)
 
550
  if (tool->display          &&
 
551
      tool->display != display &&
 
552
      tool->display->image == display->image)
636
553
    {
637
554
      /*  if this is a different display, but the same image, HACK around
638
555
       *  in tool internals AFTER stopping the current draw_tool, so
640
557
       *  same image.
641
558
       */
642
559
 
643
 
      tool->gdisp = gdisp;
 
560
      tool->display = display;
644
561
    }
645
562
 
646
 
  drawable = gimp_image_active_drawable (gdisp->gimage);
 
563
  drawable = gimp_image_active_drawable (display->image);
647
564
 
648
 
  if (drawable && shell->proximity)
 
565
  if (drawable && proximity)
649
566
    {
650
 
      if (gdisp == tool->gdisp && (state & GDK_SHIFT_MASK))
 
567
      if (display == tool->display && (state & GDK_SHIFT_MASK))
651
568
        {
652
569
          /*  If shift is down and this is not the first paint stroke,
653
 
           *  draw a line
 
570
           *  draw a line.
654
571
           */
655
572
 
656
 
          gdouble  dx, dy, dist;
657
 
          gchar    status_str[STATUSBAR_SIZE];
658
 
          gint     off_x, off_y;
659
 
          gboolean hard;
 
573
          gchar    *status_help;
 
574
          gdouble   dx, dy, dist;
 
575
          gint      off_x, off_y;
 
576
          gboolean  hard;
660
577
 
661
578
          core->cur_coords = *coords;
662
579
 
672
589
          dx = core->cur_coords.x - core->last_coords.x;
673
590
          dy = core->cur_coords.y - core->last_coords.y;
674
591
 
 
592
          status_help = gimp_suggest_modifiers (paint_tool->status_line,
 
593
                                                GDK_CONTROL_MASK & ~state,
 
594
                                                NULL,
 
595
                                                _("%s for constrained angles"),
 
596
                                                NULL);
 
597
 
675
598
          /*  show distance in statusbar  */
676
599
          if (shell->unit == GIMP_UNIT_PIXEL)
677
600
            {
678
601
              dist = sqrt (SQR (dx) + SQR (dy));
679
602
 
680
 
              g_snprintf (status_str, sizeof (status_str), "%.1f %s",
681
 
                          dist, _("pixels"));
 
603
              gimp_tool_push_status (tool, display, "%.1f %s.  %s",
 
604
                                     dist, _("pixels"), status_help);
682
605
            }
683
606
          else
684
607
            {
685
 
              GimpImage *image = gdisp->gimage;
 
608
              GimpImage *image = display->image;
686
609
              gchar      format_str[64];
687
610
 
688
 
              g_snprintf (format_str, sizeof (format_str), "%%.%df %s",
 
611
              g_snprintf (format_str, sizeof (format_str), "%%.%df %s.  %%s",
689
612
                          _gimp_unit_get_digits (image->gimp, shell->unit),
690
613
                          _gimp_unit_get_symbol (image->gimp, shell->unit));
691
614
 
693
616
                      sqrt (SQR (dx / image->xresolution) +
694
617
                            SQR (dy / image->yresolution)));
695
618
 
696
 
              g_snprintf (status_str, sizeof (status_str), format_str, dist);
 
619
              gimp_tool_push_status (tool, display, format_str,
 
620
                                     dist, status_help);
697
621
            }
698
622
 
699
 
          gimp_statusbar_push (GIMP_STATUSBAR (shell->statusbar),
700
 
                               g_type_name (G_TYPE_FROM_INSTANCE (tool)),
701
 
                               status_str);
 
623
          g_free (status_help);
702
624
 
703
625
          paint_tool->draw_line = TRUE;
704
626
        }
705
627
      else
706
628
        {
 
629
          gchar           *status;
 
630
          GdkModifierType  modifiers = 0;
 
631
 
 
632
          /* HACK: A paint tool may set status_ctrl to NULL to indicate that
 
633
           * it ignores the Ctrl modifier (temporarily or permanently), so
 
634
           * it should not be suggested.  This is different from how
 
635
           * gimp_suggest_modifiers() would interpret this parameter.
 
636
           */
 
637
          if (paint_tool->status_ctrl != NULL)
 
638
            modifiers |= GDK_CONTROL_MASK;
 
639
 
 
640
          /* suggest drawing lines only after the first point is set
 
641
           */
 
642
          if (display == tool->display)
 
643
            modifiers |= GDK_SHIFT_MASK;
 
644
 
 
645
          status = gimp_suggest_modifiers (paint_tool->status,
 
646
                                           modifiers & ~state,
 
647
                                           _("%s for a straight line"),
 
648
                                           paint_tool->status_ctrl,
 
649
                                           NULL);
 
650
          gimp_tool_push_status (tool, display, status);
 
651
          g_free (status);
 
652
 
707
653
          paint_tool->draw_line = FALSE;
708
654
        }
709
655
 
710
 
      paint_tool->brush_x = coords->x;
711
 
      paint_tool->brush_y = coords->y;
712
 
 
713
 
      if (GIMP_IS_BRUSH_CORE (core))
714
 
        {
715
 
          GimpBrushCore *brush_core = GIMP_BRUSH_CORE (core);
716
 
          GimpBrush     *brush;
717
 
 
718
 
          brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options));
719
 
 
720
 
          if (brush_core->main_brush != brush)
721
 
            gimp_brush_core_set_brush (brush_core, brush);
722
 
        }
723
 
 
724
 
      gimp_draw_tool_start (draw_tool, gdisp);
 
656
      gimp_draw_tool_start (draw_tool, display);
725
657
    }
726
658
 
727
 
  GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, gdisp);
 
659
  GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, proximity,
 
660
                                               display);
728
661
}
729
662
 
730
663
static void
743
676
                                      GIMP_HANDLE_CROSS,
744
677
                                      core->last_coords.x,
745
678
                                      core->last_coords.y,
746
 
                                      TARGET_SIZE,
747
 
                                      TARGET_SIZE,
 
679
                                      HANDLE_SIZE,
 
680
                                      HANDLE_SIZE,
748
681
                                      GTK_ANCHOR_CENTER,
749
682
                                      TRUE);
750
683
 
753
686
                                      GIMP_HANDLE_CROSS,
754
687
                                      core->cur_coords.x,
755
688
                                      core->cur_coords.y,
756
 
                                      TARGET_SIZE,
757
 
                                      TARGET_SIZE,
 
689
                                      HANDLE_SIZE,
 
690
                                      HANDLE_SIZE,
758
691
                                      GTK_ANCHOR_CENTER,
759
692
                                      TRUE);
760
693
 
766
699
                                    core->cur_coords.y,
767
700
                                    TRUE);
768
701
        }
769
 
 
770
 
      if (paint_tool->draw_brush && GIMP_IS_BRUSH_CORE (core))
771
 
        {
772
 
          GimpBrushCore *brush_core = GIMP_BRUSH_CORE (core);
773
 
 
774
 
          if (! brush_core->brush_bound_segs)
775
 
            {
776
 
              TempBuf     *mask;
777
 
              PixelRegion  PR = { 0, };
778
 
 
779
 
              mask = gimp_brush_get_mask (brush_core->main_brush);
780
 
 
781
 
              PR.data      = temp_buf_data (mask);
782
 
              PR.x         = 0;
783
 
              PR.y         = 0;
784
 
              PR.w         = mask->width;
785
 
              PR.h         = mask->height;
786
 
              PR.bytes     = mask->bytes;
787
 
              PR.rowstride = PR.w * PR.bytes;
788
 
 
789
 
              brush_core->brush_bound_segs =
790
 
                find_mask_boundary (&PR, &brush_core->n_brush_bound_segs,
791
 
                                    WithinBounds,
792
 
                                    0, 0,
793
 
                                    PR.w, PR.h,
794
 
                                    0);
795
 
 
796
 
              brush_core->brush_bound_width  = mask->width;
797
 
              brush_core->brush_bound_height = mask->height;
798
 
            }
799
 
 
800
 
          if (brush_core->brush_bound_segs)
801
 
            {
802
 
              GimpTool         *tool = GIMP_TOOL (draw_tool);
803
 
              GimpPaintOptions *paint_options;
804
 
              gdouble           brush_x, brush_y;
805
 
 
806
 
              paint_options = GIMP_PAINT_OPTIONS (tool->tool_info->tool_options);
807
 
 
808
 
              brush_x = (paint_tool->brush_x -
809
 
                         ((gdouble) brush_core->brush_bound_width  / 2.0));
810
 
              brush_y = (paint_tool->brush_y -
811
 
                         ((gdouble) brush_core->brush_bound_height / 2.0));
812
 
 
813
 
              if (gimp_paint_options_get_brush_mode (paint_options) == GIMP_BRUSH_HARD)
814
 
                {
815
 
#define EPSILON 0.000001
816
 
 
817
 
                  /*  Add EPSILON before rounding since e.g.
818
 
                   *  (5.0 - 0.5) may end up at (4.499999999....)
819
 
                   *  due to floating point fnords
820
 
                   */
821
 
                  brush_x = RINT (brush_x + EPSILON);
822
 
                  brush_y = RINT (brush_y + EPSILON);
823
 
 
824
 
#undef EPSILON
825
 
                }
826
 
 
827
 
              gimp_draw_tool_draw_boundary (draw_tool,
828
 
                                            brush_core->brush_bound_segs,
829
 
                                            brush_core->n_brush_bound_segs,
830
 
                                            brush_x,
831
 
                                            brush_y,
832
 
                                            FALSE);
833
 
            }
834
 
        }
835
702
    }
836
703
 
837
704
  GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
838
705
}
839
 
 
840
 
static void
841
 
gimp_paint_tool_cursor_update (GimpTool        *tool,
842
 
                               GimpCoords      *coords,
843
 
                               GdkModifierType  state,
844
 
                               GimpDisplay     *gdisp)
845
 
{
846
 
  GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
847
 
 
848
 
  if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)) &&
849
 
      ! paint_tool->show_cursor)
850
 
    {
851
 
      gimp_tool_set_cursor (tool, gdisp,
852
 
                            GIMP_CURSOR_NONE,
853
 
                            GIMP_TOOL_CURSOR_NONE,
854
 
                            GIMP_CURSOR_MODIFIER_NONE);
855
 
 
856
 
      return;
857
 
    }
858
 
 
859
 
  GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, gdisp);
860
 
}
861
 
 
862
 
static void
863
 
gimp_paint_tool_color_picked (GimpColorTool      *color_tool,
864
 
                              GimpColorPickState  pick_state,
865
 
                              GimpImageType       sample_type,
866
 
                              GimpRGB            *color,
867
 
                              gint                color_index)
868
 
{
869
 
  GimpTool *tool = GIMP_TOOL (color_tool);
870
 
 
871
 
  if (tool->gdisp)
872
 
    {
873
 
      GimpContext *context;
874
 
 
875
 
      context = gimp_get_user_context (tool->gdisp->gimage->gimp);
876
 
 
877
 
      switch (color_tool->pick_mode)
878
 
        {
879
 
        case GIMP_COLOR_PICK_MODE_NONE:
880
 
          break;
881
 
 
882
 
        case GIMP_COLOR_PICK_MODE_FOREGROUND:
883
 
          gimp_context_set_foreground (context, color);
884
 
          break;
885
 
 
886
 
        case GIMP_COLOR_PICK_MODE_BACKGROUND:
887
 
          gimp_context_set_background (context, color);
888
 
          break;
889
 
        }
890
 
    }
891
 
}
892
 
 
893
 
static void
894
 
gimp_paint_tool_set_brush (GimpBrushCore *brush_core,
895
 
                           GimpBrush     *brush,
896
 
                           GimpPaintTool *paint_tool)
897
 
{
898
 
  gimp_draw_tool_pause (GIMP_DRAW_TOOL (paint_tool));
899
 
}
900
 
 
901
 
static void
902
 
gimp_paint_tool_set_brush_after (GimpBrushCore *brush_core,
903
 
                                 GimpBrush     *brush,
904
 
                                 GimpPaintTool *paint_tool)
905
 
{
906
 
  gimp_draw_tool_resume (GIMP_DRAW_TOOL (paint_tool));
907
 
}
908
 
 
909
 
static void
910
 
gimp_paint_tool_notify_brush (GimpDisplayConfig *config,
911
 
                              GParamSpec        *pspec,
912
 
                              GimpPaintTool     *paint_tool)
913
 
{
914
 
  gimp_draw_tool_pause (GIMP_DRAW_TOOL (paint_tool));
915
 
 
916
 
  paint_tool->show_cursor = config->show_paint_tool_cursor;
917
 
  paint_tool->draw_brush  = config->show_brush_outline;
918
 
 
919
 
  gimp_draw_tool_resume (GIMP_DRAW_TOOL (paint_tool));
920
 
}