app: merge back gegl:recursive-transform-plus propgui to recursive-transform
... following GEGL commit 6be0a86583f9c10c7710c96c21c261e4227c4727.
gegl:recursive-transform now allows applying multiple
transforamtions simultaneously, using multiple transform-grid
widgets.
(cherry picked from commit 56d15e83e9)
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
/* GIMP - The GNU Image Manipulation Program
|
||||
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* gimppropgui-recursive-transform.c
|
||||
* gimppropgui-recursive-transform-plus.c
|
||||
* Copyright (C) 2018 Ell
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@ -37,18 +37,112 @@
|
||||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
#define MAX_N_TRANSFORMS 10
|
||||
|
||||
|
||||
static void
|
||||
transform_grid_callback (GObject *config,
|
||||
GeglRectangle *area,
|
||||
const GimpMatrix3 *transform)
|
||||
add_transform (GtkButton *button,
|
||||
GObject *config)
|
||||
{
|
||||
gchar *transform_str;
|
||||
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);
|
||||
|
||||
transform_str = gegl_matrix3_to_string ((GeglMatrix3 *) transform);
|
||||
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,
|
||||
@ -62,23 +156,49 @@ config_notify (GObject *config,
|
||||
const GParamSpec *pspec,
|
||||
gpointer set_data)
|
||||
{
|
||||
GimpControllerTransformGridCallback set_func;
|
||||
GeglRectangle *area;
|
||||
gchar *transform_str;
|
||||
GimpMatrix3 transform;
|
||||
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;
|
||||
|
||||
set_func = g_object_get_data (G_OBJECT (config), "set-func");
|
||||
area = g_object_get_data (G_OBJECT (config), "area");
|
||||
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);
|
||||
|
||||
gegl_matrix3_parse_string ((GeglMatrix3 *) &transform, transform_str);
|
||||
|
||||
set_func (set_data, area, &transform);
|
||||
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 *
|
||||
@ -114,16 +234,86 @@ _gimp_prop_gui_new_recursive_transform (GObject *config,
|
||||
create_controller_func,
|
||||
creator);
|
||||
|
||||
|
||||
if (create_controller_func)
|
||||
{
|
||||
GCallback set_func;
|
||||
gpointer set_data;
|
||||
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_GRID,
|
||||
GIMP_CONTROLLER_TYPE_TRANSFORM_GRIDS,
|
||||
_("Recursive Transform: "),
|
||||
(GCallback) transform_grid_callback,
|
||||
(GCallback) transform_grids_callback,
|
||||
config,
|
||||
&set_data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user