2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-01-22 12:17:17 +08:00
|
|
|
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-01-22 12:17:17 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-01-22 12:17:17 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2001-01-22 12:17:17 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-03-30 01:19:01 +08:00
|
|
|
#include <gegl.h>
|
2001-01-22 12:17:17 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2001-01-22 12:17:17 +08:00
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "tools-types.h"
|
|
|
|
|
2006-10-19 03:54:18 +08:00
|
|
|
#include "widgets/gimppropwidgets.h"
|
2004-11-24 01:01:51 +08:00
|
|
|
#include "widgets/gimpwidgets-utils.h"
|
2003-01-07 00:25:04 +08:00
|
|
|
|
2003-02-09 05:12:03 +08:00
|
|
|
#include "gimpselectionoptions.h"
|
2003-06-30 04:40:45 +08:00
|
|
|
#include "gimptooloptions-gui.h"
|
2001-01-22 12:17:17 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-01-22 12:17:17 +08:00
|
|
|
|
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_OPERATION,
|
|
|
|
PROP_ANTIALIAS,
|
|
|
|
PROP_FEATHER,
|
2008-03-09 23:05:54 +08:00
|
|
|
PROP_FEATHER_RADIUS
|
2003-02-08 01:12:21 +08:00
|
|
|
};
|
|
|
|
|
2003-01-07 00:25:04 +08:00
|
|
|
|
2008-03-10 01:43:28 +08:00
|
|
|
static void gimp_selection_options_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_selection_options_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2003-02-08 01:12:21 +08:00
|
|
|
|
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
G_DEFINE_TYPE (GimpSelectionOptions, gimp_selection_options,
|
2006-05-15 17:46:31 +08:00
|
|
|
GIMP_TYPE_TOOL_OPTIONS)
|
2003-01-07 00:25:04 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
#define parent_class gimp_selection_options_parent_class
|
2001-01-22 12:17:17 +08:00
|
|
|
|
|
|
|
|
2003-07-17 23:22:21 +08:00
|
|
|
static void
|
2003-02-05 22:39:40 +08:00
|
|
|
gimp_selection_options_class_init (GimpSelectionOptionsClass *klass)
|
|
|
|
{
|
2008-03-10 01:43:28 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2003-02-08 01:12:21 +08:00
|
|
|
|
|
|
|
object_class->set_property = gimp_selection_options_set_property;
|
|
|
|
object_class->get_property = gimp_selection_options_get_property;
|
|
|
|
|
2016-02-12 06:44:07 +08:00
|
|
|
GIMP_CONFIG_PROP_ENUM (object_class, PROP_OPERATION,
|
|
|
|
"operation",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_CHANNEL_OPS,
|
|
|
|
GIMP_CHANNEL_OP_REPLACE,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_ANTIALIAS,
|
|
|
|
"antialias",
|
|
|
|
_("Antialiasing"),
|
|
|
|
_("Smooth edges"),
|
|
|
|
TRUE,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_FEATHER,
|
|
|
|
"feather",
|
|
|
|
_("Feather edges"),
|
|
|
|
_("Enable feathering of selection edges"),
|
|
|
|
FALSE,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_FEATHER_RADIUS,
|
|
|
|
"feather-radius",
|
|
|
|
_("Radius"),
|
|
|
|
_("Radius of feathering"),
|
|
|
|
0.0, 100.0, 10.0,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
2003-02-05 22:39:40 +08:00
|
|
|
}
|
2001-01-22 12:17:17 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
static void
|
|
|
|
gimp_selection_options_init (GimpSelectionOptions *options)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
static void
|
|
|
|
gimp_selection_options_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2003-02-05 22:39:40 +08:00
|
|
|
{
|
2004-09-24 20:01:35 +08:00
|
|
|
GimpSelectionOptions *options = GIMP_SELECTION_OPTIONS (object);
|
2003-02-05 22:39:40 +08:00
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_OPERATION:
|
|
|
|
options->operation = g_value_get_enum (value);
|
|
|
|
break;
|
2008-03-09 23:05:54 +08:00
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
case PROP_ANTIALIAS:
|
|
|
|
options->antialias = g_value_get_boolean (value);
|
|
|
|
break;
|
2008-03-09 23:05:54 +08:00
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
case PROP_FEATHER:
|
|
|
|
options->feather = g_value_get_boolean (value);
|
|
|
|
break;
|
2008-03-09 23:05:54 +08:00
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
case PROP_FEATHER_RADIUS:
|
|
|
|
options->feather_radius = g_value_get_double (value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-02-05 22:39:40 +08:00
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
static void
|
|
|
|
gimp_selection_options_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2004-09-24 20:01:35 +08:00
|
|
|
GimpSelectionOptions *options = GIMP_SELECTION_OPTIONS (object);
|
2001-01-22 12:17:17 +08:00
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
switch (property_id)
|
2001-11-21 11:54:09 +08:00
|
|
|
{
|
2003-02-08 01:12:21 +08:00
|
|
|
case PROP_OPERATION:
|
|
|
|
g_value_set_enum (value, options->operation);
|
|
|
|
break;
|
2008-03-09 23:05:54 +08:00
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
case PROP_ANTIALIAS:
|
|
|
|
g_value_set_boolean (value, options->antialias);
|
|
|
|
break;
|
2008-03-09 23:05:54 +08:00
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
case PROP_FEATHER:
|
|
|
|
g_value_set_boolean (value, options->feather);
|
|
|
|
break;
|
2008-03-09 23:05:54 +08:00
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
case PROP_FEATHER_RADIUS:
|
|
|
|
g_value_set_double (value, options->feather_radius);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-07 18:16:01 +08:00
|
|
|
static const gchar *
|
2011-10-07 03:59:07 +08:00
|
|
|
gimp_selection_options_get_modifiers (GimpChannelOps operation)
|
2005-05-07 18:16:01 +08:00
|
|
|
{
|
2011-10-07 03:59:07 +08:00
|
|
|
GdkModifierType extend_mask;
|
|
|
|
GdkModifierType modify_mask;
|
|
|
|
GdkModifierType modifiers = 0;
|
|
|
|
|
|
|
|
extend_mask = gimp_get_extend_selection_mask ();
|
|
|
|
modify_mask = gimp_get_modify_selection_mask ();
|
2005-05-07 18:16:01 +08:00
|
|
|
|
|
|
|
switch (operation)
|
|
|
|
{
|
|
|
|
case GIMP_CHANNEL_OP_ADD:
|
2011-10-07 03:59:07 +08:00
|
|
|
modifiers = extend_mask;
|
2005-05-07 18:16:01 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_CHANNEL_OP_SUBTRACT:
|
2011-10-07 03:59:07 +08:00
|
|
|
modifiers = modify_mask;
|
2005-05-07 18:16:01 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_CHANNEL_OP_REPLACE:
|
2011-10-07 03:59:07 +08:00
|
|
|
modifiers = 0;
|
2005-05-07 18:16:01 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_CHANNEL_OP_INTERSECT:
|
2011-10-07 03:59:07 +08:00
|
|
|
modifiers = extend_mask | modify_mask;
|
2005-05-07 18:16:01 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-07 04:26:43 +08:00
|
|
|
return gimp_get_mod_string (modifiers);
|
2005-05-07 18:16:01 +08:00
|
|
|
}
|
|
|
|
|
2003-02-10 01:32:52 +08:00
|
|
|
GtkWidget *
|
2003-02-08 01:12:21 +08:00
|
|
|
gimp_selection_options_gui (GimpToolOptions *tool_options)
|
|
|
|
{
|
2004-09-24 20:01:35 +08:00
|
|
|
GObject *config = G_OBJECT (tool_options);
|
|
|
|
GimpSelectionOptions *options = GIMP_SELECTION_OPTIONS (tool_options);
|
2005-07-29 10:07:49 +08:00
|
|
|
GtkWidget *vbox = gimp_tool_options_gui (tool_options);
|
2003-02-08 01:12:21 +08:00
|
|
|
GtkWidget *button;
|
|
|
|
|
|
|
|
/* the selection operation radio buttons */
|
|
|
|
{
|
2001-11-21 11:54:09 +08:00
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *label;
|
2008-03-08 22:07:16 +08:00
|
|
|
GtkWidget *box;
|
2005-05-07 18:16:01 +08:00
|
|
|
GList *children;
|
2003-02-08 01:12:21 +08:00
|
|
|
GList *list;
|
2005-05-07 18:16:01 +08:00
|
|
|
gint i;
|
2001-11-21 11:54:09 +08:00
|
|
|
|
2011-09-30 17:29:11 +08:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
|
2001-11-21 11:54:09 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2008-03-08 22:07:16 +08:00
|
|
|
label = gtk_label_new (_("Mode:"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
2014-05-08 03:30:06 +08:00
|
|
|
box = gimp_prop_enum_icon_box_new (config, "operation",
|
|
|
|
"gimp-selection", 0, 0);
|
2008-03-08 22:07:16 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), box, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (box);
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (box));
|
2005-05-07 18:16:01 +08:00
|
|
|
|
|
|
|
/* add modifier keys to the tooltips */
|
|
|
|
for (list = children, i = 0; list; list = list->next, i++)
|
|
|
|
{
|
2007-11-09 19:17:00 +08:00
|
|
|
GtkWidget *button = list->data;
|
2011-10-07 03:59:07 +08:00
|
|
|
const gchar *modifier = gimp_selection_options_get_modifiers (i);
|
2007-11-09 19:17:00 +08:00
|
|
|
gchar *tooltip;
|
2005-05-07 18:16:01 +08:00
|
|
|
|
|
|
|
if (! modifier)
|
|
|
|
continue;
|
|
|
|
|
2007-11-09 19:17:00 +08:00
|
|
|
tooltip = gtk_widget_get_tooltip_text (button);
|
|
|
|
|
|
|
|
if (tooltip)
|
2005-05-07 18:16:01 +08:00
|
|
|
{
|
2007-11-09 19:17:00 +08:00
|
|
|
gchar *tip = g_strdup_printf ("%s <b>%s</b>", tooltip, modifier);
|
2005-05-07 18:16:01 +08:00
|
|
|
|
2007-11-22 21:59:06 +08:00
|
|
|
gimp_help_set_help_data_with_markup (button, tip, NULL);
|
2007-11-16 04:23:27 +08:00
|
|
|
|
2005-05-07 18:16:01 +08:00
|
|
|
g_free (tip);
|
2007-11-16 04:23:27 +08:00
|
|
|
g_free (tooltip);
|
2005-05-07 18:16:01 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_help_set_help_data (button, modifier, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* move GIMP_CHANNEL_OP_REPLACE to the front */
|
2008-03-08 22:07:16 +08:00
|
|
|
gtk_box_reorder_child (GTK_BOX (box),
|
2005-05-07 18:16:01 +08:00
|
|
|
GTK_WIDGET (children->next->next->data), 0);
|
|
|
|
|
|
|
|
g_list_free (children);
|
2001-11-21 11:54:09 +08:00
|
|
|
}
|
|
|
|
|
2001-01-22 12:17:17 +08:00
|
|
|
/* the antialias toggle button */
|
2016-02-12 06:44:07 +08:00
|
|
|
button = gimp_prop_check_button_new (config, "antialias", NULL);
|
2005-08-22 05:43:34 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
2006-10-19 02:54:28 +08:00
|
|
|
options->antialias_toggle = button;
|
2001-01-22 12:17:17 +08:00
|
|
|
|
2001-11-24 00:25:01 +08:00
|
|
|
/* the feather frame */
|
|
|
|
{
|
|
|
|
GtkWidget *frame;
|
2010-11-02 04:48:59 +08:00
|
|
|
GtkWidget *scale;
|
2001-11-24 00:25:01 +08:00
|
|
|
|
2010-11-02 04:48:59 +08:00
|
|
|
/* the feather radius scale */
|
2016-02-12 06:44:07 +08:00
|
|
|
scale = gimp_prop_spin_scale_new (config, "feather-radius", NULL,
|
2010-11-02 04:48:59 +08:00
|
|
|
1.0, 10.0, 1);
|
2004-11-24 01:01:51 +08:00
|
|
|
|
2016-02-12 06:44:07 +08:00
|
|
|
frame = gimp_prop_expanding_frame_new (config, "feather", NULL,
|
2010-11-02 04:48:59 +08:00
|
|
|
scale, NULL);
|
2006-10-19 03:54:18 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
2001-11-24 00:25:01 +08:00
|
|
|
}
|
|
|
|
|
2003-02-10 01:32:52 +08:00
|
|
|
return vbox;
|
2001-01-22 12:17:17 +08:00
|
|
|
}
|