~ubuntu-branches/ubuntu/hoary/gimp/hoary

« back to all changes in this revision

Viewing changes to app/tools/gimperasertool.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-04-04 14:51:23 UTC
  • Revision ID: james.westby@ubuntu.com-20050404145123-9py049eeelfymur8
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The GIMP -- an 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 "libgimpwidgets/gimpwidgets.h"
 
24
 
 
25
#include "tools-types.h"
 
26
 
 
27
#include "core/gimptoolinfo.h"
 
28
 
 
29
#include "paint/gimperaseroptions.h"
 
30
 
 
31
#include "widgets/gimphelp-ids.h"
 
32
#include "widgets/gimppropwidgets.h"
 
33
#include "widgets/gimpwidgets-utils.h"
 
34
 
 
35
#include "gimperasertool.h"
 
36
#include "gimppaintoptions-gui.h"
 
37
#include "gimptoolcontrol.h"
 
38
 
 
39
#include "gimp-intl.h"
 
40
 
 
41
 
 
42
static void   gimp_eraser_tool_class_init    (GimpEraserToolClass  *klass);
 
43
static void   gimp_eraser_tool_init          (GimpEraserTool       *eraser);
 
44
 
 
45
static void   gimp_eraser_tool_modifier_key  (GimpTool             *tool,
 
46
                                              GdkModifierType       key,
 
47
                                              gboolean              press,
 
48
                                              GdkModifierType       state,
 
49
                                              GimpDisplay          *gdisp);
 
50
static void   gimp_eraser_tool_cursor_update (GimpTool             *tool,
 
51
                                              GimpCoords           *coords,
 
52
                                              GdkModifierType       state,
 
53
                                              GimpDisplay          *gdisp);
 
54
 
 
55
static GtkWidget * gimp_eraser_options_gui   (GimpToolOptions      *tool_options);
 
56
 
 
57
 
 
58
static GimpPaintToolClass *parent_class = NULL;
 
59
 
 
60
 
 
61
void
 
62
gimp_eraser_tool_register (GimpToolRegisterCallback  callback,
 
63
                           gpointer                  data)
 
64
{
 
65
  (* callback) (GIMP_TYPE_ERASER_TOOL,
 
66
                GIMP_TYPE_ERASER_OPTIONS,
 
67
                gimp_eraser_options_gui,
 
68
                GIMP_PAINT_OPTIONS_CONTEXT_MASK,
 
69
                "gimp-eraser-tool",
 
70
                _("Eraser"),
 
71
                _("Erase to background or transparency"),
 
72
                N_("_Eraser"), "<shift>E",
 
73
                NULL, GIMP_HELP_TOOL_ERASER,
 
74
                GIMP_STOCK_TOOL_ERASER,
 
75
                data);
 
76
}
 
77
 
 
78
GType
 
79
gimp_eraser_tool_get_type (void)
 
80
{
 
81
  static GType tool_type = 0;
 
82
 
 
83
  if (! tool_type)
 
84
    {
 
85
      static const GTypeInfo tool_info =
 
86
      {
 
87
        sizeof (GimpEraserToolClass),
 
88
        (GBaseInitFunc) NULL,
 
89
        (GBaseFinalizeFunc) NULL,
 
90
        (GClassInitFunc) gimp_eraser_tool_class_init,
 
91
        NULL,           /* class_finalize */
 
92
        NULL,           /* class_data     */
 
93
        sizeof (GimpEraserTool),
 
94
        0,              /* n_preallocs    */
 
95
        (GInstanceInitFunc) gimp_eraser_tool_init,
 
96
      };
 
97
 
 
98
      tool_type = g_type_register_static (GIMP_TYPE_PAINT_TOOL,
 
99
                                          "GimpEraserTool",
 
100
                                          &tool_info, 0);
 
101
    }
 
102
 
 
103
  return tool_type;
 
104
}
 
105
 
 
106
static void
 
107
gimp_eraser_tool_class_init (GimpEraserToolClass *klass)
 
108
{
 
109
  GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
 
110
 
 
111
  parent_class = g_type_class_peek_parent (klass);
 
112
 
 
113
  tool_class->modifier_key  = gimp_eraser_tool_modifier_key;
 
114
  tool_class->cursor_update = gimp_eraser_tool_cursor_update;
 
115
}
 
116
 
 
117
static void
 
118
gimp_eraser_tool_init (GimpEraserTool *eraser)
 
119
{
 
120
  GimpTool *tool = GIMP_TOOL (eraser);
 
121
 
 
122
  gimp_tool_control_set_tool_cursor            (tool->control,
 
123
                                                GIMP_TOOL_CURSOR_ERASER);
 
124
  gimp_tool_control_set_toggle_tool_cursor     (tool->control,
 
125
                                                GIMP_TOOL_CURSOR_ERASER);
 
126
  gimp_tool_control_set_toggle_cursor_modifier (tool->control,
 
127
                                                GIMP_CURSOR_MODIFIER_MINUS);
 
128
 
 
129
  gimp_paint_tool_enable_color_picker (GIMP_PAINT_TOOL (eraser),
 
130
                                       GIMP_COLOR_PICK_MODE_BACKGROUND);
 
131
}
 
132
 
 
133
static void
 
134
gimp_eraser_tool_modifier_key (GimpTool        *tool,
 
135
                               GdkModifierType  key,
 
136
                               gboolean         press,
 
137
                               GdkModifierType  state,
 
138
                               GimpDisplay     *gdisp)
 
139
{
 
140
  if (key == GDK_MOD1_MASK)
 
141
    {
 
142
      GimpEraserOptions *options;
 
143
 
 
144
      options = GIMP_ERASER_OPTIONS (tool->tool_info->tool_options);
 
145
 
 
146
      g_object_set (options,
 
147
                    "anti-erase", ! options->anti_erase,
 
148
                    NULL);
 
149
    }
 
150
 
 
151
  GIMP_TOOL_CLASS (parent_class)->modifier_key (tool, key, press, state, gdisp);
 
152
}
 
153
 
 
154
static void
 
155
gimp_eraser_tool_cursor_update (GimpTool        *tool,
 
156
                                GimpCoords      *coords,
 
157
                                GdkModifierType  state,
 
158
                                GimpDisplay     *gdisp)
 
159
{
 
160
  GimpEraserOptions *options;
 
161
 
 
162
  options = GIMP_ERASER_OPTIONS (tool->tool_info->tool_options);
 
163
 
 
164
  gimp_tool_control_set_toggle (tool->control, options->anti_erase);
 
165
 
 
166
  GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, gdisp);
 
167
}
 
168
 
 
169
 
 
170
/*  tool options stuff  */
 
171
 
 
172
static GtkWidget *
 
173
gimp_eraser_options_gui (GimpToolOptions *tool_options)
 
174
{
 
175
  GObject   *config;
 
176
  GtkWidget *vbox;
 
177
  GtkWidget *button;
 
178
  gchar     *str;
 
179
 
 
180
  config = G_OBJECT (tool_options);
 
181
 
 
182
  vbox = gimp_paint_options_gui (tool_options);
 
183
 
 
184
  /* the anti_erase toggle */
 
185
  str = g_strdup_printf (_("Anti erase  %s"),
 
186
                         gimp_get_mod_string (GDK_MOD1_MASK));
 
187
 
 
188
  button = gimp_prop_check_button_new (config, "anti-erase", str);
 
189
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
 
190
  gtk_widget_show (button);
 
191
 
 
192
  g_free (str);
 
193
 
 
194
  return vbox;
 
195
}