52
53
#include "gimp-intl.h"
55
static void gimp_selection_editor_class_init (GimpSelectionEditorClass *klass);
56
static void gimp_selection_editor_init (GimpSelectionEditor *selection_editor);
56
static void gimp_selection_editor_docked_iface_init (GimpDockedInterface *iface);
58
58
static GObject * gimp_selection_editor_constructor (GType type,
60
60
GObjectConstructParam *params);
62
62
static void gimp_selection_editor_set_image (GimpImageEditor *editor,
65
static gboolean gimp_selection_preview_button_press(GtkWidget *widget,
65
static void gimp_selection_editor_set_context (GimpDocked *docked,
66
GimpContext *context);
68
static gboolean gimp_selection_view_button_press (GtkWidget *widget,
66
69
GdkEventButton *bevent,
67
70
GimpSelectionEditor *editor);
68
71
static void gimp_selection_editor_drop_color (GtkWidget *widget,
69
74
const GimpRGB *color,
72
static void gimp_selection_editor_mask_changed (GimpImage *gimage,
77
static void gimp_selection_editor_mask_changed (GimpImage *image,
73
78
GimpSelectionEditor *editor);
76
static GimpImageEditorClass *parent_class = NULL;
80
gimp_selection_editor_get_type (void)
82
static GType editor_type = 0;
86
static const GTypeInfo editor_info =
88
sizeof (GimpSelectionEditorClass),
90
(GBaseFinalizeFunc) NULL,
91
(GClassInitFunc) gimp_selection_editor_class_init,
92
NULL, /* class_finalize */
93
NULL, /* class_data */
94
sizeof (GimpSelectionEditor),
96
(GInstanceInitFunc) gimp_selection_editor_init,
99
editor_type = g_type_register_static (GIMP_TYPE_IMAGE_EDITOR,
100
"GimpSelectionEditor",
81
G_DEFINE_TYPE_WITH_CODE (GimpSelectionEditor, gimp_selection_editor,
82
GIMP_TYPE_IMAGE_EDITOR,
83
G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
84
gimp_selection_editor_docked_iface_init))
86
#define parent_class gimp_selection_editor_parent_class
88
static GimpDockedInterface *parent_docked_iface = NULL;
108
gimp_selection_editor_class_init (GimpSelectionEditorClass* klass)
92
gimp_selection_editor_class_init (GimpSelectionEditorClass *klass)
110
94
GObjectClass *object_class = G_OBJECT_CLASS (klass);
111
95
GimpImageEditorClass *image_editor_class = GIMP_IMAGE_EDITOR_CLASS (klass);
113
parent_class = g_type_class_peek_parent (klass);
115
97
object_class->constructor = gimp_selection_editor_constructor;
117
99
image_editor_class->set_image = gimp_selection_editor_set_image;
103
gimp_selection_editor_docked_iface_init (GimpDockedInterface *iface)
105
parent_docked_iface = g_type_interface_peek_parent (iface);
107
if (! parent_docked_iface)
108
parent_docked_iface = g_type_default_interface_peek (GIMP_TYPE_DOCKED);
110
iface->set_context = gimp_selection_editor_set_context;
121
114
gimp_selection_editor_init (GimpSelectionEditor *editor)
123
116
GtkWidget *frame;
127
120
gtk_box_pack_start (GTK_BOX (editor), frame, TRUE, TRUE, 0);
128
121
gtk_widget_show (frame);
130
editor->preview = gimp_view_new_by_types (GIMP_TYPE_VIEW,
134
gimp_view_renderer_set_background (GIMP_VIEW (editor->preview)->renderer,
123
editor->view = gimp_view_new_by_types (NULL,
128
gimp_view_renderer_set_background (GIMP_VIEW (editor->view)->renderer,
135
129
GIMP_STOCK_TEXTURE);
136
gtk_widget_set_size_request (editor->preview,
130
gtk_widget_set_size_request (editor->view,
137
131
GIMP_VIEW_SIZE_HUGE, GIMP_VIEW_SIZE_HUGE);
138
gimp_view_set_expand (GIMP_VIEW (editor->preview), TRUE);
139
gtk_container_add (GTK_CONTAINER (frame), editor->preview);
140
gtk_widget_show (editor->preview);
132
gimp_view_set_expand (GIMP_VIEW (editor->view), TRUE);
133
gtk_container_add (GTK_CONTAINER (frame), editor->view);
134
gtk_widget_show (editor->view);
142
g_signal_connect (editor->preview, "button_press_event",
143
G_CALLBACK (gimp_selection_preview_button_press),
136
g_signal_connect (editor->view, "button-press-event",
137
G_CALLBACK (gimp_selection_view_button_press),
146
gimp_dnd_color_dest_add (editor->preview,
140
gimp_dnd_color_dest_add (editor->view,
147
141
gimp_selection_editor_drop_color,
199
193
gimp_selection_editor_set_image (GimpImageEditor *image_editor,
202
196
GimpSelectionEditor *editor = GIMP_SELECTION_EDITOR (image_editor);
204
if (image_editor->gimage)
198
if (image_editor->image)
206
g_signal_handlers_disconnect_by_func (image_editor->gimage,
200
g_signal_handlers_disconnect_by_func (image_editor->image,
207
201
gimp_selection_editor_mask_changed,
211
GIMP_IMAGE_EDITOR_CLASS (parent_class)->set_image (image_editor, gimage);
205
GIMP_IMAGE_EDITOR_CLASS (parent_class)->set_image (image_editor, image);
215
g_signal_connect (gimage, "mask_changed",
209
g_signal_connect (image, "mask-changed",
216
210
G_CALLBACK (gimp_selection_editor_mask_changed),
219
gimp_view_set_viewable (GIMP_VIEW (editor->preview),
220
GIMP_VIEWABLE (gimp_image_get_mask (gimage)));
213
gimp_view_set_viewable (GIMP_VIEW (editor->view),
214
GIMP_VIEWABLE (gimp_image_get_mask (image)));
224
gimp_view_set_viewable (GIMP_VIEW (editor->preview), NULL);
218
gimp_view_set_viewable (GIMP_VIEW (editor->view), NULL);
223
gimp_selection_editor_set_context (GimpDocked *docked,
224
GimpContext *context)
226
GimpSelectionEditor *editor = GIMP_SELECTION_EDITOR (docked);
228
parent_docked_iface->set_context (docked, context);
230
gimp_view_renderer_set_context (GIMP_VIEW (editor->view)->renderer,
229
235
/* public functions */
236
242
return g_object_new (GIMP_TYPE_SELECTION_EDITOR,
237
243
"menu-factory", menu_factory,
238
"menu-identifier", "<SelectionEditor>",
239
"ui-path", "/selection-editor-popup",
244
"menu-identifier", "<Selection>",
245
"ui-path", "/selection-popup",
244
gimp_selection_preview_button_press (GtkWidget *widget,
245
GdkEventButton *bevent,
246
GimpSelectionEditor *editor)
250
gimp_selection_view_button_press (GtkWidget *widget,
251
GdkEventButton *bevent,
252
GimpSelectionEditor *editor)
248
254
GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
249
255
GimpViewRenderer *renderer;
250
256
GimpToolInfo *tool_info;
251
257
GimpSelectionOptions *options;
252
258
GimpDrawable *drawable;
253
SelectOps operation = SELECTION_REPLACE;
259
GimpChannelOps operation = GIMP_CHANNEL_OP_REPLACE;
257
if (! image_editor->gimage)
263
if (! image_editor->image)
260
renderer = GIMP_VIEW (editor->preview)->renderer;
266
renderer = GIMP_VIEW (editor->view)->renderer;
262
tool_info = (GimpToolInfo *)
263
gimp_container_get_child_by_name (image_editor->gimage->gimp->tool_info_list,
264
"gimp-by-color-select-tool");
268
tool_info = gimp_get_tool_info (image_editor->image->gimp,
269
"gimp-by-color-select-tool");
269
274
options = GIMP_SELECTION_OPTIONS (tool_info->tool_options);
271
drawable = gimp_image_active_drawable (image_editor->gimage);
276
drawable = gimp_image_active_drawable (image_editor->image);
278
283
if (bevent->state & GDK_CONTROL_MASK)
280
operation = SELECTION_INTERSECT;
285
operation = GIMP_CHANNEL_OP_INTERSECT;
284
operation = SELECTION_ADD;
289
operation = GIMP_CHANNEL_OP_ADD;
287
292
else if (bevent->state & GDK_CONTROL_MASK)
289
operation = SELECTION_SUBTRACT;
294
operation = GIMP_CHANNEL_OP_SUBTRACT;
292
x = image_editor->gimage->width * bevent->x / renderer->width;
293
y = image_editor->gimage->height * bevent->y / renderer->height;
297
x = image_editor->image->width * bevent->x / renderer->width;
298
y = image_editor->image->height * bevent->y / renderer->height;
295
if (gimp_image_pick_color (image_editor->gimage, drawable, x, y,
300
if (gimp_image_pick_color (image_editor->image, drawable, x, y,
296
301
options->sample_merged,
301
gimp_channel_select_by_color (gimp_image_get_mask (image_editor->gimage),
306
gimp_channel_select_by_color (gimp_image_get_mask (image_editor->image),
303
308
options->sample_merged,
305
310
options->threshold,
306
311
options->select_transparent,
312
options->select_criterion,
308
314
options->antialias,
309
315
options->feather,
310
316
options->feather_radius,
311
317
options->feather_radius);
312
gimp_image_flush (image_editor->gimage);
318
gimp_image_flush (image_editor->image);
325
333
GimpSelectionOptions *options;
326
334
GimpDrawable *drawable;
328
if (! editor->gimage)
331
tool_info = (GimpToolInfo *)
332
gimp_container_get_child_by_name (editor->gimage->gimp->tool_info_list,
333
"gimp-by-color-select-tool");
339
tool_info = gimp_get_tool_info (editor->image->gimp,
340
"gimp-by-color-select-tool");
338
344
options = GIMP_SELECTION_OPTIONS (tool_info->tool_options);
340
drawable = gimp_image_active_drawable (editor->gimage);
346
drawable = gimp_image_active_drawable (editor->image);
345
gimp_channel_select_by_color (gimp_image_get_mask (editor->gimage),
351
gimp_channel_select_by_color (gimp_image_get_mask (editor->image),
347
353
options->sample_merged,
349
355
options->threshold,
350
356
options->select_transparent,
357
options->select_criterion,
351
358
options->operation,
352
359
options->antialias,
353
360
options->feather,
354
361
options->feather_radius,
355
362
options->feather_radius);
356
gimp_image_flush (editor->gimage);
363
gimp_image_flush (editor->image);
360
gimp_selection_editor_mask_changed (GimpImage *gimage,
367
gimp_selection_editor_mask_changed (GimpImage *image,
361
368
GimpSelectionEditor *editor)
363
gimp_view_renderer_invalidate (GIMP_VIEW (editor->preview)->renderer);
370
gimp_view_renderer_invalidate (GIMP_VIEW (editor->view)->renderer);