2008-02-05 07:32:45 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2008-02-05 07:32:45 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2008-02-05 07:32:45 +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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-02-05 07:32:45 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-02-05 21:20:11 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2008-02-05 07:32:45 +08:00
|
|
|
#include <gegl.h>
|
2008-04-26 19:49:25 +08:00
|
|
|
#include <gegl-plugin.h>
|
2008-02-05 07:32:45 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2008-02-05 21:20:11 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2008-02-05 07:32:45 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "tools-types.h"
|
|
|
|
|
2010-02-18 03:45:20 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2008-02-05 21:20:11 +08:00
|
|
|
#include "widgets/gimppropwidgets.h"
|
|
|
|
|
2012-05-01 05:49:09 +08:00
|
|
|
#include "gimpcoloroptions.h"
|
2008-02-05 07:32:45 +08:00
|
|
|
#include "gimpgegltool.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2008-10-21 19:34:00 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
COLUMN_NAME,
|
|
|
|
COLUMN_LABEL,
|
|
|
|
COLUMN_STOCK_ID,
|
2008-11-17 04:17:43 +08:00
|
|
|
N_COLUMNS
|
2008-10-21 19:34:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-02-05 07:32:45 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2012-03-27 02:59:49 +08:00
|
|
|
static void gimp_gegl_tool_dialog (GimpImageMapTool *im_tool);
|
2008-02-05 07:32:45 +08:00
|
|
|
|
2012-03-27 02:59:49 +08:00
|
|
|
static void gimp_gegl_tool_operation_changed (GtkWidget *widget,
|
|
|
|
GimpGeglTool *tool);
|
2008-02-05 07:32:45 +08:00
|
|
|
|
|
|
|
|
2012-03-27 02:59:49 +08:00
|
|
|
G_DEFINE_TYPE (GimpGeglTool, gimp_gegl_tool, GIMP_TYPE_OPERATION_TOOL)
|
2008-02-05 07:32:45 +08:00
|
|
|
|
|
|
|
#define parent_class gimp_gegl_tool_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_gegl_tool_register (GimpToolRegisterCallback callback,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
(* callback) (GIMP_TYPE_GEGL_TOOL,
|
2012-05-01 05:49:09 +08:00
|
|
|
GIMP_TYPE_COLOR_OPTIONS,
|
|
|
|
gimp_color_options_gui,
|
2008-02-05 07:32:45 +08:00
|
|
|
0,
|
|
|
|
"gimp-gegl-tool",
|
|
|
|
_("GEGL Operation"),
|
2008-02-06 03:12:22 +08:00
|
|
|
_("GEGL Tool: Use an arbitrary GEGL operation"),
|
2008-02-05 07:32:45 +08:00
|
|
|
N_("_GEGL Operation..."), NULL,
|
2010-02-18 01:41:04 +08:00
|
|
|
NULL, GIMP_HELP_TOOL_GEGL,
|
2008-02-05 08:38:08 +08:00
|
|
|
GIMP_STOCK_GEGL,
|
2008-02-05 07:32:45 +08:00
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_gegl_tool_class_init (GimpGeglToolClass *klass)
|
|
|
|
{
|
|
|
|
GimpImageMapToolClass *im_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
|
|
|
|
|
2012-03-27 02:59:49 +08:00
|
|
|
im_tool_class->dialog_desc = _("GEGL Operation");
|
2008-02-05 07:32:45 +08:00
|
|
|
|
2012-03-27 02:59:49 +08:00
|
|
|
im_tool_class->dialog = gimp_gegl_tool_dialog;
|
2008-02-05 07:32:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_gegl_tool_init (GimpGeglTool *tool)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-09-06 01:11:48 +08:00
|
|
|
static gboolean
|
2010-03-18 07:39:46 +08:00
|
|
|
gimp_gegl_tool_operation_blacklisted (const gchar *name,
|
|
|
|
const gchar *categories_str)
|
2008-09-06 01:11:48 +08:00
|
|
|
{
|
2010-03-18 07:39:46 +08:00
|
|
|
static const gchar * const category_blacklist[] =
|
|
|
|
{
|
|
|
|
"compositors",
|
|
|
|
"core",
|
|
|
|
"debug",
|
|
|
|
"hidden",
|
|
|
|
"input",
|
|
|
|
"output",
|
|
|
|
"programming",
|
|
|
|
"transform",
|
|
|
|
"video"
|
|
|
|
};
|
|
|
|
static const gchar * const name_blacklist[] =
|
2008-09-06 01:37:17 +08:00
|
|
|
{
|
2012-05-02 01:41:32 +08:00
|
|
|
"gegl:color", /* pointless */
|
|
|
|
"gegl:color-temperature", /* in gimp */
|
|
|
|
"gegl:color-to-alpha", /* in gimp */
|
|
|
|
"gegl:colorize", /* in gimp */
|
|
|
|
"gegl:contrast-curve",
|
2010-02-01 00:36:56 +08:00
|
|
|
"gegl:convert-format",
|
2012-05-02 01:41:32 +08:00
|
|
|
"gegl:display",
|
|
|
|
"gegl:fill-path",
|
|
|
|
"gegl:gaussian-blur", /* in gimp */
|
|
|
|
"gegl:grey", /* in gimp */
|
|
|
|
"gegl:hstack",
|
2010-02-01 00:36:56 +08:00
|
|
|
"gegl:introspect",
|
2012-05-02 01:41:32 +08:00
|
|
|
"gegl:invert", /* in gimp */
|
2010-03-18 07:39:46 +08:00
|
|
|
"gegl:layer",
|
2011-07-25 21:20:53 +08:00
|
|
|
"gegl:lens-correct",
|
2012-04-02 08:40:45 +08:00
|
|
|
"gegl:opacity", /* pointless */
|
2012-05-02 01:41:32 +08:00
|
|
|
"gegl:path",
|
2012-04-28 03:47:09 +08:00
|
|
|
"gegl:pixelize", /* in gimp */
|
|
|
|
"gegl:polar-coordinates", /* in gimp */
|
2012-04-02 08:40:45 +08:00
|
|
|
"gegl:posterize", /* in gimp */
|
2012-05-02 01:41:32 +08:00
|
|
|
"gegl:rotate", /* in gimp */
|
2012-04-02 08:40:45 +08:00
|
|
|
"gegl:scale", /* in gimp */
|
2012-05-03 21:06:45 +08:00
|
|
|
"gegl:sdl-display", /* useless */
|
2012-04-02 08:40:45 +08:00
|
|
|
"gegl:shear", /* in gimp */
|
2012-05-02 01:41:32 +08:00
|
|
|
"gegl:text",
|
|
|
|
"gegl:threshold", /* in gimp */
|
2012-04-02 08:40:45 +08:00
|
|
|
"gegl:transform", /* in gimp */
|
2012-05-02 01:41:32 +08:00
|
|
|
"gegl:translate", /* pointless */
|
2012-04-02 08:40:45 +08:00
|
|
|
"gegl:value-invert", /* in gimp */
|
2012-05-02 01:41:32 +08:00
|
|
|
"gegl:vector-stroke",
|
2010-03-18 07:39:46 +08:00
|
|
|
"gimp-",
|
|
|
|
"gimp:"
|
2008-09-06 01:37:17 +08:00
|
|
|
};
|
2011-04-04 14:19:12 +08:00
|
|
|
|
|
|
|
gchar **categories;
|
|
|
|
gint i;
|
2008-09-06 01:11:48 +08:00
|
|
|
|
2010-03-18 07:39:46 +08:00
|
|
|
/* Operations with no name are abstract base classes */
|
2011-04-04 14:19:12 +08:00
|
|
|
if (! name)
|
2010-03-18 07:39:46 +08:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (name_blacklist); i++)
|
2008-09-06 01:11:48 +08:00
|
|
|
{
|
2010-03-18 07:39:46 +08:00
|
|
|
if (g_str_has_prefix (name, name_blacklist[i]))
|
2008-09-06 01:11:48 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-04-04 14:19:12 +08:00
|
|
|
if (! categories_str)
|
2010-03-18 07:39:46 +08:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
categories = g_strsplit (categories_str, ":", 0);
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (category_blacklist); i++)
|
|
|
|
{
|
|
|
|
gint j;
|
2011-04-04 14:19:12 +08:00
|
|
|
|
2010-03-18 07:39:46 +08:00
|
|
|
for (j = 0; categories[j]; j++)
|
2011-04-04 14:19:12 +08:00
|
|
|
if (! strcmp (categories[j], category_blacklist[i]))
|
2010-03-18 07:39:46 +08:00
|
|
|
{
|
|
|
|
g_strfreev (categories);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (categories);
|
2011-04-04 14:19:12 +08:00
|
|
|
|
2008-09-06 01:11:48 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Builds a GList of the class structures of all subtypes of type.
|
2008-04-26 19:49:25 +08:00
|
|
|
*/
|
|
|
|
static GList *
|
|
|
|
gimp_get_subtype_classes (GType type,
|
|
|
|
GList *classes)
|
|
|
|
{
|
2008-09-06 01:11:48 +08:00
|
|
|
GeglOperationClass *klass;
|
|
|
|
GType *ops;
|
2012-03-30 02:37:40 +08:00
|
|
|
const gchar *categories;
|
2008-09-06 01:11:48 +08:00
|
|
|
guint n_ops;
|
|
|
|
gint i;
|
2008-04-26 19:49:25 +08:00
|
|
|
|
2008-09-06 01:11:48 +08:00
|
|
|
if (! type)
|
2008-04-26 19:49:25 +08:00
|
|
|
return classes;
|
|
|
|
|
2008-09-06 01:11:48 +08:00
|
|
|
klass = GEGL_OPERATION_CLASS (g_type_class_ref (type));
|
2008-04-26 20:12:26 +08:00
|
|
|
ops = g_type_children (type, &n_ops);
|
2008-04-26 19:49:25 +08:00
|
|
|
|
2012-03-30 02:37:40 +08:00
|
|
|
categories = gegl_operation_class_get_key (klass, "categories");
|
|
|
|
|
|
|
|
if (! gimp_gegl_tool_operation_blacklisted (klass->name, categories))
|
2010-03-18 07:39:46 +08:00
|
|
|
classes = g_list_prepend (classes, klass);
|
2008-04-26 19:49:25 +08:00
|
|
|
|
2008-04-26 20:12:26 +08:00
|
|
|
for (i = 0; i < n_ops; i++)
|
|
|
|
classes = gimp_get_subtype_classes (ops[i], classes);
|
2008-04-26 19:49:25 +08:00
|
|
|
|
|
|
|
if (ops)
|
|
|
|
g_free (ops);
|
2008-04-26 20:12:26 +08:00
|
|
|
|
2008-04-26 19:49:25 +08:00
|
|
|
return classes;
|
|
|
|
}
|
|
|
|
|
2008-04-26 20:12:26 +08:00
|
|
|
static gint
|
|
|
|
gimp_gegl_tool_compare_operation_names (GeglOperationClass *a,
|
|
|
|
GeglOperationClass *b)
|
2008-04-26 19:49:25 +08:00
|
|
|
{
|
|
|
|
return strcmp (a->name, b->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GList *
|
|
|
|
gimp_get_geglopclasses (void)
|
|
|
|
{
|
2008-04-26 20:12:26 +08:00
|
|
|
GList *opclasses;
|
2008-04-26 19:49:25 +08:00
|
|
|
|
|
|
|
opclasses = gimp_get_subtype_classes (GEGL_TYPE_OPERATION, NULL);
|
2008-04-26 20:12:26 +08:00
|
|
|
|
|
|
|
opclasses = g_list_sort (opclasses,
|
|
|
|
(GCompareFunc)
|
|
|
|
gimp_gegl_tool_compare_operation_names);
|
2008-04-26 19:49:25 +08:00
|
|
|
|
|
|
|
return opclasses;
|
|
|
|
}
|
|
|
|
|
2008-02-05 07:32:45 +08:00
|
|
|
|
|
|
|
/*****************/
|
|
|
|
/* Gegl dialog */
|
|
|
|
/*****************/
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_gegl_tool_dialog (GimpImageMapTool *image_map_tool)
|
|
|
|
{
|
2012-03-27 02:59:49 +08:00
|
|
|
GimpGeglTool *tool = GIMP_GEGL_TOOL (image_map_tool);
|
|
|
|
GimpOperationTool *o_tool = GIMP_OPERATION_TOOL (image_map_tool);
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkCellRenderer *cell;
|
|
|
|
GtkWidget *main_vbox;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *combo;
|
|
|
|
GList *opclasses;
|
|
|
|
GList *iter;
|
|
|
|
|
|
|
|
GIMP_IMAGE_MAP_TOOL_CLASS (parent_class)->dialog (image_map_tool);
|
2008-02-05 07:32:45 +08:00
|
|
|
|
2008-06-29 21:54:01 +08:00
|
|
|
main_vbox = gimp_image_map_tool_dialog_get_vbox (image_map_tool);
|
2008-06-03 18:51:04 +08:00
|
|
|
|
2008-02-05 07:32:45 +08:00
|
|
|
/* The operation combo box */
|
2011-09-30 17:29:11 +08:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
2008-06-03 18:51:04 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
|
2012-03-27 02:59:49 +08:00
|
|
|
gtk_box_reorder_child (GTK_BOX (main_vbox), hbox, 0);
|
2008-02-05 07:32:45 +08:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2008-11-17 04:17:43 +08:00
|
|
|
store = gtk_list_store_new (N_COLUMNS,
|
2011-07-25 21:20:53 +08:00
|
|
|
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
|
2008-02-05 07:32:45 +08:00
|
|
|
|
2008-04-26 19:49:25 +08:00
|
|
|
opclasses = gimp_get_geglopclasses ();
|
2008-04-26 20:12:26 +08:00
|
|
|
|
2008-10-21 19:34:00 +08:00
|
|
|
for (iter = opclasses; iter; iter = iter->next)
|
2008-04-26 19:49:25 +08:00
|
|
|
{
|
|
|
|
GeglOperationClass *opclass = GEGL_OPERATION_CLASS (iter->data);
|
2010-03-18 07:39:46 +08:00
|
|
|
const gchar *stock_id;
|
|
|
|
const gchar *label;
|
2008-04-26 20:12:26 +08:00
|
|
|
|
2010-03-18 07:39:46 +08:00
|
|
|
if (g_str_has_prefix (opclass->name, "gegl:"))
|
|
|
|
{
|
2011-07-25 21:20:53 +08:00
|
|
|
label = opclass->name + strlen ("gegl:");
|
|
|
|
stock_id = GIMP_STOCK_GEGL;
|
|
|
|
}
|
2010-03-18 07:39:46 +08:00
|
|
|
else
|
2008-08-19 23:42:31 +08:00
|
|
|
{
|
2010-03-18 07:39:46 +08:00
|
|
|
label = opclass->name;
|
|
|
|
stock_id = NULL;
|
2008-08-19 23:42:31 +08:00
|
|
|
}
|
2010-03-18 07:39:46 +08:00
|
|
|
|
|
|
|
gtk_list_store_insert_with_values (store, NULL, -1,
|
|
|
|
COLUMN_NAME, opclass->name,
|
2011-07-25 21:20:53 +08:00
|
|
|
COLUMN_LABEL, label,
|
|
|
|
COLUMN_STOCK_ID, stock_id,
|
2010-03-18 07:39:46 +08:00
|
|
|
-1);
|
2008-04-26 20:12:26 +08:00
|
|
|
}
|
|
|
|
|
2008-04-26 19:49:25 +08:00
|
|
|
g_list_free (opclasses);
|
2008-02-05 07:32:45 +08:00
|
|
|
|
|
|
|
combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
|
2008-10-21 19:34:00 +08:00
|
|
|
g_object_unref (store);
|
2008-02-05 07:32:45 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (combo);
|
|
|
|
|
2008-10-21 19:34:00 +08:00
|
|
|
cell = gtk_cell_renderer_pixbuf_new ();
|
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, FALSE);
|
|
|
|
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), cell,
|
|
|
|
"stock-id", COLUMN_STOCK_ID);
|
|
|
|
|
|
|
|
cell = gtk_cell_renderer_text_new ();
|
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
|
|
|
|
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), cell,
|
|
|
|
"text", COLUMN_LABEL);
|
2008-02-05 07:32:45 +08:00
|
|
|
|
|
|
|
g_signal_connect (combo, "changed",
|
|
|
|
G_CALLBACK (gimp_gegl_tool_operation_changed),
|
|
|
|
tool);
|
|
|
|
|
|
|
|
tool->operation_combo = combo;
|
|
|
|
|
|
|
|
/* The options vbox */
|
2012-03-27 02:59:49 +08:00
|
|
|
o_tool->options_table =
|
|
|
|
gtk_label_new (_("Select an operation from the list above"));
|
|
|
|
gimp_label_set_attributes (GTK_LABEL (o_tool->options_table),
|
2008-02-18 23:31:23 +08:00
|
|
|
PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
|
|
|
|
-1);
|
2012-03-27 02:59:49 +08:00
|
|
|
gtk_misc_set_padding (GTK_MISC (o_tool->options_table), 0, 4);
|
2012-04-01 00:58:13 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (o_tool->options_box),
|
2012-03-27 02:59:49 +08:00
|
|
|
o_tool->options_table);
|
|
|
|
gtk_widget_show (o_tool->options_table);
|
2008-02-05 07:32:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_gegl_tool_operation_changed (GtkWidget *widget,
|
|
|
|
GimpGeglTool *tool)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
2012-03-27 02:59:49 +08:00
|
|
|
gchar *operation;
|
2008-02-05 07:32:45 +08:00
|
|
|
|
|
|
|
if (! gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter))
|
|
|
|
return;
|
|
|
|
|
|
|
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, &iter,
|
2012-03-27 02:59:49 +08:00
|
|
|
COLUMN_NAME, &operation,
|
2008-02-05 07:32:45 +08:00
|
|
|
-1);
|
|
|
|
|
2012-03-27 02:59:49 +08:00
|
|
|
if (operation)
|
2008-02-05 21:54:25 +08:00
|
|
|
{
|
2012-03-27 02:59:49 +08:00
|
|
|
gimp_operation_tool_set_operation (GIMP_OPERATION_TOOL (tool),
|
2012-03-27 04:56:53 +08:00
|
|
|
operation, NULL);
|
2012-03-27 02:59:49 +08:00
|
|
|
g_free (operation);
|
2008-02-05 21:54:25 +08:00
|
|
|
}
|
2008-02-05 07:32:45 +08:00
|
|
|
}
|