Commit b5ed0a5a authored by Øyvind Kolås's avatar Øyvind Kolås

Added new infrsatructure to do redirects of properties between meta

	operations and their inner nodes.

	* docs/index-static.html.in:
	* gegl/gegl-node.c: (property_changed):
	* gegl/gegl-operation-meta.c: (gegl_operation_meta_init),
	(redirect_new), (redirect_free),
	(gegl_node_copy_property_property), (gegl_operation_meta_redirect),
	(gegl_operation_meta_property_changed):
	* gegl/gegl-operation-meta.h:
	* operations/meta/dropshadow.c: (associate), (class_init): Use the new
	meta op infrastructure.
parent c52a3d01
2006-11-04 Øyvind Kolås <pippin@gimp.org>
Added new infrsatructure to do redirects of properties between meta
operations and their inner nodes.
* docs/index-static.html.in:
* gegl/gegl-node.c: (property_changed):
* gegl/gegl-operation-meta.c: (gegl_operation_meta_init),
(redirect_new), (redirect_free),
(gegl_node_copy_property_property), (gegl_operation_meta_redirect),
(gegl_operation_meta_property_changed):
* gegl/gegl-operation-meta.h:
* operations/meta/dropshadow.c: (associate), (class_init): Use the new
meta op infrastructure.
2006-11-04 Øyvind Kolås <pippin@gimp.org>
* gegl/gegl.h: added gegl_node_set/gegl_node_get property.
2006-11-03 Øyvind Kolås <pippin@gimp.org> 2006-11-03 Øyvind Kolås <pippin@gimp.org>
* operations/file-io/png-load.c: added Kevin Cozens to copyright * operations/file-io/png-load.c: added Kevin Cozens to copyright
......
...@@ -122,10 +122,11 @@ ...@@ -122,10 +122,11 @@
<ul> <ul>
<li>8bit, 16bit integer and 32bit floating point, RGB, CIE Lab, <li>8bit, 16bit integer and 32bit floating point, RGB, CIE Lab,
YCbCr and naive CMYK output.</li> YCbCr and naive CMYK output.</li>
<li>Easily extendable through plug-ins.</li> <li>Extendable through plug-ins.</li>
<li>XML, C and Python interfaces.</li> <li>XML, C and Python interfaces.</li>
<li>Memory efficient evaluation of subregions.</li> <li>Memory efficient evaluation of subregions.</li>
<li>Tiled sparse data storage</li> <li>Tiled sparse data storage</li>
<li>Rich core set of processing <a <li>Rich core set of processing <a
href='operations.html'>operations</a> href='operations.html'>operations</a>
<ul> <ul>
......
...@@ -842,7 +842,8 @@ static void property_changed (GObject *gobject, ...@@ -842,7 +842,8 @@ static void property_changed (GObject *gobject,
if (self->operation && if (self->operation &&
g_type_is_a (G_OBJECT_TYPE(self->operation), GEGL_TYPE_OPERATION_META)) g_type_is_a (G_OBJECT_TYPE(self->operation), GEGL_TYPE_OPERATION_META))
{ {
gegl_operation_prepare (self->operation); gegl_operation_meta_property_changed (
GEGL_OPERATION_META (self->operation), arg1, user_data);
} }
if ((arg1 && if ((arg1 &&
......
...@@ -35,6 +35,8 @@ static void set_property (GObject *gobject, ...@@ -35,6 +35,8 @@ static void set_property (GObject *gobject,
guint prop_id, guint prop_id,
const GValue *value, const GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
static void finalize (GObject *self_object);
G_DEFINE_TYPE (GeglOperationMeta, gegl_operation_meta, GEGL_TYPE_OPERATION) G_DEFINE_TYPE (GeglOperationMeta, gegl_operation_meta, GEGL_TYPE_OPERATION)
...@@ -45,11 +47,13 @@ gegl_operation_meta_class_init (GeglOperationMetaClass * klass) ...@@ -45,11 +47,13 @@ gegl_operation_meta_class_init (GeglOperationMetaClass * klass)
object_class->set_property = set_property; object_class->set_property = set_property;
object_class->get_property = get_property; object_class->get_property = get_property;
object_class->finalize = finalize;
} }
static void static void
gegl_operation_meta_init (GeglOperationMeta *self) gegl_operation_meta_init (GeglOperationMeta *self)
{ {
self->redirects = NULL;
} }
...@@ -76,6 +80,49 @@ typedef struct Redirect { ...@@ -76,6 +80,49 @@ typedef struct Redirect {
gchar *internal_name; gchar *internal_name;
} Redirect; } Redirect;
static Redirect *redirect_new (const gchar *name,
void *data,
GeglNode *internal,
const gchar *internal_name)
{
Redirect *self = g_malloc0 (sizeof (Redirect));
self->name = g_strdup (name);
self->data = data;
self->internal = internal;
self->internal_name = g_strdup (internal_name);
return self;
}
static void redirect_destroy (Redirect *self)
{
if (!self)
return;
if (self->name)
g_free (self->name);
if (self->internal_name)
g_free (self->internal_name);
g_free (self);
}
/* FIXME: take GeglNode's as parameters, since we need
* extra behavior provided by GeglNode on top of GObject.
*/
static void
gegl_node_copy_property_property (GObject *source,
const gchar *source_property,
GObject *destination,
const gchar *destination_property)
{
GValue value = {0};
GParamSpec *spec = g_object_class_find_property (
G_OBJECT_GET_CLASS (source), source_property);
g_assert (spec);
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (spec));
gegl_node_get_property (GEGL_OPERATION(source)->node, source_property, &value);
gegl_node_set_property (GEGL_OPERATION(destination)->node, destination_property, &value);
g_value_unset (&value);
}
void void
gegl_operation_meta_redirect (GeglOperation *operation, gegl_operation_meta_redirect (GeglOperation *operation,
const gchar *name, const gchar *name,
...@@ -83,5 +130,50 @@ gegl_operation_meta_redirect (GeglOperation *operation, ...@@ -83,5 +130,50 @@ gegl_operation_meta_redirect (GeglOperation *operation,
GeglNode *internal, GeglNode *internal,
const gchar *internal_name) const gchar *internal_name)
{ {
g_warning ("redirect request for %s->%s", name, internal_name); GeglOperationMeta *self = GEGL_OPERATION_META (operation);
Redirect *redirect = redirect_new (name, data, internal, internal_name);
self->redirects = g_slist_prepend (self->redirects, redirect);
/* set default value */
gegl_node_copy_property_property (G_OBJECT (operation), name, G_OBJECT (internal->operation), internal_name);
} }
void gegl_operation_meta_property_changed (GeglOperationMeta *self,
GParamSpec *arg1,
gpointer user_data)
{
g_assert (GEGL_IS_OPERATION_META (self));
if (arg1)
{
GSList *iter = self->redirects;
while (iter)
{
Redirect *redirect = iter->data;
if (!strcmp (redirect->name, arg1->name))
{
gegl_node_copy_property_property (G_OBJECT (self), arg1->name,
G_OBJECT (redirect->internal->operation),
redirect->internal_name);
}
iter=iter->next;
}
}
}
static void
finalize (GObject *gobject)
{
GeglOperationMeta *self = GEGL_OPERATION_META (gobject);
GSList *iter = self->redirects;
while (iter)
{
Redirect *redirect = iter->data;
iter = g_slist_remove (iter, redirect);
redirect_destroy (redirect);
}
G_OBJECT_CLASS (gegl_operation_meta_parent_class)->finalize (gobject);
}
...@@ -40,6 +40,7 @@ typedef struct _GeglOperationMeta GeglOperationMeta; ...@@ -40,6 +40,7 @@ typedef struct _GeglOperationMeta GeglOperationMeta;
struct _GeglOperationMeta struct _GeglOperationMeta
{ {
GeglOperation operation; GeglOperation operation;
GSList *redirects;
}; };
typedef struct _GeglOperationMetaClass GeglOperationMetaClass; typedef struct _GeglOperationMetaClass GeglOperationMetaClass;
...@@ -57,6 +58,10 @@ void gegl_operation_meta_redirect (GeglOperation *operation, ...@@ -57,6 +58,10 @@ void gegl_operation_meta_redirect (GeglOperation *operation,
GeglNode *internal, GeglNode *internal,
const gchar *internal_name); const gchar *internal_name);
void gegl_operation_meta_property_changed (GeglOperationMeta *self,
GParamSpec *arg1,
gpointer user_data);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
......
...@@ -50,66 +50,25 @@ struct _Priv ...@@ -50,66 +50,25 @@ struct _Priv
GeglNode *blur; GeglNode *blur;
GeglNode *darken; GeglNode *darken;
GeglNode *black; GeglNode *black;
double p_opacity;
double p_x;
double p_y;
double p_radius;
}; };
/* prepare for an evaluation */
static void
prepare (GeglOperation *operation)
{
GeglChantOperation *self = GEGL_CHANT_OPERATION (operation);
Priv *priv;
priv = (Priv*)self->priv;
if (self->x != priv->p_x ||
self->y != priv->p_y)
{
gegl_node_set (priv->translate, "x", self->x,
"y", self->y,
NULL);
priv->p_x = self->x;
priv->p_y = self->y;
}
if (self->opacity != priv->p_opacity)
{
gegl_node_set (priv->opacity, "value", self->opacity,
NULL);
priv->p_opacity = self->opacity;
}
if (self->radius != priv->p_radius)
{
gegl_node_set (priv->blur, "radius-x", self->radius,
"radius-y", self->radius,
NULL);
priv->p_radius = self->radius;
}
}
/* in associate we hook into graph adding the needed nodes */ /* in associate we hook into graph adding the needed nodes */
static void associate (GeglOperation *operation) static void associate (GeglOperation *operation)
{ {
GeglChantOperation *self = GEGL_CHANT_OPERATION (operation); GeglChantOperation *self = GEGL_CHANT_OPERATION (operation);
Priv *priv = (Priv*)self->priv; Priv *priv = (Priv*)self->priv;
GeglNode *gegl;
g_assert (priv == NULL); g_assert (priv == NULL);
priv = g_malloc0 (sizeof (Priv)); priv = g_malloc0 (sizeof (Priv));
self->priv = (void*) priv; self->priv = (void*) priv;
priv->self = GEGL_OPERATION (self)->node; priv->self = GEGL_OPERATION (self)->node;
gegl = priv->self;
priv->input = gegl_graph_input (gegl, "input");
priv->output = gegl_graph_output (gegl, "output");
if (!priv->over) if (!priv->over)
{ {
GeglNode *gegl = priv->self;
priv->input = gegl_graph_input (gegl, "input");
priv->output = gegl_graph_output (gegl, "output");
priv->over = gegl_graph_new_node (gegl, "operation", "over", NULL); priv->over = gegl_graph_new_node (gegl, "operation", "over", NULL);
priv->translate = gegl_graph_new_node (gegl, "operation", "translate", NULL); priv->translate = gegl_graph_new_node (gegl, "operation", "translate", NULL);
priv->opacity = gegl_graph_new_node (gegl, "operation", "opacity", NULL); priv->opacity = gegl_graph_new_node (gegl, "operation", "opacity", NULL);
...@@ -123,6 +82,7 @@ static void associate (GeglOperation *operation) ...@@ -123,6 +82,7 @@ static void associate (GeglOperation *operation)
gegl_node_connect (priv->over, "aux", priv->input, "output"); gegl_node_connect (priv->over, "aux", priv->input, "output");
gegl_node_connect (priv->darken, "aux", priv->black, "output"); gegl_node_connect (priv->darken, "aux", priv->black, "output");
gegl_operation_meta_redirect (operation, "opacity", &self->radius, priv->opacity, "value");
gegl_operation_meta_redirect (operation, "radius", &self->radius, priv->blur, "radius-x"); gegl_operation_meta_redirect (operation, "radius", &self->radius, priv->blur, "radius-x");
gegl_operation_meta_redirect (operation, "radius", &self->radius, priv->blur, "radius-y"); gegl_operation_meta_redirect (operation, "radius", &self->radius, priv->blur, "radius-y");
gegl_operation_meta_redirect (operation, "x", &self->x, priv->translate, "x"); gegl_operation_meta_redirect (operation, "x", &self->x, priv->translate, "x");
...@@ -132,7 +92,6 @@ static void associate (GeglOperation *operation) ...@@ -132,7 +92,6 @@ static void associate (GeglOperation *operation)
static void class_init (GeglOperationClass *klass) static void class_init (GeglOperationClass *klass)
{ {
klass->prepare = prepare;
klass->associate = associate; klass->associate = associate;
} }
......
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