From 96357dbfd36d227f7203918b612f9367d720c497 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Mon, 26 Mar 2012 22:56:53 +0200 Subject: [PATCH] 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(-) create mode 100644 app/actions/filters-actions.c create mode 100644 app/actions/filters-actions.h create mode 100644 app/actions/filters-commands.c create mode 100644 app/actions/filters-commands.h diff --git a/app/actions/Makefile.am b/app/actions/Makefile.am index afffe7a3df..3d0b6c6403 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 c4ca0abbb5..36bd0b9e40 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 0000000000..2ec97c3590 --- /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 . + */ + +#include "config.h" + +#include +#include + +#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 0000000000..a7a1c08a91 --- /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 . + */ + +#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 0000000000..ef1886983b --- /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 . + */ + +#include "config.h" + +#include +#include + +#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 0000000000..744b49e92e --- /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 . + */ + +#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 8c4d9e5614..b2533e66f1 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 58cdac36f2..10230fc25e 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", "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", "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 6959383d95..f54670505d 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 d91ff8ba1e..48d590c7e3 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 a0e83f80bc..7fbc5a7367 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 5ec8b28a6c..a4a8ad1f12 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 27c747a1bf..8acf747e8b 100644 --- a/menus/image-menu.xml.in +++ b/menus/image-menu.xml.in @@ -586,7 +586,10 @@ - + + + +