2002-08-22 20:49:01 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#warning #include "tools/tools-types.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "tools/tools-types.h"
|
|
|
|
|
2003-04-04 00:13:12 +08:00
|
|
|
#include "config/gimpcoreconfig.h"
|
|
|
|
|
2003-02-09 05:20:07 +08:00
|
|
|
#include "core/gimp.h"
|
removed the feather(), sharpen(), all(), invert(), border(), grow() and
2003-09-03 Michael Natterer <mitch@gimp.org>
* app/core/gimpimage-mask.[ch]: removed the feather(), sharpen(),
all(), invert(), border(), grow() and shrink() wrappers.
* app/core/gimpselection.[ch]: changed gimp_selection_invalidate()
and gimp_selection_push_undo() to take GimpChannel parameters, not
GimpSelection ones. They will be made virtual GimpChannel
functions anyway.
* app/core/gimpedit.c
* app/gui/select-commands.c
* app/widgets/gimpselectioneditor.c
* tools/pdbgen/pdb/selection.pdb: changed accordingly.
* app/pdb/selection_cmds.c: regenerated.
2003-09-03 21:37:49 +08:00
|
|
|
#include "core/gimpchannel.h"
|
2003-02-09 05:20:07 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
2002-08-22 20:49:01 +08:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimpimage-mask-select.h"
|
|
|
|
#include "core/gimpimage-projection.h"
|
2003-09-05 04:18:08 +08:00
|
|
|
#include "core/gimpselection.h"
|
2002-08-22 20:49:01 +08:00
|
|
|
#include "core/gimptoolinfo.h"
|
|
|
|
|
2003-02-09 05:20:07 +08:00
|
|
|
#include "tools/gimpselectionoptions.h"
|
2002-08-22 20:49:01 +08:00
|
|
|
|
|
|
|
#include "gimpselectioneditor.h"
|
|
|
|
#include "gimpdnd.h"
|
2003-08-24 21:52:51 +08:00
|
|
|
#include "gimphelp-ids.h"
|
2002-08-22 20:49:01 +08:00
|
|
|
#include "gimppreview.h"
|
2003-03-01 11:53:41 +08:00
|
|
|
#include "gimppreviewrenderer.h"
|
2003-06-03 01:57:11 +08:00
|
|
|
#include "gimpwidgets-utils.h"
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2002-08-22 20:49:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void gimp_selection_editor_class_init (GimpSelectionEditorClass *klass);
|
|
|
|
static void gimp_selection_editor_init (GimpSelectionEditor *selection_editor);
|
|
|
|
|
2003-02-20 23:40:15 +08:00
|
|
|
static void gimp_selection_editor_set_image (GimpImageEditor *editor,
|
|
|
|
GimpImage *gimage);
|
2002-08-22 20:49:01 +08:00
|
|
|
|
|
|
|
static void gimp_selection_editor_invert_clicked (GtkWidget *widget,
|
2003-02-20 23:40:15 +08:00
|
|
|
GimpImageEditor *editor);
|
2002-08-22 20:49:01 +08:00
|
|
|
static void gimp_selection_editor_all_clicked (GtkWidget *widget,
|
2003-02-20 23:40:15 +08:00
|
|
|
GimpImageEditor *editor);
|
2002-08-22 20:49:01 +08:00
|
|
|
static void gimp_selection_editor_none_clicked (GtkWidget *widget,
|
2003-02-20 23:40:15 +08:00
|
|
|
GimpImageEditor *editor);
|
2002-08-23 00:24:44 +08:00
|
|
|
static void gimp_selection_editor_save_clicked (GtkWidget *widget,
|
2003-02-20 23:40:15 +08:00
|
|
|
GimpImageEditor *editor);
|
2003-06-03 01:57:11 +08:00
|
|
|
static void gimp_selection_editor_path_clicked (GtkWidget *widget,
|
|
|
|
GimpImageEditor *editor);
|
|
|
|
static void gimp_selection_editor_path_extended_clicked (GtkWidget *widget,
|
|
|
|
guint state,
|
|
|
|
GimpImageEditor *editor);
|
2003-05-10 05:41:53 +08:00
|
|
|
static void gimp_selection_editor_stroke_clicked (GtkWidget *widget,
|
|
|
|
GimpImageEditor *editor);
|
2002-08-22 20:49:01 +08:00
|
|
|
|
|
|
|
static gboolean gimp_selection_preview_button_press(GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GimpSelectionEditor *editor);
|
|
|
|
static void gimp_selection_editor_drop_color (GtkWidget *widget,
|
|
|
|
const GimpRGB *color,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static void gimp_selection_editor_mask_changed (GimpImage *gimage,
|
|
|
|
GimpSelectionEditor *editor);
|
|
|
|
|
|
|
|
|
2003-02-20 23:40:15 +08:00
|
|
|
static GimpImageEditorClass *parent_class = NULL;
|
2002-08-22 20:49:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gimp_selection_editor_get_type (void)
|
|
|
|
{
|
|
|
|
static GType editor_type = 0;
|
|
|
|
|
|
|
|
if (! editor_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo editor_info =
|
|
|
|
{
|
|
|
|
sizeof (GimpSelectionEditorClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_selection_editor_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpSelectionEditor),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_selection_editor_init,
|
|
|
|
};
|
|
|
|
|
2003-02-20 23:40:15 +08:00
|
|
|
editor_type = g_type_register_static (GIMP_TYPE_IMAGE_EDITOR,
|
2002-08-22 20:49:01 +08:00
|
|
|
"GimpSelectionEditor",
|
|
|
|
&editor_info, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return editor_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_selection_editor_class_init (GimpSelectionEditorClass* klass)
|
|
|
|
{
|
2003-02-20 23:40:15 +08:00
|
|
|
GimpImageEditorClass *image_editor_class;
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2003-02-20 23:40:15 +08:00
|
|
|
image_editor_class = GIMP_IMAGE_EDITOR_CLASS (klass);
|
2002-08-22 20:49:01 +08:00
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2003-02-20 23:40:15 +08:00
|
|
|
image_editor_class->set_image = gimp_selection_editor_set_image;
|
2002-08-22 20:49:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_selection_editor_init (GimpSelectionEditor *selection_editor)
|
|
|
|
{
|
2003-03-10 22:07:22 +08:00
|
|
|
GtkWidget *frame;
|
2003-06-03 01:57:11 +08:00
|
|
|
gchar *str;
|
2002-08-22 20:49:01 +08:00
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
|
|
|
gtk_box_pack_start (GTK_BOX (selection_editor), frame, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2003-06-03 01:57:11 +08:00
|
|
|
selection_editor->selection_to_vectors_func = NULL;
|
|
|
|
|
2003-03-03 20:59:03 +08:00
|
|
|
selection_editor->preview = gimp_preview_new_by_types (GIMP_TYPE_PREVIEW,
|
|
|
|
GIMP_TYPE_DRAWABLE,
|
2003-03-10 22:07:22 +08:00
|
|
|
GIMP_PREVIEW_SIZE_HUGE,
|
2003-03-23 06:53:29 +08:00
|
|
|
0, TRUE);
|
2003-03-10 22:07:22 +08:00
|
|
|
gtk_widget_set_size_request (selection_editor->preview,
|
|
|
|
GIMP_PREVIEW_SIZE_HUGE, GIMP_PREVIEW_SIZE_HUGE);
|
|
|
|
gimp_preview_set_expand (GIMP_PREVIEW (selection_editor->preview), TRUE);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), selection_editor->preview);
|
2002-08-22 20:49:01 +08:00
|
|
|
gtk_widget_show (selection_editor->preview);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (selection_editor->preview, "button_press_event",
|
2002-08-22 20:49:01 +08:00
|
|
|
G_CALLBACK (gimp_selection_preview_button_press),
|
|
|
|
selection_editor);
|
|
|
|
|
2002-09-02 22:39:08 +08:00
|
|
|
gimp_dnd_color_dest_add (selection_editor->preview,
|
2002-08-22 20:49:01 +08:00
|
|
|
gimp_selection_editor_drop_color,
|
|
|
|
selection_editor);
|
|
|
|
|
|
|
|
selection_editor->all_button =
|
|
|
|
gimp_editor_add_button (GIMP_EDITOR (selection_editor),
|
2003-08-24 21:52:51 +08:00
|
|
|
GIMP_STOCK_SELECTION_ALL, _("Select All"),
|
|
|
|
GIMP_HELP_SELECTION_ALL,
|
2002-08-22 20:49:01 +08:00
|
|
|
G_CALLBACK (gimp_selection_editor_all_clicked),
|
|
|
|
NULL,
|
|
|
|
selection_editor);
|
|
|
|
|
|
|
|
selection_editor->none_button =
|
|
|
|
gimp_editor_add_button (GIMP_EDITOR (selection_editor),
|
2003-08-24 21:52:51 +08:00
|
|
|
GIMP_STOCK_SELECTION_NONE, _("Select None"),
|
|
|
|
GIMP_HELP_SELECTION_NONE,
|
2002-08-22 20:49:01 +08:00
|
|
|
G_CALLBACK (gimp_selection_editor_none_clicked),
|
|
|
|
NULL,
|
|
|
|
selection_editor);
|
2003-02-26 03:12:11 +08:00
|
|
|
|
|
|
|
selection_editor->invert_button =
|
|
|
|
gimp_editor_add_button (GIMP_EDITOR (selection_editor),
|
2003-08-24 21:52:51 +08:00
|
|
|
GIMP_STOCK_INVERT, _("Invert Selection"),
|
|
|
|
GIMP_HELP_SELECTION_INVERT,
|
2003-02-26 03:12:11 +08:00
|
|
|
G_CALLBACK (gimp_selection_editor_invert_clicked),
|
|
|
|
NULL,
|
|
|
|
selection_editor);
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2002-08-23 00:24:44 +08:00
|
|
|
selection_editor->save_button =
|
|
|
|
gimp_editor_add_button (GIMP_EDITOR (selection_editor),
|
|
|
|
GIMP_STOCK_SELECTION_TO_CHANNEL,
|
2003-08-24 21:52:51 +08:00
|
|
|
_("Save Selection to Channel"),
|
|
|
|
GIMP_HELP_SELECTION_TO_CHANNEL,
|
2002-08-23 00:24:44 +08:00
|
|
|
G_CALLBACK (gimp_selection_editor_save_clicked),
|
|
|
|
NULL,
|
|
|
|
selection_editor);
|
|
|
|
|
2003-06-03 01:57:11 +08:00
|
|
|
str = g_strdup_printf (_("Selection to Path\n"
|
|
|
|
"%s Advanced Options"),
|
|
|
|
gimp_get_mod_name_shift ());
|
|
|
|
|
|
|
|
selection_editor->path_button =
|
|
|
|
gimp_editor_add_button (GIMP_EDITOR (selection_editor),
|
2003-08-24 21:52:51 +08:00
|
|
|
GIMP_STOCK_SELECTION_TO_PATH, str,
|
|
|
|
GIMP_HELP_SELECTION_TO_PATH,
|
2003-06-03 01:57:11 +08:00
|
|
|
G_CALLBACK (gimp_selection_editor_path_clicked),
|
|
|
|
G_CALLBACK (gimp_selection_editor_path_extended_clicked),
|
|
|
|
selection_editor);
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
|
2003-05-10 05:41:53 +08:00
|
|
|
selection_editor->stroke_button =
|
|
|
|
gimp_editor_add_button (GIMP_EDITOR (selection_editor),
|
2003-06-03 01:57:11 +08:00
|
|
|
GIMP_STOCK_SELECTION_STROKE,
|
2003-08-24 21:52:51 +08:00
|
|
|
_("Stroke Selection"),
|
|
|
|
GIMP_HELP_SELECTION_STROKE,
|
2003-05-10 05:41:53 +08:00
|
|
|
G_CALLBACK (gimp_selection_editor_stroke_clicked),
|
|
|
|
NULL,
|
|
|
|
selection_editor);
|
|
|
|
|
2003-06-03 01:57:11 +08:00
|
|
|
|
2002-08-22 20:49:01 +08:00
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (selection_editor), FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-02-20 23:40:15 +08:00
|
|
|
gimp_selection_editor_set_image (GimpImageEditor *image_editor,
|
|
|
|
GimpImage *gimage)
|
2002-08-22 20:49:01 +08:00
|
|
|
{
|
|
|
|
GimpSelectionEditor *editor;
|
|
|
|
|
2003-02-20 23:40:15 +08:00
|
|
|
editor = GIMP_SELECTION_EDITOR (image_editor);
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2003-02-20 23:40:15 +08:00
|
|
|
if (image_editor->gimage)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (image_editor->gimage,
|
|
|
|
gimp_selection_editor_mask_changed,
|
|
|
|
editor);
|
|
|
|
}
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2003-02-20 23:40:15 +08:00
|
|
|
GIMP_IMAGE_EDITOR_CLASS (parent_class)->set_image (image_editor, gimage);
|
|
|
|
|
|
|
|
if (gimage)
|
|
|
|
{
|
|
|
|
g_signal_connect (gimage, "mask_changed",
|
|
|
|
G_CALLBACK (gimp_selection_editor_mask_changed),
|
|
|
|
editor);
|
|
|
|
|
|
|
|
gimp_preview_set_viewable (GIMP_PREVIEW (editor->preview),
|
|
|
|
GIMP_VIEWABLE (gimp_image_get_mask (gimage)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_preview_set_viewable (GIMP_PREVIEW (editor->preview), NULL);
|
|
|
|
}
|
2002-08-22 20:49:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
#define PREVIEW_WIDTH 256
|
|
|
|
#define PREVIEW_HEIGHT 256
|
|
|
|
|
|
|
|
GtkWidget *
|
2003-04-11 19:18:12 +08:00
|
|
|
gimp_selection_editor_new (GimpImage *gimage)
|
2002-08-22 20:49:01 +08:00
|
|
|
{
|
|
|
|
GimpSelectionEditor *editor;
|
|
|
|
|
|
|
|
g_return_val_if_fail (! gimage || GIMP_IS_IMAGE (gimage), NULL);
|
|
|
|
|
|
|
|
editor = g_object_new (GIMP_TYPE_SELECTION_EDITOR, NULL);
|
|
|
|
|
2003-04-11 19:18:12 +08:00
|
|
|
gimp_preview_renderer_set_background (GIMP_PREVIEW (editor->preview)->renderer,
|
|
|
|
GIMP_STOCK_TEXTURE);
|
2003-04-04 00:13:12 +08:00
|
|
|
|
2002-08-22 20:49:01 +08:00
|
|
|
if (gimage)
|
2003-02-20 23:40:15 +08:00
|
|
|
gimp_image_editor_set_image (GIMP_IMAGE_EDITOR (editor), gimage);
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2003-02-20 23:40:15 +08:00
|
|
|
return GTK_WIDGET (editor);
|
2002-08-22 20:49:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-02-20 23:40:15 +08:00
|
|
|
gimp_selection_editor_invert_clicked (GtkWidget *widget,
|
|
|
|
GimpImageEditor *editor)
|
2002-08-22 20:49:01 +08:00
|
|
|
{
|
|
|
|
if (editor->gimage)
|
|
|
|
{
|
removed the feather(), sharpen(), all(), invert(), border(), grow() and
2003-09-03 Michael Natterer <mitch@gimp.org>
* app/core/gimpimage-mask.[ch]: removed the feather(), sharpen(),
all(), invert(), border(), grow() and shrink() wrappers.
* app/core/gimpselection.[ch]: changed gimp_selection_invalidate()
and gimp_selection_push_undo() to take GimpChannel parameters, not
GimpSelection ones. They will be made virtual GimpChannel
functions anyway.
* app/core/gimpedit.c
* app/gui/select-commands.c
* app/widgets/gimpselectioneditor.c
* tools/pdbgen/pdb/selection.pdb: changed accordingly.
* app/pdb/selection_cmds.c: regenerated.
2003-09-03 21:37:49 +08:00
|
|
|
gimp_channel_invert (gimp_image_get_mask (editor->gimage), TRUE);
|
2002-08-22 20:49:01 +08:00
|
|
|
gimp_image_flush (editor->gimage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-02-20 23:40:15 +08:00
|
|
|
gimp_selection_editor_all_clicked (GtkWidget *widget,
|
|
|
|
GimpImageEditor *editor)
|
2002-08-22 20:49:01 +08:00
|
|
|
{
|
|
|
|
if (editor->gimage)
|
|
|
|
{
|
removed the feather(), sharpen(), all(), invert(), border(), grow() and
2003-09-03 Michael Natterer <mitch@gimp.org>
* app/core/gimpimage-mask.[ch]: removed the feather(), sharpen(),
all(), invert(), border(), grow() and shrink() wrappers.
* app/core/gimpselection.[ch]: changed gimp_selection_invalidate()
and gimp_selection_push_undo() to take GimpChannel parameters, not
GimpSelection ones. They will be made virtual GimpChannel
functions anyway.
* app/core/gimpedit.c
* app/gui/select-commands.c
* app/widgets/gimpselectioneditor.c
* tools/pdbgen/pdb/selection.pdb: changed accordingly.
* app/pdb/selection_cmds.c: regenerated.
2003-09-03 21:37:49 +08:00
|
|
|
gimp_channel_all (gimp_image_get_mask (editor->gimage), TRUE);
|
2002-08-22 20:49:01 +08:00
|
|
|
gimp_image_flush (editor->gimage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-02-20 23:40:15 +08:00
|
|
|
gimp_selection_editor_none_clicked (GtkWidget *widget,
|
|
|
|
GimpImageEditor *editor)
|
2002-08-22 20:49:01 +08:00
|
|
|
{
|
|
|
|
if (editor->gimage)
|
|
|
|
{
|
removed the feather(), sharpen(), all(), invert(), border(), grow() and
2003-09-03 Michael Natterer <mitch@gimp.org>
* app/core/gimpimage-mask.[ch]: removed the feather(), sharpen(),
all(), invert(), border(), grow() and shrink() wrappers.
* app/core/gimpselection.[ch]: changed gimp_selection_invalidate()
and gimp_selection_push_undo() to take GimpChannel parameters, not
GimpSelection ones. They will be made virtual GimpChannel
functions anyway.
* app/core/gimpedit.c
* app/gui/select-commands.c
* app/widgets/gimpselectioneditor.c
* tools/pdbgen/pdb/selection.pdb: changed accordingly.
* app/pdb/selection_cmds.c: regenerated.
2003-09-03 21:37:49 +08:00
|
|
|
gimp_channel_clear (gimp_image_get_mask (editor->gimage), NULL, TRUE);
|
2002-08-22 20:49:01 +08:00
|
|
|
gimp_image_flush (editor->gimage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-23 00:24:44 +08:00
|
|
|
static void
|
2003-02-20 23:40:15 +08:00
|
|
|
gimp_selection_editor_save_clicked (GtkWidget *widget,
|
|
|
|
GimpImageEditor *editor)
|
2002-08-23 00:24:44 +08:00
|
|
|
{
|
|
|
|
if (editor->gimage)
|
|
|
|
{
|
2003-09-05 04:18:08 +08:00
|
|
|
gimp_selection_save (gimp_image_get_mask (editor->gimage));
|
2002-08-23 00:24:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-03 01:57:11 +08:00
|
|
|
static void
|
|
|
|
gimp_selection_editor_path_clicked (GtkWidget *widget,
|
|
|
|
GimpImageEditor *editor)
|
|
|
|
{
|
|
|
|
gimp_selection_editor_path_extended_clicked (widget, 0, editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_selection_editor_path_extended_clicked (GtkWidget *widget,
|
|
|
|
guint state,
|
|
|
|
GimpImageEditor *editor)
|
|
|
|
{
|
|
|
|
if (editor->gimage)
|
|
|
|
{
|
|
|
|
GimpSelectionEditor *sel_editor = GIMP_SELECTION_EDITOR (editor);
|
|
|
|
|
|
|
|
if (sel_editor->selection_to_vectors_func)
|
|
|
|
sel_editor->selection_to_vectors_func (editor->gimage,
|
|
|
|
(state & GDK_SHIFT_MASK) != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-10 05:41:53 +08:00
|
|
|
static void
|
|
|
|
gimp_selection_editor_stroke_clicked (GtkWidget *widget,
|
|
|
|
GimpImageEditor *editor)
|
|
|
|
{
|
2003-09-30 10:44:17 +08:00
|
|
|
if (editor->gimage)
|
2003-05-10 05:41:53 +08:00
|
|
|
{
|
2003-09-30 10:44:17 +08:00
|
|
|
GimpSelectionEditor *sel_editor = GIMP_SELECTION_EDITOR (editor);
|
2003-05-10 05:41:53 +08:00
|
|
|
|
2003-09-30 10:44:17 +08:00
|
|
|
if (sel_editor->stroke_item_func)
|
|
|
|
sel_editor->stroke_item_func (GIMP_ITEM (gimp_image_get_mask (editor->gimage)));
|
2003-05-10 05:41:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-22 20:49:01 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_selection_preview_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GimpSelectionEditor *editor)
|
|
|
|
{
|
2003-02-20 23:40:15 +08:00
|
|
|
GimpImageEditor *image_editor;
|
2003-03-10 22:07:22 +08:00
|
|
|
GimpPreviewRenderer *renderer;
|
2003-02-05 22:39:40 +08:00
|
|
|
GimpToolInfo *tool_info;
|
|
|
|
GimpSelectionOptions *options;
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
SelectOps operation = SELECTION_REPLACE;
|
|
|
|
gint x, y;
|
|
|
|
guchar *col;
|
|
|
|
GimpRGB color;
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2003-02-20 23:40:15 +08:00
|
|
|
image_editor = GIMP_IMAGE_EDITOR (editor);
|
|
|
|
|
|
|
|
if (! image_editor->gimage)
|
2002-08-22 20:49:01 +08:00
|
|
|
return TRUE;
|
|
|
|
|
2003-03-10 22:07:22 +08:00
|
|
|
renderer = GIMP_PREVIEW (editor->preview)->renderer;
|
|
|
|
|
2003-02-09 05:20:07 +08:00
|
|
|
tool_info = (GimpToolInfo *)
|
2003-02-20 23:40:15 +08:00
|
|
|
gimp_container_get_child_by_name (image_editor->gimage->gimp->tool_info_list,
|
2003-02-09 05:20:07 +08:00
|
|
|
"gimp-by-color-select-tool");
|
|
|
|
|
|
|
|
if (! tool_info)
|
|
|
|
return TRUE;
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2003-02-05 22:39:40 +08:00
|
|
|
options = GIMP_SELECTION_OPTIONS (tool_info->tool_options);
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2003-02-20 23:40:15 +08:00
|
|
|
drawable = gimp_image_active_drawable (image_editor->gimage);
|
2002-08-22 20:49:01 +08:00
|
|
|
|
|
|
|
if (! drawable)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (bevent->state & GDK_SHIFT_MASK)
|
|
|
|
{
|
|
|
|
if (bevent->state & GDK_CONTROL_MASK)
|
|
|
|
{
|
|
|
|
operation = SELECTION_INTERSECT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
operation = SELECTION_ADD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (bevent->state & GDK_CONTROL_MASK)
|
|
|
|
{
|
|
|
|
operation = SELECTION_SUBTRACT;
|
|
|
|
}
|
|
|
|
|
2003-03-10 22:07:22 +08:00
|
|
|
x = image_editor->gimage->width * bevent->x / renderer->width;
|
|
|
|
y = image_editor->gimage->height * bevent->y / renderer->height;
|
|
|
|
|
2003-02-05 22:39:40 +08:00
|
|
|
if (options->sample_merged)
|
2002-08-22 20:49:01 +08:00
|
|
|
{
|
|
|
|
if (x < 0 || y < 0 ||
|
2003-02-20 23:40:15 +08:00
|
|
|
x >= image_editor->gimage->width ||
|
|
|
|
y >= image_editor->gimage->height)
|
2002-08-22 20:49:01 +08:00
|
|
|
return TRUE;
|
|
|
|
|
2003-02-20 23:40:15 +08:00
|
|
|
col = gimp_image_projection_get_color_at (image_editor->gimage, x, y);
|
2002-08-22 20:49:01 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-05-08 21:12:46 +08:00
|
|
|
GimpItem *item;
|
|
|
|
gint off_x, off_y;
|
|
|
|
|
|
|
|
item = GIMP_ITEM (drawable);
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2003-05-08 22:06:03 +08:00
|
|
|
gimp_item_offsets (item, &off_x, &off_y);
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2003-03-10 22:07:22 +08:00
|
|
|
x -= off_x;
|
|
|
|
y -= off_y;
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2003-05-08 21:12:46 +08:00
|
|
|
if (x < 0 || y < 0 ||
|
|
|
|
x >= gimp_item_width (item) ||
|
|
|
|
y >= gimp_item_height (item))
|
2002-08-22 20:49:01 +08:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
col = gimp_drawable_get_color_at (drawable, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_rgba_set_uchar (&color, col[0], col[1], col[2], col[3]);
|
|
|
|
|
|
|
|
g_free (col);
|
|
|
|
|
2003-02-20 23:40:15 +08:00
|
|
|
gimp_image_mask_select_by_color (image_editor->gimage, drawable,
|
2003-02-05 22:39:40 +08:00
|
|
|
options->sample_merged,
|
2002-08-22 20:49:01 +08:00
|
|
|
&color,
|
2003-02-05 22:39:40 +08:00
|
|
|
options->threshold,
|
|
|
|
options->select_transparent,
|
2002-08-22 20:49:01 +08:00
|
|
|
operation,
|
2003-02-05 22:39:40 +08:00
|
|
|
options->antialias,
|
|
|
|
options->feather,
|
|
|
|
options->feather_radius,
|
|
|
|
options->feather_radius);
|
2003-02-20 23:40:15 +08:00
|
|
|
gimp_image_flush (image_editor->gimage);
|
2002-08-22 20:49:01 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_selection_editor_drop_color (GtkWidget *widget,
|
|
|
|
const GimpRGB *color,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2003-02-05 22:39:40 +08:00
|
|
|
GimpToolInfo *tool_info;
|
|
|
|
GimpSelectionOptions *options;
|
|
|
|
GimpDrawable *drawable;
|
2003-02-20 23:40:15 +08:00
|
|
|
GimpImageEditor *editor;
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2003-02-20 23:40:15 +08:00
|
|
|
editor = GIMP_IMAGE_EDITOR (data);
|
2002-08-22 20:49:01 +08:00
|
|
|
|
|
|
|
if (! editor->gimage)
|
|
|
|
return;
|
|
|
|
|
2003-02-09 05:20:07 +08:00
|
|
|
tool_info = (GimpToolInfo *)
|
|
|
|
gimp_container_get_child_by_name (editor->gimage->gimp->tool_info_list,
|
|
|
|
"gimp-by-color-select-tool");
|
|
|
|
|
|
|
|
if (! tool_info)
|
|
|
|
return;
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2003-02-05 22:39:40 +08:00
|
|
|
options = GIMP_SELECTION_OPTIONS (tool_info->tool_options);
|
2002-08-22 20:49:01 +08:00
|
|
|
|
|
|
|
drawable = gimp_image_active_drawable (editor->gimage);
|
|
|
|
|
|
|
|
if (! drawable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gimp_image_mask_select_by_color (editor->gimage, drawable,
|
2003-02-05 22:39:40 +08:00
|
|
|
options->sample_merged,
|
2002-08-22 20:49:01 +08:00
|
|
|
color,
|
2003-02-05 22:39:40 +08:00
|
|
|
options->threshold,
|
|
|
|
options->select_transparent,
|
2003-02-08 01:12:21 +08:00
|
|
|
options->operation,
|
2003-02-05 22:39:40 +08:00
|
|
|
options->antialias,
|
|
|
|
options->feather,
|
|
|
|
options->feather_radius,
|
|
|
|
options->feather_radius);
|
2002-08-22 20:49:01 +08:00
|
|
|
gimp_image_flush (editor->gimage);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_selection_editor_mask_changed (GimpImage *gimage,
|
|
|
|
GimpSelectionEditor *editor)
|
|
|
|
{
|
2003-03-03 20:59:03 +08:00
|
|
|
gimp_preview_renderer_invalidate (GIMP_PREVIEW (editor->preview)->renderer);
|
2002-08-22 20:49:01 +08:00
|
|
|
}
|