[gimp] pdb, libgimp: add gimp_context_set/get_mypaint_brush()



commit 80f713c9b8264a6800567d44029d06cab856c74f
Author: Michael Natterer <mitch gimp org>
Date:   Sat Jan 2 13:40:38 2016 +0100

    pdb, libgimp: add gimp_context_set/get_mypaint_brush()

 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    |   67 +++++++++++++++++++++++++++
 libgimp/gimpcontext_pdb.h    |    2 +
 tools/pdbgen/pdb/context.pdb |   62 +++++++++++++++++++++++++
 8 files changed, 276 insertions(+), 1 deletions(-)
---
diff --git a/app/pdb/context-cmds.c b/app/pdb/context-cmds.c
index e8af63e..59a558b 100644
--- a/app/pdb/context-cmds.c
+++ b/app/pdb/context-cmds.c
@@ -1397,6 +1397,61 @@ context_set_dynamics_invoker (GimpProcedure         *procedure,
 }
 
 static GimpValueArray *
+context_get_mypaint_brush_invoker (GimpProcedure         *procedure,
+                                   Gimp                  *gimp,
+                                   GimpContext           *context,
+                                   GimpProgress          *progress,
+                                   const GimpValueArray  *args,
+                                   GError               **error)
+{
+  gboolean success = TRUE;
+  GimpValueArray *return_vals;
+  gchar *name = NULL;
+
+  GimpMybrush *brush = gimp_context_get_mybrush (context);
+
+  if (brush)
+    name = g_strdup (gimp_object_get_name (brush));
+  else
+    success = FALSE;
+
+  return_vals = gimp_procedure_get_return_values (procedure, success,
+                                                  error ? *error : NULL);
+
+  if (success)
+    g_value_take_string (gimp_value_array_index (return_vals, 1), name);
+
+  return return_vals;
+}
+
+static GimpValueArray *
+context_set_mypaint_brush_invoker (GimpProcedure         *procedure,
+                                   Gimp                  *gimp,
+                                   GimpContext           *context,
+                                   GimpProgress          *progress,
+                                   const GimpValueArray  *args,
+                                   GError               **error)
+{
+  gboolean success = TRUE;
+  const gchar *name;
+
+  name = g_value_get_string (gimp_value_array_index (args, 0));
+
+  if (success)
+    {
+      GimpMybrush *brush = gimp_pdb_get_mybrush (gimp, name, FALSE, error);
+
+      if (brush)
+        gimp_context_set_mybrush (context, brush);
+      else
+        success = FALSE;
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
+static GimpValueArray *
 context_get_pattern_invoker (GimpProcedure         *procedure,
                              Gimp                  *gimp,
                              GimpContext           *context,
@@ -3841,6 +3896,54 @@ register_context_procs (GimpPDB *pdb)
   g_object_unref (procedure);
 
   /*
+   * gimp-context-get-mypaint-brush
+   */
+  procedure = gimp_procedure_new (context_get_mypaint_brush_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-context-get-mypaint-brush");
+  gimp_procedure_set_static_strings (procedure,
+                                     "gimp-context-get-mypaint-brush",
+                                     "Retrieve the currently active MyPaint brush.",
+                                     "This procedure returns the name of the currently active MyPaint 
brush.",
+                                     "Michael Natterer <mitch gimp org>",
+                                     "Michael Natterer",
+                                     "2016",
+                                     NULL);
+  gimp_procedure_add_return_value (procedure,
+                                   gimp_param_spec_string ("name",
+                                                           "name",
+                                                           "The name of the active MyPaint brush",
+                                                           FALSE, FALSE, FALSE,
+                                                           NULL,
+                                                           GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
+   * gimp-context-set-mypaint-brush
+   */
+  procedure = gimp_procedure_new (context_set_mypaint_brush_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-context-set-mypaint-brush");
+  gimp_procedure_set_static_strings (procedure,
+                                     "gimp-context-set-mypaint-brush",
+                                     "Set the specified MyPaint brush as the active MyPaint brush.",
+                                     "This procedure allows the active MyPaint brush to be set by specifying 
its name. The name is simply a string which corresponds to one of the names of the installed MyPaint brushes. 
If there is no matching MyPaint brush found, this procedure will return an error. Otherwise, the specified 
MyPaint brush becomes active and will be used in all subsequent MyPaint paint operations.",
+                                     "Michael Natterer <mitch gimp org>",
+                                     "Michael Natterer",
+                                     "2016",
+                                     NULL);
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_string ("name",
+                                                       "name",
+                                                       "The name of the MyPaint brush",
+                                                       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 b8d71d5..3d32b71 100644
--- a/app/pdb/gimppdb-utils.c
+++ b/app/pdb/gimppdb-utils.c
@@ -154,6 +154,41 @@ gimp_pdb_get_dynamics (Gimp         *gimp,
   return dynamics;
 }
 
+GimpMybrush *
+gimp_pdb_get_mybrush (Gimp         *gimp,
+                      const gchar  *name,
+                      gboolean      writable,
+                      GError      **error)
+{
+  GimpMybrush *brush;
+
+  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_ERROR_INVALID_ARGUMENT,
+                          _("Invalid empty MyPaint brush name"));
+      return NULL;
+    }
+
+  brush = (GimpMybrush *) gimp_pdb_get_data_factory_item (gimp->mybrush_factory, name);
+
+  if (! brush)
+    {
+      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
+                   _("MyPaint brush '%s' not found"), name);
+    }
+  else if (writable && ! gimp_data_is_writable (GIMP_DATA (brush)))
+    {
+      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
+                   _("MyPaint brush '%s' is not editable"), name);
+      return NULL;
+    }
+
+  return brush;
+}
+
 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 3d1dd4f..e5b3805 100644
--- a/app/pdb/gimppdb-utils.h
+++ b/app/pdb/gimppdb-utils.h
@@ -31,6 +31,10 @@ GimpDynamics  * gimp_pdb_get_dynamics           (Gimp               *gimp,
                                                  const gchar        *name,
                                                  gboolean            writable,
                                                  GError            **error);
+GimpMybrush   * gimp_pdb_get_mybrush            (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 d5ca2f7..b479a71 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 791 procedures registered total */
+/* 793 procedures registered total */
 
 void
 internal_procs_init (GimpPDB *pdb)
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index 5f49b68..be1fe1f 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -99,6 +99,7 @@ EXPORTS
        gimp_context_get_line_miter_limit
        gimp_context_get_line_width
        gimp_context_get_line_width_unit
+       gimp_context_get_mypaint_brush
        gimp_context_get_opacity
        gimp_context_get_paint_method
        gimp_context_get_paint_mode
@@ -152,6 +153,7 @@ EXPORTS
        gimp_context_set_line_miter_limit
        gimp_context_set_line_width
        gimp_context_set_line_width_unit
+       gimp_context_set_mypaint_brush
        gimp_context_set_opacity
        gimp_context_set_paint_method
        gimp_context_set_paint_mode
diff --git a/libgimp/gimpcontext_pdb.c b/libgimp/gimpcontext_pdb.c
index 51f1659..c70d7e8 100644
--- a/libgimp/gimpcontext_pdb.c
+++ b/libgimp/gimpcontext_pdb.c
@@ -1699,6 +1699,73 @@ gimp_context_set_dynamics (const gchar *name)
 }
 
 /**
+ * gimp_context_get_mypaint_brush:
+ *
+ * Retrieve the currently active MyPaint brush.
+ *
+ * This procedure returns the name of the currently active MyPaint
+ * brush.
+ *
+ * Returns: The name of the active MyPaint brush.
+ *
+ * Since: 2.10
+ **/
+gchar *
+gimp_context_get_mypaint_brush (void)
+{
+  GimpParam *return_vals;
+  gint nreturn_vals;
+  gchar *name = NULL;
+
+  return_vals = gimp_run_procedure ("gimp-context-get-mypaint-brush",
+                                    &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_mypaint_brush:
+ * @name: The name of the MyPaint brush.
+ *
+ * Set the specified MyPaint brush as the active MyPaint brush.
+ *
+ * This procedure allows the active MyPaint brush to be set by
+ * specifying its name. The name is simply a string which corresponds
+ * to one of the names of the installed MyPaint brushes. If there is no
+ * matching MyPaint brush found, this procedure will return an error.
+ * Otherwise, the specified MyPaint brush becomes active and will be
+ * used in all subsequent MyPaint paint operations.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 2.10
+ **/
+gboolean
+gimp_context_set_mypaint_brush (const gchar *name)
+{
+  GimpParam *return_vals;
+  gint nreturn_vals;
+  gboolean success = TRUE;
+
+  return_vals = gimp_run_procedure ("gimp-context-set-mypaint-brush",
+                                    &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 361379c..2bd21b5 100644
--- a/libgimp/gimpcontext_pdb.h
+++ b/libgimp/gimpcontext_pdb.h
@@ -86,6 +86,8 @@ gdouble                gimp_context_get_brush_force            (void);
 gboolean               gimp_context_set_brush_force            (gdouble                   force);
 gchar*                 gimp_context_get_dynamics               (void);
 gboolean               gimp_context_set_dynamics               (const gchar              *name);
+gchar*                 gimp_context_get_mypaint_brush          (void);
+gboolean               gimp_context_set_mypaint_brush          (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 31d4b7b..35f75d3 100644
--- a/tools/pdbgen/pdb/context.pdb
+++ b/tools/pdbgen/pdb/context.pdb
@@ -1507,6 +1507,67 @@ CODE
     );
 }
 
+sub context_get_mypaint_brush {
+    $blurb = 'Retrieve the currently active MyPaint brush.';
+
+    $help = <<'HELP';
+This procedure returns the name of the currently active MyPaint brush.
+HELP
+
+    &mitch_pdb_misc('2016', '2.10');
+
+    @outargs = (
+       { name  => 'name', type  => 'string',
+         desc  => 'The name of the active MyPaint brush' }
+    );
+
+    %invoke = (
+       code => <<'CODE'
+{
+  GimpMybrush *brush = gimp_context_get_mybrush (context);
+
+  if (brush)
+    name = g_strdup (gimp_object_get_name (brush));
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
+sub context_set_mypaint_brush {
+    $blurb = 'Set the specified MyPaint brush as the active MyPaint brush.';
+
+    $help = <<'HELP';
+This procedure allows the active MyPaint brush to be set by
+specifying its name.  The name is simply a string which corresponds to
+one of the names of the installed MyPaint brushes. If there is no
+matching MyPaint brush found, this procedure will return an error.
+Otherwise, the specified MyPaint brush becomes active and will be
+used in all subsequent MyPaint paint operations.
+HELP
+
+    &mitch_pdb_misc('2016', '2.10');
+
+    @inargs = (
+        { name => 'name', type => 'string', non_empty => 1,
+          desc => 'The name of the MyPaint brush' }
+    );
+
+    %invoke = (
+       code => <<'CODE'
+{
+  GimpMybrush *brush = gimp_pdb_get_mybrush (gimp, name, FALSE, error);
+
+  if (brush)
+    gimp_context_set_mybrush (context, brush);
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
 sub context_get_pattern {
     $blurb = 'Retrieve the currently active pattern.';
 
@@ -2947,6 +3008,7 @@ CODE
             context_get_brush_force
             context_set_brush_force
             context_get_dynamics context_set_dynamics
+            context_get_mypaint_brush context_set_mypaint_brush
             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]