Commit 6fdcc5f4 authored by Michael Natterer's avatar Michael Natterer 😴

app: add a progress indicator for cage transform

- add a double "progress" property to GimpOperationCageTransform
  and update it every 20 rows
- connect to the notify::progress in the tool and display a tool
  progress
parent 41b905ba
......@@ -35,7 +35,8 @@ enum
{
PROP_0,
PROP_CONFIG,
PROP_FILL
PROP_FILL,
PROP_PROGRESS
};
......@@ -121,6 +122,13 @@ gimp_operation_cage_transform_class_init (GimpOperationCageTransformClass *klass
"Fill the original position of the cage with a plain color",
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_PROGRESS,
g_param_spec_double ("progress",
"Progress",
"Progress indicator, and a bad hack",
0.0, 1.0, 0.0,
G_PARAM_READABLE));
}
static void
......@@ -159,6 +167,9 @@ gimp_operation_cage_transform_get_property (GObject *object,
case PROP_FILL:
g_value_set_boolean (value, self->fill_plain_color);
break;
case PROP_PROGRESS:
g_value_set_double (value, self->progress);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
......@@ -274,6 +285,9 @@ gimp_operation_cage_transform_process (GeglOperation *operation,
}
}
oct->progress = 0.0;
g_object_notify (G_OBJECT (oct), "progress");
/* pre-allocate memory outside of the loop */
coords = g_slice_alloc (2 * sizeof (gfloat));
coef = g_malloc (config->n_cage_vertices * 2 * sizeof (gfloat));
......@@ -328,11 +342,27 @@ gimp_operation_cage_transform_process (GeglOperation *operation,
coords);
}
}
if ((y - cage_bb.y) % 20 == 0)
{
gdouble fraction = ((gdouble) (y - cage_bb.y) /
(gdouble) (cage_bb.height));
/* 0.0 and 1.0 indicate progress start/end, so avoid them */
if (fraction > 0.0 && fraction < 1.0)
{
oct->progress = fraction;
g_object_notify (G_OBJECT (oct), "progress");
}
}
}
g_free (coef);
g_slice_free1 (2 * sizeof (gfloat), coords);
oct->progress = 1.0;
g_object_notify (G_OBJECT (oct), "progress");
return TRUE;
}
......
......@@ -43,6 +43,8 @@ struct _GimpOperationCageTransform
gboolean fill_plain_color;
Babl *format_coords;
gdouble progress; /* bad hack */
};
struct _GimpOperationCageTransformClass
......
......@@ -961,7 +961,7 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct,
gdouble value;
progress = gimp_progress_start (GIMP_PROGRESS (ct),
_("Coefficient computation"), FALSE);
_("Computing Cage Coefficients"), FALSE);
if (ct->coef)
{
......@@ -1008,6 +1008,30 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct,
ct->dirty_coef = FALSE;
}
static void
gimp_cage_tool_transform_progress (GObject *object,
const GParamSpec *pspec,
GimpCageTool *ct)
{
GimpProgress *progress = GIMP_PROGRESS (ct);
gdouble value;
g_object_get (object, "progress", &value, NULL);
if (value == 0.0)
{
gimp_progress_start (progress, _("Cage Transform"), FALSE);
}
else if (value == 1.0)
{
gimp_progress_end (progress);
}
else
{
gimp_progress_set_value (progress, value);
}
}
static void
gimp_cage_tool_create_render_node (GimpCageTool *ct)
{
......@@ -1015,6 +1039,7 @@ gimp_cage_tool_create_render_node (GimpCageTool *ct)
GeglNode *coef, *cage, *render; /* Render nodes */
GeglNode *input, *output; /* Proxy nodes*/
GeglNode *node; /* wraper to be returned */
GObject *transform;
g_return_if_fail (ct->render_node == NULL);
/* render_node is not supposed to be recreated */
......@@ -1057,6 +1082,12 @@ gimp_cage_tool_create_render_node (GimpCageTool *ct)
ct->render_node = node;
ct->cage_node = cage;
ct->coef_node = coef;
g_object_get (cage, "gegl-operation", &transform, NULL);
g_signal_connect (transform, "notify::progress",
G_CALLBACK (gimp_cage_tool_transform_progress),
ct);
g_object_unref (transform);
}
static void
......
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