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

« back to all changes in this revision

Viewing changes to app/tools/gimpsourcetool.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
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 */
 
18
 
 
19
#include "config.h"
 
20
 
 
21
#include <gtk/gtk.h>
 
22
 
 
23
#include "tools-types.h"
 
24
 
 
25
#include "core/gimpchannel.h"
 
26
#include "core/gimpimage.h"
 
27
#include "core/gimppickable.h"
 
28
 
 
29
#include "paint/gimpsourcecore.h"
 
30
#include "paint/gimpsourceoptions.h"
 
31
 
 
32
#include "widgets/gimpwidgets-utils.h"
 
33
 
 
34
#include "display/gimpdisplay.h"
 
35
 
 
36
#include "gimpsourcetool.h"
 
37
#include "gimptoolcontrol.h"
 
38
 
 
39
#include "gimp-intl.h"
 
40
 
 
41
 
 
42
#define TARGET_SIZE  15
 
43
 
 
44
 
 
45
static gboolean      gimp_source_tool_has_display   (GimpTool        *tool,
 
46
                                                     GimpDisplay     *display);
 
47
static GimpDisplay * gimp_source_tool_has_image     (GimpTool        *tool,
 
48
                                                     GimpImage       *image);
 
49
static void          gimp_source_tool_control       (GimpTool        *tool,
 
50
                                                     GimpToolAction   action,
 
51
                                                     GimpDisplay     *display);
 
52
static void          gimp_source_tool_button_press  (GimpTool        *tool,
 
53
                                                     GimpCoords      *coords,
 
54
                                                     guint32          time,
 
55
                                                     GdkModifierType  state,
 
56
                                                     GimpDisplay     *display);
 
57
static void          gimp_source_tool_motion        (GimpTool        *tool,
 
58
                                                     GimpCoords      *coords,
 
59
                                                     guint32          time,
 
60
                                                     GdkModifierType  state,
 
61
                                                     GimpDisplay     *display);
 
62
static void          gimp_source_tool_cursor_update (GimpTool        *tool,
 
63
                                                     GimpCoords      *coords,
 
64
                                                     GdkModifierType  state,
 
65
                                                     GimpDisplay     *display);
 
66
static void          gimp_source_tool_modifier_key  (GimpTool        *tool,
 
67
                                                     GdkModifierType  key,
 
68
                                                     gboolean         press,
 
69
                                                     GdkModifierType  state,
 
70
                                                     GimpDisplay     *display);
 
71
static void          gimp_source_tool_oper_update   (GimpTool        *tool,
 
72
                                                     GimpCoords      *coords,
 
73
                                                     GdkModifierType  state,
 
74
                                                     gboolean         proximity,
 
75
                                                     GimpDisplay     *display);
 
76
 
 
77
static void          gimp_source_tool_draw          (GimpDrawTool    *draw_tool);
 
78
 
 
79
 
 
80
G_DEFINE_TYPE (GimpSourceTool, gimp_source_tool, GIMP_TYPE_BRUSH_TOOL)
 
81
 
 
82
#define parent_class gimp_source_tool_parent_class
 
83
 
 
84
 
 
85
static void
 
86
gimp_source_tool_class_init (GimpSourceToolClass *klass)
 
87
{
 
88
  GimpToolClass     *tool_class      = GIMP_TOOL_CLASS (klass);
 
89
  GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
 
90
 
 
91
  tool_class->has_display   = gimp_source_tool_has_display;
 
92
  tool_class->has_image     = gimp_source_tool_has_image;
 
93
  tool_class->control       = gimp_source_tool_control;
 
94
  tool_class->button_press  = gimp_source_tool_button_press;
 
95
  tool_class->motion        = gimp_source_tool_motion;
 
96
  tool_class->modifier_key  = gimp_source_tool_modifier_key;
 
97
  tool_class->oper_update   = gimp_source_tool_oper_update;
 
98
  tool_class->cursor_update = gimp_source_tool_cursor_update;
 
99
 
 
100
  draw_tool_class->draw     = gimp_source_tool_draw;
 
101
}
 
102
 
 
103
static void
 
104
gimp_source_tool_init (GimpSourceTool *source)
 
105
{
 
106
}
 
107
 
 
108
static gboolean
 
109
gimp_source_tool_has_display (GimpTool    *tool,
 
110
                              GimpDisplay *display)
 
111
{
 
112
  GimpSourceTool *source_tool = GIMP_SOURCE_TOOL (tool);
 
113
 
 
114
  return (display == source_tool->src_display ||
 
115
          GIMP_TOOL_CLASS (parent_class)->has_display (tool, display));
 
116
}
 
117
 
 
118
static GimpDisplay *
 
119
gimp_source_tool_has_image (GimpTool  *tool,
 
120
                            GimpImage *image)
 
121
{
 
122
  GimpSourceTool *source_tool = GIMP_SOURCE_TOOL (tool);
 
123
  GimpDisplay    *display;
 
124
 
 
125
  display = GIMP_TOOL_CLASS (parent_class)->has_image (tool, image);
 
126
 
 
127
  if (! display && source_tool->src_display)
 
128
    {
 
129
      if (image && source_tool->src_display->image == image)
 
130
        display = source_tool->src_display;
 
131
 
 
132
      /*  NULL image means any display  */
 
133
      if (! image)
 
134
        display = source_tool->src_display;
 
135
    }
 
136
 
 
137
  return display;
 
138
}
 
139
 
 
140
static void
 
141
gimp_source_tool_control (GimpTool       *tool,
 
142
                          GimpToolAction  action,
 
143
                          GimpDisplay    *display)
 
144
{
 
145
  GimpSourceTool *source_tool = GIMP_SOURCE_TOOL (tool);
 
146
 
 
147
  /*  chain up early so the draw tool can undraw the source marker
 
148
   *  while we still know about source drawable and display
 
149
   */
 
150
  GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
 
151
 
 
152
  switch (action)
 
153
    {
 
154
    case GIMP_TOOL_ACTION_PAUSE:
 
155
    case GIMP_TOOL_ACTION_RESUME:
 
156
      break;
 
157
 
 
158
    case GIMP_TOOL_ACTION_HALT:
 
159
      source_tool->src_display = NULL;
 
160
      g_object_set (GIMP_PAINT_TOOL (tool)->core,
 
161
                    "src-drawable", NULL,
 
162
                    NULL);
 
163
      break;
 
164
    }
 
165
}
 
166
 
 
167
static void
 
168
gimp_source_tool_button_press (GimpTool        *tool,
 
169
                               GimpCoords      *coords,
 
170
                               guint32          time,
 
171
                               GdkModifierType  state,
 
172
                               GimpDisplay     *display)
 
173
{
 
174
  GimpPaintTool  *paint_tool  = GIMP_PAINT_TOOL (tool);
 
175
  GimpSourceTool *source_tool = GIMP_SOURCE_TOOL (tool);
 
176
  GimpSourceCore *source      = GIMP_SOURCE_CORE (paint_tool->core);
 
177
 
 
178
  gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
 
179
 
 
180
  if ((state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) == GDK_CONTROL_MASK)
 
181
    {
 
182
      source->set_source = TRUE;
 
183
 
 
184
      source_tool->src_display = display;
 
185
    }
 
186
  else
 
187
    {
 
188
      source->set_source = FALSE;
 
189
    }
 
190
 
 
191
  GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state,
 
192
                                                display);
 
193
 
 
194
  source_tool->src_x = source->src_x;
 
195
  source_tool->src_y = source->src_y;
 
196
 
 
197
  gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
 
198
}
 
199
 
 
200
static void
 
201
gimp_source_tool_motion (GimpTool        *tool,
 
202
                         GimpCoords      *coords,
 
203
                         guint32          time,
 
204
                         GdkModifierType  state,
 
205
                         GimpDisplay     *display)
 
206
{
 
207
  GimpSourceTool *source_tool = GIMP_SOURCE_TOOL (tool);
 
208
  GimpPaintTool  *paint_tool  = GIMP_PAINT_TOOL (tool);
 
209
  GimpSourceCore *source      = GIMP_SOURCE_CORE (paint_tool->core);
 
210
 
 
211
  gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
 
212
 
 
213
  if ((state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) == GDK_CONTROL_MASK)
 
214
    source->set_source = TRUE;
 
215
  else
 
216
    source->set_source = FALSE;
 
217
 
 
218
  GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state, display);
 
219
 
 
220
  source_tool->src_x = source->src_x;
 
221
  source_tool->src_y = source->src_y;
 
222
 
 
223
  gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
 
224
}
 
225
 
 
226
static void
 
227
gimp_source_tool_modifier_key (GimpTool        *tool,
 
228
                               GdkModifierType  key,
 
229
                               gboolean         press,
 
230
                               GdkModifierType  state,
 
231
                               GimpDisplay     *display)
 
232
{
 
233
  GimpSourceTool    *source_tool = GIMP_SOURCE_TOOL (tool);
 
234
  GimpPaintTool     *paint_tool  = GIMP_PAINT_TOOL (tool);
 
235
  GimpSourceOptions *options     = GIMP_SOURCE_TOOL_GET_OPTIONS (tool);
 
236
 
 
237
  if (options->use_source && key == GDK_CONTROL_MASK)
 
238
    {
 
239
      if (press)
 
240
        paint_tool->status = source_tool->status_set_source;
 
241
      else
 
242
        paint_tool->status = source_tool->status_paint;
 
243
    }
 
244
 
 
245
  GIMP_TOOL_CLASS (parent_class)->modifier_key (tool, key, press, state,
 
246
                                                display);
 
247
}
 
248
 
 
249
static void
 
250
gimp_source_tool_cursor_update (GimpTool        *tool,
 
251
                                GimpCoords      *coords,
 
252
                                GdkModifierType  state,
 
253
                                GimpDisplay     *display)
 
254
{
 
255
  GimpSourceOptions  *options  = GIMP_SOURCE_TOOL_GET_OPTIONS (tool);
 
256
  GimpCursorType      cursor   = GIMP_CURSOR_MOUSE;
 
257
  GimpCursorModifier  modifier = GIMP_CURSOR_MODIFIER_NONE;
 
258
 
 
259
  if (options->use_source)
 
260
    {
 
261
      if ((state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) == GDK_CONTROL_MASK)
 
262
        {
 
263
          cursor = GIMP_CURSOR_CROSSHAIR_SMALL;
 
264
        }
 
265
      else if (! GIMP_SOURCE_CORE (GIMP_PAINT_TOOL (tool)->core)->src_drawable)
 
266
        {
 
267
          modifier = GIMP_CURSOR_MODIFIER_BAD;
 
268
        }
 
269
    }
 
270
 
 
271
  gimp_tool_control_set_cursor          (tool->control, cursor);
 
272
  gimp_tool_control_set_cursor_modifier (tool->control, modifier);
 
273
 
 
274
  GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
 
275
}
 
276
 
 
277
static void
 
278
gimp_source_tool_oper_update (GimpTool        *tool,
 
279
                              GimpCoords      *coords,
 
280
                              GdkModifierType  state,
 
281
                              gboolean         proximity,
 
282
                              GimpDisplay     *display)
 
283
{
 
284
  GimpSourceTool    *source_tool = GIMP_SOURCE_TOOL (tool);
 
285
  GimpSourceOptions *options     = GIMP_SOURCE_TOOL_GET_OPTIONS (tool);
 
286
 
 
287
  if (proximity)
 
288
    {
 
289
      GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
 
290
 
 
291
      if (options->use_source)
 
292
        paint_tool->status_ctrl = source_tool->status_set_source_ctrl;
 
293
      else
 
294
        paint_tool->status_ctrl = NULL;
 
295
    }
 
296
 
 
297
  GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, proximity,
 
298
                                               display);
 
299
 
 
300
  if (options->use_source)
 
301
    {
 
302
      GimpSourceCore *source = GIMP_SOURCE_CORE (GIMP_PAINT_TOOL (tool)->core);
 
303
 
 
304
      if (source->src_drawable == NULL)
 
305
        {
 
306
          if (state & GDK_CONTROL_MASK)
 
307
            gimp_tool_replace_status (tool, display,
 
308
                                      source_tool->status_set_source);
 
309
          else
 
310
            {
 
311
              gchar *status;
 
312
 
 
313
              status = g_strconcat (gimp_get_mod_name_control (),
 
314
                                    gimp_get_mod_separator (),
 
315
                                    source_tool->status_set_source,
 
316
                                    NULL);
 
317
              gimp_tool_replace_status (tool, display, status);
 
318
              g_free (status);
 
319
            }
 
320
        }
 
321
      else
 
322
        {
 
323
          gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
 
324
 
 
325
          source_tool->src_x = source->src_x;
 
326
          source_tool->src_y = source->src_y;
 
327
 
 
328
          if (! source->first_stroke)
 
329
            {
 
330
              switch (options->align_mode)
 
331
                {
 
332
                case GIMP_SOURCE_ALIGN_YES:
 
333
                  source_tool->src_x = coords->x + source->offset_x;
 
334
                  source_tool->src_y = coords->y + source->offset_y;
 
335
                  break;
 
336
 
 
337
                case GIMP_SOURCE_ALIGN_REGISTERED:
 
338
                  source_tool->src_x = coords->x;
 
339
                  source_tool->src_y = coords->y;
 
340
                  break;
 
341
 
 
342
                default:
 
343
                  break;
 
344
                }
 
345
            }
 
346
 
 
347
          gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
 
348
        }
 
349
    }
 
350
}
 
351
 
 
352
static void
 
353
gimp_source_tool_draw (GimpDrawTool *draw_tool)
 
354
{
 
355
  GimpTool          *tool        = GIMP_TOOL (draw_tool);
 
356
  GimpSourceTool    *source_tool = GIMP_SOURCE_TOOL (draw_tool);
 
357
  GimpSourceCore    *source      = GIMP_SOURCE_CORE (GIMP_PAINT_TOOL (tool)->core);
 
358
  GimpSourceOptions *options     = GIMP_SOURCE_TOOL_GET_OPTIONS (draw_tool);
 
359
 
 
360
  if (options->use_source && source->src_drawable && source_tool->src_display)
 
361
    {
 
362
      GimpDisplay *tmp_display;
 
363
      gint         off_x;
 
364
      gint         off_y;
 
365
 
 
366
      gimp_item_offsets (GIMP_ITEM (source->src_drawable), &off_x, &off_y);
 
367
 
 
368
      tmp_display = draw_tool->display;
 
369
      draw_tool->display = source_tool->src_display;
 
370
 
 
371
      gimp_draw_tool_draw_handle (draw_tool,
 
372
                                  GIMP_HANDLE_CROSS,
 
373
                                  source_tool->src_x + off_x,
 
374
                                  source_tool->src_y + off_y,
 
375
                                  TARGET_SIZE, TARGET_SIZE,
 
376
                                  GTK_ANCHOR_CENTER,
 
377
                                  FALSE);
 
378
 
 
379
      draw_tool->display = tmp_display;
 
380
    }
 
381
 
 
382
  GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
 
383
}