[gegl] chanting: add a way to declare and register enum in the op file
- From: Michael Murà <mmure src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] chanting: add a way to declare and register enum in the op file
- Date: Tue, 17 Apr 2012 00:56:45 +0000 (UTC)
commit 544fa7576baa02d407d494fa15705669a8a7b702
Author: Michael Murà <mure michael gmail com>
Date: Sun Apr 15 22:23:04 2012 +0900
chanting: add a way to declare and register enum in the op file
if you are offended by this code, i'm sorry, i am offended too.
gegl/gegl-chant.h | 90 ++++++++++++++++++++++++++++++++++---
gegl/gegl-enums.h | 24 ----------
operations/common/map-absolute.c | 2 +-
operations/common/map-relative.c | 2 +-
operations/common/ripple.c | 9 +++-
operations/common/waves.c | 2 +-
operations/workshop/ditto.c | 2 +-
operations/workshop/warp.c | 15 +++++--
8 files changed, 104 insertions(+), 42 deletions(-)
---
diff --git a/gegl/gegl-chant.h b/gegl/gegl-chant.h
index 9fbcc9f..38ccd88 100644
--- a/gegl/gegl-chant.h
+++ b/gegl/gegl-chant.h
@@ -334,6 +334,80 @@ gegl_module_register (GTypeModule *module)
}
#endif
+/* enum registration */
+#define gegl_chant_int(name, nick, min, max, def, blurb)
+#define gegl_chant_int_ui(name, nick, min, max, def, ui_min, ui_max, ui_gamma, blurb)
+#define gegl_chant_double(name, nick, min, max, def, blurb)
+#define gegl_chant_double_ui(name, nick, min, max, def, ui_min, ui_max, ui_gamma, blurb)
+#define gegl_chant_boolean(name, nick, def, blurb)
+#define gegl_chant_string(name, nick, def, blurb)
+#define gegl_chant_enum(name, nick, enum, lower, def, blurb)
+#define gegl_chant_file_path(name, nick, def, blurb)
+#define gegl_chant_multiline(name, nick, def, blurb)
+#define gegl_chant_object(name,nick, blurb)
+#define gegl_chant_pointer(name, nick, blurb)
+#define gegl_chant_color(name, nick, def, blurb)
+#define gegl_chant_curve(name, nick, blurb)
+#define gegl_chant_path(name, nick, blurb)
+#define gegl_chant_register_enum(enum_name) \
+typedef enum {
+
+#define enum_value(value, nick) \
+ value ,
+
+#define gegl_chant_register_enum_end(enum) \
+} enum ;
+
+#include GEGL_CHANT_C_FILE
+
+
+#undef gegl_chant_register_enum
+#undef enum_value
+#undef gegl_chant_register_enum_end
+
+#define gegl_chant_register_enum(enum_name) \
+GType enum_name ## _get_type (void) G_GNUC_CONST; \
+GType enum_name ## _get_type (void) \
+{ \
+ static GType etype = 0; \
+ if (etype == 0) { \
+ static const GEnumValue values[] = {
+
+#define enum_value(value, nick) \
+ { value, nick, nick },
+
+#define gegl_chant_register_enum_end(enum) \
+ { 0, NULL, NULL } \
+ }; \
+ etype = g_enum_register_static (#enum, values); \
+ } \
+ return etype; \
+} \
+
+#include GEGL_CHANT_C_FILE
+
+#undef gegl_chant_int
+#undef gegl_chant_int_ui
+#undef gegl_chant_double
+#undef gegl_chant_double_ui
+#undef gegl_chant_boolean
+#undef gegl_chant_string
+#undef gegl_chant_enum
+#undef gegl_chant_file_path
+#undef gegl_chant_multiline
+#undef gegl_chant_object
+#undef gegl_chant_pointer
+#undef gegl_chant_color
+#undef gegl_chant_curve
+#undef gegl_chant_path
+#undef gegl_chant_register_enum
+#undef enum_value
+#undef gegl_chant_register_enum_end
+#define gegl_chant_register_enum(enum_name)
+#define enum_value(value, nick)
+#define gegl_chant_register_enum_end(enum)
+
+/* Properties */
struct _GeglChantO
{
@@ -348,7 +422,7 @@ struct _GeglChantO
#define gegl_chant_double_ui(name, nick, min, max, def, ui_min, ui_max, ui_gamma, blurb) gdouble name;
#define gegl_chant_boolean(name, nick, def, blurb) gboolean name;
#define gegl_chant_string(name, nick, def, blurb) gchar *name;
-#define gegl_chant_enum(name, nick, enum, type, def, blurb) enum name;
+#define gegl_chant_enum(name, nick, enum, lower, def, blurb) enum name;
#define gegl_chant_file_path(name, nick, def, blurb) gchar *name;
#define gegl_chant_multiline(name, nick, def, blurb) gchar *name;
#define gegl_chant_object(name,nick, blurb) GObject *name;
@@ -387,7 +461,7 @@ enum
#define gegl_chant_double_ui(name, nick, min, max, def, ui_min, ui_max, ui_gamma, blurb) PROP_##name,
#define gegl_chant_boolean(name, nick, def, blurb) PROP_##name,
#define gegl_chant_string(name, nick, def, blurb) PROP_##name,
-#define gegl_chant_enum(name, nick, enum, type, def, blurb) PROP_##name,
+#define gegl_chant_enum(name, nick, enum, lower, def, blurb) PROP_##name,
#define gegl_chant_file_path(name, nick, def, blurb) PROP_##name,
#define gegl_chant_multiline(name, nick, def, blurb) PROP_##name,
#define gegl_chant_object(name, nick, blurb) PROP_##name,
@@ -451,7 +525,7 @@ get_property (GObject *gobject,
case PROP_##name: \
g_value_set_string (value, properties->name); \
break;
-#define gegl_chant_enum(name, nick, enum, type, def, blurb) \
+#define gegl_chant_enum(name, nick, enum, lower, def, blurb) \
case PROP_##name: \
g_value_set_enum (value, properties->name); \
break;
@@ -546,7 +620,7 @@ set_property (GObject *gobject,
g_free (properties->name); \
properties->name = g_strdup (g_value_get_string (value)); \
break;
-#define gegl_chant_enum(name, nick, enum, type, def, blurb) \
+#define gegl_chant_enum(name, nick, enum, lower, def, blurb) \
case PROP_##name: \
properties->name = g_value_get_enum (value); \
break;
@@ -641,7 +715,7 @@ static void gegl_chant_destroy_notify (gpointer data)
g_free (properties->name); \
properties->name = NULL; \
}
-#define gegl_chant_enum(name, nick, enum, type, def, blurb)
+#define gegl_chant_enum(name, nick, enum, lower, def, blurb)
#define gegl_chant_file_path(name, nick, def, blurb) \
if (properties->name) \
{ \
@@ -720,7 +794,7 @@ gegl_chant_constructor (GType type,
#define gegl_chant_double_ui(name, nick, min, max, def, ui_min, ui_max, ui_gamma, blurb)
#define gegl_chant_boolean(name, nick, def, blurb)
#define gegl_chant_string(name, nick, def, blurb)
-#define gegl_chant_enum(name, nick, enum, type, def, blurb)
+#define gegl_chant_enum(name, nick, enum, lower, def, blurb)
#define gegl_chant_file_path(name, nick, def, blurb)
#define gegl_chant_multiline(name, nick, def, blurb)
#define gegl_chant_object(name, nick, blurb)
@@ -810,10 +884,10 @@ gegl_chant_class_intern_init (gpointer klass)
G_PARAM_READWRITE | \
G_PARAM_CONSTRUCT | \
GEGL_PARAM_PAD_INPUT)));
-#define gegl_chant_enum(name, nick, enum, type, def, blurb) \
+#define gegl_chant_enum(name, nick, enum, lower, def, blurb) \
g_object_class_install_property (object_class, PROP_##name, \
g_param_spec_enum (#name, nick, blurb, \
- type, \
+ lower ## _get_type (), \
def, \
(GParamFlags) ( \
G_PARAM_READWRITE | \
diff --git a/gegl/gegl-enums.h b/gegl/gegl-enums.h
index aeb6346..434dc8b 100644
--- a/gegl/gegl-enums.h
+++ b/gegl/gegl-enums.h
@@ -46,30 +46,6 @@ typedef enum {
GType gegl_abyss_policy_get_type (void) G_GNUC_CONST;
#define GEGL_ABYSS_POLICY_TYPE (gegl_abyss_policy_get_type())
-/*
- * Operation specific enum
- */
-
-typedef enum {
- GEGl_RIPPLE_WAVE_TYPE_SINE,
- GEGl_RIPPLE_WAVE_TYPE_SAWTOOTH
-} GeglRippleWaveType;
-GType gegl_ripple_wave_type_get_type (void) G_GNUC_CONST;
-#define GEGL_RIPPLE_WAVE_TYPE (gegl_ripple_wave_type_get_type())
-
-typedef enum
-{
- GEGL_WARP_BEHAVIOR_MOVE, /*< desc="Move pixels" >*/
- GEGL_WARP_BEHAVIOR_GROW, /*< desc="Grow area" >*/
- GEGL_WARP_BEHAVIOR_SHRINK, /*< desc="Shrink area" >*/
- GEGL_WARP_BEHAVIOR_SWIRL_CW, /*< desc="Swirl clockwise" >*/
- GEGL_WARP_BEHAVIOR_SWIRL_CCW, /*< desc="Swirl counter-clockwise" >*/
- GEGL_WARP_BEHAVIOR_ERASE, /*< desc="Erase warping" >*/
- GEGL_WARP_BEHAVIOR_SMOOTH /*< desc="Smooth warping" >*/
-} GeglWarpBehavior;
-GType gegl_warp_behavior_get_type (void) G_GNUC_CONST;
-#define GEGL_TYPE_WARP_BEHAVIOR (gegl_warp_behavior_get_type ())
-
G_END_DECLS
#endif /* __GEGL_ENUMS_H__ */
diff --git a/operations/common/map-absolute.c b/operations/common/map-absolute.c
index 6d90c6a..9073fb7 100644
--- a/operations/common/map-absolute.c
+++ b/operations/common/map-absolute.c
@@ -19,7 +19,7 @@
#ifdef GEGL_CHANT_PROPERTIES
-gegl_chant_enum (sampler_type, _("Sampler"), GeglSamplerType, GEGL_TYPE_SAMPLER_TYPE,
+gegl_chant_enum (sampler_type, _("Sampler"), GeglSamplerType, gegl_sampler_type,
GEGL_SAMPLER_CUBIC, _("Sampler used internaly"))
#else
diff --git a/operations/common/map-relative.c b/operations/common/map-relative.c
index 3a4eb24..052a0da 100644
--- a/operations/common/map-relative.c
+++ b/operations/common/map-relative.c
@@ -23,7 +23,7 @@
gegl_chant_double (scaling, _("Scaling"), 0.0, 5000.0, 1.0,
_("scaling factor of displacement, indicates how large spatial"
" displacement a relative mapping value of 1.0 corresponds to."))
-gegl_chant_enum (sampler_type, _("Sampler"), GeglSamplerType, GEGL_TYPE_SAMPLER_TYPE,
+gegl_chant_enum (sampler_type, _("Sampler"), GeglSamplerType, gegl_sampler_type,
GEGL_SAMPLER_CUBIC, _("Sampler used internaly"))
#else
diff --git a/operations/common/ripple.c b/operations/common/ripple.c
index 30d6d53..392242c 100644
--- a/operations/common/ripple.c
+++ b/operations/common/ripple.c
@@ -36,10 +36,15 @@ gegl_chant_double (phi, _("Phase shift"), -1.0, 1.0, 0.0,
gegl_chant_double (angle, _("Angle"), -180.0, 180.0, 0.0,
_("Angle in degree"))
-gegl_chant_enum (sampler_type, _("Sampler"), GeglSamplerType, GEGL_TYPE_SAMPLER_TYPE,
+gegl_chant_enum (sampler_type, _("Sampler"), GeglSamplerType, gegl_sampler_type,
GEGL_SAMPLER_CUBIC, _("Sampler used internally"))
-gegl_chant_enum (wave_type, _("Wave type"), GeglRippleWaveType, GEGL_RIPPLE_WAVE_TYPE,
+gegl_chant_register_enum (gegl_ripple_wave_type)
+ enum_value (GEGl_RIPPLE_WAVE_TYPE_SINE, "Sine")
+ enum_value (GEGl_RIPPLE_WAVE_TYPE_SAWTOOTH, "Sawtooth")
+gegl_chant_register_enum_end (GeglRippleWaveType)
+
+gegl_chant_enum (wave_type, _("Wave type"), GeglRippleWaveType, gegl_ripple_wave_type,
GEGl_RIPPLE_WAVE_TYPE_SINE, _("Type of wave"))
#else
diff --git a/operations/common/waves.c b/operations/common/waves.c
index 895aea1..e65c894 100644
--- a/operations/common/waves.c
+++ b/operations/common/waves.c
@@ -38,7 +38,7 @@ gegl_chant_double (period, _("Period"), 0.0, 1000.0, 200.0,
gegl_chant_double (phi, _("Phase shift"), -1.0, 1.0, 0.0,
_("Phase shift"))
-gegl_chant_enum (sampler_type, _("Sampler"), GeglSamplerType, GEGL_TYPE_SAMPLER_TYPE,
+gegl_chant_enum (sampler_type, _("Sampler"), GeglSamplerType, gegl_sampler_type,
GEGL_SAMPLER_CUBIC, _("Sampler used internally"))
diff --git a/operations/workshop/ditto.c b/operations/workshop/ditto.c
index 9a19df9..0019b29 100644
--- a/operations/workshop/ditto.c
+++ b/operations/workshop/ditto.c
@@ -24,7 +24,7 @@
#ifdef GEGL_CHANT_PROPERTIES
-gegl_chant_enum (sampler_type, _("Sampler"), GeglSamplerType, GEGL_TYPE_SAMPLER_TYPE,
+gegl_chant_enum (sampler_type, _("Sampler"), GeglSamplerType, gegl_sampler_type,
GEGL_SAMPLER_CUBIC, _("Sampler used internally"))
#else
diff --git a/operations/workshop/warp.c b/operations/workshop/warp.c
index fcd19b8..c7f1a5e 100644
--- a/operations/workshop/warp.c
+++ b/operations/workshop/warp.c
@@ -19,10 +19,19 @@
#include "config.h"
#include <glib/gi18n-lib.h>
#include <math.h>
-#include <stdio.h> /* for test only */
#ifdef GEGL_CHANT_PROPERTIES
+gegl_chant_register_enum (gegl_warp_behavior)
+ enum_value (GEGL_WARP_BEHAVIOR_MOVE, "Move pixels")
+ enum_value (GEGL_WARP_BEHAVIOR_GROW, "Grow area")
+ enum_value (GEGL_WARP_BEHAVIOR_SHRINK, "Shrink area")
+ enum_value (GEGL_WARP_BEHAVIOR_SWIRL_CW, "Swirl clockwise")
+ enum_value (GEGL_WARP_BEHAVIOR_SWIRL_CCW, "Swirl counter-clockwise")
+ enum_value (GEGL_WARP_BEHAVIOR_ERASE, "Erase warping")
+ enum_value (GEGL_WARP_BEHAVIOR_SMOOTH, "Smooth warping")
+gegl_chant_register_enum_end (GeglWarpBehavior)
+
gegl_chant_double (strength, _("Strength"), 0.0, 100.0, 50,
_("Effect Strength"))
gegl_chant_double (size, _("Size"), 1.0, 10000.0, 40.0,
@@ -30,7 +39,7 @@ gegl_chant_double (size, _("Size"), 1.0, 10000.0, 40.0,
gegl_chant_double (hardness, _("Hardness"), 0.0, 1.0, 0.5,
_("Effect Hardness"))
gegl_chant_path (stroke, _("Stroke"), _("Effect Strength"))
-gegl_chant_enum (behavior, _("Behavior"), GeglWarpBehavior, GEGL_TYPE_WARP_BEHAVIOR,
+gegl_chant_enum (behavior, _("Behavior"), GeglWarpBehavior, gegl_warp_behavior,
GEGL_WARP_BEHAVIOR_MOVE, _("Behavior of the op"))
#else
@@ -320,8 +329,6 @@ process (GeglOperation *operation,
gulong i;
GeglPathList *event;
- printf("Process %p\n", operation);
-
priv->buffer = gegl_buffer_dup (input);
event = gegl_path_get_path (o->stroke);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]