[gimp/wip/gradient-edit: 28/42] app: add "modify active gradient" option to the blend tool
- From: N/A <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/wip/gradient-edit: 28/42] app: add "modify active gradient" option to the blend tool
- Date: Mon, 9 Oct 2017 15:54:34 +0000 (UTC)
commit 3c0f07ab782181dd664a245b5c7590d40d144700
Author: Ell <ell_se yahoo com>
Date: Tue Aug 1 09:18:50 2017 -0400
app: add "modify active gradient" option to the blend tool
Add a boolean "modify active gradient" option to the blend tool.
when checked, the active gradient is modified in-place while edited.
When unchecked, the active gradient is copied to the internal
"custom" gradient upon editing, and the custom gradient becomes
subsequently active.
Show a hint when the option is checked, but the active gradient is
non-writable, and can't be edited directly.
This commit adds the new gimpblendtool-editor.[hc] files, which are
where the gradient-editing related functionality of the blend tool
is going to go.
app/tools/Makefile.am | 2 +
app/tools/gimpblendoptions.c | 53 +++++++++++++-
app/tools/gimpblendoptions.h | 3 +
app/tools/gimpblendtool-editor.c | 153 ++++++++++++++++++++++++++++++++++++++
app/tools/gimpblendtool-editor.h | 25 ++++++
app/tools/gimpblendtool.c | 3 +
app/tools/gimpblendtool.h | 4 +
po/POTFILES.in | 1 +
8 files changed, 243 insertions(+), 1 deletions(-)
---
diff --git a/app/tools/Makefile.am b/app/tools/Makefile.am
index 4baa7c7..fbda7b8 100644
--- a/app/tools/Makefile.am
+++ b/app/tools/Makefile.am
@@ -30,6 +30,8 @@ libapptools_a_sources = \
gimpblendoptions.h \
gimpblendtool.c \
gimpblendtool.h \
+ gimpblendtool-editor.c \
+ gimpblendtool-editor.h \
gimpbrightnesscontrasttool.c \
gimpbrightnesscontrasttool.h \
gimpbrushtool.c \
diff --git a/app/tools/gimpblendoptions.c b/app/tools/gimpblendoptions.c
index 6f8f631..b952e44 100644
--- a/app/tools/gimpblendoptions.c
+++ b/app/tools/gimpblendoptions.c
@@ -25,7 +25,9 @@
#include "tools-types.h"
+#include "core/gimpdata.h"
#include "core/gimpdatafactory.h"
+#include "core/gimp-gradients.h"
#include "widgets/gimppropwidgets.h"
#include "widgets/gimpviewablebox.h"
@@ -47,7 +49,8 @@ enum
PROP_SUPERSAMPLE_DEPTH,
PROP_SUPERSAMPLE_THRESHOLD,
PROP_DITHER,
- PROP_INSTANT
+ PROP_INSTANT,
+ PROP_MODIFY_ACTIVE
};
@@ -129,6 +132,13 @@ gimp_blend_options_class_init (GimpBlendOptionsClass *klass)
_("Commit gradient instantly"),
FALSE,
GIMP_PARAM_STATIC_STRINGS);
+
+ GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_MODIFY_ACTIVE,
+ "modify-active",
+ _("Modify active gradient"),
+ _("Modify the active gradient in-place"),
+ FALSE,
+ GIMP_PARAM_STATIC_STRINGS);
}
static void
@@ -174,6 +184,9 @@ gimp_blend_options_set_property (GObject *object,
case PROP_INSTANT:
options->instant = g_value_get_boolean (value);
break;
+ case PROP_MODIFY_ACTIVE:
+ options->modify_active = g_value_get_boolean (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -219,6 +232,9 @@ gimp_blend_options_get_property (GObject *object,
case PROP_INSTANT:
g_value_set_boolean (value, options->instant);
break;
+ case PROP_MODIFY_ACTIVE:
+ g_value_set_boolean (value, options->modify_active);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -230,6 +246,7 @@ GtkWidget *
gimp_blend_options_gui (GimpToolOptions *tool_options)
{
GObject *config = G_OBJECT (tool_options);
+ GimpContext *context = GIMP_CONTEXT (tool_options);
GimpBlendOptions *options = GIMP_BLEND_OPTIONS (tool_options);
GtkWidget *vbox = gimp_paint_options_gui (tool_options);
GtkWidget *vbox2;
@@ -237,8 +254,10 @@ gimp_blend_options_gui (GimpToolOptions *tool_options)
GtkWidget *scale;
GtkWidget *combo;
GtkWidget *button;
+ GtkWidget *label;
gchar *str;
GdkModifierType extend_mask;
+ GimpGradient *gradient;
extend_mask = gimp_get_extend_selection_mask ();
@@ -315,6 +334,38 @@ gimp_blend_options_gui (GimpToolOptions *tool_options)
options->instant_toggle = button;
+ /* the modify active toggle */
+ vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
+ frame = gimp_prop_expanding_frame_new (config, "modify-active", NULL,
+ vbox2, NULL);
+ gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
+ gtk_widget_show (frame);
+
+ options->modify_active_frame = frame;
+
+ label = gtk_label_new (_("The active gradient is non-writable "
+ "and cannot be edited directly. "
+ "Uncheck this option "
+ "to edit a copy of it."));
+ gtk_box_pack_start (GTK_BOX (vbox2), label, TRUE, TRUE, 0);
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ gtk_label_set_width_chars (GTK_LABEL (label), 24);
+ gtk_label_set_xalign (GTK_LABEL (label), 0.0);
+ gimp_label_set_attributes (GTK_LABEL (label),
+ PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
+ -1);
+
+ options->modify_active_hint = label;
+
+ gradient = gimp_context_get_gradient (GIMP_CONTEXT (options));
+
+ gtk_widget_set_sensitive (options->modify_active_frame,
+ gradient !=
+ gimp_gradients_get_custom (context->gimp));
+ gtk_widget_set_visible (options->modify_active_hint,
+ gradient &&
+ ! gimp_data_is_writable (GIMP_DATA (gradient)));
+
return vbox;
}
diff --git a/app/tools/gimpblendoptions.h b/app/tools/gimpblendoptions.h
index 092b2ad..0eaeda8 100644
--- a/app/tools/gimpblendoptions.h
+++ b/app/tools/gimpblendoptions.h
@@ -47,9 +47,12 @@ struct _GimpBlendOptions
gboolean dither;
gboolean instant;
+ gboolean modify_active;
/* options gui */
GtkWidget *instant_toggle;
+ GtkWidget *modify_active_frame;
+ GtkWidget *modify_active_hint;
};
diff --git a/app/tools/gimpblendtool-editor.c b/app/tools/gimpblendtool-editor.c
new file mode 100644
index 0000000..1e9cd5a
--- /dev/null
+++ b/app/tools/gimpblendtool-editor.c
@@ -0,0 +1,153 @@
+/* GIMP - The GNU 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gegl.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+
+#include "libgimpwidgets/gimpwidgets.h"
+
+#include "tools-types.h"
+
+#include "operations/gimp-operation-config.h"
+
+#include "core/gimpdata.h"
+#include "core/gimpgradient.h"
+#include "core/gimp-gradients.h"
+
+#include "widgets/gimpwidgets-utils.h"
+
+#include "display/gimpdisplay.h"
+#include "display/gimptoolline.h"
+
+#include "gimpblendoptions.h"
+#include "gimpblendtool.h"
+#include "gimpblendtool-editor.h"
+
+#include "gimp-intl.h"
+
+
+/* local function prototypes */
+
+static gboolean gimp_blend_tool_editor_is_gradient_editable (GimpBlendTool *blend_tool);
+
+static void gimp_blend_tool_editor_block_handlers (GimpBlendTool *blend_tool);
+static void gimp_blend_tool_editor_unblock_handlers (GimpBlendTool *blend_tool);
+static gboolean gimp_blend_tool_editor_are_handlers_blocked (GimpBlendTool *blend_tool);
+
+static void gimp_blend_tool_editor_freeze_gradient (GimpBlendTool *blend_tool);
+static void gimp_blend_tool_editor_thaw_gradient (GimpBlendTool *blend_tool);
+
+
+/* private functions */
+
+
+static gboolean
+gimp_blend_tool_editor_is_gradient_editable (GimpBlendTool *blend_tool)
+{
+ GimpBlendOptions *options = GIMP_BLEND_TOOL_GET_OPTIONS (blend_tool);
+
+ return ! options->modify_active ||
+ gimp_data_is_writable (GIMP_DATA (blend_tool->gradient));
+}
+
+static void
+gimp_blend_tool_editor_block_handlers (GimpBlendTool *blend_tool)
+{
+ blend_tool->block_handlers_count++;
+}
+
+static void
+gimp_blend_tool_editor_unblock_handlers (GimpBlendTool *blend_tool)
+{
+ g_assert (blend_tool->block_handlers_count > 0);
+
+ blend_tool->block_handlers_count--;
+}
+
+static gboolean
+gimp_blend_tool_editor_are_handlers_blocked (GimpBlendTool *blend_tool)
+{
+ return blend_tool->block_handlers_count > 0;
+}
+
+static void
+gimp_blend_tool_editor_freeze_gradient (GimpBlendTool *blend_tool)
+{
+ GimpBlendOptions *options = GIMP_BLEND_TOOL_GET_OPTIONS (blend_tool);
+ GimpGradient *custom;
+
+ gimp_blend_tool_editor_block_handlers (blend_tool);
+
+ custom = gimp_gradients_get_custom (GIMP_CONTEXT (options)->gimp);
+
+ if (blend_tool->gradient == custom || options->modify_active)
+ {
+ g_assert (gimp_blend_tool_editor_is_gradient_editable (blend_tool));
+
+ gimp_data_freeze (GIMP_DATA (blend_tool->gradient));
+ }
+ else
+ {
+ /* copy the active gradient to the custom gradient, and make the custom
+ * gradient active.
+ */
+ gimp_data_freeze (GIMP_DATA (custom));
+
+ gimp_data_copy (GIMP_DATA (custom), GIMP_DATA (blend_tool->gradient));
+
+ gimp_context_set_gradient (GIMP_CONTEXT (options), custom);
+
+ g_assert (blend_tool->gradient == custom);
+ g_assert (gimp_blend_tool_editor_is_gradient_editable (blend_tool));
+ }
+}
+
+static void
+gimp_blend_tool_editor_thaw_gradient(GimpBlendTool *blend_tool)
+{
+ gimp_data_thaw (GIMP_DATA (blend_tool->gradient));
+
+ gimp_blend_tool_editor_unblock_handlers (blend_tool);
+}
+
+
+/* public functions */
+
+
+void
+gimp_blend_tool_editor_gradient_changed (GimpBlendTool *blend_tool)
+{
+ GimpBlendOptions *options = GIMP_BLEND_TOOL_GET_OPTIONS (blend_tool);
+ GimpContext *context = GIMP_CONTEXT (options);
+
+ if (options->modify_active_frame)
+ {
+ gtk_widget_set_sensitive (options->modify_active_frame,
+ blend_tool->gradient !=
+ gimp_gradients_get_custom (context->gimp));
+ }
+
+ if (options->modify_active_hint)
+ {
+ gtk_widget_set_visible (options->modify_active_hint,
+ blend_tool->gradient &&
+ ! gimp_data_is_writable (GIMP_DATA (blend_tool->gradient)));
+ }
+}
diff --git a/app/tools/gimpblendtool-editor.h b/app/tools/gimpblendtool-editor.h
new file mode 100644
index 0000000..5e49e60
--- /dev/null
+++ b/app/tools/gimpblendtool-editor.h
@@ -0,0 +1,25 @@
+/* GIMP - The GNU 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_BLEND_TOOL_EDITOR_H__
+#define __GIMP_BLEND_TOOL_EDITOR_H__
+
+
+void gimp_blend_tool_editor_gradient_changed (GimpBlendTool *blend_tool);
+
+
+#endif /* __GIMP_BLEND_TOOL_EDITOR_H__ */
diff --git a/app/tools/gimpblendtool.c b/app/tools/gimpblendtool.c
index 3b1343d..a279a48 100644
--- a/app/tools/gimpblendtool.c
+++ b/app/tools/gimpblendtool.c
@@ -47,6 +47,7 @@
#include "gimpblendoptions.h"
#include "gimpblendtool.h"
+#include "gimpblendtool-editor.h"
#include "gimptoolcontrol.h"
#include "gimp-intl.h"
@@ -954,6 +955,8 @@ gimp_blend_tool_set_gradient (GimpBlendTool *blend_tool,
"gradient", blend_tool->gradient,
NULL);
}
+
+ gimp_blend_tool_editor_gradient_changed (blend_tool);
}
static gboolean
diff --git a/app/tools/gimpblendtool.h b/app/tools/gimpblendtool.h
index df7a032..1a0bc87 100644
--- a/app/tools/gimpblendtool.h
+++ b/app/tools/gimpblendtool.h
@@ -61,6 +61,10 @@ struct _GimpBlendTool
GeglNode *dist_node;
GeglBuffer *dist_buffer;
GimpDrawableFilter *filter;
+
+ /* editor */
+
+ gint block_handlers_count;
};
struct _GimpBlendToolClass
diff --git a/po/POTFILES.in b/po/POTFILES.in
index f88aa56..dda15a2 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -395,6 +395,7 @@ app/tools/gimpalignoptions.c
app/tools/gimpaligntool.c
app/tools/gimpblendoptions.c
app/tools/gimpblendtool.c
+app/tools/gimpblendtool-editor.c
app/tools/gimpbrightnesscontrasttool.c
app/tools/gimpbucketfilloptions.c
app/tools/gimpbucketfilltool.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]