[gegl] introduce gegl paramspecs for doubles and ints



commit 89231a1ad5a1fd5886051e57af7d629699b4e9d6
Author: Ãyvind KolÃs <pippin gimp org>
Date:   Fri Mar 30 15:58:47 2012 +0100

    introduce gegl paramspecs for doubles and ints
    
    These paramspecs contain adidtional ui ranges, that specify reasonably ranges
    for human interaction in addition to the paramspec classes they derive from.

 gegl/property-types/gegl-paramspecs.c |  141 +++++++++++++++++++++++++++++++++
 gegl/property-types/gegl-paramspecs.h |   71 +++++++++++++++++
 2 files changed, 212 insertions(+), 0 deletions(-)
---
diff --git a/gegl/property-types/gegl-paramspecs.c b/gegl/property-types/gegl-paramspecs.c
index d51c42e..4d513f7 100644
--- a/gegl/property-types/gegl-paramspecs.c
+++ b/gegl/property-types/gegl-paramspecs.c
@@ -26,6 +26,146 @@
 #include <glib-object.h>
 #include "gegl-paramspecs.h"
 
+static void       gegl_param_double_class_init (GParamSpecClass *klass);
+static void       gegl_param_double_init       (GParamSpec      *pspec);
+
+GType
+gegl_param_double_get_type (void)
+{
+  static GType type = 0;
+
+  if (!type)
+    {
+      const GTypeInfo info =
+      {
+        sizeof (GParamSpecClass),
+        NULL, NULL,
+        (GClassInitFunc) gegl_param_double_class_init,
+        NULL, NULL,
+        sizeof (GeglParamSpecDouble),
+        0,
+        (GInstanceInitFunc) gegl_param_double_init
+      };
+      type = g_type_register_static (G_TYPE_PARAM_DOUBLE,
+                                     "GeglParamDouble", &info, 0);
+    }
+  return type;
+}
+
+static void
+gegl_param_double_class_init (GParamSpecClass *klass)
+{
+  klass->value_type     = G_TYPE_DOUBLE;
+}
+
+static void
+gegl_param_double_init (GParamSpec *pspec)
+{
+  GParamSpecDouble    *dpspec  = G_PARAM_SPEC_DOUBLE (pspec);
+  GeglParamSpecDouble *gdpspec = GEGL_PARAM_SPEC_DOUBLE (pspec);
+  gdpspec->ui_minimum = dpspec->minimum;
+  gdpspec->ui_maximum = dpspec->maximum;
+  gdpspec->ui_gamma   = 1.0;
+}
+
+GParamSpec *
+gegl_param_spec_double (const gchar *name,
+                        const gchar *nick,
+                        const gchar *blurb,
+                        gdouble      minimum,
+                        gdouble      maximum,
+                        gdouble      default_value,
+                        gdouble      ui_minimum,
+                        gdouble      ui_maximum,
+                        gdouble      ui_gamma,
+                        GParamFlags  flags)
+{
+  GeglParamSpecDouble *pspec;
+  GParamSpecDouble *dspec;
+  
+  pspec = g_param_spec_internal (GEGL_TYPE_PARAM_DOUBLE,
+                                 name, nick, blurb, flags);
+  dspec = G_PARAM_SPEC_DOUBLE (pspec);
+
+  dspec->minimum = minimum;
+  dspec->maximum = maximum;
+  dspec->default_value = default_value;
+  pspec->ui_minimum = ui_minimum;
+  pspec->ui_maximum = ui_maximum;
+  pspec->ui_gamma   = ui_gamma;
+
+  return G_PARAM_SPEC (pspec);
+}
+
+static void       gegl_param_int_class_init (GParamSpecClass *klass);
+static void       gegl_param_int_init       (GParamSpec      *pspec);
+
+GType
+gegl_param_int_get_type (void)
+{
+  static GType type = 0;
+
+  if (!type)
+    {
+      const GTypeInfo info =
+      {
+        sizeof (GParamSpecClass),
+        NULL, NULL,
+        (GClassInitFunc) gegl_param_int_class_init,
+        NULL, NULL,
+        sizeof (GeglParamSpecInt),
+        0,
+        (GInstanceInitFunc) gegl_param_int_init
+      };
+      type = g_type_register_static (G_TYPE_PARAM_INT,
+                                     "GeglParamint", &info, 0);
+    }
+  return type;
+}
+
+static void
+gegl_param_int_class_init (GParamSpecClass *klass)
+{
+  klass->value_type     = G_TYPE_INT;
+}
+
+static void
+gegl_param_int_init (GParamSpec *pspec)
+{
+  GParamSpecInt    *dpspec  = G_PARAM_SPEC_INT (pspec);
+  GeglParamSpecInt *gdpspec = GEGL_PARAM_SPEC_INT (pspec);
+  gdpspec->ui_minimum = dpspec->minimum;
+  gdpspec->ui_maximum = dpspec->maximum;
+}
+
+GParamSpec *
+gegl_param_spec_int (const gchar *name,
+                     const gchar *nick,
+                     const gchar *blurb,
+                     gint         minimum,
+                     gint         maximum,
+                     gint         default_value,
+                     gint         ui_minimum,
+                     gint         ui_maximum,
+                     GParamFlags  flags)
+{
+  GeglParamSpecInt *pspec;
+  GParamSpecInt *ispec;
+  
+
+  pspec = g_param_spec_internal (GEGL_TYPE_PARAM_INT,
+                                 name, nick, blurb, flags);
+  ispec = G_PARAM_SPEC_INT (pspec);
+
+  ispec->minimum = minimum;
+  ispec->maximum = maximum;
+  ispec->default_value = default_value;
+  pspec->ui_minimum = ui_minimum;
+  pspec->ui_maximum = ui_maximum;
+
+  return G_PARAM_SPEC (pspec);
+}
+
 /*
  * GEGL_TYPE_PARAM_STRING
  */
@@ -132,6 +272,7 @@ gegl_param_spec_string (const gchar *name,
   return G_PARAM_SPEC (sspec);
 }
 
+
 /*
  * GEGL_TYPE_PARAM_FILE_PATH
  */
diff --git a/gegl/property-types/gegl-paramspecs.h b/gegl/property-types/gegl-paramspecs.h
index ed3e87a..2de05bb 100644
--- a/gegl/property-types/gegl-paramspecs.h
+++ b/gegl/property-types/gegl-paramspecs.h
@@ -32,6 +32,77 @@ G_BEGIN_DECLS
  */
 #define GEGL_PARAM_NO_VALIDATE (1 << (6 + G_PARAM_USER_SHIFT))
 
+typedef struct _GeglParamSpecString GeglParamSpecString;
+typedef struct _GeglParamSpecDouble GeglParamSpecDouble;
+typedef struct _GeglParamSpecInt    GeglParamSpecInt;
+
+
+
+
+/*
+ * GEGL_TYPE_PARAM_DOUBLE
+ */
+
+#define GEGL_TYPE_PARAM_DOUBLE             (gegl_param_double_get_type ())
+#define GEGL_PARAM_SPEC_DOUBLE(pspec)      (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GEGL_TYPE_PARAM_DOUBLE, GeglParamSpecDouble))
+#define GEGL_IS_PARAM_SPEC_DOUBLE          (pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GEGL_TYPE_PARAM_DOUBLE))
+
+
+struct _GeglParamSpecDouble
+{
+  GParamSpecDouble parent_instance;
+  gdouble          ui_minimum; /* reasonable range to present to user */
+  gdouble          ui_maximum;
+  gdouble          ui_gamma;   /* a desired non-linear mapping or 1.0, useful
+                                  when the control the user needs is not a
+                                  linear mapping, like controlling brush-size
+                                  or gaussian blur radius - where more
+                                  detailed control of small values is needed
+                                  */
+};
+
+GType        gegl_param_double_get_type (void) G_GNUC_CONST;
+
+GParamSpec * gegl_param_spec_double (const gchar *name,
+                                     const gchar *nick,
+                                     const gchar *blurb,
+                                     gdouble      minimum,
+                                     gdouble      maximum,
+                                     gdouble      default_value,
+                                     gdouble      ui_minimum,
+                                     gdouble      ui_maximum,
+                                     gdouble      ui_gamma,
+                                     GParamFlags  flags);
+
+
+/*
+ * GEGL_TYPE_PARAM_INT
+ */
+
+#define GEGL_TYPE_PARAM_INT             (gegl_param_int_get_type ())
+#define GEGL_PARAM_SPEC_INT(pspec)      (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GEGL_TYPE_PARAM_INT, GeglParamSpecInt))
+#define GEGL_IS_PARAM_SPEC_INT          (pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GEGL_TYPE_PARAM_INT))
+
+
+struct _GeglParamSpecInt
+{
+  GParamSpecInt parent_instance;
+  gint          ui_minimum; /* reasonable range to present to user */
+  gint          ui_maximum;
+};
+
+GType        gegl_param_int_get_type (void) G_GNUC_CONST;
+
+GParamSpec * gegl_param_spec_int (const gchar *name,
+                                  const gchar *nick,
+                                  const gchar *blurb,
+                                  gint         minimum,
+                                  gint         maximum,
+                                  gint         default_value,
+                                  gint         ui_minimum,
+                                  gint         ui_maximum,
+                                  GParamFlags  flags);
+
 
 /*
  * GEGL_TYPE_PARAM_STRING



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