1
/* The GIMP -- an image manipulation program
1
/* GIMP - The GNU Image Manipulation Program
2
2
* Copyright (C) 1995-2001 Spencer Kimball, Peter Mattis, and others
4
4
* This program is free software; you can redistribute it and/or modify
26
26
#include "tools-types.h"
28
#include "core/gimp.h"
29
28
#include "core/gimpdrawable.h"
30
#include "core/gimpimage.h"
31
#include "core/gimptoolinfo.h"
33
30
#include "widgets/gimpcolorframe.h"
34
#include "widgets/gimpdialogfactory.h"
35
31
#include "widgets/gimphelp-ids.h"
36
#include "widgets/gimppaletteeditor.h"
37
32
#include "widgets/gimptooldialog.h"
38
#include "widgets/gimpviewabledialog.h"
33
#include "widgets/gimpwidgets-utils.h"
40
35
#include "display/gimpdisplay.h"
49
44
/* local function prototypes */
51
static void gimp_color_picker_tool_class_init (GimpColorPickerToolClass *klass);
52
static void gimp_color_picker_tool_init (GimpColorPickerTool *tool);
53
static GObject * gimp_color_picker_tool_constructor(GType type,
55
GObjectConstructParam *params);
46
static GObject * gimp_color_picker_tool_constructor (GType type,
48
GObjectConstructParam *params);
56
49
static void gimp_color_picker_tool_finalize (GObject *object);
58
51
static void gimp_color_picker_tool_control (GimpTool *tool,
59
52
GimpToolAction action,
53
GimpDisplay *display);
61
54
static void gimp_color_picker_tool_modifier_key (GimpTool *tool,
62
55
GdkModifierType key,
64
57
GdkModifierType state,
58
GimpDisplay *display);
66
59
static void gimp_color_picker_tool_oper_update (GimpTool *tool,
67
60
GimpCoords *coords,
68
61
GdkModifierType state,
63
GimpDisplay *display);
71
65
static void gimp_color_picker_tool_picked (GimpColorTool *color_tool,
72
66
GimpColorPickState pick_state,
94
91
(* callback) (GIMP_TYPE_COLOR_PICKER_TOOL,
95
92
GIMP_TYPE_COLOR_PICKER_OPTIONS,
96
93
gimp_color_picker_options_gui,
94
GIMP_CONTEXT_FOREGROUND_MASK | GIMP_CONTEXT_BACKGROUND_MASK,
98
95
"gimp-color-picker-tool",
100
_("Pick colors from the image"),
97
_("Color Picker Tool: Set colors from image pixels"),
101
98
N_("C_olor Picker"), "O",
102
99
NULL, GIMP_HELP_TOOL_COLOR_PICKER,
103
100
GIMP_STOCK_TOOL_COLOR_PICKER,
108
gimp_color_picker_tool_get_type (void)
110
static GtkType tool_type = 0;
114
static const GTypeInfo tool_info =
116
sizeof (GimpColorPickerToolClass),
117
(GBaseInitFunc) NULL,
118
(GBaseFinalizeFunc) NULL,
119
(GClassInitFunc) gimp_color_picker_tool_class_init,
120
NULL, /* class_finalize */
121
NULL, /* class_data */
122
sizeof (GimpColorPickerTool),
124
(GInstanceInitFunc) gimp_color_picker_tool_init,
127
tool_type = g_type_register_static (GIMP_TYPE_COLOR_TOOL,
128
"GimpColorPickerTool",
136
105
gimp_color_picker_tool_class_init (GimpColorPickerToolClass *klass)
139
108
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
140
109
GimpColorToolClass *color_tool_class = GIMP_COLOR_TOOL_CLASS (klass);
142
parent_class = g_type_class_peek_parent (klass);
144
111
object_class->constructor = gimp_color_picker_tool_constructor;
145
112
object_class->finalize = gimp_color_picker_tool_finalize;
172
139
tool = GIMP_TOOL (object);
174
141
gimp_color_tool_enable (GIMP_COLOR_TOOL (object),
175
GIMP_COLOR_OPTIONS (tool->tool_info->tool_options));
142
GIMP_COLOR_TOOL_GET_OPTIONS (tool));
183
150
GimpColorPickerTool *picker_tool = GIMP_COLOR_PICKER_TOOL (object);
185
152
if (picker_tool->dialog)
186
gimp_color_picker_tool_info_response (NULL, GTK_RESPONSE_CLOSE, picker_tool);
153
gimp_color_picker_tool_info_response (NULL, GTK_RESPONSE_CLOSE,
188
156
G_OBJECT_CLASS (parent_class)->finalize (object);
192
160
gimp_color_picker_tool_control (GimpTool *tool,
193
161
GimpToolAction action,
162
GimpDisplay *display)
196
164
GimpColorPickerTool *picker_tool = GIMP_COLOR_PICKER_TOOL (tool);
168
case GIMP_TOOL_ACTION_PAUSE:
169
case GIMP_TOOL_ACTION_RESUME:
172
case GIMP_TOOL_ACTION_HALT:
201
173
if (picker_tool->dialog)
202
174
gimp_color_picker_tool_info_response (NULL, GTK_RESPONSE_CLOSE,
210
GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
179
GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
215
184
GdkModifierType key,
217
186
GdkModifierType state,
187
GimpDisplay *display)
220
GimpColorPickerOptions *options;
222
options = GIMP_COLOR_PICKER_OPTIONS (tool->tool_info->tool_options);
189
GimpColorPickerOptions *options = GIMP_COLOR_PICKER_TOOL_GET_OPTIONS (tool);
224
191
if (key == GDK_SHIFT_MASK)
226
g_object_set (options, "add-to-palette", ! options->add_to_palette,
193
g_object_set (options, "use-info-window", ! options->use_info_window,
229
196
else if (key == GDK_CONTROL_MASK)
231
switch (options->pick_mode)
198
switch (options->pick_mode)
233
case GIMP_COLOR_PICK_MODE_NONE:
236
200
case GIMP_COLOR_PICK_MODE_FOREGROUND:
237
201
g_object_set (options, "pick-mode", GIMP_COLOR_PICK_MODE_BACKGROUND,
251
218
gimp_color_picker_tool_oper_update (GimpTool *tool,
252
219
GimpCoords *coords,
253
220
GdkModifierType state,
222
GimpDisplay *display)
256
GimpColorPickerOptions *options;
258
options = GIMP_COLOR_PICKER_OPTIONS (tool->tool_info->tool_options);
224
GimpColorPickerTool *picker_tool = GIMP_COLOR_PICKER_TOOL (tool);
225
GimpColorPickerOptions *options = GIMP_COLOR_PICKER_TOOL_GET_OPTIONS (tool);
260
227
GIMP_COLOR_TOOL (tool)->pick_mode = options->pick_mode;
229
gimp_tool_pop_status (tool, display);
232
gchar *status_help = NULL;
233
GdkModifierType shift_mod = 0;
235
if (! picker_tool->dialog)
237
shift_mod = GDK_SHIFT_MASK;
239
switch (options->pick_mode)
241
case GIMP_COLOR_PICK_MODE_NONE:
242
status_help = gimp_suggest_modifiers (_("Click in any image to view"
248
case GIMP_COLOR_PICK_MODE_FOREGROUND:
249
status_help = gimp_suggest_modifiers (_("Click in any image to pick"
250
" the foreground color"),
252
| GDK_CONTROL_MASK) & ~state,
256
case GIMP_COLOR_PICK_MODE_BACKGROUND:
257
status_help = gimp_suggest_modifiers (_("Click in any image to pick"
258
" the background color"),
260
| GDK_CONTROL_MASK) & ~state,
264
case GIMP_COLOR_PICK_MODE_PALETTE:
265
status_help = gimp_suggest_modifiers (_("Click in any image to add"
266
" the color to the palette"),
271
if (status_help != NULL)
273
gimp_tool_push_status (tool, display, status_help);
274
g_free (status_help);
278
GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, proximity,
268
287
gint color_index)
270
GimpTool *tool = GIMP_TOOL (color_tool);
271
289
GimpColorPickerTool *picker_tool = GIMP_COLOR_PICKER_TOOL (color_tool);
272
290
GimpColorPickerOptions *options;
273
GimpContext *user_context;
275
options = GIMP_COLOR_PICKER_OPTIONS (color_tool->options);
277
if (! picker_tool->dialog)
292
options = GIMP_COLOR_PICKER_TOOL_GET_OPTIONS (color_tool);
294
if (options->use_info_window && ! picker_tool->dialog)
278
295
gimp_color_picker_tool_info_create (picker_tool);
280
gimp_color_picker_tool_info_update (picker_tool, sample_type,
283
user_context = gimp_get_user_context (tool->gdisp->gimage->gimp);
285
if (options->add_to_palette)
287
GimpDialogFactory *dialog_factory;
290
GtkWidget *palette_editor;
293
dialog_factory = gimp_dialog_factory_from_name ("dock");
294
screen = gtk_widget_get_screen (tool->gdisp->shell);
296
dockable = gimp_dialog_factory_dialog_raise (dialog_factory,
298
"gimp-palette-editor",
301
palette_editor = gtk_bin_get_child (GTK_BIN (dockable));
303
data = gimp_data_editor_get_data (GIMP_DATA_EDITOR (palette_editor));
307
data = GIMP_DATA (gimp_context_get_palette (user_context));
309
gimp_data_editor_set_data (GIMP_DATA_EDITOR (palette_editor), data);
312
gimp_palette_editor_pick_color (GIMP_PALETTE_EDITOR (palette_editor),
316
switch (options->pick_mode)
318
case GIMP_COLOR_PICK_MODE_NONE:
321
case GIMP_COLOR_PICK_MODE_FOREGROUND:
322
gimp_context_set_foreground (user_context, color);
325
case GIMP_COLOR_PICK_MODE_BACKGROUND:
326
gimp_context_set_background (user_context, color);
297
if (picker_tool->dialog)
298
gimp_color_picker_tool_info_update (picker_tool, sample_type,
301
GIMP_COLOR_TOOL_CLASS (parent_class)->picked (color_tool, pick_state,
339
314
g_return_if_fail (tool->drawable != NULL);
341
316
picker_tool->dialog = gimp_tool_dialog_new (tool->tool_info,
342
NULL /* tool->gdisp->shell */,
317
NULL /* tool->display->shell */,
343
318
_("Color Picker Information"),
325
gtk_window_set_focus_on_map (GTK_WINDOW (picker_tool->dialog), FALSE);
350
327
gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (picker_tool->dialog),
351
GIMP_VIEWABLE (tool->drawable));
328
GIMP_VIEWABLE (tool->drawable),
329
GIMP_CONTEXT (gimp_tool_get_options (tool)));
353
331
g_signal_connect (picker_tool->dialog, "response",
354
332
G_CALLBACK (gimp_color_picker_tool_info_response),
412
390
gint color_index)
414
gimp_color_area_set_color (GIMP_COLOR_AREA (picker_tool->color_area), color);
392
gimp_color_area_set_color (GIMP_COLOR_AREA (picker_tool->color_area),
416
395
gimp_color_frame_set_color (GIMP_COLOR_FRAME (picker_tool->color_frame1),
417
396
sample_type, color, color_index);