[gimp] pdb: add dynamics accessors to the context procedures



commit 01344f811da0d6545d87a74f70648b8e7ced0609
Author: Michael Natterer <mitch gimp org>
Date:   Mon Oct 31 21:07:08 2011 +0100

    pdb: add dynamics accessors to the context procedures

 app/pdb/context-cmds.c       |  103 ++++++++++++++++++++++++++++++++++++++++++
 app/pdb/gimppdb-utils.c      |   35 ++++++++++++++
 app/pdb/gimppdb-utils.h      |    4 ++
 app/pdb/internal-procs.c     |    2 +-
 libgimp/gimp.def             |    2 +
 libgimp/gimpcontext_pdb.c    |   68 +++++++++++++++++++++++++++
 libgimp/gimpcontext_pdb.h    |    2 +
 tools/pdbgen/pdb/context.pdb |   64 ++++++++++++++++++++++++++
 8 files changed, 279 insertions(+), 1 deletions(-)
---
diff --git a/app/pdb/context-cmds.c b/app/pdb/context-cmds.c
index cff909f..9e8777b 100644
--- a/app/pdb/context-cmds.c
+++ b/app/pdb/context-cmds.c
@@ -424,6 +424,61 @@ context_set_brush_invoker (GimpProcedure      *procedure,
 }
 
 static GValueArray *
+context_get_dynamics_invoker (GimpProcedure      *procedure,
+                              Gimp               *gimp,
+                              GimpContext        *context,
+                              GimpProgress       *progress,
+                              const GValueArray  *args,
+                              GError            **error)
+{
+  gboolean success = TRUE;
+  GValueArray *return_vals;
+  gchar *name = NULL;
+
+  GimpDynamics *dynamics = gimp_context_get_dynamics (context);
+
+  if (dynamics)
+    name = g_strdup (gimp_object_get_name (dynamics));
+  else
+    success = FALSE;
+
+  return_vals = gimp_procedure_get_return_values (procedure, success,
+                                                  error ? *error : NULL);
+
+  if (success)
+    g_value_take_string (&return_vals->values[1], name);
+
+  return return_vals;
+}
+
+static GValueArray *
+context_set_dynamics_invoker (GimpProcedure      *procedure,
+                              Gimp               *gimp,
+                              GimpContext        *context,
+                              GimpProgress       *progress,
+                              const GValueArray  *args,
+                              GError            **error)
+{
+  gboolean success = TRUE;
+  const gchar *name;
+
+  name = g_value_get_string (&args->values[0]);
+
+  if (success)
+    {
+      GimpDynamics *dynamics = gimp_pdb_get_dynamics (gimp, name, FALSE, error);
+
+      if (dynamics)
+        gimp_context_set_dynamics (context, dynamics);
+      else
+        success = FALSE;
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
+static GValueArray *
 context_get_pattern_invoker (GimpProcedure      *procedure,
                              Gimp               *gimp,
                              GimpContext        *context,
@@ -1599,6 +1654,54 @@ register_context_procs (GimpPDB *pdb)
   g_object_unref (procedure);
 
   /*
+   * gimp-context-get-dynamics
+   */
+  procedure = gimp_procedure_new (context_get_dynamics_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-context-get-dynamics");
+  gimp_procedure_set_static_strings (procedure,
+                                     "gimp-context-get-dynamics",
+                                     "Retrieve the currently active paint dynamics.",
+                                     "This procedure returns the name of the currently active paint dynamics. All paint operations and stroke operations use this paint dynamics to control the application of paint to the image.",
+                                     "Michael Natterer <mitch gimp org>",
+                                     "Michael Natterer",
+                                     "2011",
+                                     NULL);
+  gimp_procedure_add_return_value (procedure,
+                                   gimp_param_spec_string ("name",
+                                                           "name",
+                                                           "The name of the active paint dynamics",
+                                                           FALSE, FALSE, FALSE,
+                                                           NULL,
+                                                           GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
+   * gimp-context-set-dynamics
+   */
+  procedure = gimp_procedure_new (context_set_dynamics_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-context-set-dynamics");
+  gimp_procedure_set_static_strings (procedure,
+                                     "gimp-context-set-dynamics",
+                                     "Set the specified paint dynamics as the active paint dynamics.",
+                                     "This procedure allows the active paint dynamics to be set by specifying its name. The name is simply a string which corresponds to one of the names of the installed paint dynamics. If there is no matching paint dynamics found, this procedure will return an error. Otherwise, the specified paint dynamics becomes active and will be used in all subsequent paint operations.",
+                                     "Michael Natterer <mitch gimp org>",
+                                     "Michael Natterer",
+                                     "2011",
+                                     NULL);
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_string ("name",
+                                                       "name",
+                                                       "The name of the paint dynamics",
+                                                       FALSE, FALSE, TRUE,
+                                                       NULL,
+                                                       GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
    * gimp-context-get-pattern
    */
   procedure = gimp_procedure_new (context_get_pattern_invoker);
diff --git a/app/pdb/gimppdb-utils.c b/app/pdb/gimppdb-utils.c
index 1f87938..ea7056f 100644
--- a/app/pdb/gimppdb-utils.c
+++ b/app/pdb/gimppdb-utils.c
@@ -117,6 +117,41 @@ gimp_pdb_get_generated_brush (Gimp         *gimp,
   return brush;
 }
 
+GimpDynamics *
+gimp_pdb_get_dynamics (Gimp         *gimp,
+                       const gchar  *name,
+                       gboolean      writable,
+                       GError      **error)
+{
+  GimpDynamics *dynamics;
+
+  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
+  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+  if (! name || ! strlen (name))
+    {
+      g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
+			   _("Invalid empty paint dynamics name"));
+      return NULL;
+    }
+
+  dynamics = (GimpDynamics *) gimp_pdb_get_data_factory_item (gimp->dynamics_factory, name);
+
+  if (! dynamics)
+    {
+      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
+                   _("Paint dynamics '%s' not found"), name);
+    }
+  else if (writable && ! gimp_data_is_writable (GIMP_DATA (dynamics)))
+    {
+      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
+                   _("Paint dynamics '%s' is not editable"), name);
+      return NULL;
+    }
+
+  return dynamics;
+}
+
 GimpPattern *
 gimp_pdb_get_pattern (Gimp         *gimp,
                       const gchar  *name,
diff --git a/app/pdb/gimppdb-utils.h b/app/pdb/gimppdb-utils.h
index d25a23a..1fc7370 100644
--- a/app/pdb/gimppdb-utils.h
+++ b/app/pdb/gimppdb-utils.h
@@ -27,6 +27,10 @@ GimpBrush     * gimp_pdb_get_generated_brush    (Gimp               *gimp,
                                                  const gchar        *name,
                                                  gboolean            writable,
                                                  GError            **error);
+GimpDynamics  * gimp_pdb_get_dynamics           (Gimp               *gimp,
+                                                 const gchar        *name,
+                                                 gboolean            writable,
+                                                 GError            **error);
 GimpPattern   * gimp_pdb_get_pattern            (Gimp               *gimp,
                                                  const gchar        *name,
                                                  GError            **error);
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 97edc7b..ec3a289 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 636 procedures registered total */
+/* 638 procedures registered total */
 
 void
 internal_procs_init (GimpPDB *pdb)
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index 260c3c3..3129452 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -72,6 +72,7 @@ EXPORTS
 	gimp_context_get_antialias
 	gimp_context_get_background
 	gimp_context_get_brush
+	gimp_context_get_dynamics
 	gimp_context_get_feather
 	gimp_context_get_feather_radius
 	gimp_context_get_font
@@ -99,6 +100,7 @@ EXPORTS
 	gimp_context_set_brush
 	gimp_context_set_default_colors
 	gimp_context_set_defaults
+	gimp_context_set_dynamics
 	gimp_context_set_feather
 	gimp_context_set_feather_radius
 	gimp_context_set_font
diff --git a/libgimp/gimpcontext_pdb.c b/libgimp/gimpcontext_pdb.c
index efb018b..fc64d30 100644
--- a/libgimp/gimpcontext_pdb.c
+++ b/libgimp/gimpcontext_pdb.c
@@ -635,6 +635,74 @@ gimp_context_set_brush (const gchar *name)
 }
 
 /**
+ * gimp_context_get_dynamics:
+ *
+ * Retrieve the currently active paint dynamics.
+ *
+ * This procedure returns the name of the currently active paint
+ * dynamics. All paint operations and stroke operations use this paint
+ * dynamics to control the application of paint to the image.
+ *
+ * Returns: The name of the active paint dynamics.
+ *
+ * Since: GIMP 2.8
+ **/
+gchar *
+gimp_context_get_dynamics (void)
+{
+  GimpParam *return_vals;
+  gint nreturn_vals;
+  gchar *name = NULL;
+
+  return_vals = gimp_run_procedure ("gimp-context-get-dynamics",
+                                    &nreturn_vals,
+                                    GIMP_PDB_END);
+
+  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
+    name = g_strdup (return_vals[1].data.d_string);
+
+  gimp_destroy_params (return_vals, nreturn_vals);
+
+  return name;
+}
+
+/**
+ * gimp_context_set_dynamics:
+ * @name: The name of the paint dynamics.
+ *
+ * Set the specified paint dynamics as the active paint dynamics.
+ *
+ * This procedure allows the active paint dynamics to be set by
+ * specifying its name. The name is simply a string which corresponds
+ * to one of the names of the installed paint dynamics. If there is no
+ * matching paint dynamics found, this procedure will return an error.
+ * Otherwise, the specified paint dynamics becomes active and will be
+ * used in all subsequent paint operations.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: GIMP 2.8
+ **/
+gboolean
+gimp_context_set_dynamics (const gchar *name)
+{
+  GimpParam *return_vals;
+  gint nreturn_vals;
+  gboolean success = TRUE;
+
+  return_vals = gimp_run_procedure ("gimp-context-set-dynamics",
+                                    &nreturn_vals,
+                                    GIMP_PDB_STRING, name,
+                                    GIMP_PDB_END);
+
+  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
+
+  gimp_destroy_params (return_vals, nreturn_vals);
+
+  return success;
+}
+
+/**
  * gimp_context_get_pattern:
  *
  * Retrieve the currently active pattern.
diff --git a/libgimp/gimpcontext_pdb.h b/libgimp/gimpcontext_pdb.h
index 2eff163..c84f584 100644
--- a/libgimp/gimpcontext_pdb.h
+++ b/libgimp/gimpcontext_pdb.h
@@ -51,6 +51,8 @@ GimpLayerModeEffects   gimp_context_get_paint_mode           (void);
 gboolean               gimp_context_set_paint_mode           (GimpLayerModeEffects      paint_mode);
 gchar*                 gimp_context_get_brush                (void);
 gboolean               gimp_context_set_brush                (const gchar              *name);
+gchar*                 gimp_context_get_dynamics             (void);
+gboolean               gimp_context_set_dynamics             (const gchar              *name);
 gchar*                 gimp_context_get_pattern              (void);
 gboolean               gimp_context_set_pattern              (const gchar              *name);
 gchar*                 gimp_context_get_gradient             (void);
diff --git a/tools/pdbgen/pdb/context.pdb b/tools/pdbgen/pdb/context.pdb
index 4c2e2a1..9c61197 100644
--- a/tools/pdbgen/pdb/context.pdb
+++ b/tools/pdbgen/pdb/context.pdb
@@ -487,6 +487,69 @@ CODE
     );
 }
 
+sub context_get_dynamics {
+    $blurb = 'Retrieve the currently active paint dynamics.';
+
+    $help = <<'HELP';
+This procedure returns the name of the currently active paint
+dynamics.  All paint operations and stroke operations use this paint
+dynamics to control the application of paint to the image.
+HELP
+
+    &mitch_pdb_misc('2011', '2.8');
+
+    @outargs = (
+	{ name  => 'name', type  => 'string',
+	  desc  => 'The name of the active paint dynamics' }
+    );
+
+    %invoke = (
+	code => <<'CODE'
+{
+  GimpDynamics *dynamics = gimp_context_get_dynamics (context);
+
+  if (dynamics)
+    name = g_strdup (gimp_object_get_name (dynamics));
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
+sub context_set_dynamics {
+    $blurb = 'Set the specified paint dynamics as the active paint dynamics.';
+
+    $help = <<'HELP';
+This procedure allows the active paint dynamics to be set by
+specifying its name.  The name is simply a string which corresponds to
+one of the names of the installed paint dynamics. If there is no
+matching paint dynamics found, this procedure will return an error.
+Otherwise, the specified paint dynamics becomes active and will be
+used in all subsequent paint operations.
+HELP
+
+    &mitch_pdb_misc('2011', '2.8');
+
+    @inargs = (
+        { name => 'name', type => 'string', non_empty => 1,
+          desc => 'The name of the paint dynamics' }
+    );
+
+    %invoke = (
+	code => <<'CODE'
+{
+  GimpDynamics *dynamics = gimp_pdb_get_dynamics (gimp, name, FALSE, error);
+
+  if (dynamics)
+    gimp_context_set_dynamics (context, dynamics);
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
 sub context_get_pattern {
     $blurb = 'Retrieve the currently active pattern.';
 
@@ -1452,6 +1515,7 @@ CODE
             context_get_opacity context_set_opacity
             context_get_paint_mode context_set_paint_mode
             context_get_brush context_set_brush
+            context_get_dynamics context_set_dynamics
             context_get_pattern context_set_pattern
             context_get_gradient context_set_gradient
             context_get_palette context_set_palette



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