[gimp] pdb: pdb definitions for spacing in tool options



commit 6f4fb84645c796e4bb607aa8520746d3a04d7fbc
Author: Alexia Death <alexiadeath gmail com>
Date:   Thu Nov 13 14:47:32 2014 +0200

    pdb: pdb definitions for spacing in tool options

 app/pdb/context-cmds.c       |  160 ++++++++++++++++++++++++++++++++++++++++++
 app/pdb/internal-procs.c     |    2 +-
 libgimp/gimpcontext_pdb.c    |   93 ++++++++++++++++++++++++
 libgimp/gimpcontext_pdb.h    |    3 +
 tools/pdbgen/pdb/context.pdb |   97 +++++++++++++++++++++++++
 tools/pdbgen/stddefs.pdb     |    4 +
 6 files changed, 358 insertions(+), 1 deletions(-)
---
diff --git a/app/pdb/context-cmds.c b/app/pdb/context-cmds.c
index 4fd84cb..c2b4687 100644
--- a/app/pdb/context-cmds.c
+++ b/app/pdb/context-cmds.c
@@ -656,6 +656,103 @@ context_set_brush_angle_invoker (GimpProcedure         *procedure,
 }
 
 static GimpValueArray *
+context_get_brush_spacing_invoker (GimpProcedure         *procedure,
+                                   Gimp                  *gimp,
+                                   GimpContext           *context,
+                                   GimpProgress          *progress,
+                                   const GimpValueArray  *args,
+                                   GError               **error)
+{
+  gboolean success = TRUE;
+  GimpValueArray *return_vals;
+  gdouble spacing = 0.0;
+
+  /* all options should have the same value, so pick a random one */
+  GimpPaintOptions *options =
+    gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context),
+                                        "gimp-paintbrush");
+
+  if (options)
+    g_object_get (options,
+                  "brush-spacing", &spacing,
+                   NULL);
+  else
+    success = FALSE;
+
+  return_vals = gimp_procedure_get_return_values (procedure, success,
+                                                  error ? *error : NULL);
+
+  if (success)
+    g_value_set_double (gimp_value_array_index (return_vals, 1), spacing);
+
+  return return_vals;
+}
+
+static GimpValueArray *
+context_set_brush_spacing_invoker (GimpProcedure         *procedure,
+                                   Gimp                  *gimp,
+                                   GimpContext           *context,
+                                   GimpProgress          *progress,
+                                   const GimpValueArray  *args,
+                                   GError               **error)
+{
+  gboolean success = TRUE;
+  gdouble spacing;
+
+  spacing = g_value_get_double (gimp_value_array_index (args, 0));
+
+  if (success)
+    {
+      GList *options;
+      GList *list;
+
+      options = gimp_pdb_context_get_brush_options (GIMP_PDB_CONTEXT (context));
+
+      for (list = options; list; list = g_list_next (list))
+        g_object_set (list->data,
+                      "brush-spacing", (gdouble) spacing,
+                       NULL);
+
+      g_list_free (options);
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
+static GimpValueArray *
+context_set_brush_default_spacing_invoker (GimpProcedure         *procedure,
+                                           Gimp                  *gimp,
+                                           GimpContext           *context,
+                                           GimpProgress          *progress,
+                                           const GimpValueArray  *args,
+                                           GError               **error)
+{
+  gboolean success = TRUE;
+  GimpBrush *brush = gimp_context_get_brush (context);
+
+  if (brush)
+    {
+      GList *options;
+      GList *list;
+
+      options = gimp_pdb_context_get_brush_options (GIMP_PDB_CONTEXT (context));
+
+      for (list = options; list; list = g_list_next (list))
+        gimp_paint_options_set_default_brush_spacing (list->data, brush);
+
+      g_list_free (options);
+    }
+  else
+    {
+      success = FALSE;
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
+static GimpValueArray *
 context_get_dynamics_invoker (GimpProcedure         *procedure,
                               Gimp                  *gimp,
                               GimpContext           *context,
@@ -2538,6 +2635,69 @@ register_context_procs (GimpPDB *pdb)
   g_object_unref (procedure);
 
   /*
+   * gimp-context-get-brush-spacing
+   */
+  procedure = gimp_procedure_new (context_get_brush_spacing_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-context-get-brush-spacing");
+  gimp_procedure_set_static_strings (procedure,
+                                     "gimp-context-get-brush-spacing",
+                                     "Get brush spacing as percent of size.",
+                                     "Get the brush spacing as percent of size for brush based paint tools.",
+                                     "Alexia Death",
+                                     "Alexia Death",
+                                     "2014",
+                                     NULL);
+  gimp_procedure_add_return_value (procedure,
+                                   g_param_spec_double ("spacing",
+                                                        "spacing",
+                                                        "brush spacing as percent of size",
+                                                        0, G_MAXDOUBLE, 0,
+                                                        GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
+   * gimp-context-set-brush-spacing
+   */
+  procedure = gimp_procedure_new (context_set_brush_spacing_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-context-set-brush-spacing");
+  gimp_procedure_set_static_strings (procedure,
+                                     "gimp-context-set-brush-spacing",
+                                     "Set brush spacing as percent of size.",
+                                     "Set the brush spacing as percent of size for brush based paint tools.",
+                                     "Alexia Death",
+                                     "Alexia Death",
+                                     "2014",
+                                     NULL);
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_double ("spacing",
+                                                    "spacing",
+                                                    "brush spacing as percent of size",
+                                                    0, G_MAXDOUBLE, 0,
+                                                    GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
+   * gimp-context-set-brush-default-spacing
+   */
+  procedure = gimp_procedure_new (context_set_brush_default_spacing_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-context-set-brush-default-spacing");
+  gimp_procedure_set_static_strings (procedure,
+                                     "gimp-context-set-brush-default-spacing",
+                                     "Set brush spacing to its default.",
+                                     "Set the brush spacing to the default for paintbrush, airbrush, or 
pencil tools.",
+                                     "Alexia Death",
+                                     "Alexia Death",
+                                     "2014",
+                                     NULL);
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
    * gimp-context-get-dynamics
    */
   procedure = gimp_procedure_new (context_get_dynamics_invoker);
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 872acab..97498a4 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 734 procedures registered total */
+/* 737 procedures registered total */
 
 void
 internal_procs_init (GimpPDB *pdb)
diff --git a/libgimp/gimpcontext_pdb.c b/libgimp/gimpcontext_pdb.c
index 3c866da..8c5e3a2 100644
--- a/libgimp/gimpcontext_pdb.c
+++ b/libgimp/gimpcontext_pdb.c
@@ -849,6 +849,99 @@ gimp_context_set_brush_angle (gdouble angle)
 }
 
 /**
+ * gimp_context_get_brush_spacing:
+ *
+ * Get brush spacing as percent of size.
+ *
+ * Get the brush spacing as percent of size for brush based paint
+ * tools.
+ *
+ * Returns: brush spacing as percent of size.
+ *
+ * Since: GIMP 2.9
+ **/
+gdouble
+gimp_context_get_brush_spacing (void)
+{
+  GimpParam *return_vals;
+  gint nreturn_vals;
+  gdouble spacing = 0.0;
+
+  return_vals = gimp_run_procedure ("gimp-context-get-brush-spacing",
+                                    &nreturn_vals,
+                                    GIMP_PDB_END);
+
+  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
+    spacing = return_vals[1].data.d_float;
+
+  gimp_destroy_params (return_vals, nreturn_vals);
+
+  return spacing;
+}
+
+/**
+ * gimp_context_set_brush_spacing:
+ * @spacing: brush spacing as percent of size.
+ *
+ * Set brush spacing as percent of size.
+ *
+ * Set the brush spacing as percent of size for brush based paint
+ * tools.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: GIMP 2.9
+ **/
+gboolean
+gimp_context_set_brush_spacing (gdouble spacing)
+{
+  GimpParam *return_vals;
+  gint nreturn_vals;
+  gboolean success = TRUE;
+
+  return_vals = gimp_run_procedure ("gimp-context-set-brush-spacing",
+                                    &nreturn_vals,
+                                    GIMP_PDB_FLOAT, spacing,
+                                    GIMP_PDB_END);
+
+  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
+
+  gimp_destroy_params (return_vals, nreturn_vals);
+
+  return success;
+}
+
+/**
+ * gimp_context_set_brush_default_spacing:
+ *
+ * Set brush spacing to its default.
+ *
+ * Set the brush spacing to the default for paintbrush, airbrush, or
+ * pencil tools.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: GIMP 2.9
+ **/
+gboolean
+gimp_context_set_brush_default_spacing (void)
+{
+  GimpParam *return_vals;
+  gint nreturn_vals;
+  gboolean success = TRUE;
+
+  return_vals = gimp_run_procedure ("gimp-context-set-brush-default-spacing",
+                                    &nreturn_vals,
+                                    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_dynamics:
  *
  * Retrieve the currently active paint dynamics.
diff --git a/libgimp/gimpcontext_pdb.h b/libgimp/gimpcontext_pdb.h
index 90a524b..ccbeba5 100644
--- a/libgimp/gimpcontext_pdb.h
+++ b/libgimp/gimpcontext_pdb.h
@@ -58,6 +58,9 @@ gdouble                gimp_context_get_brush_aspect_ratio    (void);
 gboolean               gimp_context_set_brush_aspect_ratio    (gdouble                   aspect);
 gdouble                gimp_context_get_brush_angle           (void);
 gboolean               gimp_context_set_brush_angle           (gdouble                   angle);
+gdouble                gimp_context_get_brush_spacing         (void);
+gboolean               gimp_context_set_brush_spacing         (gdouble                   spacing);
+gboolean               gimp_context_set_brush_default_spacing (void);
 gchar*                 gimp_context_get_dynamics              (void);
 gboolean               gimp_context_set_dynamics              (const gchar              *name);
 gchar*                 gimp_context_get_pattern               (void);
diff --git a/tools/pdbgen/pdb/context.pdb b/tools/pdbgen/pdb/context.pdb
index 0360e93..ecf2045 100644
--- a/tools/pdbgen/pdb/context.pdb
+++ b/tools/pdbgen/pdb/context.pdb
@@ -702,6 +702,101 @@ CODE
     );
 }
 
+sub context_get_brush_spacing {
+    $blurb = 'Get brush spacing as percent of size.';
+    $help = 'Get the brush spacing as percent of size for brush based paint tools.';
+
+    &adeath_pdb_misc('2014', '2.9');
+
+    @outargs = (
+        { name => "spacing", type => "0 < float",
+          desc => "brush spacing as percent of size" }
+    );
+
+    %invoke = (
+       code => <<'CODE'
+{
+  /* all options should have the same value, so pick a random one */
+  GimpPaintOptions *options =
+    gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context),
+                                        "gimp-paintbrush");
+
+  if (options)
+    g_object_get (options,
+                  "brush-spacing", &spacing,
+                   NULL);
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
+sub context_set_brush_spacing {
+    $blurb = 'Set brush spacing as percent of size.';
+    $help = 'Set the brush spacing as percent of size for brush based paint tools.';
+
+    &adeath_pdb_misc('2014', '2.9');
+
+    @inargs = (
+        { name => "spacing", type => "0 < float",
+          desc => "brush spacing as percent of size" }
+    );
+
+    %invoke = (
+       code => <<'CODE'
+{
+  GList *options;
+  GList *list;
+
+  options = gimp_pdb_context_get_brush_options (GIMP_PDB_CONTEXT (context));
+
+  for (list = options; list; list = g_list_next (list))
+    g_object_set (list->data,
+                  "brush-spacing", (gdouble) spacing,
+                   NULL);
+
+  g_list_free (options);
+}
+CODE
+    );
+}
+
+sub context_set_brush_default_spacing {
+    $blurb = 'Set brush spacing to its default.';
+    $help = <<'HELP';
+Set the brush spacing to the default  for
+paintbrush, airbrush, or pencil tools.
+HELP
+
+    &adeath_pdb_misc('2014', '2.9');
+
+    %invoke = (
+       code => <<'CODE'
+{
+  GimpBrush *brush = gimp_context_get_brush (context);
+
+  if (brush)
+    {
+      GList *options;
+      GList *list;
+
+      options = gimp_pdb_context_get_brush_options (GIMP_PDB_CONTEXT (context));
+
+      for (list = options; list; list = g_list_next (list))
+        gimp_paint_options_set_default_brush_spacing (list->data, brush);
+
+      g_list_free (options);
+    }
+  else
+    {
+      success = FALSE;
+    }
+}
+CODE
+    );
+}
+
 sub context_get_dynamics {
     $blurb = 'Retrieve the currently active paint dynamics.';
 
@@ -2188,6 +2283,8 @@ CODE
             context_set_brush_size context_set_brush_default_size
             context_get_brush_aspect_ratio context_set_brush_aspect_ratio
             context_get_brush_angle context_set_brush_angle
+            context_get_brush_spacing
+            context_set_brush_spacing context_set_brush_default_spacing
             context_get_dynamics context_set_dynamics
             context_get_pattern context_set_pattern
             context_get_gradient context_set_gradient
diff --git a/tools/pdbgen/stddefs.pdb b/tools/pdbgen/stddefs.pdb
index 2f79546..c73bb67 100644
--- a/tools/pdbgen/stddefs.pdb
+++ b/tools/pdbgen/stddefs.pdb
@@ -49,6 +49,10 @@ sub adrian_pdb_misc {
     contrib_pdb_misc('Adrian Likins', 'adrian gimp org', @_);
 }
 
+sub adeath_pdb_misc {
+    contrib_pdb_misc('Alexia Death', '', @_);
+}
+
 sub andy_pdb_misc {
     contrib_pdb_misc('Andy Thomas', '', @_);
 }


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