From 99828a697a7b6a91b27a060aa3d4bd348bd379a2 Mon Sep 17 00:00:00 2001 From: Ell Date: Tue, 5 Jun 2018 03:56:21 -0400 Subject: [PATCH] app: add custom GUI for gegl:recursive-transform-plus gegl:recursive-transform-plus is an extension of gegl:recursive-transform, allowing multiple transformations to be applied simultaneously; it will eventually be merged back into gegl:recursive-transform. See GEGL commit 9829bc22e85526d789c4e80c05949d4c6202a207. The GUI uses the new TRANSFORM_GRIDS controller, allowing adding, duplicating, and removing transformations, and controlling them through on-canvas transform grids. --- app/propgui/Makefile.am | 2 + .../gimppropgui-recursive-transform-plus.c | 334 ++++++++++++++++++ .../gimppropgui-recursive-transform-plus.h | 35 ++ app/propgui/gimppropgui.c | 3 + po/POTFILES.in | 1 + 5 files changed, 375 insertions(+) create mode 100644 app/propgui/gimppropgui-recursive-transform-plus.c create mode 100644 app/propgui/gimppropgui-recursive-transform-plus.h diff --git a/app/propgui/Makefile.am b/app/propgui/Makefile.am index a15c04b1e3..1a9b5d19a5 100644 --- a/app/propgui/Makefile.am +++ b/app/propgui/Makefile.am @@ -41,6 +41,8 @@ libapppropgui_a_SOURCES = \ gimppropgui-panorama-projection.h \ gimppropgui-recursive-transform.c \ gimppropgui-recursive-transform.h \ + gimppropgui-recursive-transform-plus.c \ + gimppropgui-recursive-transform-plus.h \ gimppropgui-shadows-highlights.c \ gimppropgui-shadows-highlights.h \ gimppropgui-spiral.c \ diff --git a/app/propgui/gimppropgui-recursive-transform-plus.c b/app/propgui/gimppropgui-recursive-transform-plus.c new file mode 100644 index 0000000000..c2b14d5b28 --- /dev/null +++ b/app/propgui/gimppropgui-recursive-transform-plus.c @@ -0,0 +1,334 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis + * + * gimppropgui-recursive-transform-plus.c + * Copyright (C) 2018 Ell + * + * 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 "libgimpmath/gimpmath.h" +#include "libgimpwidgets/gimpwidgets.h" + +#include "propgui-types.h" + +#include "core/gimpcontext.h" + +#include "gimppropgui.h" +#include "gimppropgui-generic.h" +#include "gimppropgui-recursive-transform-plus.h" + +#include "gimp-intl.h" + + +#define MAX_N_TRANSFORMS 10 + + +static void +add_transform (GtkButton *button, + GObject *config) +{ + gchar *transform; + gchar *new_transform; + + g_object_get (config, + "transform", &transform, + NULL); + + new_transform = g_strdup_printf ("%s;matrix (1, 0, 0, 0, 1, 0, 0, 0, 1)", + transform); + + g_object_set (config, + "transform", new_transform, + NULL); + + g_free (transform); + g_free (new_transform); +} + +static void +duplicate_transform (GtkButton *button, + GObject *config) +{ + gchar *transform; + gchar *new_transform; + gchar *delim; + + g_object_get (config, + "transform", &transform, + NULL); + + delim = strrchr (transform, ';'); + + if (! delim) + delim = transform; + else + delim++; + + new_transform = g_strdup_printf ("%s;%s", transform, delim); + + g_object_set (config, + "transform", new_transform, + NULL); + + g_free (transform); + g_free (new_transform); +} + +static void +remove_transform (GtkButton *button, + GObject *config) +{ + gchar *transform; + gchar *delim; + + g_object_get (config, + "transform", &transform, + NULL); + + delim = strrchr (transform, ';'); + + if (delim) + { + *delim = '\0'; + + g_object_set (config, + "transform", transform, + NULL); + } + + g_free (transform); +} + +static void +transform_grids_callback (GObject *config, + GeglRectangle *area, + const GimpMatrix3 *transforms, + gint n_transforms) +{ + GString *transforms_str = g_string_new (NULL); + gchar *transform_str; + gint i; + + g_object_set_data_full (G_OBJECT (config), "area", + g_memdup (area, sizeof (GeglRectangle)), + (GDestroyNotify) g_free); + + for (i = 0; i < n_transforms; i++) + { + if (i > 0) + g_string_append (transforms_str, ";"); + + transform_str = gegl_matrix3_to_string ((GeglMatrix3 *) &transforms[i]); + + g_string_append (transforms_str, transform_str); + + g_free (transform_str); + } + + transform_str = g_string_free (transforms_str, FALSE); + + g_object_set (config, + "transform", transform_str, + NULL); + + g_free (transform_str); +} + +static void +config_notify (GObject *config, + const GParamSpec *pspec, + gpointer set_data) +{ + GtkWidget *add_button; + GtkWidget *duplicate_button; + GtkWidget *remove_button; + GimpControllerTransformGridsCallback set_func; + GeglRectangle *area; + gchar *transform_str; + gchar **transform_strs; + GimpMatrix3 *transforms; + gint n_transforms; + gint i; + + add_button = g_object_get_data (G_OBJECT (config), "add-transform-button"); + duplicate_button = g_object_get_data (G_OBJECT (config), "duplicate-transform-button"); + remove_button = g_object_get_data (G_OBJECT (config), "remove-transform-button"); + set_func = g_object_get_data (G_OBJECT (config), "set-func"); + area = g_object_get_data (G_OBJECT (config), "area"); + + g_object_get (config, + "transform", &transform_str, + NULL); + + transform_strs = g_strsplit (transform_str, ";", -1); + + g_free (transform_str); + + for (n_transforms = 0; transform_strs[n_transforms]; n_transforms++); + + transforms = g_new (GimpMatrix3, n_transforms); + + for (i = 0; i < n_transforms; i++) + { + gegl_matrix3_parse_string ((GeglMatrix3 *) &transforms[i], + transform_strs[i]); + } + + set_func (set_data, area, transforms, n_transforms); + + g_strfreev (transform_strs); + g_free (transforms); + + gtk_widget_set_sensitive (add_button, n_transforms < MAX_N_TRANSFORMS); + gtk_widget_set_sensitive (duplicate_button, n_transforms < MAX_N_TRANSFORMS); + gtk_widget_set_sensitive (remove_button, n_transforms > 1); +} + +GtkWidget * +_gimp_prop_gui_new_recursive_transform_plus (GObject *config, + GParamSpec **param_specs, + guint n_param_specs, + GeglRectangle *area, + GimpContext *context, + GimpCreatePickerFunc create_picker_func, + GimpCreateControllerFunc create_controller_func, + gpointer creator) +{ + GtkWidget *vbox; + + g_return_val_if_fail (G_IS_OBJECT (config), NULL); + g_return_val_if_fail (param_specs != NULL, NULL); + g_return_val_if_fail (n_param_specs > 0, NULL); + g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); + + /* skip the "transform" property, which is controlled by a transform-grid + * controller. + */ + if (create_controller_func) + { + param_specs++; + n_param_specs--; + } + + vbox = _gimp_prop_gui_new_generic (config, + param_specs, n_param_specs, + area, context, + create_picker_func, + create_controller_func, + creator); + + if (create_controller_func) + { + GtkWidget *outer_vbox; + GtkWidget *hbox; + GtkWidget *button; + GtkWidget *image; + GCallback set_func; + gpointer set_data; + + outer_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, + gtk_box_get_spacing (GTK_BOX (vbox))); + + gtk_box_pack_start (GTK_BOX (outer_vbox), vbox, FALSE, FALSE, 0); + gtk_widget_show (vbox); + + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); + gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE); + gtk_box_pack_start (GTK_BOX (outer_vbox), hbox, FALSE, FALSE, 2); + gtk_widget_show (hbox); + + button = gtk_button_new (); + gimp_help_set_help_data (button, + _("Add transform"), + NULL); + gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); + gtk_widget_show (button); + + image = gtk_image_new_from_icon_name (GIMP_ICON_LIST_ADD, + GTK_ICON_SIZE_MENU); + gtk_container_add (GTK_CONTAINER (button), image); + gtk_widget_show (image); + + g_signal_connect (button, "clicked", + G_CALLBACK (add_transform), + config); + + g_object_set_data (config, "add-transform-button", button); + + button = gtk_button_new (); + gimp_help_set_help_data (button, + _("Duplicate transform"), + NULL); + gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); + gtk_widget_show (button); + + image = gtk_image_new_from_icon_name (GIMP_ICON_OBJECT_DUPLICATE, + GTK_ICON_SIZE_MENU); + gtk_container_add (GTK_CONTAINER (button), image); + gtk_widget_show (image); + + g_signal_connect (button, "clicked", + G_CALLBACK (duplicate_transform), + config); + + g_object_set_data (config, "duplicate-transform-button", button); + + button = gtk_button_new (); + gimp_help_set_help_data (button, + _("Remove transform"), + NULL); + gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); + gtk_widget_show (button); + + image = gtk_image_new_from_icon_name (GIMP_ICON_LIST_REMOVE, + GTK_ICON_SIZE_MENU); + gtk_container_add (GTK_CONTAINER (button), image); + gtk_widget_show (image); + + g_signal_connect (button, "clicked", + G_CALLBACK (remove_transform), + config); + + g_object_set_data (config, "remove-transform-button", button); + + vbox = outer_vbox; + + set_func = create_controller_func (creator, + GIMP_CONTROLLER_TYPE_TRANSFORM_GRIDS, + _("Recursive Transform: "), + (GCallback) transform_grids_callback, + config, + &set_data); + + g_object_set_data (G_OBJECT (config), "set-func", set_func); + + g_object_set_data_full (G_OBJECT (config), "area", + g_memdup (area, sizeof (GeglRectangle)), + (GDestroyNotify) g_free); + + config_notify (config, NULL, set_data); + + g_signal_connect (config, "notify", + G_CALLBACK (config_notify), + set_data); + } + + return vbox; +} diff --git a/app/propgui/gimppropgui-recursive-transform-plus.h b/app/propgui/gimppropgui-recursive-transform-plus.h new file mode 100644 index 0000000000..74ff222f29 --- /dev/null +++ b/app/propgui/gimppropgui-recursive-transform-plus.h @@ -0,0 +1,35 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis + * + * gimppropgui-recursive-transform-plus.h + * + * 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 __GIMP_PROP_GUI_RECURSIVE_TRANSFORM_PLUS_H__ +#define __GIMP_PROP_GUI_RECURSIVE_TRANSFORM_PLUS_H__ + + +GtkWidget * +_gimp_prop_gui_new_recursive_transform_plus (GObject *config, + GParamSpec **param_specs, + guint n_param_specs, + GeglRectangle *area, + GimpContext *context, + GimpCreatePickerFunc create_picker_func, + GimpCreateControllerFunc create_controller_func, + gpointer creator); + + +#endif /* __GIMP_PROP_GUI_RECURSIVE_TRANSFORM_PLUS_H__ */ diff --git a/app/propgui/gimppropgui.c b/app/propgui/gimppropgui.c index c7899afee9..f5291588e2 100644 --- a/app/propgui/gimppropgui.c +++ b/app/propgui/gimppropgui.c @@ -56,6 +56,7 @@ #include "gimppropgui-hue-saturation.h" #include "gimppropgui-panorama-projection.h" #include "gimppropgui-recursive-transform.h" +#include "gimppropgui-recursive-transform-plus.h" #include "gimppropgui-shadows-highlights.h" #include "gimppropgui-spiral.h" #include "gimppropgui-supernova.h" @@ -456,6 +457,8 @@ gui_new_funcs[] = _gimp_prop_gui_new_panorama_projection }, { "GimpGegl-gegl-recursive-transform-config", _gimp_prop_gui_new_recursive_transform }, + { "GimpGegl-gegl-recursive-transform-plus-config", + _gimp_prop_gui_new_recursive_transform_plus }, { "GimpGegl-gegl-shadows-highlights-config", _gimp_prop_gui_new_shadows_highlights }, { "GimpGegl-gegl-spiral-config", diff --git a/po/POTFILES.in b/po/POTFILES.in index d09949544e..784df9effc 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -385,6 +385,7 @@ app/propgui/gimppropgui-generic.c app/propgui/gimppropgui-hue-saturation.c app/propgui/gimppropgui-panorama-projection.c app/propgui/gimppropgui-recursive-transform.c +app/propgui/gimppropgui-recursive-transform-plus.c app/propgui/gimppropgui-shadows-highlights.c app/propgui/gimppropgui-spiral.c app/propgui/gimppropgui-supernova.c