[gegl/soc-2012-ops: 35/58] gegl_chant_seed



commit a4b7e2bf38877cd34db087fc89568c9346422ce2
Author: Hans Lo <hansshulo gmail com>
Date:   Wed Aug 8 05:31:43 2012 -0400

    gegl_chant_seed
    
    Essentially a gegl_chant_int with a random default value intended for
    operations that use randomness.

 gegl/gegl-chant.h                     |   28 +++++++++++++
 gegl/property-types/gegl-paramspecs.c |   72 ++++++++++++++++++++++++++++++++-
 gegl/property-types/gegl-paramspecs.h |   25 +++++++++++-
 3 files changed, 122 insertions(+), 3 deletions(-)
---
diff --git a/gegl/gegl-chant.h b/gegl/gegl-chant.h
index 8ee92b2..7b1c786 100644
--- a/gegl/gegl-chant.h
+++ b/gegl/gegl-chant.h
@@ -348,6 +348,7 @@ gegl_module_register (GTypeModule *module)
 #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_seed(name, nick, blurb)
 #define gegl_chant_path(name, nick, blurb)
 #define gegl_chant_register_enum(enum_name) \
 typedef enum {
@@ -399,6 +400,7 @@ GType enum_name ## _get_type (void)               \
 #undef gegl_chant_pointer
 #undef gegl_chant_color
 #undef gegl_chant_curve
+#undef gegl_chant_seed
 #undef gegl_chant_path
 #undef gegl_chant_register_enum
 #undef enum_value
@@ -429,6 +431,7 @@ struct _GeglChantO
 #define gegl_chant_pointer(name, nick, blurb)                                   gpointer           name;
 #define gegl_chant_color(name, nick, def, blurb)                                GeglColor         *name;
 #define gegl_chant_curve(name, nick, blurb)                                     GeglCurve         *name;
+#define gegl_chant_seed(name, nick, blurb)                                      gint               name;
 #define gegl_chant_path(name, nick, blurb)                                      GeglPath          *name;\
                                                                                 guint path_changed_handler;
 
@@ -447,6 +450,7 @@ struct _GeglChantO
 #undef gegl_chant_pointer
 #undef gegl_chant_color
 #undef gegl_chant_curve
+#undef gegl_chant_seed
 #undef gegl_chant_path
 };
 
@@ -468,6 +472,7 @@ enum
 #define gegl_chant_pointer(name, nick, blurb)                                   PROP_##name,
 #define gegl_chant_color(name, nick, def, blurb)                                PROP_##name,
 #define gegl_chant_curve(name, nick, blurb)                                     PROP_##name,
+#define gegl_chant_seed(name, nick, blurb)                                      PROP_##name,
 #define gegl_chant_path(name, nick, blurb)                                      PROP_##name,
 
 #include GEGL_CHANT_C_FILE
@@ -485,6 +490,7 @@ enum
 #undef gegl_chant_pointer
 #undef gegl_chant_color
 #undef gegl_chant_curve
+#undef gegl_chant_seed
 #undef gegl_chant_path
   PROP_LAST
 };
@@ -553,6 +559,10 @@ get_property (GObject      *gobject,
     case PROP_##name:                                         \
       g_value_set_object (value, properties->name);           \
       break;
+#define gegl_chant_seed(name, nick, blurb)                    \
+    case PROP_##name:                                         \
+      g_value_set_int (value, properties->name);              \
+      break;
 #define gegl_chant_path(name, nick, blurb)                    \
     case PROP_##name:                                         \
       if (!properties->name)properties->name = gegl_path_new (); /* this feels ugly */\
@@ -574,6 +584,7 @@ get_property (GObject      *gobject,
 #undef gegl_chant_pointer
 #undef gegl_chant_color
 #undef gegl_chant_curve
+#undef gegl_chant_seed
 #undef gegl_chant_path
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
@@ -658,6 +669,10 @@ set_property (GObject      *gobject,
          g_object_unref (properties->name);                           \
       properties->name = g_value_dup_object (value);                  \
       break;
+#define gegl_chant_seed(name, nick, blurb)                            \
+    case PROP_##name:                                                 \
+      properties->name = g_value_get_int (value);                     \
+    break;
 #define gegl_chant_path(name, nick, blurb)                            \
     case PROP_##name:                                                 \
       if (properties->name != NULL)                                   \
@@ -690,6 +705,7 @@ set_property (GObject      *gobject,
 #undef gegl_chant_pointer
 #undef gegl_chant_color
 #undef gegl_chant_curve
+#undef gegl_chant_seed
 #undef gegl_chant_path
 
     default:
@@ -747,6 +763,7 @@ static void gegl_chant_destroy_notify (gpointer data)
       g_object_unref (properties->name);            \
       properties->name = NULL;                      \
     }
+#define gegl_chant_seed(name, nick, blurb)
 #define gegl_chant_path(name, nick, blurb)          \
   if (properties->name)                             \
     {                                               \
@@ -769,6 +786,7 @@ static void gegl_chant_destroy_notify (gpointer data)
 #undef gegl_chant_pointer
 #undef gegl_chant_color
 #undef gegl_chant_curve
+#undef gegl_chant_seed
 #undef gegl_chant_path
 
   g_slice_free (GeglChantO, properties);
@@ -802,6 +820,7 @@ gegl_chant_constructor (GType                  type,
 #define gegl_chant_color(name, nick, def, blurb)              \
     if (properties->name == NULL) \
     {properties->name = gegl_color_new(def?def:"black");}
+#define gegl_chant_seed(name, nick, blurb)
 #define gegl_chant_path(name, nick, blurb)
 #define gegl_chant_curve(name, nick, blurb)
 
@@ -820,6 +839,7 @@ gegl_chant_constructor (GType                  type,
 #undef gegl_chant_pointer
 #undef gegl_chant_color
 #undef gegl_chant_curve
+#undef gegl_chant_seed
 #undef gegl_chant_path
 
   g_object_set_data_full (obj, "chant-data", obj, gegl_chant_destroy_notify);
@@ -933,6 +953,13 @@ gegl_chant_class_intern_init (gpointer klass)
                                                           G_PARAM_READWRITE |\
                                                           G_PARAM_CONSTRUCT | \
                                                           GEGL_PARAM_PAD_INPUT)));
+#define gegl_chant_seed(name, nick, blurb)                                   \
+  g_object_class_install_property (object_class, PROP_##name,                \
+                                   gegl_param_spec_seed (#name, nick, blurb, \
+                                                     (GParamFlags) (         \
+                                                     G_PARAM_READWRITE |     \
+                                                     G_PARAM_CONSTRUCT |     \
+                                                     GEGL_PARAM_PAD_INPUT)));
 #define gegl_chant_path(name, nick, blurb)                                 \
   g_object_class_install_property (object_class, PROP_##name,                \
                                    gegl_param_spec_path (#name, nick, blurb,\
@@ -965,6 +992,7 @@ gegl_chant_class_intern_init (gpointer klass)
 #undef gegl_chant_pointer
 #undef gegl_chant_color
 #undef gegl_chant_curve
+#undef gegl_chant_seed
 #undef gegl_chant_path
 }
 
diff --git a/gegl/property-types/gegl-paramspecs.c b/gegl/property-types/gegl-paramspecs.c
index 23e016c..d276043 100644
--- a/gegl/property-types/gegl-paramspecs.c
+++ b/gegl/property-types/gegl-paramspecs.c
@@ -82,7 +82,7 @@ gegl_param_spec_double (const gchar *name,
 {
   GeglParamSpecDouble *pspec;
   GParamSpecDouble *dspec;
-  
+
   pspec = g_param_spec_internal (GEGL_TYPE_PARAM_DOUBLE,
                                  name, nick, blurb, flags);
   dspec = G_PARAM_SPEC_DOUBLE (pspec);
@@ -153,7 +153,7 @@ gegl_param_spec_int (const gchar *name,
 {
   GeglParamSpecInt *pspec;
   GParamSpecInt *ispec;
-  
+
 
   pspec = g_param_spec_internal (GEGL_TYPE_PARAM_INT,
                                  name, nick, blurb, flags);
@@ -618,3 +618,71 @@ gegl_param_spec_enum_exclude_value (GeglParamSpecEnum *espec,
   espec->excluded_values = g_slist_prepend (espec->excluded_values,
                                             GINT_TO_POINTER (value));
 }
+
+/*
+ * GEGL_TYPE_PARAM_SEED
+ */
+
+static void       gegl_param_seed_class_init (GParamSpecClass *klass);
+static void       gegl_param_seed_init       (GParamSpec      *pspec);
+
+GType
+gegl_param_seed_get_type (void)
+{
+  static GType type = 0;
+
+  if (!type)
+    {
+      const GTypeInfo info =
+      {
+        sizeof (GParamSpecClass),
+        NULL, NULL,
+        (GClassInitFunc) gegl_param_seed_class_init,
+        NULL, NULL,
+        sizeof (GeglParamSpecSeed),
+        0,
+        (GInstanceInitFunc) gegl_param_seed_init
+      };
+      type = g_type_register_static (G_TYPE_PARAM_INT,
+                                     "GeglParamseed", &info, 0);
+    }
+  return type;
+}
+
+static void
+gegl_param_seed_class_init (GParamSpecClass *klass)
+{
+  klass->value_type     = G_TYPE_INT;
+}
+
+static void
+gegl_param_seed_init (GParamSpec *pspec)
+{
+  GeglParamSpecSeed *gdpspec = GEGL_PARAM_SPEC_SEED (pspec);
+
+  gdpspec->ui_minimum = 0;
+  gdpspec->ui_maximum = G_MAXINT;
+}
+
+GParamSpec *
+gegl_param_spec_seed (const gchar *name,
+                      const gchar *nick,
+                      const gchar *blurb,
+                      GParamFlags  flags)
+{
+  GeglParamSpecSeed *pspec;
+  GParamSpecInt *ispec;
+
+
+  pspec = g_param_spec_internal (GEGL_TYPE_PARAM_SEED,
+                                 name, nick, blurb, flags);
+  ispec = G_PARAM_SPEC_INT (pspec);
+
+  ispec->minimum = 0;
+  ispec->maximum = G_MAXINT;
+  ispec->default_value = g_random_int_range(0, G_MAXINT);
+  pspec->ui_minimum = 0;
+  pspec->ui_maximum = G_MAXINT;
+
+  return G_PARAM_SPEC (pspec);
+}
diff --git a/gegl/property-types/gegl-paramspecs.h b/gegl/property-types/gegl-paramspecs.h
index 57a0705..636c486 100644
--- a/gegl/property-types/gegl-paramspecs.h
+++ b/gegl/property-types/gegl-paramspecs.h
@@ -35,7 +35,7 @@ G_BEGIN_DECLS
 typedef struct _GeglParamSpecString GeglParamSpecString;
 typedef struct _GeglParamSpecDouble GeglParamSpecDouble;
 typedef struct _GeglParamSpecInt    GeglParamSpecInt;
-
+typedef struct _GeglParamSpecSeed   GeglParamSpecSeed;
 
 
 
@@ -222,5 +222,28 @@ void   gegl_param_spec_enum_exclude_value (GeglParamSpecEnum *espec,
 
 
 
+/*
+ * GEGL_TYPE_PARAM_SEED
+ */
+
+#define GEGL_TYPE_PARAM_SEED           (gegl_param_seed_get_type ())
+#define GEGL_PARAM_SPEC_SEED(pspec)    (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GEGL_TYPE_PARAM_SEED, GeglParamSpecSeed))
+#define GEGL_IS_PARAM_SPEC_SEED(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GEGL_TYPE_PARAM_SEED))
+
+struct _GeglParamSpecSeed
+{
+  GParamSpecInt parent_instance;
+
+  gint          ui_minimum;
+  gint          ui_maximum;
+};
+
+GType        gegl_param_seed_get_type (void) G_GNUC_CONST;
+
+GParamSpec * gegl_param_spec_seed (const gchar *name,
+                                   const gchar *nick,
+                                   const gchar *blurb,
+                                   GParamFlags  flags);
+
 G_END_DECLS
 #endif  /*  __GEGL_PARAM_SPECS_H__  */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]