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

« back to all changes in this revision

Viewing changes to app/tools/gimpclonetool.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
24
24
 
25
25
#include "tools-types.h"
26
26
 
27
 
#include "core/gimpchannel.h"
28
 
#include "core/gimpimage.h"
29
 
#include "core/gimptoolinfo.h"
30
 
 
31
27
#include "paint/gimpclone.h"
32
28
#include "paint/gimpcloneoptions.h"
33
29
 
34
30
#include "widgets/gimphelp-ids.h"
35
 
#include "widgets/gimppropwidgets.h"
36
31
#include "widgets/gimpviewablebox.h"
37
32
#include "widgets/gimpwidgets-utils.h"
38
33
 
45
40
#include "gimp-intl.h"
46
41
 
47
42
 
48
 
#define TARGET_WIDTH  15
49
 
#define TARGET_HEIGHT 15
50
 
 
51
 
 
52
 
static void   gimp_clone_tool_class_init       (GimpCloneToolClass *klass);
53
 
static void   gimp_clone_tool_init             (GimpCloneTool      *tool);
54
 
 
55
 
static void   gimp_clone_tool_button_press     (GimpTool        *tool,
56
 
                                                GimpCoords      *coords,
57
 
                                                guint32          time,
58
 
                                                GdkModifierType  state,
59
 
                                                GimpDisplay     *gdisp);
60
 
static void   gimp_clone_tool_motion           (GimpTool        *tool,
61
 
                                                GimpCoords      *coords,
62
 
                                                guint32          time,
63
 
                                                GdkModifierType  state,
64
 
                                                GimpDisplay     *gdisp);
65
 
 
66
 
static void   gimp_clone_tool_cursor_update    (GimpTool        *tool,
67
 
                                                GimpCoords      *coords,
68
 
                                                GdkModifierType  state,
69
 
                                                GimpDisplay     *gdisp);
70
 
 
71
 
static void   gimp_clone_tool_draw             (GimpDrawTool    *draw_tool);
72
 
 
73
 
static GtkWidget * gimp_clone_options_gui      (GimpToolOptions *tool_options);
74
 
 
75
 
 
76
 
static GimpPaintToolClass *parent_class;
 
43
static GtkWidget * gimp_clone_options_gui (GimpToolOptions *tool_options);
 
44
 
 
45
 
 
46
G_DEFINE_TYPE (GimpCloneTool, gimp_clone_tool, GIMP_TYPE_SOURCE_TOOL)
 
47
 
 
48
#define parent_class gimp_clone_tool_parent_class
77
49
 
78
50
 
79
51
void
87
59
                GIMP_CONTEXT_PATTERN_MASK,
88
60
                "gimp-clone-tool",
89
61
                _("Clone"),
90
 
                _("Paint using Patterns or Image Regions"),
 
62
                _("Clone Tool: Selectively copy from an image or pattern, using a brush"),
91
63
                N_("_Clone"), "C",
92
64
                NULL, GIMP_HELP_TOOL_CLONE,
93
65
                GIMP_STOCK_TOOL_CLONE,
94
66
                data);
95
67
}
96
68
 
97
 
GType
98
 
gimp_clone_tool_get_type (void)
99
 
{
100
 
  static GType tool_type = 0;
101
 
 
102
 
  if (! tool_type)
103
 
    {
104
 
      static const GTypeInfo tool_info =
105
 
      {
106
 
        sizeof (GimpCloneToolClass),
107
 
        (GBaseInitFunc) NULL,
108
 
        (GBaseFinalizeFunc) NULL,
109
 
        (GClassInitFunc) gimp_clone_tool_class_init,
110
 
        NULL,           /* class_finalize */
111
 
        NULL,           /* class_data     */
112
 
        sizeof (GimpCloneTool),
113
 
        0,              /* n_preallocs    */
114
 
        (GInstanceInitFunc) gimp_clone_tool_init,
115
 
      };
116
 
 
117
 
      tool_type = g_type_register_static (GIMP_TYPE_PAINT_TOOL,
118
 
                                          "GimpCloneTool",
119
 
                                          &tool_info, 0);
120
 
    }
121
 
 
122
 
  return tool_type;
123
 
}
124
 
 
125
69
static void
126
70
gimp_clone_tool_class_init (GimpCloneToolClass *klass)
127
71
{
128
 
  GimpToolClass     *tool_class      = GIMP_TOOL_CLASS (klass);
129
 
  GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
130
 
 
131
 
  parent_class = g_type_class_peek_parent (klass);
132
 
 
133
 
  tool_class->button_press  = gimp_clone_tool_button_press;
134
 
  tool_class->motion        = gimp_clone_tool_motion;
135
 
  tool_class->cursor_update = gimp_clone_tool_cursor_update;
136
 
 
137
 
  draw_tool_class->draw     = gimp_clone_tool_draw;
138
72
}
139
73
 
140
74
static void
141
75
gimp_clone_tool_init (GimpCloneTool *clone)
142
76
{
143
 
  GimpTool *tool = GIMP_TOOL (clone);
144
 
 
145
 
  gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_CLONE);
146
 
}
147
 
 
148
 
static void
149
 
gimp_clone_tool_button_press (GimpTool        *tool,
150
 
                              GimpCoords      *coords,
151
 
                              guint32          time,
152
 
                              GdkModifierType  state,
153
 
                              GimpDisplay     *gdisp)
154
 
{
155
 
  GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
156
 
  GimpCloneTool *clone_tool = GIMP_CLONE_TOOL (tool);
157
 
 
158
 
  if ((state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) == GDK_CONTROL_MASK)
159
 
    {
160
 
      GIMP_CLONE (paint_tool->core)->set_source = TRUE;
161
 
 
162
 
      if (gdisp != clone_tool->src_gdisp)
163
 
        {
164
 
          if (clone_tool->src_gdisp)
165
 
            g_object_remove_weak_pointer (G_OBJECT (clone_tool->src_gdisp),
166
 
                                          (gpointer *) &clone_tool->src_gdisp);
167
 
 
168
 
          clone_tool->src_gdisp = gdisp;
169
 
          g_object_add_weak_pointer (G_OBJECT (gdisp),
170
 
                                     (gpointer *) &clone_tool->src_gdisp);
171
 
        }
172
 
    }
173
 
  else
174
 
    GIMP_CLONE (paint_tool->core)->set_source = FALSE;
175
 
 
176
 
  GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state,
177
 
                                                gdisp);
178
 
}
179
 
 
180
 
static void
181
 
gimp_clone_tool_motion (GimpTool        *tool,
182
 
                        GimpCoords      *coords,
183
 
                        guint32          time,
184
 
                        GdkModifierType  state,
185
 
                        GimpDisplay     *gdisp)
186
 
{
187
 
  GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
188
 
 
189
 
  if ((state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) == GDK_CONTROL_MASK)
190
 
    GIMP_CLONE (paint_tool->core)->set_source = TRUE;
191
 
  else
192
 
    GIMP_CLONE (paint_tool->core)->set_source = FALSE;
193
 
 
194
 
  GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state, gdisp);
195
 
}
196
 
 
197
 
void
198
 
gimp_clone_tool_cursor_update (GimpTool        *tool,
199
 
                               GimpCoords      *coords,
200
 
                               GdkModifierType  state,
201
 
                               GimpDisplay     *gdisp)
202
 
{
203
 
  GimpCloneOptions *options;
204
 
  GimpCursorType    ctype = GIMP_CURSOR_MOUSE;
205
 
 
206
 
  options = (GimpCloneOptions *) tool->tool_info->tool_options;
207
 
 
208
 
  if (gimp_image_coords_in_active_drawable (gdisp->gimage, coords))
209
 
    {
210
 
      GimpChannel *selection = gimp_image_get_mask (gdisp->gimage);
211
 
 
212
 
      /*  One more test--is there a selected region?
213
 
       *  if so, is cursor inside?
214
 
       */
215
 
      if (gimp_channel_is_empty (selection))
216
 
        ctype = GIMP_CURSOR_MOUSE;
217
 
      else if (gimp_channel_value (selection, coords->x, coords->y))
218
 
        ctype = GIMP_CURSOR_MOUSE;
219
 
    }
220
 
 
221
 
  if (options->clone_type == GIMP_IMAGE_CLONE)
222
 
    {
223
 
      if ((state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) == GDK_CONTROL_MASK)
224
 
        ctype = GIMP_CURSOR_CROSSHAIR_SMALL;
225
 
      else if (! GIMP_CLONE (GIMP_PAINT_TOOL (tool)->core)->src_drawable)
226
 
        ctype = GIMP_CURSOR_BAD;
227
 
    }
228
 
 
229
 
  gimp_tool_control_set_cursor (tool->control, ctype);
230
 
 
231
 
  GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, gdisp);
232
 
}
233
 
 
234
 
static void
235
 
gimp_clone_tool_draw (GimpDrawTool *draw_tool)
236
 
{
237
 
  GimpTool *tool = GIMP_TOOL (draw_tool);
238
 
 
239
 
  if (gimp_tool_control_is_active (tool->control))
240
 
    {
241
 
      GimpClone        *clone = GIMP_CLONE (GIMP_PAINT_TOOL (draw_tool)->core);
242
 
      GimpCloneOptions *options;
243
 
 
244
 
      options = (GimpCloneOptions *) tool->tool_info->tool_options;
245
 
 
246
 
      if (options->clone_type == GIMP_IMAGE_CLONE && clone->src_drawable)
247
 
        {
248
 
          gint           off_x;
249
 
          gint           off_y;
250
 
          GimpDisplay   *tmp_gdisp;
251
 
          GimpCloneTool *clone_tool = GIMP_CLONE_TOOL (draw_tool);
252
 
 
253
 
          gimp_item_offsets (GIMP_ITEM (clone->src_drawable), &off_x, &off_y);
254
 
 
255
 
          tmp_gdisp = draw_tool->gdisp;
256
 
          draw_tool->gdisp = clone_tool->src_gdisp;
257
 
 
258
 
          if (draw_tool->gdisp)
259
 
            gimp_draw_tool_draw_handle (draw_tool,
260
 
                                        GIMP_HANDLE_CROSS,
261
 
                                        clone->src_x + off_x,
262
 
                                        clone->src_y + off_y,
263
 
                                        TARGET_WIDTH, TARGET_WIDTH,
264
 
                                        GTK_ANCHOR_CENTER,
265
 
                                        FALSE);
266
 
 
267
 
          draw_tool->gdisp = tmp_gdisp;
268
 
        }
269
 
    }
270
 
 
271
 
  GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
 
77
  GimpTool       *tool        = GIMP_TOOL (clone);
 
78
  GimpPaintTool  *paint_tool  = GIMP_PAINT_TOOL (tool);
 
79
  GimpSourceTool *source_tool = GIMP_SOURCE_TOOL (tool);
 
80
 
 
81
  gimp_tool_control_set_tool_cursor     (tool->control,
 
82
                                         GIMP_TOOL_CURSOR_CLONE);
 
83
  gimp_tool_control_set_action_object_2 (tool->control,
 
84
                                         "context/context-pattern-select-set");
 
85
 
 
86
  paint_tool->status      = _("Click to clone");
 
87
  paint_tool->status_ctrl = _("%s to set a new clone source");
 
88
 
 
89
  source_tool->status_paint           = _("Click to clone");
 
90
  source_tool->status_set_source      = _("Click to set a new clone source");
 
91
  source_tool->status_set_source_ctrl = _("%s to set a new clone source");
272
92
}
273
93
 
274
94
 
278
98
gimp_clone_options_gui (GimpToolOptions *tool_options)
279
99
{
280
100
  GObject   *config = G_OBJECT (tool_options);
281
 
  GtkWidget *vbox;
 
101
  GtkWidget *vbox   = gimp_paint_options_gui (tool_options);
282
102
  GtkWidget *frame;
 
103
  GtkWidget *button;
283
104
  GtkWidget *hbox;
284
 
 
285
 
  vbox = gimp_paint_options_gui (tool_options);
 
105
  GtkWidget *table;
 
106
  GtkWidget *combo;
286
107
 
287
108
  frame = gimp_prop_enum_radio_frame_new (config, "clone-type",
288
 
                                          _("Source"),
289
 
                                          0, 0);
 
109
                                          _("Source"), 0, 0);
290
110
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
291
111
  gtk_widget_show (frame);
292
112
 
293
 
  hbox = gimp_pattern_box_new (NULL, GIMP_CONTEXT (tool_options), 2);
 
113
  button = gimp_prop_check_button_new (config, "sample-merged",
 
114
                                       _("Sample merged"));
 
115
  gimp_enum_radio_frame_add (GTK_FRAME (frame), button, GIMP_IMAGE_CLONE);
 
116
 
 
117
  hbox = gimp_prop_pattern_box_new (NULL, GIMP_CONTEXT (tool_options), 2,
 
118
                                    "pattern-view-type", "pattern-view-size");
294
119
  gimp_enum_radio_frame_add (GTK_FRAME (frame), hbox, GIMP_PATTERN_CLONE);
295
120
 
296
 
  frame = gimp_prop_enum_radio_frame_new (config, "align-mode",
297
 
                                          _("Alignment"),
298
 
                                          0, 0);
299
 
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
300
 
  gtk_widget_show (frame);
 
121
  table = gtk_table_new (1, 2, FALSE);
 
122
  gtk_table_set_col_spacings (GTK_TABLE (table), 2);
 
123
  gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
 
124
  gtk_widget_show (table);
 
125
 
 
126
  combo = gimp_prop_enum_combo_box_new (config, "align-mode", 0, 0);
 
127
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
 
128
                             _("Alignment:"), 0.0, 0.5,
 
129
                             combo, 1, FALSE);
301
130
 
302
131
  return vbox;
303
132
}