[gimp/goat-invasion: 268/401] app: add infrastructure to invoke GEGL filters from a menu item
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/goat-invasion: 268/401] app: add infrastructure to invoke GEGL filters from a menu item
- Date: Mon, 2 Apr 2012 12:10:39 +0000 (UTC)
commit c02d21f767f1fef658f5305a199a1adf8b3efe4a
Author: Michael Natterer <mitch gimp org>
Date: Mon Mar 26 22:56:53 2012 +0200
app: add infrastructure to invoke GEGL filters from a menu item
and for fun add pixelize and gaussian blur to Filters -> Blur.
app/actions/Makefile.am | 4 ++
app/actions/actions.c | 4 ++
app/actions/filters-actions.c | 101 ++++++++++++++++++++++++++++++++++++++++
app/actions/filters-actions.h | 27 +++++++++++
app/actions/filters-commands.c | 84 +++++++++++++++++++++++++++++++++
app/actions/filters-commands.h | 27 +++++++++++
app/dialogs/dialogs.c | 1 +
app/menus/menus.c | 4 ++
app/tools/gimp-tools.c | 2 +
app/tools/gimpgegltool.c | 2 +-
app/tools/gimpoperationtool.c | 31 ++++++++----
app/tools/gimpoperationtool.h | 11 ++--
menus/image-menu.xml.in | 5 ++-
13 files changed, 285 insertions(+), 18 deletions(-)
---
diff --git a/app/actions/Makefile.am b/app/actions/Makefile.am
index afffe7a..3d0b6c6 100644
--- a/app/actions/Makefile.am
+++ b/app/actions/Makefile.am
@@ -91,6 +91,10 @@ libappactions_a_SOURCES = \
file-actions.h \
file-commands.c \
file-commands.h \
+ filters-actions.c \
+ filters-actions.h \
+ filters-commands.c \
+ filters-commands.h \
fonts-actions.c \
fonts-actions.h \
fonts-commands.c \
diff --git a/app/actions/actions.c b/app/actions/actions.c
index c4ca0ab..36bd0b9 100644
--- a/app/actions/actions.c
+++ b/app/actions/actions.c
@@ -69,6 +69,7 @@
#include "edit-actions.h"
#include "error-console-actions.h"
#include "file-actions.h"
+#include "filters-actions.h"
#include "fonts-actions.h"
#include "gradient-editor-actions.h"
#include "gradients-actions.h"
@@ -163,6 +164,9 @@ static const GimpActionFactoryEntry action_groups[] =
{ "file", N_("File"), GTK_STOCK_FILE,
file_actions_setup,
file_actions_update },
+ { "filters", N_("Filters"), GIMP_STOCK_GEGL,
+ filters_actions_setup,
+ filters_actions_update },
{ "fonts", N_("Fonts"), GIMP_STOCK_FONT,
fonts_actions_setup,
fonts_actions_update },
diff --git a/app/actions/filters-actions.c b/app/actions/filters-actions.c
new file mode 100644
index 0000000..2ec97c3
--- /dev/null
+++ b/app/actions/filters-actions.c
@@ -0,0 +1,101 @@
+/* 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 "libgimpwidgets/gimpwidgets.h"
+
+#include "actions-types.h"
+
+#include "core/gimpimage.h"
+#include "core/gimplayermask.h"
+
+#include "widgets/gimpactiongroup.h"
+#include "widgets/gimphelp-ids.h"
+
+#include "actions.h"
+#include "filters-actions.h"
+#include "filters-commands.h"
+
+#include "gimp-intl.h"
+
+
+static const GimpStringActionEntry filters_actions[] =
+{
+ { "filters-pixelize", GIMP_STOCK_GEGL,
+ NC_("filters-action", "_Pixelize"), NULL,
+ NC_("filters-action", "Simplify image into an array of solid-colored squares"),
+ "gegl:pixelise",
+ NULL /* FIXME GIMP_HELP_FILTER_PIXELIZE */ },
+
+ { "filters-gaussian-blur", GIMP_STOCK_GEGL,
+ NC_("filters-action", "_Gaussian Blur"), NULL,
+ NC_("filters-action", "Apply a gaussian blur"),
+ "gegl:gaussian-blur",
+ NULL /* FIXME GIMP_HELP_FILTER_GAUSSIAN_BLUR */ },
+};
+
+void
+filters_actions_setup (GimpActionGroup *group)
+{
+ gimp_action_group_add_string_actions (group, "filters-action",
+ filters_actions,
+ G_N_ELEMENTS (filters_actions),
+ G_CALLBACK (filters_filter_cmd_callback));
+}
+
+void
+filters_actions_update (GimpActionGroup *group,
+ gpointer data)
+{
+ GimpImage *image;
+ GimpDrawable *drawable = NULL;
+ gboolean writable = FALSE;
+ gboolean children = FALSE;
+
+ image = action_data_get_image (data);
+
+ if (image)
+ {
+ drawable = gimp_image_get_active_drawable (image);
+
+ if (drawable)
+ {
+ GimpItem *item;
+
+ if (GIMP_IS_LAYER_MASK (drawable))
+ item = GIMP_ITEM (gimp_layer_mask_get_layer (GIMP_LAYER_MASK (drawable)));
+ else
+ item = GIMP_ITEM (drawable);
+
+ writable = ! gimp_item_is_content_locked (item);
+
+ if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)))
+ children = TRUE;
+ }
+ }
+
+#define SET_SENSITIVE(action,condition) \
+ gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
+
+ SET_SENSITIVE ("filters-pixelize", writable && !children);
+
+#undef SET_SENSITIVE
+}
diff --git a/app/actions/filters-actions.h b/app/actions/filters-actions.h
new file mode 100644
index 0000000..a7a1c08
--- /dev/null
+++ b/app/actions/filters-actions.h
@@ -0,0 +1,27 @@
+/* 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 __FILTERS_ACTIONS_H__
+#define __FILTERS_ACTIONS_H__
+
+
+void filters_actions_setup (GimpActionGroup *group);
+void filters_actions_update (GimpActionGroup *group,
+ gpointer data);
+
+
+#endif /* __FILTERS_ACTIONS_H__ */
diff --git a/app/actions/filters-commands.c b/app/actions/filters-commands.c
new file mode 100644
index 0000000..ef18869
--- /dev/null
+++ b/app/actions/filters-commands.c
@@ -0,0 +1,84 @@
+/* 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 "libgimpbase/gimpbase.h"
+#include "libgimpwidgets/gimpwidgets.h"
+
+#include "actions-types.h"
+
+#include "core/gimp.h"
+#include "core/gimpdrawable.h"
+#include "core/gimpimage.h"
+#include "core/gimptooloptions.h"
+#include "core/gimptoolinfo.h"
+
+#include "tools/gimpimagemapoptions.h"
+#include "tools/gimpoperationtool.h"
+#include "tools/tool_manager.h"
+
+#include "actions.h"
+#include "filters-commands.h"
+
+#include "gimp-intl.h"
+
+
+/* public functions */
+
+void
+filters_filter_cmd_callback (GtkAction *action,
+ const gchar *operation,
+ gpointer data)
+{
+ GimpImage *image;
+ GimpDrawable *drawable;
+ GimpDisplay *display;
+ GimpTool *active_tool;
+ return_if_no_drawable (image, drawable, data);
+ return_if_no_display (display, data);
+
+ active_tool = tool_manager_get_active (image->gimp);
+
+ if (! GIMP_IS_OPERATION_TOOL (active_tool))
+ {
+ GimpToolInfo *tool_info = gimp_get_tool_info (image->gimp,
+ "gimp-operation-tool");
+
+ if (GIMP_IS_TOOL_INFO (tool_info))
+ {
+ gimp_context_set_tool (action_data_get_context (data), tool_info);
+ active_tool = tool_manager_get_active (image->gimp);
+ }
+ }
+
+ if (GIMP_IS_OPERATION_TOOL (active_tool))
+ {
+ gchar *label = gimp_strip_uline (gtk_action_get_label (action));
+
+ tool_manager_control_active (image->gimp, GIMP_TOOL_ACTION_HALT,
+ display);
+ tool_manager_initialize_active (image->gimp, display);
+ gimp_operation_tool_set_operation (GIMP_OPERATION_TOOL (active_tool),
+ operation, label);
+
+ g_free (label);
+ }
+}
diff --git a/app/actions/filters-commands.h b/app/actions/filters-commands.h
new file mode 100644
index 0000000..744b49e
--- /dev/null
+++ b/app/actions/filters-commands.h
@@ -0,0 +1,27 @@
+/* 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 __FILTERS_COMMANDS_H__
+#define __FILTERS_COMMANDS_H__
+
+
+void filters_filter_cmd_callback (GtkAction *action,
+ const gchar *operation,
+ gpointer data);
+
+
+#endif /* __FILTERS_COMMANDS_H__ */
diff --git a/app/dialogs/dialogs.c b/app/dialogs/dialogs.c
index 8c4d9e5..b2533e6 100644
--- a/app/dialogs/dialogs.c
+++ b/app/dialogs/dialogs.c
@@ -231,6 +231,7 @@ static const GimpDialogFactoryEntry entries[] =
FOREIGN ("gimp-hue-saturation-tool-dialog", TRUE, FALSE),
FOREIGN ("gimp-levels-tool-dialog", TRUE, TRUE),
FOREIGN ("gimp-measure-tool-dialog", TRUE, FALSE),
+ FOREIGN ("gimp-operation-tool-dialog", TRUE, FALSE),
FOREIGN ("gimp-posterize-tool-dialog", TRUE, FALSE),
FOREIGN ("gimp-rotate-tool-dialog", TRUE, FALSE),
FOREIGN ("gimp-scale-tool-dialog", TRUE, FALSE),
diff --git a/app/menus/menus.c b/app/menus/menus.c
index 58cdac3..10230fc 100644
--- a/app/menus/menus.c
+++ b/app/menus/menus.c
@@ -109,6 +109,7 @@ menus_init (Gimp *gimp,
"dialogs",
"windows",
"plug-in",
+ "filters",
"quick-mask",
NULL,
"/image-menubar",
@@ -135,6 +136,7 @@ menus_init (Gimp *gimp,
"windows",
"dialogs",
"plug-in",
+ "filters",
"quick-mask",
NULL,
NULL);
@@ -162,6 +164,7 @@ menus_init (Gimp *gimp,
gimp_menu_factory_manager_register (global_menu_factory, "<Layers>",
"layers",
"plug-in",
+ "filters",
NULL,
"/layers-popup",
"layers-menu.xml", plug_in_menus_setup,
@@ -170,6 +173,7 @@ menus_init (Gimp *gimp,
gimp_menu_factory_manager_register (global_menu_factory, "<Channels>",
"channels",
"plug-in",
+ "filters",
NULL,
"/channels-popup",
"channels-menu.xml", plug_in_menus_setup,
diff --git a/app/tools/gimp-tools.c b/app/tools/gimp-tools.c
index 6959383..f546705 100644
--- a/app/tools/gimp-tools.c
+++ b/app/tools/gimp-tools.c
@@ -66,6 +66,7 @@
#include "gimpinktool.h"
#include "gimpiscissorstool.h"
#include "gimplevelstool.h"
+#include "gimpoperationtool.h"
#include "gimpmagnifytool.h"
#include "gimpmeasuretool.h"
#include "gimpmovetool.h"
@@ -118,6 +119,7 @@ gimp_tools_init (Gimp *gimp)
/* register tools in reverse order */
/* color tools */
+ gimp_operation_tool_register,
gimp_gegl_tool_register,
gimp_posterize_tool_register,
gimp_curves_tool_register,
diff --git a/app/tools/gimpgegltool.c b/app/tools/gimpgegltool.c
index d91ff8b..48d590c 100644
--- a/app/tools/gimpgegltool.c
+++ b/app/tools/gimpgegltool.c
@@ -330,7 +330,7 @@ gimp_gegl_tool_operation_changed (GtkWidget *widget,
if (operation)
{
gimp_operation_tool_set_operation (GIMP_OPERATION_TOOL (tool),
- operation);
+ operation, NULL);
g_free (operation);
}
}
diff --git a/app/tools/gimpoperationtool.c b/app/tools/gimpoperationtool.c
index a0e83f8..7fbc5a7 100644
--- a/app/tools/gimpoperationtool.c
+++ b/app/tools/gimpoperationtool.c
@@ -73,7 +73,6 @@ G_DEFINE_TYPE (GimpOperationTool, gimp_operation_tool,
#define parent_class gimp_operation_tool_parent_class
-#if 0
void
gimp_operation_tool_register (GimpToolRegisterCallback callback,
gpointer data)
@@ -85,11 +84,10 @@ gimp_operation_tool_register (GimpToolRegisterCallback callback,
_("GEGL Operation"),
_("Operation Tool: Use an arbitrary GEGL operation"),
N_("_GEGL Operation..."), NULL,
- NULL, GIMP_HELP_TOOL_OPERATION,
+ NULL, GIMP_HELP_TOOL_GEGL,
GIMP_STOCK_GEGL,
data);
}
-#endif
static void
gimp_operation_tool_class_init (GimpOperationToolClass *klass)
@@ -140,9 +138,9 @@ gimp_operation_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error)
{
- GimpOperationTool *o_tool = GIMP_OPERATION_TOOL (tool);
- GimpImage *image = gimp_display_get_image (display);
- GimpDrawable *drawable = gimp_image_get_active_drawable (image);
+ GimpOperationTool *o_tool = GIMP_OPERATION_TOOL (tool);
+ GimpImage *image = gimp_display_get_image (display);
+ GimpDrawable *drawable = gimp_image_get_active_drawable (image);
if (! drawable)
return FALSE;
@@ -150,7 +148,14 @@ gimp_operation_tool_initialize (GimpTool *tool,
if (o_tool->config)
gimp_config_reset (GIMP_CONFIG (o_tool->config));
- return GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
+ if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
+ {
+ return FALSE;
+ }
+
+ gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
+
+ return TRUE;
}
static GeglNode *
@@ -170,9 +175,9 @@ gimp_operation_tool_map (GimpImageMapTool *image_map_tool)
}
-/*****************/
+/**********************/
/* Operation dialog */
-/*****************/
+/**********************/
static void
gimp_operation_tool_dialog (GimpImageMapTool *image_map_tool)
@@ -208,7 +213,8 @@ gimp_operation_tool_config_notify (GObject *object,
void
gimp_operation_tool_set_operation (GimpOperationTool *tool,
- const gchar *operation)
+ const gchar *operation,
+ const gchar *label)
{
g_return_if_fail (GIMP_IS_OPERATION_TOOL (tool));
g_return_if_fail (operation != NULL);
@@ -263,5 +269,10 @@ gimp_operation_tool_set_operation (GimpOperationTool *tool,
gtk_widget_show (tool->options_table);
}
+ if (label)
+ g_object_set (GIMP_IMAGE_MAP_TOOL (tool)->dialog,
+ "description", label,
+ NULL);
+
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
}
diff --git a/app/tools/gimpoperationtool.h b/app/tools/gimpoperationtool.h
index 5ec8b28..a4a8ad1 100644
--- a/app/tools/gimpoperationtool.h
+++ b/app/tools/gimpoperationtool.h
@@ -51,15 +51,14 @@ struct _GimpOperationToolClass
};
-#if 0
-void gimp_operation_tool_register (GimpToolRegisterCallback callback,
- gpointer data);
-#endif
+void gimp_operation_tool_register (GimpToolRegisterCallback callback,
+ gpointer data);
GType gimp_operation_tool_get_type (void) G_GNUC_CONST;
-void gimp_operation_tool_set_operation (GimpOperationTool *tool,
- const gchar *operation);
+void gimp_operation_tool_set_operation (GimpOperationTool *tool,
+ const gchar *operation,
+ const gchar *label);
#endif /* __GIMP_OPERATION_TOOL_H__ */
diff --git a/menus/image-menu.xml.in b/menus/image-menu.xml.in
index 27c747a..8acf747 100644
--- a/menus/image-menu.xml.in
+++ b/menus/image-menu.xml.in
@@ -586,7 +586,10 @@
</menu>
<menuitem action="plug-in-reset-all" />
<separator />
- <menu action="plug-in-blur-menu" name="Blur" />
+ <menu action="plug-in-blur-menu" name="Blur">
+ <menuitem action="filters-gaussian-blur" />
+ <menuitem action="filters-pixelize" />
+ </menu>
<menu action="plug-in-enhance-menu" name="Enhance" />
<menu action="plug-in-distorts-menu" name="Distorts" />
<menu action="plug-in-light-shadow-menu" name="Light and Shadow">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]