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