Commit 96357dbf authored by Michael Natterer's avatar Michael Natterer 😴

app: add infrastructure to invoke GEGL filters from a menu item

and for fun add pixelize and gaussian blur to Filters -> Blur.
parent 98ccc951
......@@ -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 \
......
......@@ -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 },
......
/* 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
}
/* 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__ */
/* 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);
}
}
/* 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__ */
......@@ -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),
......
......@@ -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,
......
......@@ -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,
......
......@@ -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);
}
}
......@@ -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));
}
......@@ -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__ */
......@@ -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">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment